raspberrypi.patch 3.0 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572
  1. diff -Nur linux-3.15/arch/arm/configs/bcmrpi_cutdown_defconfig linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig
  2. --- linux-3.15/arch/arm/configs/bcmrpi_cutdown_defconfig 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-rpi/arch/arm/configs/bcmrpi_cutdown_defconfig 2014-06-11 21:03:19.000000000 +0200
  4. @@ -0,0 +1,503 @@
  5. +CONFIG_EXPERIMENTAL=y
  6. +# CONFIG_LOCALVERSION_AUTO is not set
  7. +CONFIG_SYSVIPC=y
  8. +CONFIG_POSIX_MQUEUE=y
  9. +CONFIG_IKCONFIG=y
  10. +CONFIG_IKCONFIG_PROC=y
  11. +# CONFIG_UID16 is not set
  12. +# CONFIG_KALLSYMS is not set
  13. +CONFIG_EMBEDDED=y
  14. +# CONFIG_VM_EVENT_COUNTERS is not set
  15. +# CONFIG_COMPAT_BRK is not set
  16. +CONFIG_SLAB=y
  17. +CONFIG_MODULES=y
  18. +CONFIG_MODULE_UNLOAD=y
  19. +CONFIG_MODVERSIONS=y
  20. +CONFIG_MODULE_SRCVERSION_ALL=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_ARCH_BCM2708=y
  23. +CONFIG_NO_HZ=y
  24. +CONFIG_HIGH_RES_TIMERS=y
  25. +CONFIG_AEABI=y
  26. +CONFIG_ZBOOT_ROM_TEXT=0x0
  27. +CONFIG_ZBOOT_ROM_BSS=0x0
  28. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  29. +CONFIG_CPU_IDLE=y
  30. +CONFIG_VFP=y
  31. +CONFIG_BINFMT_MISC=m
  32. +CONFIG_NET=y
  33. +CONFIG_PACKET=y
  34. +CONFIG_UNIX=y
  35. +CONFIG_XFRM_USER=y
  36. +CONFIG_NET_KEY=m
  37. +CONFIG_INET=y
  38. +CONFIG_IP_MULTICAST=y
  39. +CONFIG_IP_PNP=y
  40. +CONFIG_IP_PNP_DHCP=y
  41. +CONFIG_IP_PNP_RARP=y
  42. +CONFIG_SYN_COOKIES=y
  43. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  44. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  45. +# CONFIG_INET_XFRM_MODE_BEET is not set
  46. +# CONFIG_INET_LRO is not set
  47. +# CONFIG_INET_DIAG is not set
  48. +# CONFIG_IPV6 is not set
  49. +CONFIG_NET_PKTGEN=m
  50. +CONFIG_IRDA=m
  51. +CONFIG_IRLAN=m
  52. +CONFIG_IRCOMM=m
  53. +CONFIG_IRDA_ULTRA=y
  54. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  55. +CONFIG_IRDA_FAST_RR=y
  56. +CONFIG_IRTTY_SIR=m
  57. +CONFIG_KINGSUN_DONGLE=m
  58. +CONFIG_KSDAZZLE_DONGLE=m
  59. +CONFIG_KS959_DONGLE=m
  60. +CONFIG_USB_IRDA=m
  61. +CONFIG_SIGMATEL_FIR=m
  62. +CONFIG_MCS_FIR=m
  63. +CONFIG_BT=m
  64. +CONFIG_BT_L2CAP=y
  65. +CONFIG_BT_SCO=y
  66. +CONFIG_BT_RFCOMM=m
  67. +CONFIG_BT_RFCOMM_TTY=y
  68. +CONFIG_BT_BNEP=m
  69. +CONFIG_BT_BNEP_MC_FILTER=y
  70. +CONFIG_BT_BNEP_PROTO_FILTER=y
  71. +CONFIG_BT_HIDP=m
  72. +CONFIG_BT_HCIBTUSB=m
  73. +CONFIG_BT_HCIBCM203X=m
  74. +CONFIG_BT_HCIBPA10X=m
  75. +CONFIG_BT_HCIBFUSB=m
  76. +CONFIG_BT_HCIVHCI=m
  77. +CONFIG_BT_MRVL=m
  78. +CONFIG_BT_MRVL_SDIO=m
  79. +CONFIG_BT_ATH3K=m
  80. +CONFIG_CFG80211=m
  81. +CONFIG_MAC80211=m
  82. +CONFIG_MAC80211_RC_PID=y
  83. +CONFIG_MAC80211_MESH=y
  84. +CONFIG_WIMAX=m
  85. +CONFIG_NET_9P=m
  86. +CONFIG_NFC=m
  87. +CONFIG_NFC_PN533=m
  88. +CONFIG_DEVTMPFS=y
  89. +CONFIG_BLK_DEV_LOOP=y
  90. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  91. +CONFIG_BLK_DEV_NBD=m
  92. +CONFIG_BLK_DEV_RAM=y
  93. +CONFIG_CDROM_PKTCDVD=m
  94. +CONFIG_MISC_DEVICES=y
  95. +CONFIG_SCSI=y
  96. +# CONFIG_SCSI_PROC_FS is not set
  97. +CONFIG_BLK_DEV_SD=m
  98. +CONFIG_BLK_DEV_SR=m
  99. +CONFIG_SCSI_MULTI_LUN=y
  100. +# CONFIG_SCSI_LOWLEVEL is not set
  101. +CONFIG_NETDEVICES=y
  102. +CONFIG_TUN=m
  103. +CONFIG_PHYLIB=m
  104. +CONFIG_MDIO_BITBANG=m
  105. +CONFIG_NET_ETHERNET=y
  106. +# CONFIG_NETDEV_1000 is not set
  107. +# CONFIG_NETDEV_10000 is not set
  108. +CONFIG_LIBERTAS_THINFIRM=m
  109. +CONFIG_LIBERTAS_THINFIRM_USB=m
  110. +CONFIG_AT76C50X_USB=m
  111. +CONFIG_USB_ZD1201=m
  112. +CONFIG_USB_NET_RNDIS_WLAN=m
  113. +CONFIG_RTL8187=m
  114. +CONFIG_MAC80211_HWSIM=m
  115. +CONFIG_ATH_COMMON=m
  116. +CONFIG_ATH9K=m
  117. +CONFIG_ATH9K_HTC=m
  118. +CONFIG_CARL9170=m
  119. +CONFIG_B43=m
  120. +CONFIG_B43LEGACY=m
  121. +CONFIG_HOSTAP=m
  122. +CONFIG_IWM=m
  123. +CONFIG_LIBERTAS=m
  124. +CONFIG_LIBERTAS_USB=m
  125. +CONFIG_LIBERTAS_SDIO=m
  126. +CONFIG_P54_COMMON=m
  127. +CONFIG_P54_USB=m
  128. +CONFIG_RT2X00=m
  129. +CONFIG_RT2500USB=m
  130. +CONFIG_RT73USB=m
  131. +CONFIG_RT2800USB=m
  132. +CONFIG_RT2800USB_RT53XX=y
  133. +CONFIG_RTL8192CU=m
  134. +CONFIG_WL1251=m
  135. +CONFIG_WL12XX_MENU=m
  136. +CONFIG_ZD1211RW=m
  137. +CONFIG_MWIFIEX=m
  138. +CONFIG_MWIFIEX_SDIO=m
  139. +CONFIG_WIMAX_I2400M_USB=m
  140. +CONFIG_USB_CATC=m
  141. +CONFIG_USB_KAWETH=m
  142. +CONFIG_USB_PEGASUS=m
  143. +CONFIG_USB_RTL8150=m
  144. +CONFIG_USB_USBNET=y
  145. +CONFIG_USB_NET_AX8817X=m
  146. +CONFIG_USB_NET_CDCETHER=m
  147. +CONFIG_USB_NET_CDC_EEM=m
  148. +CONFIG_USB_NET_DM9601=m
  149. +CONFIG_USB_NET_SMSC75XX=m
  150. +CONFIG_USB_NET_SMSC95XX=y
  151. +CONFIG_USB_NET_GL620A=m
  152. +CONFIG_USB_NET_NET1080=m
  153. +CONFIG_USB_NET_PLUSB=m
  154. +CONFIG_USB_NET_MCS7830=m
  155. +CONFIG_USB_NET_CDC_SUBSET=m
  156. +CONFIG_USB_ALI_M5632=y
  157. +CONFIG_USB_AN2720=y
  158. +CONFIG_USB_KC2190=y
  159. +# CONFIG_USB_NET_ZAURUS is not set
  160. +CONFIG_USB_NET_CX82310_ETH=m
  161. +CONFIG_USB_NET_KALMIA=m
  162. +CONFIG_USB_NET_INT51X1=m
  163. +CONFIG_USB_IPHETH=m
  164. +CONFIG_USB_SIERRA_NET=m
  165. +CONFIG_USB_VL600=m
  166. +CONFIG_PPP=m
  167. +CONFIG_PPP_ASYNC=m
  168. +CONFIG_PPP_SYNC_TTY=m
  169. +CONFIG_PPP_DEFLATE=m
  170. +CONFIG_PPP_BSDCOMP=m
  171. +CONFIG_SLIP=m
  172. +CONFIG_SLIP_COMPRESSED=y
  173. +CONFIG_NETCONSOLE=m
  174. +CONFIG_INPUT_POLLDEV=m
  175. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  176. +CONFIG_INPUT_JOYDEV=m
  177. +CONFIG_INPUT_EVDEV=m
  178. +# CONFIG_INPUT_KEYBOARD is not set
  179. +# CONFIG_INPUT_MOUSE is not set
  180. +CONFIG_INPUT_MISC=y
  181. +CONFIG_INPUT_AD714X=m
  182. +CONFIG_INPUT_ATI_REMOTE=m
  183. +CONFIG_INPUT_ATI_REMOTE2=m
  184. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  185. +CONFIG_INPUT_POWERMATE=m
  186. +CONFIG_INPUT_YEALINK=m
  187. +CONFIG_INPUT_CM109=m
  188. +CONFIG_INPUT_UINPUT=m
  189. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  190. +CONFIG_INPUT_ADXL34X=m
  191. +CONFIG_INPUT_CMA3000=m
  192. +CONFIG_SERIO=m
  193. +CONFIG_SERIO_RAW=m
  194. +CONFIG_GAMEPORT=m
  195. +CONFIG_GAMEPORT_NS558=m
  196. +CONFIG_GAMEPORT_L4=m
  197. +CONFIG_VT_HW_CONSOLE_BINDING=y
  198. +# CONFIG_LEGACY_PTYS is not set
  199. +# CONFIG_DEVKMEM is not set
  200. +CONFIG_SERIAL_AMBA_PL011=y
  201. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  202. +# CONFIG_HW_RANDOM is not set
  203. +CONFIG_RAW_DRIVER=y
  204. +CONFIG_GPIO_SYSFS=y
  205. +# CONFIG_HWMON is not set
  206. +CONFIG_WATCHDOG=y
  207. +CONFIG_BCM2708_WDT=m
  208. +# CONFIG_MFD_SUPPORT is not set
  209. +CONFIG_FB=y
  210. +CONFIG_FB_BCM2708=y
  211. +CONFIG_FRAMEBUFFER_CONSOLE=y
  212. +CONFIG_LOGO=y
  213. +# CONFIG_LOGO_LINUX_MONO is not set
  214. +# CONFIG_LOGO_LINUX_VGA16 is not set
  215. +CONFIG_SOUND=y
  216. +CONFIG_SND=m
  217. +CONFIG_SND_SEQUENCER=m
  218. +CONFIG_SND_SEQ_DUMMY=m
  219. +CONFIG_SND_MIXER_OSS=m
  220. +CONFIG_SND_PCM_OSS=m
  221. +CONFIG_SND_SEQUENCER_OSS=y
  222. +CONFIG_SND_HRTIMER=m
  223. +CONFIG_SND_DUMMY=m
  224. +CONFIG_SND_ALOOP=m
  225. +CONFIG_SND_VIRMIDI=m
  226. +CONFIG_SND_MTPAV=m
  227. +CONFIG_SND_SERIAL_U16550=m
  228. +CONFIG_SND_MPU401=m
  229. +CONFIG_SND_BCM2835=m
  230. +CONFIG_SND_USB_AUDIO=m
  231. +CONFIG_SND_USB_UA101=m
  232. +CONFIG_SND_USB_CAIAQ=m
  233. +CONFIG_SND_USB_6FIRE=m
  234. +CONFIG_SOUND_PRIME=m
  235. +CONFIG_HID_PID=y
  236. +CONFIG_USB_HIDDEV=y
  237. +CONFIG_HID_A4TECH=m
  238. +CONFIG_HID_ACRUX=m
  239. +CONFIG_HID_APPLE=m
  240. +CONFIG_HID_BELKIN=m
  241. +CONFIG_HID_CHERRY=m
  242. +CONFIG_HID_CHICONY=m
  243. +CONFIG_HID_CYPRESS=m
  244. +CONFIG_HID_DRAGONRISE=m
  245. +CONFIG_HID_EMS_FF=m
  246. +CONFIG_HID_ELECOM=m
  247. +CONFIG_HID_EZKEY=m
  248. +CONFIG_HID_HOLTEK=m
  249. +CONFIG_HID_KEYTOUCH=m
  250. +CONFIG_HID_KYE=m
  251. +CONFIG_HID_UCLOGIC=m
  252. +CONFIG_HID_WALTOP=m
  253. +CONFIG_HID_GYRATION=m
  254. +CONFIG_HID_TWINHAN=m
  255. +CONFIG_HID_KENSINGTON=m
  256. +CONFIG_HID_LCPOWER=m
  257. +CONFIG_HID_LOGITECH=m
  258. +CONFIG_HID_MAGICMOUSE=m
  259. +CONFIG_HID_MICROSOFT=m
  260. +CONFIG_HID_MONTEREY=m
  261. +CONFIG_HID_MULTITOUCH=m
  262. +CONFIG_HID_NTRIG=m
  263. +CONFIG_HID_ORTEK=m
  264. +CONFIG_HID_PANTHERLORD=m
  265. +CONFIG_HID_PETALYNX=m
  266. +CONFIG_HID_PICOLCD=m
  267. +CONFIG_HID_QUANTA=m
  268. +CONFIG_HID_ROCCAT=m
  269. +CONFIG_HID_SAMSUNG=m
  270. +CONFIG_HID_SONY=m
  271. +CONFIG_HID_SPEEDLINK=m
  272. +CONFIG_HID_SUNPLUS=m
  273. +CONFIG_HID_GREENASIA=m
  274. +CONFIG_HID_SMARTJOYPLUS=m
  275. +CONFIG_HID_TOPSEED=m
  276. +CONFIG_HID_THRUSTMASTER=m
  277. +CONFIG_HID_WACOM=m
  278. +CONFIG_HID_WIIMOTE=m
  279. +CONFIG_HID_ZEROPLUS=m
  280. +CONFIG_HID_ZYDACRON=m
  281. +CONFIG_USB=y
  282. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  283. +CONFIG_USB_MON=m
  284. +CONFIG_USB_DWCOTG=y
  285. +CONFIG_USB_STORAGE=y
  286. +CONFIG_USB_STORAGE_REALTEK=m
  287. +CONFIG_USB_STORAGE_DATAFAB=m
  288. +CONFIG_USB_STORAGE_FREECOM=m
  289. +CONFIG_USB_STORAGE_ISD200=m
  290. +CONFIG_USB_STORAGE_USBAT=m
  291. +CONFIG_USB_STORAGE_SDDR09=m
  292. +CONFIG_USB_STORAGE_SDDR55=m
  293. +CONFIG_USB_STORAGE_JUMPSHOT=m
  294. +CONFIG_USB_STORAGE_ALAUDA=m
  295. +CONFIG_USB_STORAGE_ONETOUCH=m
  296. +CONFIG_USB_STORAGE_KARMA=m
  297. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  298. +CONFIG_USB_STORAGE_ENE_UB6250=m
  299. +CONFIG_USB_UAS=m
  300. +CONFIG_USB_LIBUSUAL=y
  301. +CONFIG_USB_MDC800=m
  302. +CONFIG_USB_MICROTEK=m
  303. +CONFIG_USB_SERIAL=m
  304. +CONFIG_USB_SERIAL_GENERIC=y
  305. +CONFIG_USB_SERIAL_AIRCABLE=m
  306. +CONFIG_USB_SERIAL_ARK3116=m
  307. +CONFIG_USB_SERIAL_BELKIN=m
  308. +CONFIG_USB_SERIAL_CH341=m
  309. +CONFIG_USB_SERIAL_WHITEHEAT=m
  310. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  311. +CONFIG_USB_SERIAL_CP210X=m
  312. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  313. +CONFIG_USB_SERIAL_EMPEG=m
  314. +CONFIG_USB_SERIAL_FTDI_SIO=m
  315. +CONFIG_USB_SERIAL_FUNSOFT=m
  316. +CONFIG_USB_SERIAL_VISOR=m
  317. +CONFIG_USB_SERIAL_IPAQ=m
  318. +CONFIG_USB_SERIAL_IR=m
  319. +CONFIG_USB_SERIAL_EDGEPORT=m
  320. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  321. +CONFIG_USB_SERIAL_GARMIN=m
  322. +CONFIG_USB_SERIAL_IPW=m
  323. +CONFIG_USB_SERIAL_IUU=m
  324. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  325. +CONFIG_USB_SERIAL_KEYSPAN=m
  326. +CONFIG_USB_SERIAL_KLSI=m
  327. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  328. +CONFIG_USB_SERIAL_MCT_U232=m
  329. +CONFIG_USB_SERIAL_MOS7720=m
  330. +CONFIG_USB_SERIAL_MOS7840=m
  331. +CONFIG_USB_SERIAL_MOTOROLA=m
  332. +CONFIG_USB_SERIAL_NAVMAN=m
  333. +CONFIG_USB_SERIAL_PL2303=m
  334. +CONFIG_USB_SERIAL_OTI6858=m
  335. +CONFIG_USB_SERIAL_QCAUX=m
  336. +CONFIG_USB_SERIAL_QUALCOMM=m
  337. +CONFIG_USB_SERIAL_SPCP8X5=m
  338. +CONFIG_USB_SERIAL_HP4X=m
  339. +CONFIG_USB_SERIAL_SAFE=m
  340. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  341. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  342. +CONFIG_USB_SERIAL_SYMBOL=m
  343. +CONFIG_USB_SERIAL_TI=m
  344. +CONFIG_USB_SERIAL_CYBERJACK=m
  345. +CONFIG_USB_SERIAL_XIRCOM=m
  346. +CONFIG_USB_SERIAL_OPTION=m
  347. +CONFIG_USB_SERIAL_OMNINET=m
  348. +CONFIG_USB_SERIAL_OPTICON=m
  349. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  350. +CONFIG_USB_SERIAL_ZIO=m
  351. +CONFIG_USB_SERIAL_SSU100=m
  352. +CONFIG_USB_SERIAL_DEBUG=m
  353. +CONFIG_USB_EMI62=m
  354. +CONFIG_USB_EMI26=m
  355. +CONFIG_USB_ADUTUX=m
  356. +CONFIG_USB_SEVSEG=m
  357. +CONFIG_USB_RIO500=m
  358. +CONFIG_USB_LEGOTOWER=m
  359. +CONFIG_USB_LCD=m
  360. +CONFIG_USB_LED=m
  361. +CONFIG_USB_CYPRESS_CY7C63=m
  362. +CONFIG_USB_CYTHERM=m
  363. +CONFIG_USB_IDMOUSE=m
  364. +CONFIG_USB_FTDI_ELAN=m
  365. +CONFIG_USB_APPLEDISPLAY=m
  366. +CONFIG_USB_LD=m
  367. +CONFIG_USB_TRANCEVIBRATOR=m
  368. +CONFIG_USB_IOWARRIOR=m
  369. +CONFIG_USB_TEST=m
  370. +CONFIG_USB_ISIGHTFW=m
  371. +CONFIG_USB_YUREX=m
  372. +CONFIG_MMC=y
  373. +CONFIG_MMC_SDHCI=y
  374. +CONFIG_MMC_SDHCI_PLTFM=y
  375. +CONFIG_MMC_SDHCI_BCM2708=y
  376. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  377. +CONFIG_LEDS_GPIO=y
  378. +CONFIG_LEDS_TRIGGER_TIMER=m
  379. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  380. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  381. +CONFIG_UIO=m
  382. +CONFIG_UIO_PDRV=m
  383. +CONFIG_UIO_PDRV_GENIRQ=m
  384. +# CONFIG_IOMMU_SUPPORT is not set
  385. +CONFIG_EXT4_FS=y
  386. +CONFIG_EXT4_FS_POSIX_ACL=y
  387. +CONFIG_EXT4_FS_SECURITY=y
  388. +CONFIG_REISERFS_FS=m
  389. +CONFIG_REISERFS_FS_XATTR=y
  390. +CONFIG_REISERFS_FS_POSIX_ACL=y
  391. +CONFIG_REISERFS_FS_SECURITY=y
  392. +CONFIG_JFS_FS=m
  393. +CONFIG_JFS_POSIX_ACL=y
  394. +CONFIG_JFS_SECURITY=y
  395. +CONFIG_XFS_FS=m
  396. +CONFIG_XFS_QUOTA=y
  397. +CONFIG_XFS_POSIX_ACL=y
  398. +CONFIG_XFS_RT=y
  399. +CONFIG_GFS2_FS=m
  400. +CONFIG_OCFS2_FS=m
  401. +CONFIG_BTRFS_FS=m
  402. +CONFIG_BTRFS_FS_POSIX_ACL=y
  403. +CONFIG_NILFS2_FS=m
  404. +CONFIG_AUTOFS4_FS=y
  405. +CONFIG_FUSE_FS=m
  406. +CONFIG_CUSE=m
  407. +CONFIG_FSCACHE=y
  408. +CONFIG_CACHEFILES=y
  409. +CONFIG_ISO9660_FS=m
  410. +CONFIG_JOLIET=y
  411. +CONFIG_ZISOFS=y
  412. +CONFIG_UDF_FS=m
  413. +CONFIG_MSDOS_FS=y
  414. +CONFIG_VFAT_FS=y
  415. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  416. +CONFIG_NTFS_FS=m
  417. +CONFIG_TMPFS=y
  418. +CONFIG_TMPFS_POSIX_ACL=y
  419. +CONFIG_CONFIGFS_FS=y
  420. +CONFIG_SQUASHFS=m
  421. +CONFIG_SQUASHFS_XATTR=y
  422. +CONFIG_SQUASHFS_LZO=y
  423. +CONFIG_SQUASHFS_XZ=y
  424. +CONFIG_NFS_FS=y
  425. +CONFIG_NFS_V3=y
  426. +CONFIG_NFS_V3_ACL=y
  427. +CONFIG_NFS_V4=y
  428. +CONFIG_ROOT_NFS=y
  429. +CONFIG_NFS_FSCACHE=y
  430. +CONFIG_CIFS=m
  431. +CONFIG_CIFS_WEAK_PW_HASH=y
  432. +CONFIG_CIFS_XATTR=y
  433. +CONFIG_CIFS_POSIX=y
  434. +CONFIG_9P_FS=m
  435. +CONFIG_PARTITION_ADVANCED=y
  436. +CONFIG_MAC_PARTITION=y
  437. +CONFIG_EFI_PARTITION=y
  438. +CONFIG_NLS_DEFAULT="utf8"
  439. +CONFIG_NLS_CODEPAGE_437=y
  440. +CONFIG_NLS_CODEPAGE_737=m
  441. +CONFIG_NLS_CODEPAGE_775=m
  442. +CONFIG_NLS_CODEPAGE_850=m
  443. +CONFIG_NLS_CODEPAGE_852=m
  444. +CONFIG_NLS_CODEPAGE_855=m
  445. +CONFIG_NLS_CODEPAGE_857=m
  446. +CONFIG_NLS_CODEPAGE_860=m
  447. +CONFIG_NLS_CODEPAGE_861=m
  448. +CONFIG_NLS_CODEPAGE_862=m
  449. +CONFIG_NLS_CODEPAGE_863=m
  450. +CONFIG_NLS_CODEPAGE_864=m
  451. +CONFIG_NLS_CODEPAGE_865=m
  452. +CONFIG_NLS_CODEPAGE_866=m
  453. +CONFIG_NLS_CODEPAGE_869=m
  454. +CONFIG_NLS_CODEPAGE_936=m
  455. +CONFIG_NLS_CODEPAGE_950=m
  456. +CONFIG_NLS_CODEPAGE_932=m
  457. +CONFIG_NLS_CODEPAGE_949=m
  458. +CONFIG_NLS_CODEPAGE_874=m
  459. +CONFIG_NLS_ISO8859_8=m
  460. +CONFIG_NLS_CODEPAGE_1250=m
  461. +CONFIG_NLS_CODEPAGE_1251=m
  462. +CONFIG_NLS_ASCII=y
  463. +CONFIG_NLS_ISO8859_1=m
  464. +CONFIG_NLS_ISO8859_2=m
  465. +CONFIG_NLS_ISO8859_3=m
  466. +CONFIG_NLS_ISO8859_4=m
  467. +CONFIG_NLS_ISO8859_5=m
  468. +CONFIG_NLS_ISO8859_6=m
  469. +CONFIG_NLS_ISO8859_7=m
  470. +CONFIG_NLS_ISO8859_9=m
  471. +CONFIG_NLS_ISO8859_13=m
  472. +CONFIG_NLS_ISO8859_14=m
  473. +CONFIG_NLS_ISO8859_15=m
  474. +CONFIG_NLS_KOI8_R=m
  475. +CONFIG_NLS_KOI8_U=m
  476. +CONFIG_NLS_UTF8=m
  477. +# CONFIG_SCHED_DEBUG is not set
  478. +# CONFIG_DEBUG_BUGVERBOSE is not set
  479. +# CONFIG_FTRACE is not set
  480. +# CONFIG_ARM_UNWIND is not set
  481. +CONFIG_CRYPTO_AUTHENC=m
  482. +CONFIG_CRYPTO_SEQIV=m
  483. +CONFIG_CRYPTO_CBC=y
  484. +CONFIG_CRYPTO_HMAC=y
  485. +CONFIG_CRYPTO_XCBC=m
  486. +CONFIG_CRYPTO_MD5=y
  487. +CONFIG_CRYPTO_SHA1=y
  488. +CONFIG_CRYPTO_SHA256=m
  489. +CONFIG_CRYPTO_SHA512=m
  490. +CONFIG_CRYPTO_TGR192=m
  491. +CONFIG_CRYPTO_WP512=m
  492. +CONFIG_CRYPTO_CAST5=m
  493. +CONFIG_CRYPTO_DES=y
  494. +CONFIG_CRYPTO_DEFLATE=m
  495. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  496. +# CONFIG_CRYPTO_HW is not set
  497. +CONFIG_CRC_ITU_T=y
  498. +CONFIG_LIBCRC32C=y
  499. +CONFIG_I2C=y
  500. +CONFIG_I2C_BOARDINFO=y
  501. +CONFIG_I2C_COMPAT=y
  502. +CONFIG_I2C_CHARDEV=m
  503. +CONFIG_I2C_HELPER_AUTO=y
  504. +CONFIG_I2C_BCM2708=m
  505. +CONFIG_SPI=y
  506. +CONFIG_SPI_MASTER=y
  507. +CONFIG_SPI_BCM2708=m
  508. diff -Nur linux-3.15/arch/arm/configs/bcmrpi_defconfig linux-rpi/arch/arm/configs/bcmrpi_defconfig
  509. --- linux-3.15/arch/arm/configs/bcmrpi_defconfig 1970-01-01 01:00:00.000000000 +0100
  510. +++ linux-rpi/arch/arm/configs/bcmrpi_defconfig 2014-06-11 21:05:18.000000000 +0200
  511. @@ -0,0 +1,1099 @@
  512. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  513. +# CONFIG_LOCALVERSION_AUTO is not set
  514. +CONFIG_SYSVIPC=y
  515. +CONFIG_POSIX_MQUEUE=y
  516. +CONFIG_FHANDLE=y
  517. +CONFIG_AUDIT=y
  518. +CONFIG_NO_HZ=y
  519. +CONFIG_HIGH_RES_TIMERS=y
  520. +CONFIG_BSD_PROCESS_ACCT=y
  521. +CONFIG_BSD_PROCESS_ACCT_V3=y
  522. +CONFIG_TASKSTATS=y
  523. +CONFIG_TASK_DELAY_ACCT=y
  524. +CONFIG_TASK_XACCT=y
  525. +CONFIG_TASK_IO_ACCOUNTING=y
  526. +CONFIG_IKCONFIG=y
  527. +CONFIG_IKCONFIG_PROC=y
  528. +CONFIG_CGROUP_FREEZER=y
  529. +CONFIG_CGROUP_DEVICE=y
  530. +CONFIG_CGROUP_CPUACCT=y
  531. +CONFIG_RESOURCE_COUNTERS=y
  532. +CONFIG_MEMCG=y
  533. +CONFIG_BLK_CGROUP=y
  534. +CONFIG_NAMESPACES=y
  535. +CONFIG_SCHED_AUTOGROUP=y
  536. +CONFIG_RELAY=y
  537. +CONFIG_BLK_DEV_INITRD=y
  538. +CONFIG_EMBEDDED=y
  539. +# CONFIG_COMPAT_BRK is not set
  540. +CONFIG_PROFILING=y
  541. +CONFIG_OPROFILE=m
  542. +CONFIG_KPROBES=y
  543. +CONFIG_JUMP_LABEL=y
  544. +CONFIG_MODULES=y
  545. +CONFIG_MODULE_UNLOAD=y
  546. +CONFIG_MODVERSIONS=y
  547. +CONFIG_MODULE_SRCVERSION_ALL=y
  548. +CONFIG_BLK_DEV_THROTTLING=y
  549. +CONFIG_PARTITION_ADVANCED=y
  550. +CONFIG_MAC_PARTITION=y
  551. +CONFIG_CFQ_GROUP_IOSCHED=y
  552. +CONFIG_ARCH_BCM2708=y
  553. +CONFIG_PREEMPT=y
  554. +CONFIG_AEABI=y
  555. +CONFIG_CLEANCACHE=y
  556. +CONFIG_FRONTSWAP=y
  557. +CONFIG_CMA=y
  558. +CONFIG_UACCESS_WITH_MEMCPY=y
  559. +CONFIG_SECCOMP=y
  560. +CONFIG_ZBOOT_ROM_TEXT=0x0
  561. +CONFIG_ZBOOT_ROM_BSS=0x0
  562. +CONFIG_CMDLINE="console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  563. +CONFIG_KEXEC=y
  564. +CONFIG_CPU_FREQ=y
  565. +CONFIG_CPU_FREQ_STAT=m
  566. +CONFIG_CPU_FREQ_STAT_DETAILS=y
  567. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  568. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  569. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  570. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  571. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  572. +CONFIG_CPU_IDLE=y
  573. +CONFIG_VFP=y
  574. +CONFIG_BINFMT_MISC=m
  575. +CONFIG_NET=y
  576. +CONFIG_PACKET=y
  577. +CONFIG_UNIX=y
  578. +CONFIG_XFRM_USER=y
  579. +CONFIG_NET_KEY=m
  580. +CONFIG_INET=y
  581. +CONFIG_IP_MULTICAST=y
  582. +CONFIG_IP_ADVANCED_ROUTER=y
  583. +CONFIG_IP_MULTIPLE_TABLES=y
  584. +CONFIG_IP_ROUTE_MULTIPATH=y
  585. +CONFIG_IP_ROUTE_VERBOSE=y
  586. +CONFIG_IP_PNP=y
  587. +CONFIG_IP_PNP_DHCP=y
  588. +CONFIG_IP_PNP_RARP=y
  589. +CONFIG_NET_IPIP=m
  590. +CONFIG_NET_IPGRE_DEMUX=m
  591. +CONFIG_NET_IPGRE=m
  592. +CONFIG_IP_MROUTE=y
  593. +CONFIG_IP_MROUTE_MULTIPLE_TABLES=y
  594. +CONFIG_IP_PIMSM_V1=y
  595. +CONFIG_IP_PIMSM_V2=y
  596. +CONFIG_SYN_COOKIES=y
  597. +CONFIG_INET_AH=m
  598. +CONFIG_INET_ESP=m
  599. +CONFIG_INET_IPCOMP=m
  600. +CONFIG_INET_XFRM_MODE_TRANSPORT=m
  601. +CONFIG_INET_XFRM_MODE_TUNNEL=m
  602. +CONFIG_INET_XFRM_MODE_BEET=m
  603. +CONFIG_INET_LRO=m
  604. +CONFIG_INET_DIAG=m
  605. +CONFIG_INET6_AH=m
  606. +CONFIG_INET6_ESP=m
  607. +CONFIG_INET6_IPCOMP=m
  608. +CONFIG_IPV6_TUNNEL=m
  609. +CONFIG_IPV6_MULTIPLE_TABLES=y
  610. +CONFIG_IPV6_MROUTE=y
  611. +CONFIG_IPV6_MROUTE_MULTIPLE_TABLES=y
  612. +CONFIG_IPV6_PIMSM_V2=y
  613. +CONFIG_NETFILTER=y
  614. +CONFIG_NF_CONNTRACK=m
  615. +CONFIG_NF_CONNTRACK_ZONES=y
  616. +CONFIG_NF_CONNTRACK_EVENTS=y
  617. +CONFIG_NF_CONNTRACK_TIMESTAMP=y
  618. +CONFIG_NF_CT_PROTO_DCCP=m
  619. +CONFIG_NF_CT_PROTO_UDPLITE=m
  620. +CONFIG_NF_CONNTRACK_AMANDA=m
  621. +CONFIG_NF_CONNTRACK_FTP=m
  622. +CONFIG_NF_CONNTRACK_H323=m
  623. +CONFIG_NF_CONNTRACK_IRC=m
  624. +CONFIG_NF_CONNTRACK_NETBIOS_NS=m
  625. +CONFIG_NF_CONNTRACK_SNMP=m
  626. +CONFIG_NF_CONNTRACK_PPTP=m
  627. +CONFIG_NF_CONNTRACK_SANE=m
  628. +CONFIG_NF_CONNTRACK_SIP=m
  629. +CONFIG_NF_CONNTRACK_TFTP=m
  630. +CONFIG_NF_CT_NETLINK=m
  631. +CONFIG_NETFILTER_XT_SET=m
  632. +CONFIG_NETFILTER_XT_TARGET_AUDIT=m
  633. +CONFIG_NETFILTER_XT_TARGET_CHECKSUM=m
  634. +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m
  635. +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m
  636. +CONFIG_NETFILTER_XT_TARGET_DSCP=m
  637. +CONFIG_NETFILTER_XT_TARGET_HMARK=m
  638. +CONFIG_NETFILTER_XT_TARGET_IDLETIMER=m
  639. +CONFIG_NETFILTER_XT_TARGET_LED=m
  640. +CONFIG_NETFILTER_XT_TARGET_LOG=m
  641. +CONFIG_NETFILTER_XT_TARGET_MARK=m
  642. +CONFIG_NETFILTER_XT_TARGET_NFLOG=m
  643. +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m
  644. +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m
  645. +CONFIG_NETFILTER_XT_TARGET_TEE=m
  646. +CONFIG_NETFILTER_XT_TARGET_TPROXY=m
  647. +CONFIG_NETFILTER_XT_TARGET_TRACE=m
  648. +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m
  649. +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m
  650. +CONFIG_NETFILTER_XT_MATCH_ADDRTYPE=m
  651. +CONFIG_NETFILTER_XT_MATCH_BPF=m
  652. +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m
  653. +CONFIG_NETFILTER_XT_MATCH_COMMENT=m
  654. +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m
  655. +CONFIG_NETFILTER_XT_MATCH_CONNLABEL=m
  656. +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m
  657. +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m
  658. +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=m
  659. +CONFIG_NETFILTER_XT_MATCH_CPU=m
  660. +CONFIG_NETFILTER_XT_MATCH_DCCP=m
  661. +CONFIG_NETFILTER_XT_MATCH_DEVGROUP=m
  662. +CONFIG_NETFILTER_XT_MATCH_DSCP=m
  663. +CONFIG_NETFILTER_XT_MATCH_ESP=m
  664. +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m
  665. +CONFIG_NETFILTER_XT_MATCH_HELPER=m
  666. +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m
  667. +CONFIG_NETFILTER_XT_MATCH_IPVS=m
  668. +CONFIG_NETFILTER_XT_MATCH_LENGTH=m
  669. +CONFIG_NETFILTER_XT_MATCH_LIMIT=m
  670. +CONFIG_NETFILTER_XT_MATCH_MAC=m
  671. +CONFIG_NETFILTER_XT_MATCH_MARK=m
  672. +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m
  673. +CONFIG_NETFILTER_XT_MATCH_NFACCT=m
  674. +CONFIG_NETFILTER_XT_MATCH_OSF=m
  675. +CONFIG_NETFILTER_XT_MATCH_OWNER=m
  676. +CONFIG_NETFILTER_XT_MATCH_POLICY=m
  677. +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m
  678. +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m
  679. +CONFIG_NETFILTER_XT_MATCH_QUOTA=m
  680. +CONFIG_NETFILTER_XT_MATCH_RATEEST=m
  681. +CONFIG_NETFILTER_XT_MATCH_REALM=m
  682. +CONFIG_NETFILTER_XT_MATCH_RECENT=m
  683. +CONFIG_NETFILTER_XT_MATCH_SOCKET=m
  684. +CONFIG_NETFILTER_XT_MATCH_STATE=m
  685. +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m
  686. +CONFIG_NETFILTER_XT_MATCH_STRING=m
  687. +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m
  688. +CONFIG_NETFILTER_XT_MATCH_TIME=m
  689. +CONFIG_NETFILTER_XT_MATCH_U32=m
  690. +CONFIG_IP_SET=m
  691. +CONFIG_IP_SET_BITMAP_IP=m
  692. +CONFIG_IP_SET_BITMAP_IPMAC=m
  693. +CONFIG_IP_SET_BITMAP_PORT=m
  694. +CONFIG_IP_SET_HASH_IP=m
  695. +CONFIG_IP_SET_HASH_IPPORT=m
  696. +CONFIG_IP_SET_HASH_IPPORTIP=m
  697. +CONFIG_IP_SET_HASH_IPPORTNET=m
  698. +CONFIG_IP_SET_HASH_NET=m
  699. +CONFIG_IP_SET_HASH_NETPORT=m
  700. +CONFIG_IP_SET_HASH_NETIFACE=m
  701. +CONFIG_IP_SET_LIST_SET=m
  702. +CONFIG_IP_VS=m
  703. +CONFIG_IP_VS_PROTO_TCP=y
  704. +CONFIG_IP_VS_PROTO_UDP=y
  705. +CONFIG_IP_VS_PROTO_ESP=y
  706. +CONFIG_IP_VS_PROTO_AH=y
  707. +CONFIG_IP_VS_PROTO_SCTP=y
  708. +CONFIG_IP_VS_RR=m
  709. +CONFIG_IP_VS_WRR=m
  710. +CONFIG_IP_VS_LC=m
  711. +CONFIG_IP_VS_WLC=m
  712. +CONFIG_IP_VS_LBLC=m
  713. +CONFIG_IP_VS_LBLCR=m
  714. +CONFIG_IP_VS_DH=m
  715. +CONFIG_IP_VS_SH=m
  716. +CONFIG_IP_VS_SED=m
  717. +CONFIG_IP_VS_NQ=m
  718. +CONFIG_IP_VS_FTP=m
  719. +CONFIG_IP_VS_PE_SIP=m
  720. +CONFIG_NF_CONNTRACK_IPV4=m
  721. +CONFIG_IP_NF_IPTABLES=m
  722. +CONFIG_IP_NF_MATCH_AH=m
  723. +CONFIG_IP_NF_MATCH_ECN=m
  724. +CONFIG_IP_NF_MATCH_TTL=m
  725. +CONFIG_IP_NF_FILTER=m
  726. +CONFIG_IP_NF_TARGET_REJECT=m
  727. +CONFIG_IP_NF_TARGET_ULOG=m
  728. +CONFIG_NF_NAT_IPV4=m
  729. +CONFIG_IP_NF_TARGET_MASQUERADE=m
  730. +CONFIG_IP_NF_TARGET_NETMAP=m
  731. +CONFIG_IP_NF_TARGET_REDIRECT=m
  732. +CONFIG_IP_NF_MANGLE=m
  733. +CONFIG_IP_NF_TARGET_ECN=m
  734. +CONFIG_IP_NF_TARGET_TTL=m
  735. +CONFIG_IP_NF_RAW=m
  736. +CONFIG_IP_NF_ARPTABLES=m
  737. +CONFIG_IP_NF_ARPFILTER=m
  738. +CONFIG_IP_NF_ARP_MANGLE=m
  739. +CONFIG_NF_CONNTRACK_IPV6=m
  740. +CONFIG_IP6_NF_IPTABLES=m
  741. +CONFIG_IP6_NF_MATCH_AH=m
  742. +CONFIG_IP6_NF_MATCH_EUI64=m
  743. +CONFIG_IP6_NF_MATCH_FRAG=m
  744. +CONFIG_IP6_NF_MATCH_OPTS=m
  745. +CONFIG_IP6_NF_MATCH_HL=m
  746. +CONFIG_IP6_NF_MATCH_IPV6HEADER=m
  747. +CONFIG_IP6_NF_MATCH_MH=m
  748. +CONFIG_IP6_NF_MATCH_RT=m
  749. +CONFIG_IP6_NF_TARGET_HL=m
  750. +CONFIG_IP6_NF_FILTER=m
  751. +CONFIG_IP6_NF_TARGET_REJECT=m
  752. +CONFIG_IP6_NF_MANGLE=m
  753. +CONFIG_IP6_NF_RAW=m
  754. +CONFIG_NF_NAT_IPV6=m
  755. +CONFIG_IP6_NF_TARGET_MASQUERADE=m
  756. +CONFIG_IP6_NF_TARGET_NPT=m
  757. +CONFIG_BRIDGE_NF_EBTABLES=m
  758. +CONFIG_BRIDGE_EBT_BROUTE=m
  759. +CONFIG_BRIDGE_EBT_T_FILTER=m
  760. +CONFIG_BRIDGE_EBT_T_NAT=m
  761. +CONFIG_BRIDGE_EBT_802_3=m
  762. +CONFIG_BRIDGE_EBT_AMONG=m
  763. +CONFIG_BRIDGE_EBT_ARP=m
  764. +CONFIG_BRIDGE_EBT_IP=m
  765. +CONFIG_BRIDGE_EBT_IP6=m
  766. +CONFIG_BRIDGE_EBT_LIMIT=m
  767. +CONFIG_BRIDGE_EBT_MARK=m
  768. +CONFIG_BRIDGE_EBT_PKTTYPE=m
  769. +CONFIG_BRIDGE_EBT_STP=m
  770. +CONFIG_BRIDGE_EBT_VLAN=m
  771. +CONFIG_BRIDGE_EBT_ARPREPLY=m
  772. +CONFIG_BRIDGE_EBT_DNAT=m
  773. +CONFIG_BRIDGE_EBT_MARK_T=m
  774. +CONFIG_BRIDGE_EBT_REDIRECT=m
  775. +CONFIG_BRIDGE_EBT_SNAT=m
  776. +CONFIG_BRIDGE_EBT_LOG=m
  777. +CONFIG_BRIDGE_EBT_ULOG=m
  778. +CONFIG_BRIDGE_EBT_NFLOG=m
  779. +CONFIG_SCTP_COOKIE_HMAC_SHA1=y
  780. +CONFIG_L2TP=m
  781. +CONFIG_L2TP_V3=y
  782. +CONFIG_L2TP_IP=m
  783. +CONFIG_L2TP_ETH=m
  784. +CONFIG_BRIDGE=m
  785. +CONFIG_VLAN_8021Q=m
  786. +CONFIG_VLAN_8021Q_GVRP=y
  787. +CONFIG_ATALK=m
  788. +CONFIG_NET_SCHED=y
  789. +CONFIG_NET_SCH_CBQ=m
  790. +CONFIG_NET_SCH_HTB=m
  791. +CONFIG_NET_SCH_HFSC=m
  792. +CONFIG_NET_SCH_PRIO=m
  793. +CONFIG_NET_SCH_MULTIQ=m
  794. +CONFIG_NET_SCH_RED=m
  795. +CONFIG_NET_SCH_SFB=m
  796. +CONFIG_NET_SCH_SFQ=m
  797. +CONFIG_NET_SCH_TEQL=m
  798. +CONFIG_NET_SCH_TBF=m
  799. +CONFIG_NET_SCH_GRED=m
  800. +CONFIG_NET_SCH_DSMARK=m
  801. +CONFIG_NET_SCH_NETEM=m
  802. +CONFIG_NET_SCH_DRR=m
  803. +CONFIG_NET_SCH_MQPRIO=m
  804. +CONFIG_NET_SCH_CHOKE=m
  805. +CONFIG_NET_SCH_QFQ=m
  806. +CONFIG_NET_SCH_CODEL=m
  807. +CONFIG_NET_SCH_FQ_CODEL=m
  808. +CONFIG_NET_SCH_INGRESS=m
  809. +CONFIG_NET_SCH_PLUG=m
  810. +CONFIG_NET_CLS_BASIC=m
  811. +CONFIG_NET_CLS_TCINDEX=m
  812. +CONFIG_NET_CLS_ROUTE4=m
  813. +CONFIG_NET_CLS_FW=m
  814. +CONFIG_NET_CLS_U32=m
  815. +CONFIG_CLS_U32_MARK=y
  816. +CONFIG_NET_CLS_RSVP=m
  817. +CONFIG_NET_CLS_RSVP6=m
  818. +CONFIG_NET_CLS_FLOW=m
  819. +CONFIG_NET_CLS_CGROUP=m
  820. +CONFIG_NET_EMATCH=y
  821. +CONFIG_NET_EMATCH_CMP=m
  822. +CONFIG_NET_EMATCH_NBYTE=m
  823. +CONFIG_NET_EMATCH_U32=m
  824. +CONFIG_NET_EMATCH_META=m
  825. +CONFIG_NET_EMATCH_TEXT=m
  826. +CONFIG_NET_EMATCH_IPSET=m
  827. +CONFIG_NET_CLS_ACT=y
  828. +CONFIG_NET_ACT_POLICE=m
  829. +CONFIG_NET_ACT_GACT=m
  830. +CONFIG_GACT_PROB=y
  831. +CONFIG_NET_ACT_MIRRED=m
  832. +CONFIG_NET_ACT_IPT=m
  833. +CONFIG_NET_ACT_NAT=m
  834. +CONFIG_NET_ACT_PEDIT=m
  835. +CONFIG_NET_ACT_SIMP=m
  836. +CONFIG_NET_ACT_SKBEDIT=m
  837. +CONFIG_NET_ACT_CSUM=m
  838. +CONFIG_BATMAN_ADV=m
  839. +CONFIG_OPENVSWITCH=m
  840. +CONFIG_NET_PKTGEN=m
  841. +CONFIG_HAMRADIO=y
  842. +CONFIG_AX25=m
  843. +CONFIG_NETROM=m
  844. +CONFIG_ROSE=m
  845. +CONFIG_MKISS=m
  846. +CONFIG_6PACK=m
  847. +CONFIG_BPQETHER=m
  848. +CONFIG_BAYCOM_SER_FDX=m
  849. +CONFIG_BAYCOM_SER_HDX=m
  850. +CONFIG_YAM=m
  851. +CONFIG_IRDA=m
  852. +CONFIG_IRLAN=m
  853. +CONFIG_IRNET=m
  854. +CONFIG_IRCOMM=m
  855. +CONFIG_IRDA_ULTRA=y
  856. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  857. +CONFIG_IRDA_FAST_RR=y
  858. +CONFIG_IRTTY_SIR=m
  859. +CONFIG_KINGSUN_DONGLE=m
  860. +CONFIG_KSDAZZLE_DONGLE=m
  861. +CONFIG_KS959_DONGLE=m
  862. +CONFIG_USB_IRDA=m
  863. +CONFIG_SIGMATEL_FIR=m
  864. +CONFIG_MCS_FIR=m
  865. +CONFIG_BT=m
  866. +CONFIG_BT_RFCOMM=m
  867. +CONFIG_BT_RFCOMM_TTY=y
  868. +CONFIG_BT_BNEP=m
  869. +CONFIG_BT_BNEP_MC_FILTER=y
  870. +CONFIG_BT_BNEP_PROTO_FILTER=y
  871. +CONFIG_BT_HIDP=m
  872. +CONFIG_BT_HCIBTUSB=m
  873. +CONFIG_BT_HCIBCM203X=m
  874. +CONFIG_BT_HCIBPA10X=m
  875. +CONFIG_BT_HCIBFUSB=m
  876. +CONFIG_BT_HCIVHCI=m
  877. +CONFIG_BT_MRVL=m
  878. +CONFIG_BT_MRVL_SDIO=m
  879. +CONFIG_BT_ATH3K=m
  880. +CONFIG_BT_WILINK=m
  881. +CONFIG_CFG80211=m
  882. +CONFIG_CFG80211_WEXT=y
  883. +CONFIG_MAC80211=m
  884. +CONFIG_MAC80211_RC_PID=y
  885. +CONFIG_MAC80211_MESH=y
  886. +CONFIG_WIMAX=m
  887. +CONFIG_RFKILL=m
  888. +CONFIG_RFKILL_INPUT=y
  889. +CONFIG_NET_9P=m
  890. +CONFIG_NFC=m
  891. +CONFIG_NFC_PN533=m
  892. +CONFIG_DEVTMPFS=y
  893. +CONFIG_DEVTMPFS_MOUNT=y
  894. +CONFIG_DMA_CMA=y
  895. +CONFIG_CMA_SIZE_MBYTES=5
  896. +CONFIG_BLK_DEV_LOOP=y
  897. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  898. +CONFIG_BLK_DEV_DRBD=m
  899. +CONFIG_BLK_DEV_NBD=m
  900. +CONFIG_BLK_DEV_RAM=y
  901. +CONFIG_CDROM_PKTCDVD=m
  902. +CONFIG_SCSI=y
  903. +# CONFIG_SCSI_PROC_FS is not set
  904. +CONFIG_BLK_DEV_SD=y
  905. +CONFIG_CHR_DEV_ST=m
  906. +CONFIG_CHR_DEV_OSST=m
  907. +CONFIG_BLK_DEV_SR=m
  908. +CONFIG_CHR_DEV_SG=m
  909. +CONFIG_SCSI_MULTI_LUN=y
  910. +CONFIG_SCSI_ISCSI_ATTRS=y
  911. +CONFIG_ISCSI_TCP=m
  912. +CONFIG_ISCSI_BOOT_SYSFS=m
  913. +CONFIG_MD=y
  914. +CONFIG_MD_LINEAR=m
  915. +CONFIG_MD_RAID0=m
  916. +CONFIG_BLK_DEV_DM=m
  917. +CONFIG_DM_CRYPT=m
  918. +CONFIG_DM_SNAPSHOT=m
  919. +CONFIG_DM_MIRROR=m
  920. +CONFIG_DM_LOG_USERSPACE=m
  921. +CONFIG_DM_RAID=m
  922. +CONFIG_DM_ZERO=m
  923. +CONFIG_DM_DELAY=m
  924. +CONFIG_NETDEVICES=y
  925. +CONFIG_BONDING=m
  926. +CONFIG_DUMMY=m
  927. +CONFIG_IFB=m
  928. +CONFIG_MACVLAN=m
  929. +CONFIG_NETCONSOLE=m
  930. +CONFIG_TUN=m
  931. +CONFIG_VETH=m
  932. +CONFIG_MDIO_BITBANG=m
  933. +CONFIG_PPP=m
  934. +CONFIG_PPP_BSDCOMP=m
  935. +CONFIG_PPP_DEFLATE=m
  936. +CONFIG_PPP_FILTER=y
  937. +CONFIG_PPP_MPPE=m
  938. +CONFIG_PPP_MULTILINK=y
  939. +CONFIG_PPPOE=m
  940. +CONFIG_PPPOL2TP=m
  941. +CONFIG_PPP_ASYNC=m
  942. +CONFIG_PPP_SYNC_TTY=m
  943. +CONFIG_SLIP=m
  944. +CONFIG_SLIP_COMPRESSED=y
  945. +CONFIG_SLIP_SMART=y
  946. +CONFIG_USB_CATC=m
  947. +CONFIG_USB_KAWETH=m
  948. +CONFIG_USB_PEGASUS=m
  949. +CONFIG_USB_RTL8150=m
  950. +CONFIG_USB_RTL8152=m
  951. +CONFIG_USB_USBNET=y
  952. +CONFIG_USB_NET_AX8817X=m
  953. +CONFIG_USB_NET_AX88179_178A=m
  954. +CONFIG_USB_NET_CDCETHER=m
  955. +CONFIG_USB_NET_CDC_EEM=m
  956. +CONFIG_USB_NET_CDC_NCM=m
  957. +CONFIG_USB_NET_CDC_MBIM=m
  958. +CONFIG_USB_NET_DM9601=m
  959. +CONFIG_USB_NET_SMSC75XX=m
  960. +CONFIG_USB_NET_SMSC95XX=y
  961. +CONFIG_USB_NET_GL620A=m
  962. +CONFIG_USB_NET_NET1080=m
  963. +CONFIG_USB_NET_PLUSB=m
  964. +CONFIG_USB_NET_MCS7830=m
  965. +CONFIG_USB_NET_CDC_SUBSET=m
  966. +CONFIG_USB_ALI_M5632=y
  967. +CONFIG_USB_AN2720=y
  968. +CONFIG_USB_EPSON2888=y
  969. +CONFIG_USB_KC2190=y
  970. +CONFIG_USB_NET_ZAURUS=m
  971. +CONFIG_USB_NET_CX82310_ETH=m
  972. +CONFIG_USB_NET_KALMIA=m
  973. +CONFIG_USB_NET_QMI_WWAN=m
  974. +CONFIG_USB_HSO=m
  975. +CONFIG_USB_NET_INT51X1=m
  976. +CONFIG_USB_IPHETH=m
  977. +CONFIG_USB_SIERRA_NET=m
  978. +CONFIG_USB_VL600=m
  979. +CONFIG_LIBERTAS_THINFIRM=m
  980. +CONFIG_LIBERTAS_THINFIRM_USB=m
  981. +CONFIG_AT76C50X_USB=m
  982. +CONFIG_USB_ZD1201=m
  983. +CONFIG_USB_NET_RNDIS_WLAN=m
  984. +CONFIG_RTL8187=m
  985. +CONFIG_MAC80211_HWSIM=m
  986. +CONFIG_ATH_CARDS=m
  987. +CONFIG_ATH9K=m
  988. +CONFIG_ATH9K_HTC=m
  989. +CONFIG_CARL9170=m
  990. +CONFIG_ATH6KL=m
  991. +CONFIG_ATH6KL_USB=m
  992. +CONFIG_AR5523=m
  993. +CONFIG_B43=m
  994. +# CONFIG_B43_PHY_N is not set
  995. +CONFIG_B43LEGACY=m
  996. +CONFIG_HOSTAP=m
  997. +CONFIG_LIBERTAS=m
  998. +CONFIG_LIBERTAS_USB=m
  999. +CONFIG_LIBERTAS_SDIO=m
  1000. +CONFIG_P54_COMMON=m
  1001. +CONFIG_P54_USB=m
  1002. +CONFIG_RT2X00=m
  1003. +CONFIG_RT2500USB=m
  1004. +CONFIG_RT73USB=m
  1005. +CONFIG_RT2800USB=m
  1006. +CONFIG_RT2800USB_RT3573=y
  1007. +CONFIG_RT2800USB_RT53XX=y
  1008. +CONFIG_RT2800USB_RT55XX=y
  1009. +CONFIG_RT2800USB_UNKNOWN=y
  1010. +CONFIG_RTL8192CU=m
  1011. +CONFIG_ZD1211RW=m
  1012. +CONFIG_MWIFIEX=m
  1013. +CONFIG_MWIFIEX_SDIO=m
  1014. +CONFIG_WIMAX_I2400M_USB=m
  1015. +CONFIG_INPUT_POLLDEV=m
  1016. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1017. +CONFIG_INPUT_JOYDEV=m
  1018. +CONFIG_INPUT_EVDEV=m
  1019. +# CONFIG_INPUT_KEYBOARD is not set
  1020. +# CONFIG_INPUT_MOUSE is not set
  1021. +CONFIG_INPUT_JOYSTICK=y
  1022. +CONFIG_JOYSTICK_IFORCE=m
  1023. +CONFIG_JOYSTICK_IFORCE_USB=y
  1024. +CONFIG_JOYSTICK_XPAD=m
  1025. +CONFIG_JOYSTICK_XPAD_FF=y
  1026. +CONFIG_INPUT_MISC=y
  1027. +CONFIG_INPUT_AD714X=m
  1028. +CONFIG_INPUT_ATI_REMOTE2=m
  1029. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1030. +CONFIG_INPUT_POWERMATE=m
  1031. +CONFIG_INPUT_YEALINK=m
  1032. +CONFIG_INPUT_CM109=m
  1033. +CONFIG_INPUT_UINPUT=m
  1034. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1035. +CONFIG_INPUT_ADXL34X=m
  1036. +CONFIG_INPUT_CMA3000=m
  1037. +CONFIG_SERIO=m
  1038. +CONFIG_SERIO_RAW=m
  1039. +CONFIG_GAMEPORT=m
  1040. +CONFIG_GAMEPORT_NS558=m
  1041. +CONFIG_GAMEPORT_L4=m
  1042. +# CONFIG_LEGACY_PTYS is not set
  1043. +# CONFIG_DEVKMEM is not set
  1044. +CONFIG_SERIAL_AMBA_PL011=y
  1045. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1046. +CONFIG_TTY_PRINTK=y
  1047. +CONFIG_HW_RANDOM=y
  1048. +CONFIG_HW_RANDOM_BCM2708=m
  1049. +CONFIG_RAW_DRIVER=y
  1050. +CONFIG_BRCM_CHAR_DRIVERS=y
  1051. +CONFIG_BCM_VC_CMA=y
  1052. +CONFIG_I2C=y
  1053. +CONFIG_I2C_CHARDEV=m
  1054. +CONFIG_I2C_BCM2708=m
  1055. +CONFIG_SPI=y
  1056. +CONFIG_SPI_BCM2708=m
  1057. +CONFIG_SPI_SPIDEV=y
  1058. +CONFIG_GPIO_SYSFS=y
  1059. +CONFIG_W1=m
  1060. +CONFIG_W1_MASTER_DS2490=m
  1061. +CONFIG_W1_MASTER_DS2482=m
  1062. +CONFIG_W1_MASTER_DS1WM=m
  1063. +CONFIG_W1_MASTER_GPIO=m
  1064. +CONFIG_W1_SLAVE_THERM=m
  1065. +CONFIG_W1_SLAVE_SMEM=m
  1066. +CONFIG_W1_SLAVE_DS2408=m
  1067. +CONFIG_W1_SLAVE_DS2413=m
  1068. +CONFIG_W1_SLAVE_DS2423=m
  1069. +CONFIG_W1_SLAVE_DS2431=m
  1070. +CONFIG_W1_SLAVE_DS2433=m
  1071. +CONFIG_W1_SLAVE_DS2760=m
  1072. +CONFIG_W1_SLAVE_DS2780=m
  1073. +CONFIG_W1_SLAVE_DS2781=m
  1074. +CONFIG_W1_SLAVE_DS28E04=m
  1075. +CONFIG_W1_SLAVE_BQ27000=m
  1076. +CONFIG_BATTERY_DS2760=m
  1077. +# CONFIG_HWMON is not set
  1078. +CONFIG_THERMAL=y
  1079. +CONFIG_THERMAL_BCM2835=y
  1080. +CONFIG_WATCHDOG=y
  1081. +CONFIG_BCM2708_WDT=m
  1082. +CONFIG_MEDIA_SUPPORT=m
  1083. +CONFIG_MEDIA_CAMERA_SUPPORT=y
  1084. +CONFIG_MEDIA_ANALOG_TV_SUPPORT=y
  1085. +CONFIG_MEDIA_DIGITAL_TV_SUPPORT=y
  1086. +CONFIG_MEDIA_RADIO_SUPPORT=y
  1087. +CONFIG_MEDIA_RC_SUPPORT=y
  1088. +CONFIG_MEDIA_CONTROLLER=y
  1089. +CONFIG_LIRC=m
  1090. +CONFIG_RC_DEVICES=y
  1091. +CONFIG_RC_ATI_REMOTE=m
  1092. +CONFIG_IR_IMON=m
  1093. +CONFIG_IR_MCEUSB=m
  1094. +CONFIG_IR_REDRAT3=m
  1095. +CONFIG_IR_STREAMZAP=m
  1096. +CONFIG_IR_IGUANA=m
  1097. +CONFIG_IR_TTUSBIR=m
  1098. +CONFIG_RC_LOOPBACK=m
  1099. +CONFIG_IR_GPIO_CIR=m
  1100. +CONFIG_MEDIA_USB_SUPPORT=y
  1101. +CONFIG_USB_VIDEO_CLASS=m
  1102. +CONFIG_USB_M5602=m
  1103. +CONFIG_USB_STV06XX=m
  1104. +CONFIG_USB_GL860=m
  1105. +CONFIG_USB_GSPCA_BENQ=m
  1106. +CONFIG_USB_GSPCA_CONEX=m
  1107. +CONFIG_USB_GSPCA_CPIA1=m
  1108. +CONFIG_USB_GSPCA_ETOMS=m
  1109. +CONFIG_USB_GSPCA_FINEPIX=m
  1110. +CONFIG_USB_GSPCA_JEILINJ=m
  1111. +CONFIG_USB_GSPCA_JL2005BCD=m
  1112. +CONFIG_USB_GSPCA_KINECT=m
  1113. +CONFIG_USB_GSPCA_KONICA=m
  1114. +CONFIG_USB_GSPCA_MARS=m
  1115. +CONFIG_USB_GSPCA_MR97310A=m
  1116. +CONFIG_USB_GSPCA_NW80X=m
  1117. +CONFIG_USB_GSPCA_OV519=m
  1118. +CONFIG_USB_GSPCA_OV534=m
  1119. +CONFIG_USB_GSPCA_OV534_9=m
  1120. +CONFIG_USB_GSPCA_PAC207=m
  1121. +CONFIG_USB_GSPCA_PAC7302=m
  1122. +CONFIG_USB_GSPCA_PAC7311=m
  1123. +CONFIG_USB_GSPCA_SE401=m
  1124. +CONFIG_USB_GSPCA_SN9C2028=m
  1125. +CONFIG_USB_GSPCA_SN9C20X=m
  1126. +CONFIG_USB_GSPCA_SONIXB=m
  1127. +CONFIG_USB_GSPCA_SONIXJ=m
  1128. +CONFIG_USB_GSPCA_SPCA500=m
  1129. +CONFIG_USB_GSPCA_SPCA501=m
  1130. +CONFIG_USB_GSPCA_SPCA505=m
  1131. +CONFIG_USB_GSPCA_SPCA506=m
  1132. +CONFIG_USB_GSPCA_SPCA508=m
  1133. +CONFIG_USB_GSPCA_SPCA561=m
  1134. +CONFIG_USB_GSPCA_SPCA1528=m
  1135. +CONFIG_USB_GSPCA_SQ905=m
  1136. +CONFIG_USB_GSPCA_SQ905C=m
  1137. +CONFIG_USB_GSPCA_SQ930X=m
  1138. +CONFIG_USB_GSPCA_STK014=m
  1139. +CONFIG_USB_GSPCA_STV0680=m
  1140. +CONFIG_USB_GSPCA_SUNPLUS=m
  1141. +CONFIG_USB_GSPCA_T613=m
  1142. +CONFIG_USB_GSPCA_TOPRO=m
  1143. +CONFIG_USB_GSPCA_TV8532=m
  1144. +CONFIG_USB_GSPCA_VC032X=m
  1145. +CONFIG_USB_GSPCA_VICAM=m
  1146. +CONFIG_USB_GSPCA_XIRLINK_CIT=m
  1147. +CONFIG_USB_GSPCA_ZC3XX=m
  1148. +CONFIG_USB_PWC=m
  1149. +CONFIG_VIDEO_CPIA2=m
  1150. +CONFIG_USB_ZR364XX=m
  1151. +CONFIG_USB_STKWEBCAM=m
  1152. +CONFIG_USB_S2255=m
  1153. +CONFIG_VIDEO_PVRUSB2=m
  1154. +CONFIG_VIDEO_HDPVR=m
  1155. +CONFIG_VIDEO_TLG2300=m
  1156. +CONFIG_VIDEO_USBVISION=m
  1157. +CONFIG_VIDEO_AU0828=m
  1158. +CONFIG_VIDEO_CX231XX=m
  1159. +CONFIG_VIDEO_CX231XX_ALSA=m
  1160. +CONFIG_VIDEO_CX231XX_DVB=m
  1161. +CONFIG_VIDEO_TM6000=m
  1162. +CONFIG_VIDEO_TM6000_ALSA=m
  1163. +CONFIG_VIDEO_TM6000_DVB=m
  1164. +CONFIG_DVB_USB=m
  1165. +CONFIG_DVB_USB_A800=m
  1166. +CONFIG_DVB_USB_DIBUSB_MB=m
  1167. +CONFIG_DVB_USB_DIBUSB_MB_FAULTY=y
  1168. +CONFIG_DVB_USB_DIBUSB_MC=m
  1169. +CONFIG_DVB_USB_DIB0700=m
  1170. +CONFIG_DVB_USB_UMT_010=m
  1171. +CONFIG_DVB_USB_CXUSB=m
  1172. +CONFIG_DVB_USB_M920X=m
  1173. +CONFIG_DVB_USB_DIGITV=m
  1174. +CONFIG_DVB_USB_VP7045=m
  1175. +CONFIG_DVB_USB_VP702X=m
  1176. +CONFIG_DVB_USB_GP8PSK=m
  1177. +CONFIG_DVB_USB_NOVA_T_USB2=m
  1178. +CONFIG_DVB_USB_TTUSB2=m
  1179. +CONFIG_DVB_USB_DTT200U=m
  1180. +CONFIG_DVB_USB_OPERA1=m
  1181. +CONFIG_DVB_USB_AF9005=m
  1182. +CONFIG_DVB_USB_AF9005_REMOTE=m
  1183. +CONFIG_DVB_USB_PCTV452E=m
  1184. +CONFIG_DVB_USB_DW2102=m
  1185. +CONFIG_DVB_USB_CINERGY_T2=m
  1186. +CONFIG_DVB_USB_DTV5100=m
  1187. +CONFIG_DVB_USB_FRIIO=m
  1188. +CONFIG_DVB_USB_AZ6027=m
  1189. +CONFIG_DVB_USB_TECHNISAT_USB2=m
  1190. +CONFIG_DVB_USB_V2=m
  1191. +CONFIG_DVB_USB_AF9015=m
  1192. +CONFIG_DVB_USB_AF9035=m
  1193. +CONFIG_DVB_USB_ANYSEE=m
  1194. +CONFIG_DVB_USB_AU6610=m
  1195. +CONFIG_DVB_USB_AZ6007=m
  1196. +CONFIG_DVB_USB_CE6230=m
  1197. +CONFIG_DVB_USB_EC168=m
  1198. +CONFIG_DVB_USB_GL861=m
  1199. +CONFIG_DVB_USB_IT913X=m
  1200. +CONFIG_DVB_USB_LME2510=m
  1201. +CONFIG_DVB_USB_MXL111SF=m
  1202. +CONFIG_DVB_USB_RTL28XXU=m
  1203. +CONFIG_SMS_USB_DRV=m
  1204. +CONFIG_DVB_B2C2_FLEXCOP_USB=m
  1205. +CONFIG_VIDEO_EM28XX=m
  1206. +CONFIG_VIDEO_EM28XX_ALSA=m
  1207. +CONFIG_VIDEO_EM28XX_DVB=m
  1208. +CONFIG_V4L_PLATFORM_DRIVERS=y
  1209. +CONFIG_VIDEO_BCM2835=y
  1210. +CONFIG_VIDEO_BCM2835_MMAL=m
  1211. +CONFIG_RADIO_SI470X=y
  1212. +CONFIG_USB_SI470X=m
  1213. +CONFIG_I2C_SI470X=m
  1214. +CONFIG_RADIO_SI4713=m
  1215. +CONFIG_USB_MR800=m
  1216. +CONFIG_USB_DSBR=m
  1217. +CONFIG_RADIO_SHARK=m
  1218. +CONFIG_RADIO_SHARK2=m
  1219. +CONFIG_USB_KEENE=m
  1220. +CONFIG_USB_MA901=m
  1221. +CONFIG_RADIO_TEA5764=m
  1222. +CONFIG_RADIO_SAA7706H=m
  1223. +CONFIG_RADIO_TEF6862=m
  1224. +CONFIG_RADIO_WL1273=m
  1225. +CONFIG_RADIO_WL128X=m
  1226. +CONFIG_FB=y
  1227. +CONFIG_FB_BCM2708=y
  1228. +# CONFIG_BACKLIGHT_GENERIC is not set
  1229. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1230. +CONFIG_LOGO=y
  1231. +# CONFIG_LOGO_LINUX_MONO is not set
  1232. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1233. +CONFIG_SOUND=y
  1234. +CONFIG_SND=m
  1235. +CONFIG_SND_SEQUENCER=m
  1236. +CONFIG_SND_SEQ_DUMMY=m
  1237. +CONFIG_SND_MIXER_OSS=m
  1238. +CONFIG_SND_PCM_OSS=m
  1239. +CONFIG_SND_SEQUENCER_OSS=y
  1240. +CONFIG_SND_HRTIMER=m
  1241. +CONFIG_SND_DUMMY=m
  1242. +CONFIG_SND_ALOOP=m
  1243. +CONFIG_SND_VIRMIDI=m
  1244. +CONFIG_SND_MTPAV=m
  1245. +CONFIG_SND_SERIAL_U16550=m
  1246. +CONFIG_SND_MPU401=m
  1247. +CONFIG_SND_BCM2835=m
  1248. +CONFIG_SND_USB_AUDIO=m
  1249. +CONFIG_SND_USB_UA101=m
  1250. +CONFIG_SND_USB_CAIAQ=m
  1251. +CONFIG_SND_USB_CAIAQ_INPUT=y
  1252. +CONFIG_SND_USB_6FIRE=m
  1253. +CONFIG_SND_SOC=m
  1254. +CONFIG_SND_SOC_DMAENGINE_PCM=y
  1255. +CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y
  1256. +CONFIG_SND_SOC_WM8804=m
  1257. +CONFIG_SND_BCM2708_SOC_I2S=m
  1258. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC=m
  1259. +CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI=m
  1260. +CONFIG_SND_BCM2708_SOC_RPI_DAC=m
  1261. +CONFIG_SND_SOC_I2C_AND_SPI=m
  1262. +CONFIG_SND_SOC_PCM5102A=m
  1263. +CONFIG_SND_SOC_PCM1794A=m
  1264. +CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC=m
  1265. +CONFIG_SOUND_PRIME=m
  1266. +CONFIG_HIDRAW=y
  1267. +CONFIG_HID_A4TECH=m
  1268. +CONFIG_HID_ACRUX=m
  1269. +CONFIG_HID_APPLE=m
  1270. +CONFIG_HID_BELKIN=m
  1271. +CONFIG_HID_CHERRY=m
  1272. +CONFIG_HID_CHICONY=m
  1273. +CONFIG_HID_CYPRESS=m
  1274. +CONFIG_HID_DRAGONRISE=m
  1275. +CONFIG_HID_EMS_FF=m
  1276. +CONFIG_HID_ELECOM=m
  1277. +CONFIG_HID_EZKEY=m
  1278. +CONFIG_HID_HOLTEK=m
  1279. +CONFIG_HID_KEYTOUCH=m
  1280. +CONFIG_HID_KYE=m
  1281. +CONFIG_HID_UCLOGIC=m
  1282. +CONFIG_HID_WALTOP=m
  1283. +CONFIG_HID_GYRATION=m
  1284. +CONFIG_HID_TWINHAN=m
  1285. +CONFIG_HID_KENSINGTON=m
  1286. +CONFIG_HID_LCPOWER=m
  1287. +CONFIG_HID_LOGITECH=m
  1288. +CONFIG_HID_MAGICMOUSE=m
  1289. +CONFIG_HID_MICROSOFT=m
  1290. +CONFIG_HID_MONTEREY=m
  1291. +CONFIG_HID_MULTITOUCH=m
  1292. +CONFIG_HID_NTRIG=m
  1293. +CONFIG_HID_ORTEK=m
  1294. +CONFIG_HID_PANTHERLORD=m
  1295. +CONFIG_HID_PETALYNX=m
  1296. +CONFIG_HID_PICOLCD=m
  1297. +CONFIG_HID_ROCCAT=m
  1298. +CONFIG_HID_SAMSUNG=m
  1299. +CONFIG_HID_SONY=m
  1300. +CONFIG_HID_SPEEDLINK=m
  1301. +CONFIG_HID_SUNPLUS=m
  1302. +CONFIG_HID_GREENASIA=m
  1303. +CONFIG_HID_SMARTJOYPLUS=m
  1304. +CONFIG_HID_TOPSEED=m
  1305. +CONFIG_HID_THINGM=m
  1306. +CONFIG_HID_THRUSTMASTER=m
  1307. +CONFIG_HID_WACOM=m
  1308. +CONFIG_HID_WIIMOTE=m
  1309. +CONFIG_HID_XINMO=m
  1310. +CONFIG_HID_ZEROPLUS=m
  1311. +CONFIG_HID_ZYDACRON=m
  1312. +CONFIG_HID_PID=y
  1313. +CONFIG_USB_HIDDEV=y
  1314. +CONFIG_USB=y
  1315. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1316. +CONFIG_USB_MON=m
  1317. +CONFIG_USB_DWCOTG=y
  1318. +CONFIG_USB_PRINTER=m
  1319. +CONFIG_USB_STORAGE=y
  1320. +CONFIG_USB_STORAGE_REALTEK=m
  1321. +CONFIG_USB_STORAGE_DATAFAB=m
  1322. +CONFIG_USB_STORAGE_FREECOM=m
  1323. +CONFIG_USB_STORAGE_ISD200=m
  1324. +CONFIG_USB_STORAGE_USBAT=m
  1325. +CONFIG_USB_STORAGE_SDDR09=m
  1326. +CONFIG_USB_STORAGE_SDDR55=m
  1327. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1328. +CONFIG_USB_STORAGE_ALAUDA=m
  1329. +CONFIG_USB_STORAGE_ONETOUCH=m
  1330. +CONFIG_USB_STORAGE_KARMA=m
  1331. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1332. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1333. +CONFIG_USB_MDC800=m
  1334. +CONFIG_USB_MICROTEK=m
  1335. +CONFIG_USB_SERIAL=m
  1336. +CONFIG_USB_SERIAL_GENERIC=y
  1337. +CONFIG_USB_SERIAL_AIRCABLE=m
  1338. +CONFIG_USB_SERIAL_ARK3116=m
  1339. +CONFIG_USB_SERIAL_BELKIN=m
  1340. +CONFIG_USB_SERIAL_CH341=m
  1341. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1342. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1343. +CONFIG_USB_SERIAL_CP210X=m
  1344. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1345. +CONFIG_USB_SERIAL_EMPEG=m
  1346. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1347. +CONFIG_USB_SERIAL_VISOR=m
  1348. +CONFIG_USB_SERIAL_IPAQ=m
  1349. +CONFIG_USB_SERIAL_IR=m
  1350. +CONFIG_USB_SERIAL_EDGEPORT=m
  1351. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1352. +CONFIG_USB_SERIAL_F81232=m
  1353. +CONFIG_USB_SERIAL_GARMIN=m
  1354. +CONFIG_USB_SERIAL_IPW=m
  1355. +CONFIG_USB_SERIAL_IUU=m
  1356. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1357. +CONFIG_USB_SERIAL_KEYSPAN=m
  1358. +CONFIG_USB_SERIAL_KLSI=m
  1359. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1360. +CONFIG_USB_SERIAL_MCT_U232=m
  1361. +CONFIG_USB_SERIAL_METRO=m
  1362. +CONFIG_USB_SERIAL_MOS7720=m
  1363. +CONFIG_USB_SERIAL_MOS7840=m
  1364. +CONFIG_USB_SERIAL_NAVMAN=m
  1365. +CONFIG_USB_SERIAL_PL2303=m
  1366. +CONFIG_USB_SERIAL_OTI6858=m
  1367. +CONFIG_USB_SERIAL_QCAUX=m
  1368. +CONFIG_USB_SERIAL_QUALCOMM=m
  1369. +CONFIG_USB_SERIAL_SPCP8X5=m
  1370. +CONFIG_USB_SERIAL_SAFE=m
  1371. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1372. +CONFIG_USB_SERIAL_SYMBOL=m
  1373. +CONFIG_USB_SERIAL_TI=m
  1374. +CONFIG_USB_SERIAL_CYBERJACK=m
  1375. +CONFIG_USB_SERIAL_XIRCOM=m
  1376. +CONFIG_USB_SERIAL_OPTION=m
  1377. +CONFIG_USB_SERIAL_OMNINET=m
  1378. +CONFIG_USB_SERIAL_OPTICON=m
  1379. +CONFIG_USB_SERIAL_XSENS_MT=m
  1380. +CONFIG_USB_SERIAL_WISHBONE=m
  1381. +CONFIG_USB_SERIAL_ZTE=m
  1382. +CONFIG_USB_SERIAL_SSU100=m
  1383. +CONFIG_USB_SERIAL_QT2=m
  1384. +CONFIG_USB_SERIAL_DEBUG=m
  1385. +CONFIG_USB_EMI62=m
  1386. +CONFIG_USB_EMI26=m
  1387. +CONFIG_USB_ADUTUX=m
  1388. +CONFIG_USB_SEVSEG=m
  1389. +CONFIG_USB_RIO500=m
  1390. +CONFIG_USB_LEGOTOWER=m
  1391. +CONFIG_USB_LCD=m
  1392. +CONFIG_USB_LED=m
  1393. +CONFIG_USB_CYPRESS_CY7C63=m
  1394. +CONFIG_USB_CYTHERM=m
  1395. +CONFIG_USB_IDMOUSE=m
  1396. +CONFIG_USB_FTDI_ELAN=m
  1397. +CONFIG_USB_APPLEDISPLAY=m
  1398. +CONFIG_USB_LD=m
  1399. +CONFIG_USB_TRANCEVIBRATOR=m
  1400. +CONFIG_USB_IOWARRIOR=m
  1401. +CONFIG_USB_TEST=m
  1402. +CONFIG_USB_ISIGHTFW=m
  1403. +CONFIG_USB_YUREX=m
  1404. +CONFIG_MMC=y
  1405. +CONFIG_MMC_BLOCK_MINORS=32
  1406. +CONFIG_MMC_SDHCI=y
  1407. +CONFIG_MMC_SDHCI_PLTFM=y
  1408. +CONFIG_MMC_SDHCI_BCM2708=y
  1409. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  1410. +CONFIG_MMC_SPI=m
  1411. +CONFIG_LEDS_GPIO=m
  1412. +CONFIG_LEDS_TRIGGER_TIMER=y
  1413. +CONFIG_LEDS_TRIGGER_ONESHOT=y
  1414. +CONFIG_LEDS_TRIGGER_HEARTBEAT=y
  1415. +CONFIG_LEDS_TRIGGER_BACKLIGHT=y
  1416. +CONFIG_LEDS_TRIGGER_CPU=y
  1417. +CONFIG_LEDS_TRIGGER_GPIO=y
  1418. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=y
  1419. +CONFIG_LEDS_TRIGGER_TRANSIENT=m
  1420. +CONFIG_LEDS_TRIGGER_CAMERA=m
  1421. +CONFIG_RTC_CLASS=y
  1422. +# CONFIG_RTC_HCTOSYS is not set
  1423. +CONFIG_RTC_DRV_DS1307=m
  1424. +CONFIG_RTC_DRV_DS1374=m
  1425. +CONFIG_RTC_DRV_DS1672=m
  1426. +CONFIG_RTC_DRV_DS3232=m
  1427. +CONFIG_RTC_DRV_MAX6900=m
  1428. +CONFIG_RTC_DRV_RS5C372=m
  1429. +CONFIG_RTC_DRV_ISL1208=m
  1430. +CONFIG_RTC_DRV_ISL12022=m
  1431. +CONFIG_RTC_DRV_ISL12057=m
  1432. +CONFIG_RTC_DRV_X1205=m
  1433. +CONFIG_RTC_DRV_PCF2127=m
  1434. +CONFIG_RTC_DRV_PCF8523=m
  1435. +CONFIG_RTC_DRV_PCF8563=m
  1436. +CONFIG_RTC_DRV_PCF8583=m
  1437. +CONFIG_RTC_DRV_M41T80=m
  1438. +CONFIG_RTC_DRV_BQ32K=m
  1439. +CONFIG_RTC_DRV_S35390A=m
  1440. +CONFIG_RTC_DRV_FM3130=m
  1441. +CONFIG_RTC_DRV_RX8581=m
  1442. +CONFIG_RTC_DRV_RX8025=m
  1443. +CONFIG_RTC_DRV_EM3027=m
  1444. +CONFIG_RTC_DRV_RV3029C2=m
  1445. +CONFIG_RTC_DRV_M41T93=m
  1446. +CONFIG_RTC_DRV_M41T94=m
  1447. +CONFIG_RTC_DRV_DS1305=m
  1448. +CONFIG_RTC_DRV_DS1390=m
  1449. +CONFIG_RTC_DRV_MAX6902=m
  1450. +CONFIG_RTC_DRV_R9701=m
  1451. +CONFIG_RTC_DRV_RS5C348=m
  1452. +CONFIG_RTC_DRV_DS3234=m
  1453. +CONFIG_RTC_DRV_PCF2123=m
  1454. +CONFIG_RTC_DRV_RX4581=m
  1455. +CONFIG_DMADEVICES=y
  1456. +CONFIG_DMA_BCM2708=m
  1457. +CONFIG_DMA_ENGINE=y
  1458. +CONFIG_DMA_VIRTUAL_CHANNELS=m
  1459. +CONFIG_UIO=m
  1460. +CONFIG_UIO_PDRV_GENIRQ=m
  1461. +CONFIG_STAGING=y
  1462. +CONFIG_W35UND=m
  1463. +CONFIG_PRISM2_USB=m
  1464. +CONFIG_R8712U=m
  1465. +CONFIG_VT6656=m
  1466. +CONFIG_SPEAKUP=m
  1467. +CONFIG_SPEAKUP_SYNTH_SOFT=m
  1468. +CONFIG_STAGING_MEDIA=y
  1469. +CONFIG_DVB_AS102=m
  1470. +CONFIG_USB_SN9C102=m
  1471. +CONFIG_LIRC_STAGING=y
  1472. +CONFIG_LIRC_IGORPLUGUSB=m
  1473. +CONFIG_LIRC_IMON=m
  1474. +CONFIG_LIRC_RPI=m
  1475. +CONFIG_LIRC_SASEM=m
  1476. +CONFIG_LIRC_SERIAL=m
  1477. +# CONFIG_IOMMU_SUPPORT is not set
  1478. +CONFIG_EXT4_FS=y
  1479. +CONFIG_EXT4_FS_POSIX_ACL=y
  1480. +CONFIG_EXT4_FS_SECURITY=y
  1481. +CONFIG_REISERFS_FS=m
  1482. +CONFIG_REISERFS_FS_XATTR=y
  1483. +CONFIG_REISERFS_FS_POSIX_ACL=y
  1484. +CONFIG_REISERFS_FS_SECURITY=y
  1485. +CONFIG_JFS_FS=m
  1486. +CONFIG_JFS_POSIX_ACL=y
  1487. +CONFIG_JFS_SECURITY=y
  1488. +CONFIG_JFS_STATISTICS=y
  1489. +CONFIG_XFS_FS=m
  1490. +CONFIG_XFS_QUOTA=y
  1491. +CONFIG_XFS_POSIX_ACL=y
  1492. +CONFIG_XFS_RT=y
  1493. +CONFIG_GFS2_FS=m
  1494. +CONFIG_OCFS2_FS=m
  1495. +CONFIG_BTRFS_FS=m
  1496. +CONFIG_BTRFS_FS_POSIX_ACL=y
  1497. +CONFIG_NILFS2_FS=m
  1498. +CONFIG_FANOTIFY=y
  1499. +CONFIG_QFMT_V1=m
  1500. +CONFIG_QFMT_V2=m
  1501. +CONFIG_AUTOFS4_FS=y
  1502. +CONFIG_FUSE_FS=m
  1503. +CONFIG_CUSE=m
  1504. +CONFIG_FSCACHE=y
  1505. +CONFIG_FSCACHE_STATS=y
  1506. +CONFIG_FSCACHE_HISTOGRAM=y
  1507. +CONFIG_CACHEFILES=y
  1508. +CONFIG_ISO9660_FS=m
  1509. +CONFIG_JOLIET=y
  1510. +CONFIG_ZISOFS=y
  1511. +CONFIG_UDF_FS=m
  1512. +CONFIG_MSDOS_FS=y
  1513. +CONFIG_VFAT_FS=y
  1514. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  1515. +CONFIG_NTFS_FS=m
  1516. +CONFIG_NTFS_RW=y
  1517. +CONFIG_TMPFS=y
  1518. +CONFIG_TMPFS_POSIX_ACL=y
  1519. +CONFIG_CONFIGFS_FS=y
  1520. +CONFIG_ECRYPT_FS=m
  1521. +CONFIG_HFS_FS=m
  1522. +CONFIG_HFSPLUS_FS=m
  1523. +CONFIG_SQUASHFS=m
  1524. +CONFIG_SQUASHFS_XATTR=y
  1525. +CONFIG_SQUASHFS_LZO=y
  1526. +CONFIG_SQUASHFS_XZ=y
  1527. +CONFIG_F2FS_FS=y
  1528. +CONFIG_NFS_FS=y
  1529. +CONFIG_NFS_V3_ACL=y
  1530. +CONFIG_NFS_V4=y
  1531. +CONFIG_ROOT_NFS=y
  1532. +CONFIG_NFS_FSCACHE=y
  1533. +CONFIG_NFSD=m
  1534. +CONFIG_NFSD_V3_ACL=y
  1535. +CONFIG_NFSD_V4=y
  1536. +CONFIG_CIFS=m
  1537. +CONFIG_CIFS_WEAK_PW_HASH=y
  1538. +CONFIG_CIFS_XATTR=y
  1539. +CONFIG_CIFS_POSIX=y
  1540. +CONFIG_9P_FS=m
  1541. +CONFIG_9P_FS_POSIX_ACL=y
  1542. +CONFIG_NLS_DEFAULT="utf8"
  1543. +CONFIG_NLS_CODEPAGE_437=y
  1544. +CONFIG_NLS_CODEPAGE_737=m
  1545. +CONFIG_NLS_CODEPAGE_775=m
  1546. +CONFIG_NLS_CODEPAGE_850=m
  1547. +CONFIG_NLS_CODEPAGE_852=m
  1548. +CONFIG_NLS_CODEPAGE_855=m
  1549. +CONFIG_NLS_CODEPAGE_857=m
  1550. +CONFIG_NLS_CODEPAGE_860=m
  1551. +CONFIG_NLS_CODEPAGE_861=m
  1552. +CONFIG_NLS_CODEPAGE_862=m
  1553. +CONFIG_NLS_CODEPAGE_863=m
  1554. +CONFIG_NLS_CODEPAGE_864=m
  1555. +CONFIG_NLS_CODEPAGE_865=m
  1556. +CONFIG_NLS_CODEPAGE_866=m
  1557. +CONFIG_NLS_CODEPAGE_869=m
  1558. +CONFIG_NLS_CODEPAGE_936=m
  1559. +CONFIG_NLS_CODEPAGE_950=m
  1560. +CONFIG_NLS_CODEPAGE_932=m
  1561. +CONFIG_NLS_CODEPAGE_949=m
  1562. +CONFIG_NLS_CODEPAGE_874=m
  1563. +CONFIG_NLS_ISO8859_8=m
  1564. +CONFIG_NLS_CODEPAGE_1250=m
  1565. +CONFIG_NLS_CODEPAGE_1251=m
  1566. +CONFIG_NLS_ASCII=y
  1567. +CONFIG_NLS_ISO8859_1=m
  1568. +CONFIG_NLS_ISO8859_2=m
  1569. +CONFIG_NLS_ISO8859_3=m
  1570. +CONFIG_NLS_ISO8859_4=m
  1571. +CONFIG_NLS_ISO8859_5=m
  1572. +CONFIG_NLS_ISO8859_6=m
  1573. +CONFIG_NLS_ISO8859_7=m
  1574. +CONFIG_NLS_ISO8859_9=m
  1575. +CONFIG_NLS_ISO8859_13=m
  1576. +CONFIG_NLS_ISO8859_14=m
  1577. +CONFIG_NLS_ISO8859_15=m
  1578. +CONFIG_NLS_KOI8_R=m
  1579. +CONFIG_NLS_KOI8_U=m
  1580. +CONFIG_DLM=m
  1581. +CONFIG_PRINTK_TIME=y
  1582. +CONFIG_BOOT_PRINTK_DELAY=y
  1583. +CONFIG_DEBUG_FS=y
  1584. +CONFIG_DEBUG_MEMORY_INIT=y
  1585. +CONFIG_DETECT_HUNG_TASK=y
  1586. +CONFIG_TIMER_STATS=y
  1587. +# CONFIG_DEBUG_PREEMPT is not set
  1588. +CONFIG_LATENCYTOP=y
  1589. +# CONFIG_KPROBE_EVENT is not set
  1590. +CONFIG_KGDB=y
  1591. +CONFIG_KGDB_KDB=y
  1592. +CONFIG_KDB_KEYBOARD=y
  1593. +CONFIG_STRICT_DEVMEM=y
  1594. +CONFIG_CRYPTO_USER=m
  1595. +CONFIG_CRYPTO_NULL=m
  1596. +CONFIG_CRYPTO_CRYPTD=m
  1597. +CONFIG_CRYPTO_CBC=y
  1598. +CONFIG_CRYPTO_XTS=m
  1599. +CONFIG_CRYPTO_XCBC=m
  1600. +CONFIG_CRYPTO_SHA1_ARM=m
  1601. +CONFIG_CRYPTO_SHA512=m
  1602. +CONFIG_CRYPTO_TGR192=m
  1603. +CONFIG_CRYPTO_WP512=m
  1604. +CONFIG_CRYPTO_AES_ARM=m
  1605. +CONFIG_CRYPTO_CAST5=m
  1606. +CONFIG_CRYPTO_DES=y
  1607. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  1608. +# CONFIG_CRYPTO_HW is not set
  1609. +CONFIG_CRC_ITU_T=y
  1610. +CONFIG_LIBCRC32C=y
  1611. diff -Nur linux-3.15/arch/arm/configs/bcmrpi_emergency_defconfig linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig
  1612. --- linux-3.15/arch/arm/configs/bcmrpi_emergency_defconfig 1970-01-01 01:00:00.000000000 +0100
  1613. +++ linux-rpi/arch/arm/configs/bcmrpi_emergency_defconfig 2014-06-11 21:03:19.000000000 +0200
  1614. @@ -0,0 +1,532 @@
  1615. +CONFIG_EXPERIMENTAL=y
  1616. +# CONFIG_LOCALVERSION_AUTO is not set
  1617. +CONFIG_SYSVIPC=y
  1618. +CONFIG_POSIX_MQUEUE=y
  1619. +CONFIG_BSD_PROCESS_ACCT=y
  1620. +CONFIG_BSD_PROCESS_ACCT_V3=y
  1621. +CONFIG_FHANDLE=y
  1622. +CONFIG_AUDIT=y
  1623. +CONFIG_IKCONFIG=y
  1624. +CONFIG_IKCONFIG_PROC=y
  1625. +CONFIG_BLK_DEV_INITRD=y
  1626. +CONFIG_INITRAMFS_SOURCE="../target_fs"
  1627. +CONFIG_CGROUP_FREEZER=y
  1628. +CONFIG_CGROUP_DEVICE=y
  1629. +CONFIG_CGROUP_CPUACCT=y
  1630. +CONFIG_RESOURCE_COUNTERS=y
  1631. +CONFIG_BLK_CGROUP=y
  1632. +CONFIG_NAMESPACES=y
  1633. +CONFIG_SCHED_AUTOGROUP=y
  1634. +CONFIG_EMBEDDED=y
  1635. +# CONFIG_COMPAT_BRK is not set
  1636. +CONFIG_SLAB=y
  1637. +CONFIG_PROFILING=y
  1638. +CONFIG_OPROFILE=m
  1639. +CONFIG_KPROBES=y
  1640. +CONFIG_MODULES=y
  1641. +CONFIG_MODULE_UNLOAD=y
  1642. +CONFIG_MODVERSIONS=y
  1643. +CONFIG_MODULE_SRCVERSION_ALL=y
  1644. +# CONFIG_BLK_DEV_BSG is not set
  1645. +CONFIG_BLK_DEV_THROTTLING=y
  1646. +CONFIG_CFQ_GROUP_IOSCHED=y
  1647. +CONFIG_ARCH_BCM2708=y
  1648. +CONFIG_NO_HZ=y
  1649. +CONFIG_HIGH_RES_TIMERS=y
  1650. +CONFIG_AEABI=y
  1651. +CONFIG_SECCOMP=y
  1652. +CONFIG_CC_STACKPROTECTOR=y
  1653. +CONFIG_ZBOOT_ROM_TEXT=0x0
  1654. +CONFIG_ZBOOT_ROM_BSS=0x0
  1655. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext3 rootwait"
  1656. +CONFIG_KEXEC=y
  1657. +CONFIG_CPU_IDLE=y
  1658. +CONFIG_VFP=y
  1659. +CONFIG_BINFMT_MISC=m
  1660. +CONFIG_NET=y
  1661. +CONFIG_PACKET=y
  1662. +CONFIG_UNIX=y
  1663. +CONFIG_XFRM_USER=y
  1664. +CONFIG_NET_KEY=m
  1665. +CONFIG_INET=y
  1666. +CONFIG_IP_MULTICAST=y
  1667. +CONFIG_IP_PNP=y
  1668. +CONFIG_IP_PNP_DHCP=y
  1669. +CONFIG_IP_PNP_RARP=y
  1670. +CONFIG_SYN_COOKIES=y
  1671. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  1672. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  1673. +# CONFIG_INET_XFRM_MODE_BEET is not set
  1674. +# CONFIG_INET_LRO is not set
  1675. +# CONFIG_INET_DIAG is not set
  1676. +# CONFIG_IPV6 is not set
  1677. +CONFIG_NET_PKTGEN=m
  1678. +CONFIG_IRDA=m
  1679. +CONFIG_IRLAN=m
  1680. +CONFIG_IRCOMM=m
  1681. +CONFIG_IRDA_ULTRA=y
  1682. +CONFIG_IRDA_CACHE_LAST_LSAP=y
  1683. +CONFIG_IRDA_FAST_RR=y
  1684. +CONFIG_IRTTY_SIR=m
  1685. +CONFIG_KINGSUN_DONGLE=m
  1686. +CONFIG_KSDAZZLE_DONGLE=m
  1687. +CONFIG_KS959_DONGLE=m
  1688. +CONFIG_USB_IRDA=m
  1689. +CONFIG_SIGMATEL_FIR=m
  1690. +CONFIG_MCS_FIR=m
  1691. +CONFIG_BT=m
  1692. +CONFIG_BT_L2CAP=y
  1693. +CONFIG_BT_SCO=y
  1694. +CONFIG_BT_RFCOMM=m
  1695. +CONFIG_BT_RFCOMM_TTY=y
  1696. +CONFIG_BT_BNEP=m
  1697. +CONFIG_BT_BNEP_MC_FILTER=y
  1698. +CONFIG_BT_BNEP_PROTO_FILTER=y
  1699. +CONFIG_BT_HIDP=m
  1700. +CONFIG_BT_HCIBTUSB=m
  1701. +CONFIG_BT_HCIBCM203X=m
  1702. +CONFIG_BT_HCIBPA10X=m
  1703. +CONFIG_BT_HCIBFUSB=m
  1704. +CONFIG_BT_HCIVHCI=m
  1705. +CONFIG_BT_MRVL=m
  1706. +CONFIG_BT_MRVL_SDIO=m
  1707. +CONFIG_BT_ATH3K=m
  1708. +CONFIG_CFG80211=m
  1709. +CONFIG_MAC80211=m
  1710. +CONFIG_MAC80211_RC_PID=y
  1711. +CONFIG_MAC80211_MESH=y
  1712. +CONFIG_WIMAX=m
  1713. +CONFIG_NET_9P=m
  1714. +CONFIG_NFC=m
  1715. +CONFIG_NFC_PN533=m
  1716. +CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
  1717. +CONFIG_BLK_DEV_LOOP=y
  1718. +CONFIG_BLK_DEV_CRYPTOLOOP=m
  1719. +CONFIG_BLK_DEV_NBD=m
  1720. +CONFIG_BLK_DEV_RAM=y
  1721. +CONFIG_CDROM_PKTCDVD=m
  1722. +CONFIG_MISC_DEVICES=y
  1723. +CONFIG_SCSI=y
  1724. +# CONFIG_SCSI_PROC_FS is not set
  1725. +CONFIG_BLK_DEV_SD=y
  1726. +CONFIG_BLK_DEV_SR=m
  1727. +CONFIG_SCSI_MULTI_LUN=y
  1728. +# CONFIG_SCSI_LOWLEVEL is not set
  1729. +CONFIG_MD=y
  1730. +CONFIG_NETDEVICES=y
  1731. +CONFIG_TUN=m
  1732. +CONFIG_PHYLIB=m
  1733. +CONFIG_MDIO_BITBANG=m
  1734. +CONFIG_NET_ETHERNET=y
  1735. +# CONFIG_NETDEV_1000 is not set
  1736. +# CONFIG_NETDEV_10000 is not set
  1737. +CONFIG_LIBERTAS_THINFIRM=m
  1738. +CONFIG_LIBERTAS_THINFIRM_USB=m
  1739. +CONFIG_AT76C50X_USB=m
  1740. +CONFIG_USB_ZD1201=m
  1741. +CONFIG_USB_NET_RNDIS_WLAN=m
  1742. +CONFIG_RTL8187=m
  1743. +CONFIG_MAC80211_HWSIM=m
  1744. +CONFIG_ATH_COMMON=m
  1745. +CONFIG_ATH9K=m
  1746. +CONFIG_ATH9K_HTC=m
  1747. +CONFIG_CARL9170=m
  1748. +CONFIG_B43=m
  1749. +CONFIG_B43LEGACY=m
  1750. +CONFIG_HOSTAP=m
  1751. +CONFIG_IWM=m
  1752. +CONFIG_LIBERTAS=m
  1753. +CONFIG_LIBERTAS_USB=m
  1754. +CONFIG_LIBERTAS_SDIO=m
  1755. +CONFIG_P54_COMMON=m
  1756. +CONFIG_P54_USB=m
  1757. +CONFIG_RT2X00=m
  1758. +CONFIG_RT2500USB=m
  1759. +CONFIG_RT73USB=m
  1760. +CONFIG_RT2800USB=m
  1761. +CONFIG_RT2800USB_RT53XX=y
  1762. +CONFIG_RTL8192CU=m
  1763. +CONFIG_WL1251=m
  1764. +CONFIG_WL12XX_MENU=m
  1765. +CONFIG_ZD1211RW=m
  1766. +CONFIG_MWIFIEX=m
  1767. +CONFIG_MWIFIEX_SDIO=m
  1768. +CONFIG_WIMAX_I2400M_USB=m
  1769. +CONFIG_USB_CATC=m
  1770. +CONFIG_USB_KAWETH=m
  1771. +CONFIG_USB_PEGASUS=m
  1772. +CONFIG_USB_RTL8150=m
  1773. +CONFIG_USB_USBNET=y
  1774. +CONFIG_USB_NET_AX8817X=m
  1775. +CONFIG_USB_NET_CDCETHER=m
  1776. +CONFIG_USB_NET_CDC_EEM=m
  1777. +CONFIG_USB_NET_DM9601=m
  1778. +CONFIG_USB_NET_SMSC75XX=m
  1779. +CONFIG_USB_NET_SMSC95XX=y
  1780. +CONFIG_USB_NET_GL620A=m
  1781. +CONFIG_USB_NET_NET1080=m
  1782. +CONFIG_USB_NET_PLUSB=m
  1783. +CONFIG_USB_NET_MCS7830=m
  1784. +CONFIG_USB_NET_CDC_SUBSET=m
  1785. +CONFIG_USB_ALI_M5632=y
  1786. +CONFIG_USB_AN2720=y
  1787. +CONFIG_USB_KC2190=y
  1788. +# CONFIG_USB_NET_ZAURUS is not set
  1789. +CONFIG_USB_NET_CX82310_ETH=m
  1790. +CONFIG_USB_NET_KALMIA=m
  1791. +CONFIG_USB_NET_INT51X1=m
  1792. +CONFIG_USB_IPHETH=m
  1793. +CONFIG_USB_SIERRA_NET=m
  1794. +CONFIG_USB_VL600=m
  1795. +CONFIG_PPP=m
  1796. +CONFIG_PPP_ASYNC=m
  1797. +CONFIG_PPP_SYNC_TTY=m
  1798. +CONFIG_PPP_DEFLATE=m
  1799. +CONFIG_PPP_BSDCOMP=m
  1800. +CONFIG_SLIP=m
  1801. +CONFIG_SLIP_COMPRESSED=y
  1802. +CONFIG_NETCONSOLE=m
  1803. +CONFIG_INPUT_POLLDEV=m
  1804. +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
  1805. +CONFIG_INPUT_JOYDEV=m
  1806. +CONFIG_INPUT_EVDEV=m
  1807. +# CONFIG_INPUT_KEYBOARD is not set
  1808. +# CONFIG_INPUT_MOUSE is not set
  1809. +CONFIG_INPUT_MISC=y
  1810. +CONFIG_INPUT_AD714X=m
  1811. +CONFIG_INPUT_ATI_REMOTE=m
  1812. +CONFIG_INPUT_ATI_REMOTE2=m
  1813. +CONFIG_INPUT_KEYSPAN_REMOTE=m
  1814. +CONFIG_INPUT_POWERMATE=m
  1815. +CONFIG_INPUT_YEALINK=m
  1816. +CONFIG_INPUT_CM109=m
  1817. +CONFIG_INPUT_UINPUT=m
  1818. +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m
  1819. +CONFIG_INPUT_ADXL34X=m
  1820. +CONFIG_INPUT_CMA3000=m
  1821. +CONFIG_SERIO=m
  1822. +CONFIG_SERIO_RAW=m
  1823. +CONFIG_GAMEPORT=m
  1824. +CONFIG_GAMEPORT_NS558=m
  1825. +CONFIG_GAMEPORT_L4=m
  1826. +CONFIG_VT_HW_CONSOLE_BINDING=y
  1827. +# CONFIG_LEGACY_PTYS is not set
  1828. +# CONFIG_DEVKMEM is not set
  1829. +CONFIG_SERIAL_AMBA_PL011=y
  1830. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  1831. +# CONFIG_HW_RANDOM is not set
  1832. +CONFIG_RAW_DRIVER=y
  1833. +CONFIG_GPIO_SYSFS=y
  1834. +# CONFIG_HWMON is not set
  1835. +CONFIG_WATCHDOG=y
  1836. +CONFIG_BCM2708_WDT=m
  1837. +# CONFIG_MFD_SUPPORT is not set
  1838. +CONFIG_FB=y
  1839. +CONFIG_FB_BCM2708=y
  1840. +CONFIG_FRAMEBUFFER_CONSOLE=y
  1841. +CONFIG_LOGO=y
  1842. +# CONFIG_LOGO_LINUX_MONO is not set
  1843. +# CONFIG_LOGO_LINUX_VGA16 is not set
  1844. +CONFIG_SOUND=y
  1845. +CONFIG_SND=m
  1846. +CONFIG_SND_SEQUENCER=m
  1847. +CONFIG_SND_SEQ_DUMMY=m
  1848. +CONFIG_SND_MIXER_OSS=m
  1849. +CONFIG_SND_PCM_OSS=m
  1850. +CONFIG_SND_SEQUENCER_OSS=y
  1851. +CONFIG_SND_HRTIMER=m
  1852. +CONFIG_SND_DUMMY=m
  1853. +CONFIG_SND_ALOOP=m
  1854. +CONFIG_SND_VIRMIDI=m
  1855. +CONFIG_SND_MTPAV=m
  1856. +CONFIG_SND_SERIAL_U16550=m
  1857. +CONFIG_SND_MPU401=m
  1858. +CONFIG_SND_BCM2835=m
  1859. +CONFIG_SND_USB_AUDIO=m
  1860. +CONFIG_SND_USB_UA101=m
  1861. +CONFIG_SND_USB_CAIAQ=m
  1862. +CONFIG_SND_USB_6FIRE=m
  1863. +CONFIG_SOUND_PRIME=m
  1864. +CONFIG_HID_PID=y
  1865. +CONFIG_USB_HIDDEV=y
  1866. +CONFIG_HID_A4TECH=m
  1867. +CONFIG_HID_ACRUX=m
  1868. +CONFIG_HID_APPLE=m
  1869. +CONFIG_HID_BELKIN=m
  1870. +CONFIG_HID_CHERRY=m
  1871. +CONFIG_HID_CHICONY=m
  1872. +CONFIG_HID_CYPRESS=m
  1873. +CONFIG_HID_DRAGONRISE=m
  1874. +CONFIG_HID_EMS_FF=m
  1875. +CONFIG_HID_ELECOM=m
  1876. +CONFIG_HID_EZKEY=m
  1877. +CONFIG_HID_HOLTEK=m
  1878. +CONFIG_HID_KEYTOUCH=m
  1879. +CONFIG_HID_KYE=m
  1880. +CONFIG_HID_UCLOGIC=m
  1881. +CONFIG_HID_WALTOP=m
  1882. +CONFIG_HID_GYRATION=m
  1883. +CONFIG_HID_TWINHAN=m
  1884. +CONFIG_HID_KENSINGTON=m
  1885. +CONFIG_HID_LCPOWER=m
  1886. +CONFIG_HID_LOGITECH=m
  1887. +CONFIG_HID_MAGICMOUSE=m
  1888. +CONFIG_HID_MICROSOFT=m
  1889. +CONFIG_HID_MONTEREY=m
  1890. +CONFIG_HID_MULTITOUCH=m
  1891. +CONFIG_HID_NTRIG=m
  1892. +CONFIG_HID_ORTEK=m
  1893. +CONFIG_HID_PANTHERLORD=m
  1894. +CONFIG_HID_PETALYNX=m
  1895. +CONFIG_HID_PICOLCD=m
  1896. +CONFIG_HID_QUANTA=m
  1897. +CONFIG_HID_ROCCAT=m
  1898. +CONFIG_HID_SAMSUNG=m
  1899. +CONFIG_HID_SONY=m
  1900. +CONFIG_HID_SPEEDLINK=m
  1901. +CONFIG_HID_SUNPLUS=m
  1902. +CONFIG_HID_GREENASIA=m
  1903. +CONFIG_HID_SMARTJOYPLUS=m
  1904. +CONFIG_HID_TOPSEED=m
  1905. +CONFIG_HID_THRUSTMASTER=m
  1906. +CONFIG_HID_WACOM=m
  1907. +CONFIG_HID_WIIMOTE=m
  1908. +CONFIG_HID_ZEROPLUS=m
  1909. +CONFIG_HID_ZYDACRON=m
  1910. +CONFIG_USB=y
  1911. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  1912. +CONFIG_USB_MON=m
  1913. +CONFIG_USB_DWCOTG=y
  1914. +CONFIG_USB_STORAGE=y
  1915. +CONFIG_USB_STORAGE_REALTEK=m
  1916. +CONFIG_USB_STORAGE_DATAFAB=m
  1917. +CONFIG_USB_STORAGE_FREECOM=m
  1918. +CONFIG_USB_STORAGE_ISD200=m
  1919. +CONFIG_USB_STORAGE_USBAT=m
  1920. +CONFIG_USB_STORAGE_SDDR09=m
  1921. +CONFIG_USB_STORAGE_SDDR55=m
  1922. +CONFIG_USB_STORAGE_JUMPSHOT=m
  1923. +CONFIG_USB_STORAGE_ALAUDA=m
  1924. +CONFIG_USB_STORAGE_ONETOUCH=m
  1925. +CONFIG_USB_STORAGE_KARMA=m
  1926. +CONFIG_USB_STORAGE_CYPRESS_ATACB=m
  1927. +CONFIG_USB_STORAGE_ENE_UB6250=m
  1928. +CONFIG_USB_UAS=y
  1929. +CONFIG_USB_LIBUSUAL=y
  1930. +CONFIG_USB_MDC800=m
  1931. +CONFIG_USB_MICROTEK=m
  1932. +CONFIG_USB_SERIAL=m
  1933. +CONFIG_USB_SERIAL_GENERIC=y
  1934. +CONFIG_USB_SERIAL_AIRCABLE=m
  1935. +CONFIG_USB_SERIAL_ARK3116=m
  1936. +CONFIG_USB_SERIAL_BELKIN=m
  1937. +CONFIG_USB_SERIAL_CH341=m
  1938. +CONFIG_USB_SERIAL_WHITEHEAT=m
  1939. +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m
  1940. +CONFIG_USB_SERIAL_CP210X=m
  1941. +CONFIG_USB_SERIAL_CYPRESS_M8=m
  1942. +CONFIG_USB_SERIAL_EMPEG=m
  1943. +CONFIG_USB_SERIAL_FTDI_SIO=m
  1944. +CONFIG_USB_SERIAL_FUNSOFT=m
  1945. +CONFIG_USB_SERIAL_VISOR=m
  1946. +CONFIG_USB_SERIAL_IPAQ=m
  1947. +CONFIG_USB_SERIAL_IR=m
  1948. +CONFIG_USB_SERIAL_EDGEPORT=m
  1949. +CONFIG_USB_SERIAL_EDGEPORT_TI=m
  1950. +CONFIG_USB_SERIAL_GARMIN=m
  1951. +CONFIG_USB_SERIAL_IPW=m
  1952. +CONFIG_USB_SERIAL_IUU=m
  1953. +CONFIG_USB_SERIAL_KEYSPAN_PDA=m
  1954. +CONFIG_USB_SERIAL_KEYSPAN=m
  1955. +CONFIG_USB_SERIAL_KLSI=m
  1956. +CONFIG_USB_SERIAL_KOBIL_SCT=m
  1957. +CONFIG_USB_SERIAL_MCT_U232=m
  1958. +CONFIG_USB_SERIAL_MOS7720=m
  1959. +CONFIG_USB_SERIAL_MOS7840=m
  1960. +CONFIG_USB_SERIAL_MOTOROLA=m
  1961. +CONFIG_USB_SERIAL_NAVMAN=m
  1962. +CONFIG_USB_SERIAL_PL2303=m
  1963. +CONFIG_USB_SERIAL_OTI6858=m
  1964. +CONFIG_USB_SERIAL_QCAUX=m
  1965. +CONFIG_USB_SERIAL_QUALCOMM=m
  1966. +CONFIG_USB_SERIAL_SPCP8X5=m
  1967. +CONFIG_USB_SERIAL_HP4X=m
  1968. +CONFIG_USB_SERIAL_SAFE=m
  1969. +CONFIG_USB_SERIAL_SIEMENS_MPI=m
  1970. +CONFIG_USB_SERIAL_SIERRAWIRELESS=m
  1971. +CONFIG_USB_SERIAL_SYMBOL=m
  1972. +CONFIG_USB_SERIAL_TI=m
  1973. +CONFIG_USB_SERIAL_CYBERJACK=m
  1974. +CONFIG_USB_SERIAL_XIRCOM=m
  1975. +CONFIG_USB_SERIAL_OPTION=m
  1976. +CONFIG_USB_SERIAL_OMNINET=m
  1977. +CONFIG_USB_SERIAL_OPTICON=m
  1978. +CONFIG_USB_SERIAL_VIVOPAY_SERIAL=m
  1979. +CONFIG_USB_SERIAL_ZIO=m
  1980. +CONFIG_USB_SERIAL_SSU100=m
  1981. +CONFIG_USB_SERIAL_DEBUG=m
  1982. +CONFIG_USB_EMI62=m
  1983. +CONFIG_USB_EMI26=m
  1984. +CONFIG_USB_ADUTUX=m
  1985. +CONFIG_USB_SEVSEG=m
  1986. +CONFIG_USB_RIO500=m
  1987. +CONFIG_USB_LEGOTOWER=m
  1988. +CONFIG_USB_LCD=m
  1989. +CONFIG_USB_LED=m
  1990. +CONFIG_USB_CYPRESS_CY7C63=m
  1991. +CONFIG_USB_CYTHERM=m
  1992. +CONFIG_USB_IDMOUSE=m
  1993. +CONFIG_USB_FTDI_ELAN=m
  1994. +CONFIG_USB_APPLEDISPLAY=m
  1995. +CONFIG_USB_LD=m
  1996. +CONFIG_USB_TRANCEVIBRATOR=m
  1997. +CONFIG_USB_IOWARRIOR=m
  1998. +CONFIG_USB_TEST=m
  1999. +CONFIG_USB_ISIGHTFW=m
  2000. +CONFIG_USB_YUREX=m
  2001. +CONFIG_MMC=y
  2002. +CONFIG_MMC_SDHCI=y
  2003. +CONFIG_MMC_SDHCI_PLTFM=y
  2004. +CONFIG_MMC_SDHCI_BCM2708=y
  2005. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2006. +CONFIG_LEDS_GPIO=y
  2007. +CONFIG_LEDS_TRIGGER_TIMER=m
  2008. +CONFIG_LEDS_TRIGGER_HEARTBEAT=m
  2009. +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m
  2010. +CONFIG_UIO=m
  2011. +CONFIG_UIO_PDRV=m
  2012. +CONFIG_UIO_PDRV_GENIRQ=m
  2013. +# CONFIG_IOMMU_SUPPORT is not set
  2014. +CONFIG_EXT4_FS=y
  2015. +CONFIG_EXT4_FS_POSIX_ACL=y
  2016. +CONFIG_EXT4_FS_SECURITY=y
  2017. +CONFIG_REISERFS_FS=m
  2018. +CONFIG_REISERFS_FS_XATTR=y
  2019. +CONFIG_REISERFS_FS_POSIX_ACL=y
  2020. +CONFIG_REISERFS_FS_SECURITY=y
  2021. +CONFIG_JFS_FS=m
  2022. +CONFIG_JFS_POSIX_ACL=y
  2023. +CONFIG_JFS_SECURITY=y
  2024. +CONFIG_JFS_STATISTICS=y
  2025. +CONFIG_XFS_FS=m
  2026. +CONFIG_XFS_QUOTA=y
  2027. +CONFIG_XFS_POSIX_ACL=y
  2028. +CONFIG_XFS_RT=y
  2029. +CONFIG_GFS2_FS=m
  2030. +CONFIG_OCFS2_FS=m
  2031. +CONFIG_BTRFS_FS=m
  2032. +CONFIG_BTRFS_FS_POSIX_ACL=y
  2033. +CONFIG_NILFS2_FS=m
  2034. +CONFIG_FANOTIFY=y
  2035. +CONFIG_AUTOFS4_FS=y
  2036. +CONFIG_FUSE_FS=m
  2037. +CONFIG_CUSE=m
  2038. +CONFIG_FSCACHE=y
  2039. +CONFIG_FSCACHE_STATS=y
  2040. +CONFIG_FSCACHE_HISTOGRAM=y
  2041. +CONFIG_CACHEFILES=y
  2042. +CONFIG_ISO9660_FS=m
  2043. +CONFIG_JOLIET=y
  2044. +CONFIG_ZISOFS=y
  2045. +CONFIG_UDF_FS=m
  2046. +CONFIG_MSDOS_FS=y
  2047. +CONFIG_VFAT_FS=y
  2048. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2049. +CONFIG_NTFS_FS=m
  2050. +CONFIG_TMPFS=y
  2051. +CONFIG_TMPFS_POSIX_ACL=y
  2052. +CONFIG_CONFIGFS_FS=y
  2053. +CONFIG_SQUASHFS=m
  2054. +CONFIG_SQUASHFS_XATTR=y
  2055. +CONFIG_SQUASHFS_LZO=y
  2056. +CONFIG_SQUASHFS_XZ=y
  2057. +CONFIG_NFS_FS=y
  2058. +CONFIG_NFS_V3=y
  2059. +CONFIG_NFS_V3_ACL=y
  2060. +CONFIG_NFS_V4=y
  2061. +CONFIG_ROOT_NFS=y
  2062. +CONFIG_NFS_FSCACHE=y
  2063. +CONFIG_CIFS=m
  2064. +CONFIG_CIFS_WEAK_PW_HASH=y
  2065. +CONFIG_CIFS_XATTR=y
  2066. +CONFIG_CIFS_POSIX=y
  2067. +CONFIG_9P_FS=m
  2068. +CONFIG_9P_FS_POSIX_ACL=y
  2069. +CONFIG_PARTITION_ADVANCED=y
  2070. +CONFIG_MAC_PARTITION=y
  2071. +CONFIG_EFI_PARTITION=y
  2072. +CONFIG_NLS_DEFAULT="utf8"
  2073. +CONFIG_NLS_CODEPAGE_437=y
  2074. +CONFIG_NLS_CODEPAGE_737=m
  2075. +CONFIG_NLS_CODEPAGE_775=m
  2076. +CONFIG_NLS_CODEPAGE_850=m
  2077. +CONFIG_NLS_CODEPAGE_852=m
  2078. +CONFIG_NLS_CODEPAGE_855=m
  2079. +CONFIG_NLS_CODEPAGE_857=m
  2080. +CONFIG_NLS_CODEPAGE_860=m
  2081. +CONFIG_NLS_CODEPAGE_861=m
  2082. +CONFIG_NLS_CODEPAGE_862=m
  2083. +CONFIG_NLS_CODEPAGE_863=m
  2084. +CONFIG_NLS_CODEPAGE_864=m
  2085. +CONFIG_NLS_CODEPAGE_865=m
  2086. +CONFIG_NLS_CODEPAGE_866=m
  2087. +CONFIG_NLS_CODEPAGE_869=m
  2088. +CONFIG_NLS_CODEPAGE_936=m
  2089. +CONFIG_NLS_CODEPAGE_950=m
  2090. +CONFIG_NLS_CODEPAGE_932=m
  2091. +CONFIG_NLS_CODEPAGE_949=m
  2092. +CONFIG_NLS_CODEPAGE_874=m
  2093. +CONFIG_NLS_ISO8859_8=m
  2094. +CONFIG_NLS_CODEPAGE_1250=m
  2095. +CONFIG_NLS_CODEPAGE_1251=m
  2096. +CONFIG_NLS_ASCII=y
  2097. +CONFIG_NLS_ISO8859_1=m
  2098. +CONFIG_NLS_ISO8859_2=m
  2099. +CONFIG_NLS_ISO8859_3=m
  2100. +CONFIG_NLS_ISO8859_4=m
  2101. +CONFIG_NLS_ISO8859_5=m
  2102. +CONFIG_NLS_ISO8859_6=m
  2103. +CONFIG_NLS_ISO8859_7=m
  2104. +CONFIG_NLS_ISO8859_9=m
  2105. +CONFIG_NLS_ISO8859_13=m
  2106. +CONFIG_NLS_ISO8859_14=m
  2107. +CONFIG_NLS_ISO8859_15=m
  2108. +CONFIG_NLS_KOI8_R=m
  2109. +CONFIG_NLS_KOI8_U=m
  2110. +CONFIG_NLS_UTF8=m
  2111. +CONFIG_PRINTK_TIME=y
  2112. +CONFIG_DETECT_HUNG_TASK=y
  2113. +CONFIG_TIMER_STATS=y
  2114. +CONFIG_DEBUG_STACK_USAGE=y
  2115. +CONFIG_DEBUG_INFO=y
  2116. +CONFIG_DEBUG_MEMORY_INIT=y
  2117. +CONFIG_BOOT_PRINTK_DELAY=y
  2118. +CONFIG_LATENCYTOP=y
  2119. +CONFIG_SYSCTL_SYSCALL_CHECK=y
  2120. +CONFIG_IRQSOFF_TRACER=y
  2121. +CONFIG_SCHED_TRACER=y
  2122. +CONFIG_STACK_TRACER=y
  2123. +CONFIG_BLK_DEV_IO_TRACE=y
  2124. +CONFIG_FUNCTION_PROFILER=y
  2125. +CONFIG_KGDB=y
  2126. +CONFIG_KGDB_KDB=y
  2127. +CONFIG_KDB_KEYBOARD=y
  2128. +CONFIG_STRICT_DEVMEM=y
  2129. +CONFIG_CRYPTO_AUTHENC=m
  2130. +CONFIG_CRYPTO_SEQIV=m
  2131. +CONFIG_CRYPTO_CBC=y
  2132. +CONFIG_CRYPTO_HMAC=y
  2133. +CONFIG_CRYPTO_XCBC=m
  2134. +CONFIG_CRYPTO_MD5=y
  2135. +CONFIG_CRYPTO_SHA1=y
  2136. +CONFIG_CRYPTO_SHA256=m
  2137. +CONFIG_CRYPTO_SHA512=m
  2138. +CONFIG_CRYPTO_TGR192=m
  2139. +CONFIG_CRYPTO_WP512=m
  2140. +CONFIG_CRYPTO_CAST5=m
  2141. +CONFIG_CRYPTO_DES=y
  2142. +CONFIG_CRYPTO_DEFLATE=m
  2143. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2144. +# CONFIG_CRYPTO_HW is not set
  2145. +CONFIG_CRC_ITU_T=y
  2146. +CONFIG_LIBCRC32C=y
  2147. diff -Nur linux-3.15/arch/arm/configs/bcmrpi_quick_defconfig linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig
  2148. --- linux-3.15/arch/arm/configs/bcmrpi_quick_defconfig 1970-01-01 01:00:00.000000000 +0100
  2149. +++ linux-rpi/arch/arm/configs/bcmrpi_quick_defconfig 2014-06-11 21:03:19.000000000 +0200
  2150. @@ -0,0 +1,197 @@
  2151. +# CONFIG_ARM_PATCH_PHYS_VIRT is not set
  2152. +CONFIG_LOCALVERSION="-quick"
  2153. +# CONFIG_LOCALVERSION_AUTO is not set
  2154. +# CONFIG_SWAP is not set
  2155. +CONFIG_SYSVIPC=y
  2156. +CONFIG_POSIX_MQUEUE=y
  2157. +CONFIG_NO_HZ=y
  2158. +CONFIG_HIGH_RES_TIMERS=y
  2159. +CONFIG_IKCONFIG=y
  2160. +CONFIG_IKCONFIG_PROC=y
  2161. +CONFIG_KALLSYMS_ALL=y
  2162. +CONFIG_EMBEDDED=y
  2163. +CONFIG_PERF_EVENTS=y
  2164. +# CONFIG_COMPAT_BRK is not set
  2165. +CONFIG_SLAB=y
  2166. +CONFIG_MODULES=y
  2167. +CONFIG_MODULE_UNLOAD=y
  2168. +CONFIG_MODVERSIONS=y
  2169. +CONFIG_MODULE_SRCVERSION_ALL=y
  2170. +# CONFIG_BLK_DEV_BSG is not set
  2171. +CONFIG_ARCH_BCM2708=y
  2172. +CONFIG_PREEMPT=y
  2173. +CONFIG_AEABI=y
  2174. +CONFIG_UACCESS_WITH_MEMCPY=y
  2175. +CONFIG_ZBOOT_ROM_TEXT=0x0
  2176. +CONFIG_ZBOOT_ROM_BSS=0x0
  2177. +CONFIG_CMDLINE="dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait"
  2178. +CONFIG_CPU_FREQ=y
  2179. +CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
  2180. +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
  2181. +CONFIG_CPU_FREQ_GOV_USERSPACE=y
  2182. +CONFIG_CPU_FREQ_GOV_ONDEMAND=y
  2183. +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
  2184. +CONFIG_CPU_IDLE=y
  2185. +CONFIG_VFP=y
  2186. +CONFIG_BINFMT_MISC=y
  2187. +CONFIG_NET=y
  2188. +CONFIG_PACKET=y
  2189. +CONFIG_UNIX=y
  2190. +CONFIG_INET=y
  2191. +CONFIG_IP_MULTICAST=y
  2192. +CONFIG_IP_PNP=y
  2193. +CONFIG_IP_PNP_DHCP=y
  2194. +CONFIG_IP_PNP_RARP=y
  2195. +CONFIG_SYN_COOKIES=y
  2196. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  2197. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  2198. +# CONFIG_INET_XFRM_MODE_BEET is not set
  2199. +# CONFIG_INET_LRO is not set
  2200. +# CONFIG_INET_DIAG is not set
  2201. +# CONFIG_IPV6 is not set
  2202. +# CONFIG_WIRELESS is not set
  2203. +CONFIG_DEVTMPFS=y
  2204. +CONFIG_DEVTMPFS_MOUNT=y
  2205. +CONFIG_BLK_DEV_LOOP=y
  2206. +CONFIG_BLK_DEV_RAM=y
  2207. +CONFIG_SCSI=y
  2208. +# CONFIG_SCSI_PROC_FS is not set
  2209. +# CONFIG_SCSI_LOWLEVEL is not set
  2210. +CONFIG_NETDEVICES=y
  2211. +# CONFIG_NET_VENDOR_BROADCOM is not set
  2212. +# CONFIG_NET_VENDOR_CIRRUS is not set
  2213. +# CONFIG_NET_VENDOR_FARADAY is not set
  2214. +# CONFIG_NET_VENDOR_INTEL is not set
  2215. +# CONFIG_NET_VENDOR_MARVELL is not set
  2216. +# CONFIG_NET_VENDOR_MICREL is not set
  2217. +# CONFIG_NET_VENDOR_NATSEMI is not set
  2218. +# CONFIG_NET_VENDOR_SEEQ is not set
  2219. +# CONFIG_NET_VENDOR_STMICRO is not set
  2220. +# CONFIG_NET_VENDOR_WIZNET is not set
  2221. +CONFIG_USB_USBNET=y
  2222. +# CONFIG_USB_NET_AX8817X is not set
  2223. +# CONFIG_USB_NET_CDCETHER is not set
  2224. +# CONFIG_USB_NET_CDC_NCM is not set
  2225. +CONFIG_USB_NET_SMSC95XX=y
  2226. +# CONFIG_USB_NET_NET1080 is not set
  2227. +# CONFIG_USB_NET_CDC_SUBSET is not set
  2228. +# CONFIG_USB_NET_ZAURUS is not set
  2229. +# CONFIG_WLAN is not set
  2230. +# CONFIG_INPUT_MOUSEDEV is not set
  2231. +CONFIG_INPUT_EVDEV=y
  2232. +# CONFIG_INPUT_KEYBOARD is not set
  2233. +# CONFIG_INPUT_MOUSE is not set
  2234. +# CONFIG_SERIO is not set
  2235. +CONFIG_VT_HW_CONSOLE_BINDING=y
  2236. +# CONFIG_LEGACY_PTYS is not set
  2237. +# CONFIG_DEVKMEM is not set
  2238. +CONFIG_SERIAL_AMBA_PL011=y
  2239. +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y
  2240. +CONFIG_TTY_PRINTK=y
  2241. +CONFIG_HW_RANDOM=y
  2242. +CONFIG_HW_RANDOM_BCM2708=y
  2243. +CONFIG_RAW_DRIVER=y
  2244. +CONFIG_THERMAL=y
  2245. +CONFIG_THERMAL_BCM2835=y
  2246. +CONFIG_WATCHDOG=y
  2247. +CONFIG_BCM2708_WDT=y
  2248. +CONFIG_REGULATOR=y
  2249. +CONFIG_REGULATOR_DEBUG=y
  2250. +CONFIG_REGULATOR_FIXED_VOLTAGE=y
  2251. +CONFIG_REGULATOR_VIRTUAL_CONSUMER=y
  2252. +CONFIG_REGULATOR_USERSPACE_CONSUMER=y
  2253. +CONFIG_FB=y
  2254. +CONFIG_FB_BCM2708=y
  2255. +CONFIG_FRAMEBUFFER_CONSOLE=y
  2256. +CONFIG_LOGO=y
  2257. +# CONFIG_LOGO_LINUX_MONO is not set
  2258. +# CONFIG_LOGO_LINUX_VGA16 is not set
  2259. +CONFIG_SOUND=y
  2260. +CONFIG_SND=y
  2261. +CONFIG_SND_BCM2835=y
  2262. +# CONFIG_SND_USB is not set
  2263. +CONFIG_USB=y
  2264. +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
  2265. +CONFIG_USB_DWCOTG=y
  2266. +CONFIG_MMC=y
  2267. +CONFIG_MMC_SDHCI=y
  2268. +CONFIG_MMC_SDHCI_PLTFM=y
  2269. +CONFIG_MMC_SDHCI_BCM2708=y
  2270. +CONFIG_MMC_SDHCI_BCM2708_DMA=y
  2271. +CONFIG_NEW_LEDS=y
  2272. +CONFIG_LEDS_CLASS=y
  2273. +CONFIG_LEDS_TRIGGERS=y
  2274. +# CONFIG_IOMMU_SUPPORT is not set
  2275. +CONFIG_EXT4_FS=y
  2276. +CONFIG_EXT4_FS_POSIX_ACL=y
  2277. +CONFIG_EXT4_FS_SECURITY=y
  2278. +CONFIG_AUTOFS4_FS=y
  2279. +CONFIG_FSCACHE=y
  2280. +CONFIG_CACHEFILES=y
  2281. +CONFIG_MSDOS_FS=y
  2282. +CONFIG_VFAT_FS=y
  2283. +CONFIG_FAT_DEFAULT_IOCHARSET="ascii"
  2284. +CONFIG_TMPFS=y
  2285. +CONFIG_TMPFS_POSIX_ACL=y
  2286. +CONFIG_CONFIGFS_FS=y
  2287. +# CONFIG_MISC_FILESYSTEMS is not set
  2288. +CONFIG_NFS_FS=y
  2289. +CONFIG_NFS_V3_ACL=y
  2290. +CONFIG_NFS_V4=y
  2291. +CONFIG_ROOT_NFS=y
  2292. +CONFIG_NFS_FSCACHE=y
  2293. +CONFIG_NLS_DEFAULT="utf8"
  2294. +CONFIG_NLS_CODEPAGE_437=y
  2295. +CONFIG_NLS_CODEPAGE_737=y
  2296. +CONFIG_NLS_CODEPAGE_775=y
  2297. +CONFIG_NLS_CODEPAGE_850=y
  2298. +CONFIG_NLS_CODEPAGE_852=y
  2299. +CONFIG_NLS_CODEPAGE_855=y
  2300. +CONFIG_NLS_CODEPAGE_857=y
  2301. +CONFIG_NLS_CODEPAGE_860=y
  2302. +CONFIG_NLS_CODEPAGE_861=y
  2303. +CONFIG_NLS_CODEPAGE_862=y
  2304. +CONFIG_NLS_CODEPAGE_863=y
  2305. +CONFIG_NLS_CODEPAGE_864=y
  2306. +CONFIG_NLS_CODEPAGE_865=y
  2307. +CONFIG_NLS_CODEPAGE_866=y
  2308. +CONFIG_NLS_CODEPAGE_869=y
  2309. +CONFIG_NLS_CODEPAGE_936=y
  2310. +CONFIG_NLS_CODEPAGE_950=y
  2311. +CONFIG_NLS_CODEPAGE_932=y
  2312. +CONFIG_NLS_CODEPAGE_949=y
  2313. +CONFIG_NLS_CODEPAGE_874=y
  2314. +CONFIG_NLS_ISO8859_8=y
  2315. +CONFIG_NLS_CODEPAGE_1250=y
  2316. +CONFIG_NLS_CODEPAGE_1251=y
  2317. +CONFIG_NLS_ASCII=y
  2318. +CONFIG_NLS_ISO8859_1=y
  2319. +CONFIG_NLS_ISO8859_2=y
  2320. +CONFIG_NLS_ISO8859_3=y
  2321. +CONFIG_NLS_ISO8859_4=y
  2322. +CONFIG_NLS_ISO8859_5=y
  2323. +CONFIG_NLS_ISO8859_6=y
  2324. +CONFIG_NLS_ISO8859_7=y
  2325. +CONFIG_NLS_ISO8859_9=y
  2326. +CONFIG_NLS_ISO8859_13=y
  2327. +CONFIG_NLS_ISO8859_14=y
  2328. +CONFIG_NLS_ISO8859_15=y
  2329. +CONFIG_NLS_UTF8=y
  2330. +CONFIG_PRINTK_TIME=y
  2331. +CONFIG_DEBUG_FS=y
  2332. +CONFIG_DETECT_HUNG_TASK=y
  2333. +# CONFIG_DEBUG_PREEMPT is not set
  2334. +# CONFIG_DEBUG_BUGVERBOSE is not set
  2335. +# CONFIG_FTRACE is not set
  2336. +CONFIG_KGDB=y
  2337. +CONFIG_KGDB_KDB=y
  2338. +# CONFIG_ARM_UNWIND is not set
  2339. +CONFIG_CRYPTO_CBC=y
  2340. +CONFIG_CRYPTO_HMAC=y
  2341. +CONFIG_CRYPTO_MD5=y
  2342. +CONFIG_CRYPTO_SHA1=y
  2343. +CONFIG_CRYPTO_DES=y
  2344. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  2345. +# CONFIG_CRYPTO_HW is not set
  2346. +CONFIG_CRC_ITU_T=y
  2347. +CONFIG_LIBCRC32C=y
  2348. diff -Nur linux-3.15/arch/arm/include/asm/irqflags.h linux-rpi/arch/arm/include/asm/irqflags.h
  2349. --- linux-3.15/arch/arm/include/asm/irqflags.h 2014-06-08 20:19:54.000000000 +0200
  2350. +++ linux-rpi/arch/arm/include/asm/irqflags.h 2014-06-11 21:03:19.000000000 +0200
  2351. @@ -145,12 +145,22 @@
  2352. }
  2353. /*
  2354. - * restore saved IRQ & FIQ state
  2355. + * restore saved IRQ state
  2356. */
  2357. static inline void arch_local_irq_restore(unsigned long flags)
  2358. {
  2359. - asm volatile(
  2360. - " msr " IRQMASK_REG_NAME_W ", %0 @ local_irq_restore"
  2361. + unsigned long temp = 0;
  2362. + flags &= ~(1 << 6);
  2363. + asm volatile (
  2364. + " mrs %0, cpsr"
  2365. + : "=r" (temp)
  2366. + :
  2367. + : "memory", "cc");
  2368. + /* Preserve FIQ bit */
  2369. + temp &= (1 << 6);
  2370. + flags = flags | temp;
  2371. + asm volatile (
  2372. + " msr cpsr_c, %0 @ local_irq_restore"
  2373. :
  2374. : "r" (flags)
  2375. : "memory", "cc");
  2376. diff -Nur linux-3.15/arch/arm/Kconfig linux-rpi/arch/arm/Kconfig
  2377. --- linux-3.15/arch/arm/Kconfig 2014-06-08 20:19:54.000000000 +0200
  2378. +++ linux-rpi/arch/arm/Kconfig 2014-06-11 21:05:18.000000000 +0200
  2379. @@ -384,6 +384,24 @@
  2380. This enables support for systems based on Atmel
  2381. AT91RM9200 and AT91SAM9* processors.
  2382. +config ARCH_BCM2708
  2383. + bool "Broadcom BCM2708 family"
  2384. + select CPU_V6
  2385. + select ARM_AMBA
  2386. + select HAVE_CLK
  2387. + select HAVE_SCHED_CLOCK
  2388. + select NEED_MACH_GPIO_H
  2389. + select NEED_MACH_MEMORY_H
  2390. + select CLKDEV_LOOKUP
  2391. + select ARCH_HAS_CPUFREQ
  2392. + select GENERIC_CLOCKEVENTS
  2393. + select ARM_ERRATA_411920
  2394. + select MACH_BCM2708
  2395. + select VC4
  2396. + select FIQ
  2397. + help
  2398. + This enables support for Broadcom BCM2708 boards.
  2399. +
  2400. config ARCH_CLPS711X
  2401. bool "Cirrus Logic CLPS711x/EP721x/EP731x-based"
  2402. select ARCH_REQUIRE_GPIOLIB
  2403. @@ -1068,6 +1086,7 @@
  2404. source "arch/arm/mach-vt8500/Kconfig"
  2405. source "arch/arm/mach-w90x900/Kconfig"
  2406. +source "arch/arm/mach-bcm2708/Kconfig"
  2407. source "arch/arm/mach-zynq/Kconfig"
  2408. diff -Nur linux-3.15/arch/arm/Kconfig.debug linux-rpi/arch/arm/Kconfig.debug
  2409. --- linux-3.15/arch/arm/Kconfig.debug 2014-06-08 20:19:54.000000000 +0200
  2410. +++ linux-rpi/arch/arm/Kconfig.debug 2014-06-11 21:05:18.000000000 +0200
  2411. @@ -916,6 +916,14 @@
  2412. options; the platform specific options are deprecated
  2413. and will be soon removed.
  2414. + config DEBUG_BCM2708_UART0
  2415. + bool "Broadcom BCM2708 UART0 (PL011)"
  2416. + depends on MACH_BCM2708
  2417. + help
  2418. + Say Y here if you want the debug print routines to direct
  2419. + their output to UART 0. The port must have been initialised
  2420. + by the boot-loader before use.
  2421. +
  2422. endchoice
  2423. config DEBUG_EXYNOS_UART
  2424. diff -Nur linux-3.15/arch/arm/kernel/fiqasm.S linux-rpi/arch/arm/kernel/fiqasm.S
  2425. --- linux-3.15/arch/arm/kernel/fiqasm.S 2014-06-08 20:19:54.000000000 +0200
  2426. +++ linux-rpi/arch/arm/kernel/fiqasm.S 2014-06-11 21:03:19.000000000 +0200
  2427. @@ -47,3 +47,7 @@
  2428. mov r0, r0 @ avoid hazard prior to ARMv4
  2429. mov pc, lr
  2430. ENDPROC(__get_fiq_regs)
  2431. +
  2432. +ENTRY(__FIQ_Branch)
  2433. + mov pc, r8
  2434. +ENDPROC(__FIQ_Branch)
  2435. diff -Nur linux-3.15/arch/arm/kernel/process.c linux-rpi/arch/arm/kernel/process.c
  2436. --- linux-3.15/arch/arm/kernel/process.c 2014-06-08 20:19:54.000000000 +0200
  2437. +++ linux-rpi/arch/arm/kernel/process.c 2014-06-11 21:05:18.000000000 +0200
  2438. @@ -171,6 +171,16 @@
  2439. }
  2440. #endif
  2441. +char bcm2708_reboot_mode = 'h';
  2442. +
  2443. +int __init reboot_setup(char *str)
  2444. +{
  2445. + bcm2708_reboot_mode = str[0];
  2446. + return 1;
  2447. +}
  2448. +
  2449. +__setup("reboot=", reboot_setup);
  2450. +
  2451. /*
  2452. * Called by kexec, immediately prior to machine_kexec().
  2453. *
  2454. diff -Nur linux-3.15/arch/arm/mach-bcm2708/armctrl.c linux-rpi/arch/arm/mach-bcm2708/armctrl.c
  2455. --- linux-3.15/arch/arm/mach-bcm2708/armctrl.c 1970-01-01 01:00:00.000000000 +0100
  2456. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.c 2014-06-11 21:03:19.000000000 +0200
  2457. @@ -0,0 +1,219 @@
  2458. +/*
  2459. + * linux/arch/arm/mach-bcm2708/armctrl.c
  2460. + *
  2461. + * Copyright (C) 2010 Broadcom
  2462. + *
  2463. + * This program is free software; you can redistribute it and/or modify
  2464. + * it under the terms of the GNU General Public License as published by
  2465. + * the Free Software Foundation; either version 2 of the License, or
  2466. + * (at your option) any later version.
  2467. + *
  2468. + * This program is distributed in the hope that it will be useful,
  2469. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2470. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2471. + * GNU General Public License for more details.
  2472. + *
  2473. + * You should have received a copy of the GNU General Public License
  2474. + * along with this program; if not, write to the Free Software
  2475. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2476. + */
  2477. +#include <linux/init.h>
  2478. +#include <linux/list.h>
  2479. +#include <linux/io.h>
  2480. +#include <linux/version.h>
  2481. +#include <linux/syscore_ops.h>
  2482. +#include <linux/interrupt.h>
  2483. +
  2484. +#include <asm/mach/irq.h>
  2485. +#include <mach/hardware.h>
  2486. +#include "armctrl.h"
  2487. +
  2488. +/* For support of kernels >= 3.0 assume only one VIC for now*/
  2489. +static unsigned int remap_irqs[(INTERRUPT_ARASANSDIO + 1) - INTERRUPT_JPEG] = {
  2490. + INTERRUPT_VC_JPEG,
  2491. + INTERRUPT_VC_USB,
  2492. + INTERRUPT_VC_3D,
  2493. + INTERRUPT_VC_DMA2,
  2494. + INTERRUPT_VC_DMA3,
  2495. + INTERRUPT_VC_I2C,
  2496. + INTERRUPT_VC_SPI,
  2497. + INTERRUPT_VC_I2SPCM,
  2498. + INTERRUPT_VC_SDIO,
  2499. + INTERRUPT_VC_UART,
  2500. + INTERRUPT_VC_ARASANSDIO
  2501. +};
  2502. +
  2503. +static void armctrl_mask_irq(struct irq_data *d)
  2504. +{
  2505. + static const unsigned int disables[4] = {
  2506. + ARM_IRQ_DIBL1,
  2507. + ARM_IRQ_DIBL2,
  2508. + ARM_IRQ_DIBL3,
  2509. + 0
  2510. + };
  2511. +
  2512. + if (d->irq >= FIQ_START) {
  2513. + writel(0, __io_address(ARM_IRQ_FAST));
  2514. + } else {
  2515. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2516. + writel(1 << (data & 0x1f), __io_address(disables[(data >> 5) & 0x3]));
  2517. + }
  2518. +}
  2519. +
  2520. +static void armctrl_unmask_irq(struct irq_data *d)
  2521. +{
  2522. + static const unsigned int enables[4] = {
  2523. + ARM_IRQ_ENBL1,
  2524. + ARM_IRQ_ENBL2,
  2525. + ARM_IRQ_ENBL3,
  2526. + 0
  2527. + };
  2528. +
  2529. + if (d->irq >= FIQ_START) {
  2530. + unsigned int data =
  2531. + (unsigned int)irq_get_chip_data(d->irq) - FIQ_START;
  2532. + writel(0x80 | data, __io_address(ARM_IRQ_FAST));
  2533. + } else {
  2534. + unsigned int data = (unsigned int)irq_get_chip_data(d->irq);
  2535. + writel(1 << (data & 0x1f), __io_address(enables[(data >> 5) & 0x3]));
  2536. + }
  2537. +}
  2538. +
  2539. +#if defined(CONFIG_PM)
  2540. +
  2541. +/* for kernels 3.xx use the new syscore_ops apis but for older kernels use the sys dev class */
  2542. +
  2543. +/* Static defines
  2544. + * struct armctrl_device - VIC PM device (< 3.xx)
  2545. + * @sysdev: The system device which is registered. (< 3.xx)
  2546. + * @irq: The IRQ number for the base of the VIC.
  2547. + * @base: The register base for the VIC.
  2548. + * @resume_sources: A bitmask of interrupts for resume.
  2549. + * @resume_irqs: The IRQs enabled for resume.
  2550. + * @int_select: Save for VIC_INT_SELECT.
  2551. + * @int_enable: Save for VIC_INT_ENABLE.
  2552. + * @soft_int: Save for VIC_INT_SOFT.
  2553. + * @protect: Save for VIC_PROTECT.
  2554. + */
  2555. +struct armctrl_info {
  2556. + void __iomem *base;
  2557. + int irq;
  2558. + u32 resume_sources;
  2559. + u32 resume_irqs;
  2560. + u32 int_select;
  2561. + u32 int_enable;
  2562. + u32 soft_int;
  2563. + u32 protect;
  2564. +} armctrl;
  2565. +
  2566. +static int armctrl_suspend(void)
  2567. +{
  2568. + return 0;
  2569. +}
  2570. +
  2571. +static void armctrl_resume(void)
  2572. +{
  2573. + return;
  2574. +}
  2575. +
  2576. +/**
  2577. + * armctrl_pm_register - Register a VIC for later power management control
  2578. + * @base: The base address of the VIC.
  2579. + * @irq: The base IRQ for the VIC.
  2580. + * @resume_sources: bitmask of interrupts allowed for resume sources.
  2581. + *
  2582. + * For older kernels (< 3.xx) do -
  2583. + * Register the VIC with the system device tree so that it can be notified
  2584. + * of suspend and resume requests and ensure that the correct actions are
  2585. + * taken to re-instate the settings on resume.
  2586. + */
  2587. +static void __init armctrl_pm_register(void __iomem * base, unsigned int irq,
  2588. + u32 resume_sources)
  2589. +{
  2590. + armctrl.base = base;
  2591. + armctrl.resume_sources = resume_sources;
  2592. + armctrl.irq = irq;
  2593. +}
  2594. +
  2595. +static int armctrl_set_wake(struct irq_data *d, unsigned int on)
  2596. +{
  2597. + unsigned int off = d->irq & 31;
  2598. + u32 bit = 1 << off;
  2599. +
  2600. + if (!(bit & armctrl.resume_sources))
  2601. + return -EINVAL;
  2602. +
  2603. + if (on)
  2604. + armctrl.resume_irqs |= bit;
  2605. + else
  2606. + armctrl.resume_irqs &= ~bit;
  2607. +
  2608. + return 0;
  2609. +}
  2610. +
  2611. +#else
  2612. +static inline void armctrl_pm_register(void __iomem * base, unsigned int irq,
  2613. + u32 arg1)
  2614. +{
  2615. +}
  2616. +
  2617. +#define armctrl_suspend NULL
  2618. +#define armctrl_resume NULL
  2619. +#define armctrl_set_wake NULL
  2620. +#endif /* CONFIG_PM */
  2621. +
  2622. +static struct syscore_ops armctrl_syscore_ops = {
  2623. + .suspend = armctrl_suspend,
  2624. + .resume = armctrl_resume,
  2625. +};
  2626. +
  2627. +/**
  2628. + * armctrl_syscore_init - initicall to register VIC pm functions
  2629. + *
  2630. + * This is called via late_initcall() to register
  2631. + * the resources for the VICs due to the early
  2632. + * nature of the VIC's registration.
  2633. +*/
  2634. +static int __init armctrl_syscore_init(void)
  2635. +{
  2636. + register_syscore_ops(&armctrl_syscore_ops);
  2637. + return 0;
  2638. +}
  2639. +
  2640. +late_initcall(armctrl_syscore_init);
  2641. +
  2642. +static struct irq_chip armctrl_chip = {
  2643. + .name = "ARMCTRL",
  2644. + .irq_ack = armctrl_mask_irq,
  2645. + .irq_mask = armctrl_mask_irq,
  2646. + .irq_unmask = armctrl_unmask_irq,
  2647. + .irq_set_wake = armctrl_set_wake,
  2648. +};
  2649. +
  2650. +/**
  2651. + * armctrl_init - initialise a vectored interrupt controller
  2652. + * @base: iomem base address
  2653. + * @irq_start: starting interrupt number, must be muliple of 32
  2654. + * @armctrl_sources: bitmask of interrupt sources to allow
  2655. + * @resume_sources: bitmask of interrupt sources to allow for resume
  2656. + */
  2657. +int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2658. + u32 armctrl_sources, u32 resume_sources)
  2659. +{
  2660. + unsigned int irq;
  2661. +
  2662. + for (irq = 0; irq < NR_IRQS; irq++) {
  2663. + unsigned int data = irq;
  2664. + if (irq >= INTERRUPT_JPEG && irq <= INTERRUPT_ARASANSDIO)
  2665. + data = remap_irqs[irq - INTERRUPT_JPEG];
  2666. +
  2667. + irq_set_chip(irq, &armctrl_chip);
  2668. + irq_set_chip_data(irq, (void *)data);
  2669. + irq_set_handler(irq, handle_level_irq);
  2670. + set_irq_flags(irq, IRQF_VALID | IRQF_PROBE | IRQF_DISABLED);
  2671. + }
  2672. +
  2673. + armctrl_pm_register(base, irq_start, resume_sources);
  2674. + init_FIQ(FIQ_START);
  2675. + return 0;
  2676. +}
  2677. diff -Nur linux-3.15/arch/arm/mach-bcm2708/armctrl.h linux-rpi/arch/arm/mach-bcm2708/armctrl.h
  2678. --- linux-3.15/arch/arm/mach-bcm2708/armctrl.h 1970-01-01 01:00:00.000000000 +0100
  2679. +++ linux-rpi/arch/arm/mach-bcm2708/armctrl.h 2014-06-11 21:03:19.000000000 +0200
  2680. @@ -0,0 +1,27 @@
  2681. +/*
  2682. + * linux/arch/arm/mach-bcm2708/armctrl.h
  2683. + *
  2684. + * Copyright (C) 2010 Broadcom
  2685. + *
  2686. + * This program is free software; you can redistribute it and/or modify
  2687. + * it under the terms of the GNU General Public License as published by
  2688. + * the Free Software Foundation; either version 2 of the License, or
  2689. + * (at your option) any later version.
  2690. + *
  2691. + * This program is distributed in the hope that it will be useful,
  2692. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2693. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2694. + * GNU General Public License for more details.
  2695. + *
  2696. + * You should have received a copy of the GNU General Public License
  2697. + * along with this program; if not, write to the Free Software
  2698. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2699. + */
  2700. +
  2701. +#ifndef __BCM2708_ARMCTRL_H
  2702. +#define __BCM2708_ARMCTRL_H
  2703. +
  2704. +extern int __init armctrl_init(void __iomem * base, unsigned int irq_start,
  2705. + u32 armctrl_sources, u32 resume_sources);
  2706. +
  2707. +#endif
  2708. diff -Nur linux-3.15/arch/arm/mach-bcm2708/bcm2708.c linux-rpi/arch/arm/mach-bcm2708/bcm2708.c
  2709. --- linux-3.15/arch/arm/mach-bcm2708/bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  2710. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.c 2014-06-11 21:05:18.000000000 +0200
  2711. @@ -0,0 +1,1031 @@
  2712. +/*
  2713. + * linux/arch/arm/mach-bcm2708/bcm2708.c
  2714. + *
  2715. + * Copyright (C) 2010 Broadcom
  2716. + *
  2717. + * This program is free software; you can redistribute it and/or modify
  2718. + * it under the terms of the GNU General Public License as published by
  2719. + * the Free Software Foundation; either version 2 of the License, or
  2720. + * (at your option) any later version.
  2721. + *
  2722. + * This program is distributed in the hope that it will be useful,
  2723. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2724. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2725. + * GNU General Public License for more details.
  2726. + *
  2727. + * You should have received a copy of the GNU General Public License
  2728. + * along with this program; if not, write to the Free Software
  2729. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  2730. + */
  2731. +
  2732. +#include <linux/init.h>
  2733. +#include <linux/device.h>
  2734. +#include <linux/dma-mapping.h>
  2735. +#include <linux/serial_8250.h>
  2736. +#include <linux/platform_device.h>
  2737. +#include <linux/syscore_ops.h>
  2738. +#include <linux/interrupt.h>
  2739. +#include <linux/amba/bus.h>
  2740. +#include <linux/amba/clcd.h>
  2741. +#include <linux/clockchips.h>
  2742. +#include <linux/cnt32_to_63.h>
  2743. +#include <linux/io.h>
  2744. +#include <linux/module.h>
  2745. +#include <linux/spi/spi.h>
  2746. +#include <linux/w1-gpio.h>
  2747. +
  2748. +#include <linux/version.h>
  2749. +#include <linux/clkdev.h>
  2750. +#include <asm/system_info.h>
  2751. +#include <mach/hardware.h>
  2752. +#include <asm/irq.h>
  2753. +#include <linux/leds.h>
  2754. +#include <asm/mach-types.h>
  2755. +#include <linux/sched_clock.h>
  2756. +
  2757. +#include <asm/mach/arch.h>
  2758. +#include <asm/mach/flash.h>
  2759. +#include <asm/mach/irq.h>
  2760. +#include <asm/mach/time.h>
  2761. +#include <asm/mach/map.h>
  2762. +
  2763. +#include <mach/timex.h>
  2764. +#include <mach/dma.h>
  2765. +#include <mach/vcio.h>
  2766. +#include <mach/system.h>
  2767. +
  2768. +#include <linux/delay.h>
  2769. +
  2770. +#include "bcm2708.h"
  2771. +#include "armctrl.h"
  2772. +#include "clock.h"
  2773. +
  2774. +#ifdef CONFIG_BCM_VC_CMA
  2775. +#include <linux/broadcom/vc_cma.h>
  2776. +#endif
  2777. +
  2778. +
  2779. +/* Effectively we have an IOMMU (ARM<->VideoCore map) that is set up to
  2780. + * give us IO access only to 64Mbytes of physical memory (26 bits). We could
  2781. + * represent this window by setting our dmamasks to 26 bits but, in fact
  2782. + * we're not going to use addresses outside this range (they're not in real
  2783. + * memory) so we don't bother.
  2784. + *
  2785. + * In the future we might include code to use this IOMMU to remap other
  2786. + * physical addresses onto VideoCore memory then the use of 32-bits would be
  2787. + * more legitimate.
  2788. + */
  2789. +#define DMA_MASK_BITS_COMMON 32
  2790. +
  2791. +// use GPIO 4 for the one-wire GPIO pin, if enabled
  2792. +#define W1_GPIO 4
  2793. +// ensure one-wire GPIO pullup is disabled by default
  2794. +#define W1_PULLUP -1
  2795. +
  2796. +/* command line parameters */
  2797. +static unsigned boardrev, serial;
  2798. +static unsigned uart_clock;
  2799. +static unsigned disk_led_gpio = 16;
  2800. +static unsigned disk_led_active_low = 1;
  2801. +static unsigned reboot_part = 0;
  2802. +static unsigned w1_gpio_pin = W1_GPIO;
  2803. +static unsigned w1_gpio_pullup = W1_PULLUP;
  2804. +
  2805. +static void __init bcm2708_init_led(void);
  2806. +
  2807. +void __init bcm2708_init_irq(void)
  2808. +{
  2809. + armctrl_init(__io_address(ARMCTRL_IC_BASE), 0, 0, 0);
  2810. +}
  2811. +
  2812. +static struct map_desc bcm2708_io_desc[] __initdata = {
  2813. + {
  2814. + .virtual = IO_ADDRESS(ARMCTRL_BASE),
  2815. + .pfn = __phys_to_pfn(ARMCTRL_BASE),
  2816. + .length = SZ_4K,
  2817. + .type = MT_DEVICE},
  2818. + {
  2819. + .virtual = IO_ADDRESS(UART0_BASE),
  2820. + .pfn = __phys_to_pfn(UART0_BASE),
  2821. + .length = SZ_4K,
  2822. + .type = MT_DEVICE},
  2823. + {
  2824. + .virtual = IO_ADDRESS(UART1_BASE),
  2825. + .pfn = __phys_to_pfn(UART1_BASE),
  2826. + .length = SZ_4K,
  2827. + .type = MT_DEVICE},
  2828. + {
  2829. + .virtual = IO_ADDRESS(DMA_BASE),
  2830. + .pfn = __phys_to_pfn(DMA_BASE),
  2831. + .length = SZ_4K,
  2832. + .type = MT_DEVICE},
  2833. + {
  2834. + .virtual = IO_ADDRESS(MCORE_BASE),
  2835. + .pfn = __phys_to_pfn(MCORE_BASE),
  2836. + .length = SZ_4K,
  2837. + .type = MT_DEVICE},
  2838. + {
  2839. + .virtual = IO_ADDRESS(ST_BASE),
  2840. + .pfn = __phys_to_pfn(ST_BASE),
  2841. + .length = SZ_4K,
  2842. + .type = MT_DEVICE},
  2843. + {
  2844. + .virtual = IO_ADDRESS(USB_BASE),
  2845. + .pfn = __phys_to_pfn(USB_BASE),
  2846. + .length = SZ_128K,
  2847. + .type = MT_DEVICE},
  2848. + {
  2849. + .virtual = IO_ADDRESS(PM_BASE),
  2850. + .pfn = __phys_to_pfn(PM_BASE),
  2851. + .length = SZ_4K,
  2852. + .type = MT_DEVICE},
  2853. + {
  2854. + .virtual = IO_ADDRESS(GPIO_BASE),
  2855. + .pfn = __phys_to_pfn(GPIO_BASE),
  2856. + .length = SZ_4K,
  2857. + .type = MT_DEVICE}
  2858. +};
  2859. +
  2860. +void __init bcm2708_map_io(void)
  2861. +{
  2862. + iotable_init(bcm2708_io_desc, ARRAY_SIZE(bcm2708_io_desc));
  2863. +}
  2864. +
  2865. +/* The STC is a free running counter that increments at the rate of 1MHz */
  2866. +#define STC_FREQ_HZ 1000000
  2867. +
  2868. +static inline uint32_t timer_read(void)
  2869. +{
  2870. + /* STC: a free running counter that increments at the rate of 1MHz */
  2871. + return readl(__io_address(ST_BASE + 0x04));
  2872. +}
  2873. +
  2874. +static unsigned long bcm2708_read_current_timer(void)
  2875. +{
  2876. + return timer_read();
  2877. +}
  2878. +
  2879. +static u32 notrace bcm2708_read_sched_clock(void)
  2880. +{
  2881. + return timer_read();
  2882. +}
  2883. +
  2884. +static cycle_t clksrc_read(struct clocksource *cs)
  2885. +{
  2886. + return timer_read();
  2887. +}
  2888. +
  2889. +static struct clocksource clocksource_stc = {
  2890. + .name = "stc",
  2891. + .rating = 300,
  2892. + .read = clksrc_read,
  2893. + .mask = CLOCKSOURCE_MASK(32),
  2894. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  2895. +};
  2896. +
  2897. +unsigned long frc_clock_ticks32(void)
  2898. +{
  2899. + return timer_read();
  2900. +}
  2901. +
  2902. +static void __init bcm2708_clocksource_init(void)
  2903. +{
  2904. + if (clocksource_register_hz(&clocksource_stc, STC_FREQ_HZ)) {
  2905. + printk(KERN_ERR "timer: failed to initialize clock "
  2906. + "source %s\n", clocksource_stc.name);
  2907. + }
  2908. +}
  2909. +
  2910. +
  2911. +/*
  2912. + * These are fixed clocks.
  2913. + */
  2914. +static struct clk ref24_clk = {
  2915. + .rate = UART0_CLOCK, /* The UART is clocked at 3MHz via APB_CLK */
  2916. +};
  2917. +
  2918. +static struct clk osc_clk = {
  2919. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2920. + .rate = 27000000,
  2921. +#else
  2922. + .rate = 500000000, /* ARM clock is set from the VideoCore booter */
  2923. +#endif
  2924. +};
  2925. +
  2926. +/* warning - the USB needs a clock > 34MHz */
  2927. +
  2928. +static struct clk sdhost_clk = {
  2929. +#ifdef CONFIG_ARCH_BCM2708_CHIPIT
  2930. + .rate = 4000000, /* 4MHz */
  2931. +#else
  2932. + .rate = 250000000, /* 250MHz */
  2933. +#endif
  2934. +};
  2935. +
  2936. +static struct clk_lookup lookups[] = {
  2937. + { /* UART0 */
  2938. + .dev_id = "dev:f1",
  2939. + .clk = &ref24_clk,
  2940. + },
  2941. + { /* USB */
  2942. + .dev_id = "bcm2708_usb",
  2943. + .clk = &osc_clk,
  2944. + }, { /* SPI */
  2945. + .dev_id = "bcm2708_spi.0",
  2946. + .clk = &sdhost_clk,
  2947. + }, { /* BSC0 */
  2948. + .dev_id = "bcm2708_i2c.0",
  2949. + .clk = &sdhost_clk,
  2950. + }, { /* BSC1 */
  2951. + .dev_id = "bcm2708_i2c.1",
  2952. + .clk = &sdhost_clk,
  2953. + }
  2954. +};
  2955. +
  2956. +#define UART0_IRQ { IRQ_UART, 0 /*NO_IRQ*/ }
  2957. +#define UART0_DMA { 15, 14 }
  2958. +
  2959. +AMBA_DEVICE(uart0, "dev:f1", UART0, NULL);
  2960. +
  2961. +static struct amba_device *amba_devs[] __initdata = {
  2962. + &uart0_device,
  2963. +};
  2964. +
  2965. +static struct resource bcm2708_dmaman_resources[] = {
  2966. + {
  2967. + .start = DMA_BASE,
  2968. + .end = DMA_BASE + SZ_4K - 1,
  2969. + .flags = IORESOURCE_MEM,
  2970. + }
  2971. +};
  2972. +
  2973. +static struct platform_device bcm2708_dmaman_device = {
  2974. + .name = BCM_DMAMAN_DRIVER_NAME,
  2975. + .id = 0, /* first bcm2708_dma */
  2976. + .resource = bcm2708_dmaman_resources,
  2977. + .num_resources = ARRAY_SIZE(bcm2708_dmaman_resources),
  2978. +};
  2979. +
  2980. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  2981. +static struct w1_gpio_platform_data w1_gpio_pdata = {
  2982. + .pin = W1_GPIO,
  2983. + .ext_pullup_enable_pin = W1_PULLUP,
  2984. + .is_open_drain = 0,
  2985. +};
  2986. +
  2987. +static struct platform_device w1_device = {
  2988. + .name = "w1-gpio",
  2989. + .id = -1,
  2990. + .dev.platform_data = &w1_gpio_pdata,
  2991. +};
  2992. +#endif
  2993. +
  2994. +static u64 fb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  2995. +
  2996. +static struct platform_device bcm2708_fb_device = {
  2997. + .name = "bcm2708_fb",
  2998. + .id = -1, /* only one bcm2708_fb */
  2999. + .resource = NULL,
  3000. + .num_resources = 0,
  3001. + .dev = {
  3002. + .dma_mask = &fb_dmamask,
  3003. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3004. + },
  3005. +};
  3006. +
  3007. +static struct plat_serial8250_port bcm2708_uart1_platform_data[] = {
  3008. + {
  3009. + .mapbase = UART1_BASE + 0x40,
  3010. + .irq = IRQ_AUX,
  3011. + .uartclk = 125000000,
  3012. + .regshift = 2,
  3013. + .iotype = UPIO_MEM,
  3014. + .flags = UPF_FIXED_TYPE | UPF_IOREMAP | UPF_SKIP_TEST,
  3015. + .type = PORT_8250,
  3016. + },
  3017. + {},
  3018. +};
  3019. +
  3020. +static struct platform_device bcm2708_uart1_device = {
  3021. + .name = "serial8250",
  3022. + .id = PLAT8250_DEV_PLATFORM,
  3023. + .dev = {
  3024. + .platform_data = bcm2708_uart1_platform_data,
  3025. + },
  3026. +};
  3027. +
  3028. +static struct resource bcm2708_usb_resources[] = {
  3029. + [0] = {
  3030. + .start = USB_BASE,
  3031. + .end = USB_BASE + SZ_128K - 1,
  3032. + .flags = IORESOURCE_MEM,
  3033. + },
  3034. + [1] = {
  3035. + .start = MPHI_BASE,
  3036. + .end = MPHI_BASE + SZ_4K - 1,
  3037. + .flags = IORESOURCE_MEM,
  3038. + },
  3039. + [2] = {
  3040. + .start = IRQ_HOSTPORT,
  3041. + .end = IRQ_HOSTPORT,
  3042. + .flags = IORESOURCE_IRQ,
  3043. + },
  3044. + [3] = {
  3045. + .start = IRQ_USB,
  3046. + .end = IRQ_USB,
  3047. + .flags = IORESOURCE_IRQ,
  3048. + },
  3049. +};
  3050. +
  3051. +
  3052. +static u64 usb_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3053. +
  3054. +static struct platform_device bcm2708_usb_device = {
  3055. + .name = "bcm2708_usb",
  3056. + .id = -1, /* only one bcm2708_usb */
  3057. + .resource = bcm2708_usb_resources,
  3058. + .num_resources = ARRAY_SIZE(bcm2708_usb_resources),
  3059. + .dev = {
  3060. + .dma_mask = &usb_dmamask,
  3061. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3062. + },
  3063. +};
  3064. +
  3065. +static struct resource bcm2708_vcio_resources[] = {
  3066. + [0] = { /* mailbox/semaphore/doorbell access */
  3067. + .start = MCORE_BASE,
  3068. + .end = MCORE_BASE + SZ_4K - 1,
  3069. + .flags = IORESOURCE_MEM,
  3070. + },
  3071. +};
  3072. +
  3073. +static u64 vcio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3074. +
  3075. +static struct platform_device bcm2708_vcio_device = {
  3076. + .name = BCM_VCIO_DRIVER_NAME,
  3077. + .id = -1, /* only one VideoCore I/O area */
  3078. + .resource = bcm2708_vcio_resources,
  3079. + .num_resources = ARRAY_SIZE(bcm2708_vcio_resources),
  3080. + .dev = {
  3081. + .dma_mask = &vcio_dmamask,
  3082. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3083. + },
  3084. +};
  3085. +
  3086. +#ifdef CONFIG_BCM2708_GPIO
  3087. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3088. +
  3089. +static struct resource bcm2708_gpio_resources[] = {
  3090. + [0] = { /* general purpose I/O */
  3091. + .start = GPIO_BASE,
  3092. + .end = GPIO_BASE + SZ_4K - 1,
  3093. + .flags = IORESOURCE_MEM,
  3094. + },
  3095. +};
  3096. +
  3097. +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3098. +
  3099. +static struct platform_device bcm2708_gpio_device = {
  3100. + .name = BCM_GPIO_DRIVER_NAME,
  3101. + .id = -1, /* only one VideoCore I/O area */
  3102. + .resource = bcm2708_gpio_resources,
  3103. + .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
  3104. + .dev = {
  3105. + .dma_mask = &gpio_dmamask,
  3106. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3107. + },
  3108. +};
  3109. +#endif
  3110. +
  3111. +static struct resource bcm2708_systemtimer_resources[] = {
  3112. + [0] = { /* system timer access */
  3113. + .start = ST_BASE,
  3114. + .end = ST_BASE + SZ_4K - 1,
  3115. + .flags = IORESOURCE_MEM,
  3116. + },
  3117. + {
  3118. + .start = IRQ_TIMER3,
  3119. + .end = IRQ_TIMER3,
  3120. + .flags = IORESOURCE_IRQ,
  3121. + }
  3122. +
  3123. +};
  3124. +
  3125. +static u64 systemtimer_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3126. +
  3127. +static struct platform_device bcm2708_systemtimer_device = {
  3128. + .name = "bcm2708_systemtimer",
  3129. + .id = -1, /* only one VideoCore I/O area */
  3130. + .resource = bcm2708_systemtimer_resources,
  3131. + .num_resources = ARRAY_SIZE(bcm2708_systemtimer_resources),
  3132. + .dev = {
  3133. + .dma_mask = &systemtimer_dmamask,
  3134. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
  3135. + },
  3136. +};
  3137. +
  3138. +#ifdef CONFIG_MMC_SDHCI_BCM2708 /* Arasan emmc SD */
  3139. +static struct resource bcm2708_emmc_resources[] = {
  3140. + [0] = {
  3141. + .start = EMMC_BASE,
  3142. + .end = EMMC_BASE + SZ_256 - 1, /* we only need this area */
  3143. + /* the memory map actually makes SZ_4K available */
  3144. + .flags = IORESOURCE_MEM,
  3145. + },
  3146. + [1] = {
  3147. + .start = IRQ_ARASANSDIO,
  3148. + .end = IRQ_ARASANSDIO,
  3149. + .flags = IORESOURCE_IRQ,
  3150. + },
  3151. +};
  3152. +
  3153. +static u64 bcm2708_emmc_dmamask = 0xffffffffUL;
  3154. +
  3155. +struct platform_device bcm2708_emmc_device = {
  3156. + .name = "bcm2708_sdhci",
  3157. + .id = 0,
  3158. + .num_resources = ARRAY_SIZE(bcm2708_emmc_resources),
  3159. + .resource = bcm2708_emmc_resources,
  3160. + .dev = {
  3161. + .dma_mask = &bcm2708_emmc_dmamask,
  3162. + .coherent_dma_mask = 0xffffffffUL},
  3163. +};
  3164. +#endif /* CONFIG_MMC_SDHCI_BCM2708 */
  3165. +
  3166. +static struct resource bcm2708_powerman_resources[] = {
  3167. + [0] = {
  3168. + .start = PM_BASE,
  3169. + .end = PM_BASE + SZ_256 - 1,
  3170. + .flags = IORESOURCE_MEM,
  3171. + },
  3172. +};
  3173. +
  3174. +static u64 powerman_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3175. +
  3176. +struct platform_device bcm2708_powerman_device = {
  3177. + .name = "bcm2708_powerman",
  3178. + .id = 0,
  3179. + .num_resources = ARRAY_SIZE(bcm2708_powerman_resources),
  3180. + .resource = bcm2708_powerman_resources,
  3181. + .dev = {
  3182. + .dma_mask = &powerman_dmamask,
  3183. + .coherent_dma_mask = 0xffffffffUL},
  3184. +};
  3185. +
  3186. +
  3187. +static struct platform_device bcm2708_alsa_devices[] = {
  3188. + [0] = {
  3189. + .name = "bcm2835_AUD0",
  3190. + .id = 0, /* first audio device */
  3191. + .resource = 0,
  3192. + .num_resources = 0,
  3193. + },
  3194. + [1] = {
  3195. + .name = "bcm2835_AUD1",
  3196. + .id = 1, /* second audio device */
  3197. + .resource = 0,
  3198. + .num_resources = 0,
  3199. + },
  3200. + [2] = {
  3201. + .name = "bcm2835_AUD2",
  3202. + .id = 2, /* third audio device */
  3203. + .resource = 0,
  3204. + .num_resources = 0,
  3205. + },
  3206. + [3] = {
  3207. + .name = "bcm2835_AUD3",
  3208. + .id = 3, /* forth audio device */
  3209. + .resource = 0,
  3210. + .num_resources = 0,
  3211. + },
  3212. + [4] = {
  3213. + .name = "bcm2835_AUD4",
  3214. + .id = 4, /* fifth audio device */
  3215. + .resource = 0,
  3216. + .num_resources = 0,
  3217. + },
  3218. + [5] = {
  3219. + .name = "bcm2835_AUD5",
  3220. + .id = 5, /* sixth audio device */
  3221. + .resource = 0,
  3222. + .num_resources = 0,
  3223. + },
  3224. + [6] = {
  3225. + .name = "bcm2835_AUD6",
  3226. + .id = 6, /* seventh audio device */
  3227. + .resource = 0,
  3228. + .num_resources = 0,
  3229. + },
  3230. + [7] = {
  3231. + .name = "bcm2835_AUD7",
  3232. + .id = 7, /* eighth audio device */
  3233. + .resource = 0,
  3234. + .num_resources = 0,
  3235. + },
  3236. +};
  3237. +
  3238. +static struct resource bcm2708_spi_resources[] = {
  3239. + {
  3240. + .start = SPI0_BASE,
  3241. + .end = SPI0_BASE + SZ_256 - 1,
  3242. + .flags = IORESOURCE_MEM,
  3243. + }, {
  3244. + .start = IRQ_SPI,
  3245. + .end = IRQ_SPI,
  3246. + .flags = IORESOURCE_IRQ,
  3247. + }
  3248. +};
  3249. +
  3250. +
  3251. +static u64 bcm2708_spi_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
  3252. +static struct platform_device bcm2708_spi_device = {
  3253. + .name = "bcm2708_spi",
  3254. + .id = 0,
  3255. + .num_resources = ARRAY_SIZE(bcm2708_spi_resources),
  3256. + .resource = bcm2708_spi_resources,
  3257. + .dev = {
  3258. + .dma_mask = &bcm2708_spi_dmamask,
  3259. + .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  3260. +};
  3261. +
  3262. +#ifdef CONFIG_BCM2708_SPIDEV
  3263. +static struct spi_board_info bcm2708_spi_devices[] = {
  3264. +#ifdef CONFIG_SPI_SPIDEV
  3265. + {
  3266. + .modalias = "spidev",
  3267. + .max_speed_hz = 500000,
  3268. + .bus_num = 0,
  3269. + .chip_select = 0,
  3270. + .mode = SPI_MODE_0,
  3271. + }, {
  3272. + .modalias = "spidev",
  3273. + .max_speed_hz = 500000,
  3274. + .bus_num = 0,
  3275. + .chip_select = 1,
  3276. + .mode = SPI_MODE_0,
  3277. + }
  3278. +#endif
  3279. +};
  3280. +#endif
  3281. +
  3282. +static struct resource bcm2708_bsc0_resources[] = {
  3283. + {
  3284. + .start = BSC0_BASE,
  3285. + .end = BSC0_BASE + SZ_256 - 1,
  3286. + .flags = IORESOURCE_MEM,
  3287. + }, {
  3288. + .start = INTERRUPT_I2C,
  3289. + .end = INTERRUPT_I2C,
  3290. + .flags = IORESOURCE_IRQ,
  3291. + }
  3292. +};
  3293. +
  3294. +static struct platform_device bcm2708_bsc0_device = {
  3295. + .name = "bcm2708_i2c",
  3296. + .id = 0,
  3297. + .num_resources = ARRAY_SIZE(bcm2708_bsc0_resources),
  3298. + .resource = bcm2708_bsc0_resources,
  3299. +};
  3300. +
  3301. +
  3302. +static struct resource bcm2708_bsc1_resources[] = {
  3303. + {
  3304. + .start = BSC1_BASE,
  3305. + .end = BSC1_BASE + SZ_256 - 1,
  3306. + .flags = IORESOURCE_MEM,
  3307. + }, {
  3308. + .start = INTERRUPT_I2C,
  3309. + .end = INTERRUPT_I2C,
  3310. + .flags = IORESOURCE_IRQ,
  3311. + }
  3312. +};
  3313. +
  3314. +static struct platform_device bcm2708_bsc1_device = {
  3315. + .name = "bcm2708_i2c",
  3316. + .id = 1,
  3317. + .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  3318. + .resource = bcm2708_bsc1_resources,
  3319. +};
  3320. +
  3321. +static struct platform_device bcm2835_hwmon_device = {
  3322. + .name = "bcm2835_hwmon",
  3323. +};
  3324. +
  3325. +static struct platform_device bcm2835_thermal_device = {
  3326. + .name = "bcm2835_thermal",
  3327. +};
  3328. +
  3329. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3330. +static struct resource bcm2708_i2s_resources[] = {
  3331. + {
  3332. + .start = I2S_BASE,
  3333. + .end = I2S_BASE + 0x20,
  3334. + .flags = IORESOURCE_MEM,
  3335. + },
  3336. + {
  3337. + .start = PCM_CLOCK_BASE,
  3338. + .end = PCM_CLOCK_BASE + 0x02,
  3339. + .flags = IORESOURCE_MEM,
  3340. + }
  3341. +};
  3342. +
  3343. +static struct platform_device bcm2708_i2s_device = {
  3344. + .name = "bcm2708-i2s",
  3345. + .id = 0,
  3346. + .num_resources = ARRAY_SIZE(bcm2708_i2s_resources),
  3347. + .resource = bcm2708_i2s_resources,
  3348. +};
  3349. +#endif
  3350. +
  3351. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3352. +static struct platform_device snd_hifiberry_dac_device = {
  3353. + .name = "snd-hifiberry-dac",
  3354. + .id = 0,
  3355. + .num_resources = 0,
  3356. +};
  3357. +
  3358. +static struct platform_device snd_pcm5102a_codec_device = {
  3359. + .name = "pcm5102a-codec",
  3360. + .id = -1,
  3361. + .num_resources = 0,
  3362. +};
  3363. +#endif
  3364. +
  3365. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3366. +static struct platform_device snd_hifiberry_digi_device = {
  3367. + .name = "snd-hifiberry-digi",
  3368. + .id = 0,
  3369. + .num_resources = 0,
  3370. +};
  3371. +
  3372. +static struct i2c_board_info __initdata snd_wm8804_i2c_devices[] = {
  3373. + {
  3374. + I2C_BOARD_INFO("wm8804", 0x3b)
  3375. + },
  3376. +};
  3377. +
  3378. +#endif
  3379. +
  3380. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3381. +static struct platform_device snd_rpi_dac_device = {
  3382. + .name = "snd-rpi-dac",
  3383. + .id = 0,
  3384. + .num_resources = 0,
  3385. +};
  3386. +
  3387. +static struct platform_device snd_pcm1794a_codec_device = {
  3388. + .name = "pcm1794a-codec",
  3389. + .id = -1,
  3390. + .num_resources = 0,
  3391. +};
  3392. +#endif
  3393. +
  3394. +
  3395. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3396. +static struct platform_device snd_rpi_iqaudio_dac_device = {
  3397. + .name = "snd-rpi-iqaudio-dac",
  3398. + .id = 0,
  3399. + .num_resources = 0,
  3400. +};
  3401. +
  3402. +// Use the actual device name rather than generic driver name
  3403. +static struct i2c_board_info __initdata snd_pcm512x_i2c_devices[] = {
  3404. + {
  3405. + I2C_BOARD_INFO("pcm5122", 0x4c)
  3406. + },
  3407. +};
  3408. +#endif
  3409. +
  3410. +int __init bcm_register_device(struct platform_device *pdev)
  3411. +{
  3412. + int ret;
  3413. +
  3414. + ret = platform_device_register(pdev);
  3415. + if (ret)
  3416. + pr_debug("Unable to register platform device '%s': %d\n",
  3417. + pdev->name, ret);
  3418. +
  3419. + return ret;
  3420. +}
  3421. +
  3422. +int calc_rsts(int partition)
  3423. +{
  3424. + return PM_PASSWORD |
  3425. + ((partition & (1 << 0)) << 0) |
  3426. + ((partition & (1 << 1)) << 1) |
  3427. + ((partition & (1 << 2)) << 2) |
  3428. + ((partition & (1 << 3)) << 3) |
  3429. + ((partition & (1 << 4)) << 4) |
  3430. + ((partition & (1 << 5)) << 5);
  3431. +}
  3432. +
  3433. +static void bcm2708_restart(enum reboot_mode mode, const char *cmd)
  3434. +{
  3435. + extern char bcm2708_reboot_mode;
  3436. + uint32_t pm_rstc, pm_wdog;
  3437. + uint32_t timeout = 10;
  3438. + uint32_t pm_rsts = 0;
  3439. +
  3440. + if(bcm2708_reboot_mode == 'q')
  3441. + {
  3442. + // NOOBS < 1.3 booting with reboot=q
  3443. + pm_rsts = readl(__io_address(PM_RSTS));
  3444. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRQ_SET;
  3445. + }
  3446. + else if(bcm2708_reboot_mode == 'p')
  3447. + {
  3448. + // NOOBS < 1.3 halting
  3449. + pm_rsts = readl(__io_address(PM_RSTS));
  3450. + pm_rsts = PM_PASSWORD | pm_rsts | PM_RSTS_HADWRH_SET;
  3451. + }
  3452. + else
  3453. + {
  3454. + pm_rsts = calc_rsts(reboot_part);
  3455. + }
  3456. +
  3457. + writel(pm_rsts, __io_address(PM_RSTS));
  3458. +
  3459. + /* Setup watchdog for reset */
  3460. + pm_rstc = readl(__io_address(PM_RSTC));
  3461. +
  3462. + pm_wdog = PM_PASSWORD | (timeout & PM_WDOG_TIME_SET); // watchdog timer = timer clock / 16; need password (31:16) + value (11:0)
  3463. + pm_rstc = PM_PASSWORD | (pm_rstc & PM_RSTC_WRCFG_CLR) | PM_RSTC_WRCFG_FULL_RESET;
  3464. +
  3465. + writel(pm_wdog, __io_address(PM_WDOG));
  3466. + writel(pm_rstc, __io_address(PM_RSTC));
  3467. +}
  3468. +
  3469. +/* 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 */
  3470. +static void bcm2708_power_off(void)
  3471. +{
  3472. + extern char bcm2708_reboot_mode;
  3473. + if(bcm2708_reboot_mode == 'q')
  3474. + {
  3475. + // NOOBS < v1.3
  3476. + bcm2708_restart('p', "");
  3477. + }
  3478. + else
  3479. + {
  3480. + /* partition 63 is special code for HALT the bootloader knows not to boot*/
  3481. + reboot_part = 63;
  3482. + /* continue with normal reset mechanism */
  3483. + bcm2708_restart(0, "");
  3484. + }
  3485. +}
  3486. +
  3487. +void __init bcm2708_init(void)
  3488. +{
  3489. + int i;
  3490. +
  3491. +#if defined(CONFIG_BCM_VC_CMA)
  3492. + vc_cma_early_init();
  3493. +#endif
  3494. + printk("bcm2708.uart_clock = %d\n", uart_clock);
  3495. + pm_power_off = bcm2708_power_off;
  3496. +
  3497. + if (uart_clock)
  3498. + lookups[0].clk->rate = uart_clock;
  3499. +
  3500. + for (i = 0; i < ARRAY_SIZE(lookups); i++)
  3501. + clkdev_add(&lookups[i]);
  3502. +
  3503. + bcm_register_device(&bcm2708_dmaman_device);
  3504. + bcm_register_device(&bcm2708_vcio_device);
  3505. +#ifdef CONFIG_BCM2708_GPIO
  3506. + bcm_register_device(&bcm2708_gpio_device);
  3507. +#endif
  3508. +#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
  3509. + w1_gpio_pdata.pin = w1_gpio_pin;
  3510. + w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
  3511. + platform_device_register(&w1_device);
  3512. +#endif
  3513. + bcm_register_device(&bcm2708_systemtimer_device);
  3514. + bcm_register_device(&bcm2708_fb_device);
  3515. + bcm_register_device(&bcm2708_usb_device);
  3516. + bcm_register_device(&bcm2708_uart1_device);
  3517. + bcm_register_device(&bcm2708_powerman_device);
  3518. +
  3519. +#ifdef CONFIG_MMC_SDHCI_BCM2708
  3520. + bcm_register_device(&bcm2708_emmc_device);
  3521. +#endif
  3522. + bcm2708_init_led();
  3523. + for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  3524. + bcm_register_device(&bcm2708_alsa_devices[i]);
  3525. +
  3526. + bcm_register_device(&bcm2708_spi_device);
  3527. + bcm_register_device(&bcm2708_bsc0_device);
  3528. + bcm_register_device(&bcm2708_bsc1_device);
  3529. +
  3530. + bcm_register_device(&bcm2835_hwmon_device);
  3531. + bcm_register_device(&bcm2835_thermal_device);
  3532. +
  3533. +#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
  3534. + bcm_register_device(&bcm2708_i2s_device);
  3535. +#endif
  3536. +
  3537. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
  3538. + bcm_register_device(&snd_hifiberry_dac_device);
  3539. + bcm_register_device(&snd_pcm5102a_codec_device);
  3540. +#endif
  3541. +
  3542. +#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
  3543. + bcm_register_device(&snd_hifiberry_digi_device);
  3544. + i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
  3545. +#endif
  3546. +
  3547. +#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
  3548. + bcm_register_device(&snd_rpi_dac_device);
  3549. + bcm_register_device(&snd_pcm1794a_codec_device);
  3550. +#endif
  3551. +
  3552. +#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
  3553. + bcm_register_device(&snd_rpi_iqaudio_dac_device);
  3554. + i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
  3555. +#endif
  3556. +
  3557. +
  3558. + for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
  3559. + struct amba_device *d = amba_devs[i];
  3560. + amba_device_register(d, &iomem_resource);
  3561. + }
  3562. + system_rev = boardrev;
  3563. + system_serial_low = serial;
  3564. +
  3565. +#ifdef CONFIG_BCM2708_SPIDEV
  3566. + spi_register_board_info(bcm2708_spi_devices,
  3567. + ARRAY_SIZE(bcm2708_spi_devices));
  3568. +#endif
  3569. +}
  3570. +
  3571. +static void timer_set_mode(enum clock_event_mode mode,
  3572. + struct clock_event_device *clk)
  3573. +{
  3574. + switch (mode) {
  3575. + case CLOCK_EVT_MODE_ONESHOT: /* Leave the timer disabled, .set_next_event will enable it */
  3576. + case CLOCK_EVT_MODE_SHUTDOWN:
  3577. + break;
  3578. + case CLOCK_EVT_MODE_PERIODIC:
  3579. +
  3580. + case CLOCK_EVT_MODE_UNUSED:
  3581. + case CLOCK_EVT_MODE_RESUME:
  3582. +
  3583. + default:
  3584. + printk(KERN_ERR "timer_set_mode: unhandled mode:%d\n",
  3585. + (int)mode);
  3586. + break;
  3587. + }
  3588. +
  3589. +}
  3590. +
  3591. +static int timer_set_next_event(unsigned long cycles,
  3592. + struct clock_event_device *unused)
  3593. +{
  3594. + unsigned long stc;
  3595. + do {
  3596. + stc = readl(__io_address(ST_BASE + 0x04));
  3597. + /* We could take a FIQ here, which may push ST above STC3 */
  3598. + writel(stc + cycles, __io_address(ST_BASE + 0x18));
  3599. + } while ((signed long) (readl(__io_address(ST_BASE + 0x04)) - stc)
  3600. + >= (signed long) cycles);
  3601. + return 0;
  3602. +}
  3603. +
  3604. +static struct clock_event_device timer0_clockevent = {
  3605. + .name = "timer0",
  3606. + .shift = 32,
  3607. + .features = CLOCK_EVT_FEAT_ONESHOT,
  3608. + .set_mode = timer_set_mode,
  3609. + .set_next_event = timer_set_next_event,
  3610. +};
  3611. +
  3612. +/*
  3613. + * IRQ handler for the timer
  3614. + */
  3615. +static irqreturn_t bcm2708_timer_interrupt(int irq, void *dev_id)
  3616. +{
  3617. + struct clock_event_device *evt = &timer0_clockevent;
  3618. +
  3619. + writel(1 << 3, __io_address(ST_BASE + 0x00)); /* stcs clear timer int */
  3620. +
  3621. + evt->event_handler(evt);
  3622. +
  3623. + return IRQ_HANDLED;
  3624. +}
  3625. +
  3626. +static struct irqaction bcm2708_timer_irq = {
  3627. + .name = "BCM2708 Timer Tick",
  3628. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  3629. + .handler = bcm2708_timer_interrupt,
  3630. +};
  3631. +
  3632. +/*
  3633. + * Set up timer interrupt, and return the current time in seconds.
  3634. + */
  3635. +
  3636. +static struct delay_timer bcm2708_delay_timer = {
  3637. + .read_current_timer = bcm2708_read_current_timer,
  3638. + .freq = STC_FREQ_HZ,
  3639. +};
  3640. +
  3641. +static void __init bcm2708_timer_init(void)
  3642. +{
  3643. + /* init high res timer */
  3644. + bcm2708_clocksource_init();
  3645. +
  3646. + /*
  3647. + * Initialise to a known state (all timers off)
  3648. + */
  3649. + writel(0, __io_address(ARM_T_CONTROL));
  3650. + /*
  3651. + * Make irqs happen for the system timer
  3652. + */
  3653. + setup_irq(IRQ_TIMER3, &bcm2708_timer_irq);
  3654. +
  3655. + setup_sched_clock(bcm2708_read_sched_clock, 32, STC_FREQ_HZ);
  3656. +
  3657. + timer0_clockevent.mult =
  3658. + div_sc(STC_FREQ_HZ, NSEC_PER_SEC, timer0_clockevent.shift);
  3659. + timer0_clockevent.max_delta_ns =
  3660. + clockevent_delta2ns(0xffffffff, &timer0_clockevent);
  3661. + timer0_clockevent.min_delta_ns =
  3662. + clockevent_delta2ns(0xf, &timer0_clockevent);
  3663. +
  3664. + timer0_clockevent.cpumask = cpumask_of(0);
  3665. + clockevents_register_device(&timer0_clockevent);
  3666. +
  3667. + register_current_timer_delay(&bcm2708_delay_timer);
  3668. +}
  3669. +
  3670. +#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
  3671. +#include <linux/leds.h>
  3672. +
  3673. +static struct gpio_led bcm2708_leds[] = {
  3674. + [0] = {
  3675. + .gpio = 16,
  3676. + .name = "led0",
  3677. + .default_trigger = "mmc0",
  3678. + .active_low = 1,
  3679. + },
  3680. +};
  3681. +
  3682. +static struct gpio_led_platform_data bcm2708_led_pdata = {
  3683. + .num_leds = ARRAY_SIZE(bcm2708_leds),
  3684. + .leds = bcm2708_leds,
  3685. +};
  3686. +
  3687. +static struct platform_device bcm2708_led_device = {
  3688. + .name = "leds-gpio",
  3689. + .id = -1,
  3690. + .dev = {
  3691. + .platform_data = &bcm2708_led_pdata,
  3692. + },
  3693. +};
  3694. +
  3695. +static void __init bcm2708_init_led(void)
  3696. +{
  3697. + bcm2708_leds[0].gpio = disk_led_gpio;
  3698. + bcm2708_leds[0].active_low = disk_led_active_low;
  3699. + platform_device_register(&bcm2708_led_device);
  3700. +}
  3701. +#else
  3702. +static inline void bcm2708_init_led(void)
  3703. +{
  3704. +}
  3705. +#endif
  3706. +
  3707. +void __init bcm2708_init_early(void)
  3708. +{
  3709. + /*
  3710. + * Some devices allocate their coherent buffers from atomic
  3711. + * context. Increase size of atomic coherent pool to make sure such
  3712. + * the allocations won't fail.
  3713. + */
  3714. + init_dma_coherent_pool_size(SZ_4M);
  3715. +}
  3716. +
  3717. +static void __init board_reserve(void)
  3718. +{
  3719. +#if defined(CONFIG_BCM_VC_CMA)
  3720. + vc_cma_reserve();
  3721. +#endif
  3722. +}
  3723. +
  3724. +MACHINE_START(BCM2708, "BCM2708")
  3725. + /* Maintainer: Broadcom Europe Ltd. */
  3726. + .map_io = bcm2708_map_io,
  3727. + .init_irq = bcm2708_init_irq,
  3728. + .init_time = bcm2708_timer_init,
  3729. + .init_machine = bcm2708_init,
  3730. + .init_early = bcm2708_init_early,
  3731. + .reserve = board_reserve,
  3732. + .restart = bcm2708_restart,
  3733. +MACHINE_END
  3734. +
  3735. +module_param(boardrev, uint, 0644);
  3736. +module_param(serial, uint, 0644);
  3737. +module_param(uart_clock, uint, 0644);
  3738. +module_param(disk_led_gpio, uint, 0644);
  3739. +module_param(disk_led_active_low, uint, 0644);
  3740. +module_param(reboot_part, uint, 0644);
  3741. +module_param(w1_gpio_pin, uint, 0644);
  3742. +module_param(w1_gpio_pullup, uint, 0644);
  3743. diff -Nur linux-3.15/arch/arm/mach-bcm2708/bcm2708_gpio.c linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3744. --- linux-3.15/arch/arm/mach-bcm2708/bcm2708_gpio.c 1970-01-01 01:00:00.000000000 +0100
  3745. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708_gpio.c 2014-06-11 21:03:19.000000000 +0200
  3746. @@ -0,0 +1,361 @@
  3747. +/*
  3748. + * linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
  3749. + *
  3750. + * Copyright (C) 2010 Broadcom
  3751. + *
  3752. + * This program is free software; you can redistribute it and/or modify
  3753. + * it under the terms of the GNU General Public License version 2 as
  3754. + * published by the Free Software Foundation.
  3755. + *
  3756. + */
  3757. +
  3758. +#include <linux/spinlock.h>
  3759. +#include <linux/module.h>
  3760. +#include <linux/list.h>
  3761. +#include <linux/io.h>
  3762. +#include <linux/irq.h>
  3763. +#include <linux/interrupt.h>
  3764. +#include <linux/slab.h>
  3765. +#include <mach/gpio.h>
  3766. +#include <linux/gpio.h>
  3767. +#include <linux/platform_device.h>
  3768. +#include <mach/platform.h>
  3769. +
  3770. +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
  3771. +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
  3772. +#define BCM_GPIO_USE_IRQ 1
  3773. +
  3774. +#define GPIOFSEL(x) (0x00+(x)*4)
  3775. +#define GPIOSET(x) (0x1c+(x)*4)
  3776. +#define GPIOCLR(x) (0x28+(x)*4)
  3777. +#define GPIOLEV(x) (0x34+(x)*4)
  3778. +#define GPIOEDS(x) (0x40+(x)*4)
  3779. +#define GPIOREN(x) (0x4c+(x)*4)
  3780. +#define GPIOFEN(x) (0x58+(x)*4)
  3781. +#define GPIOHEN(x) (0x64+(x)*4)
  3782. +#define GPIOLEN(x) (0x70+(x)*4)
  3783. +#define GPIOAREN(x) (0x7c+(x)*4)
  3784. +#define GPIOAFEN(x) (0x88+(x)*4)
  3785. +#define GPIOUD(x) (0x94+(x)*4)
  3786. +#define GPIOUDCLK(x) (0x98+(x)*4)
  3787. +
  3788. +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
  3789. + GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
  3790. + GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
  3791. + GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
  3792. +};
  3793. +
  3794. + /* Each of the two spinlocks protects a different set of hardware
  3795. + * regiters and data structurs. This decouples the code of the IRQ from
  3796. + * the GPIO code. This also makes the case of a GPIO routine call from
  3797. + * the IRQ code simpler.
  3798. + */
  3799. +static DEFINE_SPINLOCK(lock); /* GPIO registers */
  3800. +
  3801. +struct bcm2708_gpio {
  3802. + struct list_head list;
  3803. + void __iomem *base;
  3804. + struct gpio_chip gc;
  3805. + unsigned long rising;
  3806. + unsigned long falling;
  3807. + unsigned long high;
  3808. + unsigned long low;
  3809. +};
  3810. +
  3811. +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
  3812. + int function)
  3813. +{
  3814. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3815. + unsigned long flags;
  3816. + unsigned gpiodir;
  3817. + unsigned gpio_bank = offset / 10;
  3818. + unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
  3819. +
  3820. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
  3821. + if (offset >= BCM2708_NR_GPIOS)
  3822. + return -EINVAL;
  3823. +
  3824. + spin_lock_irqsave(&lock, flags);
  3825. +
  3826. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3827. + gpiodir &= ~(7 << gpio_field_offset);
  3828. + gpiodir |= function << gpio_field_offset;
  3829. + writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
  3830. + spin_unlock_irqrestore(&lock, flags);
  3831. + gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
  3832. +
  3833. + return 0;
  3834. +}
  3835. +
  3836. +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
  3837. +{
  3838. + return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
  3839. +}
  3840. +
  3841. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
  3842. +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
  3843. + int value)
  3844. +{
  3845. + int ret;
  3846. + ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
  3847. + if (ret >= 0)
  3848. + bcm2708_gpio_set(gc, offset, value);
  3849. + return ret;
  3850. +}
  3851. +
  3852. +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
  3853. +{
  3854. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3855. + unsigned gpio_bank = offset / 32;
  3856. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3857. + unsigned lev;
  3858. +
  3859. + if (offset >= BCM2708_NR_GPIOS)
  3860. + return 0;
  3861. + lev = readl(gpio->base + GPIOLEV(gpio_bank));
  3862. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
  3863. + return 0x1 & (lev >> gpio_field_offset);
  3864. +}
  3865. +
  3866. +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
  3867. +{
  3868. + struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
  3869. + unsigned gpio_bank = offset / 32;
  3870. + unsigned gpio_field_offset = (offset - 32 * gpio_bank);
  3871. +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
  3872. + if (offset >= BCM2708_NR_GPIOS)
  3873. + return;
  3874. + if (value)
  3875. + writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
  3876. + else
  3877. + writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
  3878. +}
  3879. +
  3880. +/*************************************************************************************************************************
  3881. + * bcm2708 GPIO IRQ
  3882. + */
  3883. +
  3884. +#if BCM_GPIO_USE_IRQ
  3885. +
  3886. +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  3887. +{
  3888. + return gpio_to_irq(gpio);
  3889. +}
  3890. +
  3891. +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
  3892. +{
  3893. + unsigned irq = d->irq;
  3894. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3895. +
  3896. + gpio->rising &= ~(1 << irq_to_gpio(irq));
  3897. + gpio->falling &= ~(1 << irq_to_gpio(irq));
  3898. + gpio->high &= ~(1 << irq_to_gpio(irq));
  3899. + gpio->low &= ~(1 << irq_to_gpio(irq));
  3900. +
  3901. + if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  3902. + return -EINVAL;
  3903. +
  3904. + if (type & IRQ_TYPE_EDGE_RISING)
  3905. + gpio->rising |= (1 << irq_to_gpio(irq));
  3906. + if (type & IRQ_TYPE_EDGE_FALLING)
  3907. + gpio->falling |= (1 << irq_to_gpio(irq));
  3908. + if (type & IRQ_TYPE_LEVEL_HIGH)
  3909. + gpio->high |= (1 << irq_to_gpio(irq));
  3910. + if (type & IRQ_TYPE_LEVEL_LOW)
  3911. + gpio->low |= (1 << irq_to_gpio(irq));
  3912. + return 0;
  3913. +}
  3914. +
  3915. +static void bcm2708_gpio_irq_mask(struct irq_data *d)
  3916. +{
  3917. + unsigned irq = d->irq;
  3918. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3919. + unsigned gn = irq_to_gpio(irq);
  3920. + unsigned gb = gn / 32;
  3921. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3922. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3923. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3924. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3925. +
  3926. + gn = gn % 32;
  3927. +
  3928. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3929. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3930. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3931. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3932. +}
  3933. +
  3934. +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
  3935. +{
  3936. + unsigned irq = d->irq;
  3937. + struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
  3938. + unsigned gn = irq_to_gpio(irq);
  3939. + unsigned gb = gn / 32;
  3940. + unsigned long rising = readl(gpio->base + GPIOREN(gb));
  3941. + unsigned long falling = readl(gpio->base + GPIOFEN(gb));
  3942. + unsigned long high = readl(gpio->base + GPIOHEN(gb));
  3943. + unsigned long low = readl(gpio->base + GPIOLEN(gb));
  3944. +
  3945. + gn = gn % 32;
  3946. +
  3947. + writel(1 << gn, gpio->base + GPIOEDS(gb));
  3948. +
  3949. + if (gpio->rising & (1 << gn)) {
  3950. + writel(rising | (1 << gn), gpio->base + GPIOREN(gb));
  3951. + } else {
  3952. + writel(rising & ~(1 << gn), gpio->base + GPIOREN(gb));
  3953. + }
  3954. +
  3955. + if (gpio->falling & (1 << gn)) {
  3956. + writel(falling | (1 << gn), gpio->base + GPIOFEN(gb));
  3957. + } else {
  3958. + writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
  3959. + }
  3960. +
  3961. + if (gpio->high & (1 << gn)) {
  3962. + writel(high | (1 << gn), gpio->base + GPIOHEN(gb));
  3963. + } else {
  3964. + writel(high & ~(1 << gn), gpio->base + GPIOHEN(gb));
  3965. + }
  3966. +
  3967. + if (gpio->low & (1 << gn)) {
  3968. + writel(low | (1 << gn), gpio->base + GPIOLEN(gb));
  3969. + } else {
  3970. + writel(low & ~(1 << gn), gpio->base + GPIOLEN(gb));
  3971. + }
  3972. +}
  3973. +
  3974. +static struct irq_chip bcm2708_irqchip = {
  3975. + .name = "GPIO",
  3976. + .irq_enable = bcm2708_gpio_irq_unmask,
  3977. + .irq_disable = bcm2708_gpio_irq_mask,
  3978. + .irq_unmask = bcm2708_gpio_irq_unmask,
  3979. + .irq_mask = bcm2708_gpio_irq_mask,
  3980. + .irq_set_type = bcm2708_gpio_irq_set_type,
  3981. +};
  3982. +
  3983. +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
  3984. +{
  3985. + unsigned long edsr;
  3986. + unsigned bank;
  3987. + int i;
  3988. + unsigned gpio;
  3989. + for (bank = 0; bank <= 1; bank++) {
  3990. + edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
  3991. + for_each_set_bit(i, &edsr, 32) {
  3992. + gpio = i + bank * 32;
  3993. + generic_handle_irq(gpio_to_irq(gpio));
  3994. + }
  3995. + writel(0xffffffff, __io_address(GPIO_BASE) + GPIOEDS(bank));
  3996. + }
  3997. + return IRQ_HANDLED;
  3998. +}
  3999. +
  4000. +static struct irqaction bcm2708_gpio_irq = {
  4001. + .name = "BCM2708 GPIO catchall handler",
  4002. + .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
  4003. + .handler = bcm2708_gpio_interrupt,
  4004. +};
  4005. +
  4006. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4007. +{
  4008. + unsigned irq;
  4009. +
  4010. + ucb->gc.to_irq = bcm2708_gpio_to_irq;
  4011. +
  4012. + for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
  4013. + irq_set_chip_data(irq, ucb);
  4014. + irq_set_chip(irq, &bcm2708_irqchip);
  4015. + set_irq_flags(irq, IRQF_VALID);
  4016. + }
  4017. + setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
  4018. +}
  4019. +
  4020. +#else
  4021. +
  4022. +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
  4023. +{
  4024. +}
  4025. +
  4026. +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
  4027. +
  4028. +static int bcm2708_gpio_probe(struct platform_device *dev)
  4029. +{
  4030. + struct bcm2708_gpio *ucb;
  4031. + struct resource *res;
  4032. + int err = 0;
  4033. +
  4034. + printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
  4035. +
  4036. + ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
  4037. + if (NULL == ucb) {
  4038. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4039. + "mailbox memory\n");
  4040. + err = -ENOMEM;
  4041. + goto err;
  4042. + }
  4043. +
  4044. + res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  4045. +
  4046. + platform_set_drvdata(dev, ucb);
  4047. + ucb->base = __io_address(GPIO_BASE);
  4048. +
  4049. + ucb->gc.label = "bcm2708_gpio";
  4050. + ucb->gc.base = 0;
  4051. + ucb->gc.ngpio = BCM2708_NR_GPIOS;
  4052. + ucb->gc.owner = THIS_MODULE;
  4053. +
  4054. + ucb->gc.direction_input = bcm2708_gpio_dir_in;
  4055. + ucb->gc.direction_output = bcm2708_gpio_dir_out;
  4056. + ucb->gc.get = bcm2708_gpio_get;
  4057. + ucb->gc.set = bcm2708_gpio_set;
  4058. + ucb->gc.can_sleep = 0;
  4059. +
  4060. + bcm2708_gpio_irq_init(ucb);
  4061. +
  4062. + err = gpiochip_add(&ucb->gc);
  4063. + if (err)
  4064. + goto err;
  4065. +
  4066. +err:
  4067. + return err;
  4068. +
  4069. +}
  4070. +
  4071. +static int bcm2708_gpio_remove(struct platform_device *dev)
  4072. +{
  4073. + int err = 0;
  4074. + struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
  4075. +
  4076. + printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
  4077. +
  4078. + err = gpiochip_remove(&ucb->gc);
  4079. +
  4080. + platform_set_drvdata(dev, NULL);
  4081. + kfree(ucb);
  4082. +
  4083. + return err;
  4084. +}
  4085. +
  4086. +static struct platform_driver bcm2708_gpio_driver = {
  4087. + .probe = bcm2708_gpio_probe,
  4088. + .remove = bcm2708_gpio_remove,
  4089. + .driver = {
  4090. + .name = "bcm2708_gpio"},
  4091. +};
  4092. +
  4093. +static int __init bcm2708_gpio_init(void)
  4094. +{
  4095. + return platform_driver_register(&bcm2708_gpio_driver);
  4096. +}
  4097. +
  4098. +static void __exit bcm2708_gpio_exit(void)
  4099. +{
  4100. + platform_driver_unregister(&bcm2708_gpio_driver);
  4101. +}
  4102. +
  4103. +module_init(bcm2708_gpio_init);
  4104. +module_exit(bcm2708_gpio_exit);
  4105. +
  4106. +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
  4107. +MODULE_LICENSE("GPL");
  4108. diff -Nur linux-3.15/arch/arm/mach-bcm2708/bcm2708.h linux-rpi/arch/arm/mach-bcm2708/bcm2708.h
  4109. --- linux-3.15/arch/arm/mach-bcm2708/bcm2708.h 1970-01-01 01:00:00.000000000 +0100
  4110. +++ linux-rpi/arch/arm/mach-bcm2708/bcm2708.h 2014-06-11 21:03:19.000000000 +0200
  4111. @@ -0,0 +1,49 @@
  4112. +/*
  4113. + * linux/arch/arm/mach-bcm2708/bcm2708.h
  4114. + *
  4115. + * BCM2708 machine support header
  4116. + *
  4117. + * Copyright (C) 2010 Broadcom
  4118. + *
  4119. + * This program is free software; you can redistribute it and/or modify
  4120. + * it under the terms of the GNU General Public License as published by
  4121. + * the Free Software Foundation; either version 2 of the License, or
  4122. + * (at your option) any later version.
  4123. + *
  4124. + * This program is distributed in the hope that it will be useful,
  4125. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4126. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4127. + * GNU General Public License for more details.
  4128. + *
  4129. + * You should have received a copy of the GNU General Public License
  4130. + * along with this program; if not, write to the Free Software
  4131. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4132. + */
  4133. +
  4134. +#ifndef __BCM2708_BCM2708_H
  4135. +#define __BCM2708_BCM2708_H
  4136. +
  4137. +#include <linux/amba/bus.h>
  4138. +
  4139. +extern void __init bcm2708_init(void);
  4140. +extern void __init bcm2708_init_irq(void);
  4141. +extern void __init bcm2708_map_io(void);
  4142. +extern struct sys_timer bcm2708_timer;
  4143. +extern unsigned int mmc_status(struct device *dev);
  4144. +
  4145. +#define AMBA_DEVICE(name, busid, base, plat) \
  4146. +static struct amba_device name##_device = { \
  4147. + .dev = { \
  4148. + .coherent_dma_mask = ~0, \
  4149. + .init_name = busid, \
  4150. + .platform_data = plat, \
  4151. + }, \
  4152. + .res = { \
  4153. + .start = base##_BASE, \
  4154. + .end = (base##_BASE) + SZ_4K - 1,\
  4155. + .flags = IORESOURCE_MEM, \
  4156. + }, \
  4157. + .irq = base##_IRQ, \
  4158. +}
  4159. +
  4160. +#endif
  4161. diff -Nur linux-3.15/arch/arm/mach-bcm2708/clock.c linux-rpi/arch/arm/mach-bcm2708/clock.c
  4162. --- linux-3.15/arch/arm/mach-bcm2708/clock.c 1970-01-01 01:00:00.000000000 +0100
  4163. +++ linux-rpi/arch/arm/mach-bcm2708/clock.c 2014-06-11 21:03:19.000000000 +0200
  4164. @@ -0,0 +1,61 @@
  4165. +/*
  4166. + * linux/arch/arm/mach-bcm2708/clock.c
  4167. + *
  4168. + * Copyright (C) 2010 Broadcom
  4169. + *
  4170. + * This program is free software; you can redistribute it and/or modify
  4171. + * it under the terms of the GNU General Public License as published by
  4172. + * the Free Software Foundation; either version 2 of the License, or
  4173. + * (at your option) any later version.
  4174. + *
  4175. + * This program is distributed in the hope that it will be useful,
  4176. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4177. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4178. + * GNU General Public License for more details.
  4179. + *
  4180. + * You should have received a copy of the GNU General Public License
  4181. + * along with this program; if not, write to the Free Software
  4182. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4183. + */
  4184. +#include <linux/module.h>
  4185. +#include <linux/kernel.h>
  4186. +#include <linux/device.h>
  4187. +#include <linux/list.h>
  4188. +#include <linux/errno.h>
  4189. +#include <linux/err.h>
  4190. +#include <linux/string.h>
  4191. +#include <linux/clk.h>
  4192. +#include <linux/mutex.h>
  4193. +
  4194. +#include <asm/clkdev.h>
  4195. +
  4196. +#include "clock.h"
  4197. +
  4198. +int clk_enable(struct clk *clk)
  4199. +{
  4200. + return 0;
  4201. +}
  4202. +EXPORT_SYMBOL(clk_enable);
  4203. +
  4204. +void clk_disable(struct clk *clk)
  4205. +{
  4206. +}
  4207. +EXPORT_SYMBOL(clk_disable);
  4208. +
  4209. +unsigned long clk_get_rate(struct clk *clk)
  4210. +{
  4211. + return clk->rate;
  4212. +}
  4213. +EXPORT_SYMBOL(clk_get_rate);
  4214. +
  4215. +long clk_round_rate(struct clk *clk, unsigned long rate)
  4216. +{
  4217. + return clk->rate;
  4218. +}
  4219. +EXPORT_SYMBOL(clk_round_rate);
  4220. +
  4221. +int clk_set_rate(struct clk *clk, unsigned long rate)
  4222. +{
  4223. + return -EIO;
  4224. +}
  4225. +EXPORT_SYMBOL(clk_set_rate);
  4226. diff -Nur linux-3.15/arch/arm/mach-bcm2708/clock.h linux-rpi/arch/arm/mach-bcm2708/clock.h
  4227. --- linux-3.15/arch/arm/mach-bcm2708/clock.h 1970-01-01 01:00:00.000000000 +0100
  4228. +++ linux-rpi/arch/arm/mach-bcm2708/clock.h 2014-06-11 21:03:19.000000000 +0200
  4229. @@ -0,0 +1,24 @@
  4230. +/*
  4231. + * linux/arch/arm/mach-bcm2708/clock.h
  4232. + *
  4233. + * Copyright (C) 2010 Broadcom
  4234. + *
  4235. + * This program is free software; you can redistribute it and/or modify
  4236. + * it under the terms of the GNU General Public License as published by
  4237. + * the Free Software Foundation; either version 2 of the License, or
  4238. + * (at your option) any later version.
  4239. + *
  4240. + * This program is distributed in the hope that it will be useful,
  4241. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4242. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4243. + * GNU General Public License for more details.
  4244. + *
  4245. + * You should have received a copy of the GNU General Public License
  4246. + * along with this program; if not, write to the Free Software
  4247. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4248. + */
  4249. +struct module;
  4250. +
  4251. +struct clk {
  4252. + unsigned long rate;
  4253. +};
  4254. diff -Nur linux-3.15/arch/arm/mach-bcm2708/dma.c linux-rpi/arch/arm/mach-bcm2708/dma.c
  4255. --- linux-3.15/arch/arm/mach-bcm2708/dma.c 1970-01-01 01:00:00.000000000 +0100
  4256. +++ linux-rpi/arch/arm/mach-bcm2708/dma.c 2014-06-11 21:03:19.000000000 +0200
  4257. @@ -0,0 +1,407 @@
  4258. +/*
  4259. + * linux/arch/arm/mach-bcm2708/dma.c
  4260. + *
  4261. + * Copyright (C) 2010 Broadcom
  4262. + *
  4263. + * This program is free software; you can redistribute it and/or modify
  4264. + * it under the terms of the GNU General Public License version 2 as
  4265. + * published by the Free Software Foundation.
  4266. + */
  4267. +
  4268. +#include <linux/slab.h>
  4269. +#include <linux/device.h>
  4270. +#include <linux/platform_device.h>
  4271. +#include <linux/module.h>
  4272. +#include <linux/scatterlist.h>
  4273. +
  4274. +#include <mach/dma.h>
  4275. +#include <mach/irqs.h>
  4276. +
  4277. +/*****************************************************************************\
  4278. + * *
  4279. + * Configuration *
  4280. + * *
  4281. +\*****************************************************************************/
  4282. +
  4283. +#define CACHE_LINE_MASK 31
  4284. +#define DRIVER_NAME BCM_DMAMAN_DRIVER_NAME
  4285. +#define DEFAULT_DMACHAN_BITMAP 0x10 /* channel 4 only */
  4286. +
  4287. +/* valid only for channels 0 - 14, 15 has its own base address */
  4288. +#define BCM2708_DMA_CHAN(n) ((n)<<8) /* base address */
  4289. +#define BCM2708_DMA_CHANIO(dma_base, n) \
  4290. + ((void __iomem *)((char *)(dma_base)+BCM2708_DMA_CHAN(n)))
  4291. +
  4292. +
  4293. +/*****************************************************************************\
  4294. + * *
  4295. + * DMA Auxilliary Functions *
  4296. + * *
  4297. +\*****************************************************************************/
  4298. +
  4299. +/* A DMA buffer on an arbitrary boundary may separate a cache line into a
  4300. + section inside the DMA buffer and another section outside it.
  4301. + Even if we flush DMA buffers from the cache there is always the chance that
  4302. + during a DMA someone will access the part of a cache line that is outside
  4303. + the DMA buffer - which will then bring in unwelcome data.
  4304. + Without being able to dictate our own buffer pools we must insist that
  4305. + DMA buffers consist of a whole number of cache lines.
  4306. +*/
  4307. +
  4308. +extern int
  4309. +bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len)
  4310. +{
  4311. + int i;
  4312. +
  4313. + for (i = 0; i < sg_len; i++) {
  4314. + if (sg_ptr[i].offset & CACHE_LINE_MASK ||
  4315. + sg_ptr[i].length & CACHE_LINE_MASK)
  4316. + return 0;
  4317. + }
  4318. +
  4319. + return 1;
  4320. +}
  4321. +EXPORT_SYMBOL_GPL(bcm_sg_suitable_for_dma);
  4322. +
  4323. +extern void
  4324. +bcm_dma_start(void __iomem *dma_chan_base, dma_addr_t control_block)
  4325. +{
  4326. + dsb(); /* ARM data synchronization (push) operation */
  4327. +
  4328. + writel(control_block, dma_chan_base + BCM2708_DMA_ADDR);
  4329. + writel(BCM2708_DMA_ACTIVE, dma_chan_base + BCM2708_DMA_CS);
  4330. +}
  4331. +
  4332. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base)
  4333. +{
  4334. + dsb();
  4335. +
  4336. + /* ugly busy wait only option for now */
  4337. + while (readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE)
  4338. + cpu_relax();
  4339. +}
  4340. +
  4341. +EXPORT_SYMBOL_GPL(bcm_dma_start);
  4342. +
  4343. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base)
  4344. +{
  4345. + dsb();
  4346. +
  4347. + return readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_ACTIVE;
  4348. +}
  4349. +EXPORT_SYMBOL_GPL(bcm_dma_is_busy);
  4350. +
  4351. +/* Complete an ongoing DMA (assuming its results are to be ignored)
  4352. + Does nothing if there is no DMA in progress.
  4353. + This routine waits for the current AXI transfer to complete before
  4354. + terminating the current DMA. If the current transfer is hung on a DREQ used
  4355. + by an uncooperative peripheral the AXI transfer may never complete. In this
  4356. + case the routine times out and return a non-zero error code.
  4357. + Use of this routine doesn't guarantee that the ongoing or aborted DMA
  4358. + does not produce an interrupt.
  4359. +*/
  4360. +extern int
  4361. +bcm_dma_abort(void __iomem *dma_chan_base)
  4362. +{
  4363. + unsigned long int cs;
  4364. + int rc = 0;
  4365. +
  4366. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4367. +
  4368. + if (BCM2708_DMA_ACTIVE & cs) {
  4369. + long int timeout = 10000;
  4370. +
  4371. + /* write 0 to the active bit - pause the DMA */
  4372. + writel(0, dma_chan_base + BCM2708_DMA_CS);
  4373. +
  4374. + /* wait for any current AXI transfer to complete */
  4375. + while (0 != (cs & BCM2708_DMA_ISPAUSED) && --timeout >= 0)
  4376. + cs = readl(dma_chan_base + BCM2708_DMA_CS);
  4377. +
  4378. + if (0 != (cs & BCM2708_DMA_ISPAUSED)) {
  4379. + /* we'll un-pause when we set of our next DMA */
  4380. + rc = -ETIMEDOUT;
  4381. +
  4382. + } else if (BCM2708_DMA_ACTIVE & cs) {
  4383. + /* terminate the control block chain */
  4384. + writel(0, dma_chan_base + BCM2708_DMA_NEXTCB);
  4385. +
  4386. + /* abort the whole DMA */
  4387. + writel(BCM2708_DMA_ABORT | BCM2708_DMA_ACTIVE,
  4388. + dma_chan_base + BCM2708_DMA_CS);
  4389. + }
  4390. + }
  4391. +
  4392. + return rc;
  4393. +}
  4394. +EXPORT_SYMBOL_GPL(bcm_dma_abort);
  4395. +
  4396. +
  4397. +/***************************************************************************** \
  4398. + * *
  4399. + * DMA Manager Device Methods *
  4400. + * *
  4401. +\*****************************************************************************/
  4402. +
  4403. +struct vc_dmaman {
  4404. + void __iomem *dma_base;
  4405. + u32 chan_available; /* bitmap of available channels */
  4406. + u32 has_feature[BCM_DMA_FEATURE_COUNT]; /* bitmap of feature presence */
  4407. +};
  4408. +
  4409. +static void vc_dmaman_init(struct vc_dmaman *dmaman, void __iomem *dma_base,
  4410. + u32 chans_available)
  4411. +{
  4412. + dmaman->dma_base = dma_base;
  4413. + dmaman->chan_available = chans_available;
  4414. + dmaman->has_feature[BCM_DMA_FEATURE_FAST_ORD] = 0x0c; /* chans 2 & 3 */
  4415. + dmaman->has_feature[BCM_DMA_FEATURE_BULK_ORD] = 0x01; /* chan 0 */
  4416. +}
  4417. +
  4418. +static int vc_dmaman_chan_alloc(struct vc_dmaman *dmaman,
  4419. + unsigned preferred_feature_set)
  4420. +{
  4421. + u32 chans;
  4422. + int feature;
  4423. +
  4424. + chans = dmaman->chan_available;
  4425. + for (feature = 0; feature < BCM_DMA_FEATURE_COUNT; feature++)
  4426. + /* select the subset of available channels with the desired
  4427. + feature so long as some of the candidate channels have that
  4428. + feature */
  4429. + if ((preferred_feature_set & (1 << feature)) &&
  4430. + (chans & dmaman->has_feature[feature]))
  4431. + chans &= dmaman->has_feature[feature];
  4432. +
  4433. + if (chans) {
  4434. + int chan = 0;
  4435. + /* return the ordinal of the first channel in the bitmap */
  4436. + while (chans != 0 && (chans & 1) == 0) {
  4437. + chans >>= 1;
  4438. + chan++;
  4439. + }
  4440. + /* claim the channel */
  4441. + dmaman->chan_available &= ~(1 << chan);
  4442. + return chan;
  4443. + } else
  4444. + return -ENOMEM;
  4445. +}
  4446. +
  4447. +static int vc_dmaman_chan_free(struct vc_dmaman *dmaman, int chan)
  4448. +{
  4449. + if (chan < 0)
  4450. + return -EINVAL;
  4451. + else if ((1 << chan) & dmaman->chan_available)
  4452. + return -EIDRM;
  4453. + else {
  4454. + dmaman->chan_available |= (1 << chan);
  4455. + return 0;
  4456. + }
  4457. +}
  4458. +
  4459. +/*****************************************************************************\
  4460. + * *
  4461. + * DMA IRQs *
  4462. + * *
  4463. +\*****************************************************************************/
  4464. +
  4465. +static unsigned char bcm_dma_irqs[] = {
  4466. + IRQ_DMA0,
  4467. + IRQ_DMA1,
  4468. + IRQ_DMA2,
  4469. + IRQ_DMA3,
  4470. + IRQ_DMA4,
  4471. + IRQ_DMA5,
  4472. + IRQ_DMA6,
  4473. + IRQ_DMA7,
  4474. + IRQ_DMA8,
  4475. + IRQ_DMA9,
  4476. + IRQ_DMA10,
  4477. + IRQ_DMA11,
  4478. + IRQ_DMA12
  4479. +};
  4480. +
  4481. +
  4482. +/***************************************************************************** \
  4483. + * *
  4484. + * DMA Manager Monitor *
  4485. + * *
  4486. +\*****************************************************************************/
  4487. +
  4488. +static struct device *dmaman_dev; /* we assume there's only one! */
  4489. +
  4490. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  4491. + void __iomem **out_dma_base, int *out_dma_irq)
  4492. +{
  4493. + if (!dmaman_dev)
  4494. + return -ENODEV;
  4495. + else {
  4496. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4497. + int rc;
  4498. +
  4499. + device_lock(dmaman_dev);
  4500. + rc = vc_dmaman_chan_alloc(dmaman, preferred_feature_set);
  4501. + if (rc >= 0) {
  4502. + *out_dma_base = BCM2708_DMA_CHANIO(dmaman->dma_base,
  4503. + rc);
  4504. + *out_dma_irq = bcm_dma_irqs[rc];
  4505. + }
  4506. + device_unlock(dmaman_dev);
  4507. +
  4508. + return rc;
  4509. + }
  4510. +}
  4511. +EXPORT_SYMBOL_GPL(bcm_dma_chan_alloc);
  4512. +
  4513. +extern int bcm_dma_chan_free(int channel)
  4514. +{
  4515. + if (dmaman_dev) {
  4516. + struct vc_dmaman *dmaman = dev_get_drvdata(dmaman_dev);
  4517. + int rc;
  4518. +
  4519. + device_lock(dmaman_dev);
  4520. + rc = vc_dmaman_chan_free(dmaman, channel);
  4521. + device_unlock(dmaman_dev);
  4522. +
  4523. + return rc;
  4524. + } else
  4525. + return -ENODEV;
  4526. +}
  4527. +EXPORT_SYMBOL_GPL(bcm_dma_chan_free);
  4528. +
  4529. +static int dev_dmaman_register(const char *dev_name, struct device *dev)
  4530. +{
  4531. + int rc = dmaman_dev ? -EINVAL : 0;
  4532. + dmaman_dev = dev;
  4533. + return rc;
  4534. +}
  4535. +
  4536. +static void dev_dmaman_deregister(const char *dev_name, struct device *dev)
  4537. +{
  4538. + dmaman_dev = NULL;
  4539. +}
  4540. +
  4541. +/*****************************************************************************\
  4542. + * *
  4543. + * DMA Device *
  4544. + * *
  4545. +\*****************************************************************************/
  4546. +
  4547. +static int dmachans = -1; /* module parameter */
  4548. +
  4549. +static int bcm_dmaman_probe(struct platform_device *pdev)
  4550. +{
  4551. + int ret = 0;
  4552. + struct vc_dmaman *dmaman;
  4553. + struct resource *dma_res = NULL;
  4554. + void __iomem *dma_base = NULL;
  4555. + int have_dma_region = 0;
  4556. +
  4557. + dmaman = kzalloc(sizeof(*dmaman), GFP_KERNEL);
  4558. + if (NULL == dmaman) {
  4559. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  4560. + "DMA management memory\n");
  4561. + ret = -ENOMEM;
  4562. + } else {
  4563. +
  4564. + dma_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  4565. + if (dma_res == NULL) {
  4566. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  4567. + "resource\n");
  4568. + ret = -ENODEV;
  4569. + } else if (!request_mem_region(dma_res->start,
  4570. + resource_size(dma_res),
  4571. + DRIVER_NAME)) {
  4572. + dev_err(&pdev->dev, "cannot obtain DMA region\n");
  4573. + ret = -EBUSY;
  4574. + } else {
  4575. + have_dma_region = 1;
  4576. + dma_base = ioremap(dma_res->start,
  4577. + resource_size(dma_res));
  4578. + if (!dma_base) {
  4579. + dev_err(&pdev->dev, "cannot map DMA region\n");
  4580. + ret = -ENOMEM;
  4581. + } else {
  4582. + /* use module parameter if one was provided */
  4583. + if (dmachans > 0)
  4584. + vc_dmaman_init(dmaman, dma_base,
  4585. + dmachans);
  4586. + else
  4587. + vc_dmaman_init(dmaman, dma_base,
  4588. + DEFAULT_DMACHAN_BITMAP);
  4589. +
  4590. + platform_set_drvdata(pdev, dmaman);
  4591. + dev_dmaman_register(DRIVER_NAME, &pdev->dev);
  4592. +
  4593. + printk(KERN_INFO DRIVER_NAME ": DMA manager "
  4594. + "at %p\n", dma_base);
  4595. + }
  4596. + }
  4597. + }
  4598. + if (ret != 0) {
  4599. + if (dma_base)
  4600. + iounmap(dma_base);
  4601. + if (dma_res && have_dma_region)
  4602. + release_mem_region(dma_res->start,
  4603. + resource_size(dma_res));
  4604. + if (dmaman)
  4605. + kfree(dmaman);
  4606. + }
  4607. + return ret;
  4608. +}
  4609. +
  4610. +static int bcm_dmaman_remove(struct platform_device *pdev)
  4611. +{
  4612. + struct vc_dmaman *dmaman = platform_get_drvdata(pdev);
  4613. +
  4614. + platform_set_drvdata(pdev, NULL);
  4615. + dev_dmaman_deregister(DRIVER_NAME, &pdev->dev);
  4616. + kfree(dmaman);
  4617. +
  4618. + return 0;
  4619. +}
  4620. +
  4621. +static struct platform_driver bcm_dmaman_driver = {
  4622. + .probe = bcm_dmaman_probe,
  4623. + .remove = bcm_dmaman_remove,
  4624. +
  4625. + .driver = {
  4626. + .name = DRIVER_NAME,
  4627. + .owner = THIS_MODULE,
  4628. + },
  4629. +};
  4630. +
  4631. +/*****************************************************************************\
  4632. + * *
  4633. + * Driver init/exit *
  4634. + * *
  4635. +\*****************************************************************************/
  4636. +
  4637. +static int __init bcm_dmaman_drv_init(void)
  4638. +{
  4639. + int ret;
  4640. +
  4641. + ret = platform_driver_register(&bcm_dmaman_driver);
  4642. + if (ret != 0) {
  4643. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  4644. + "on platform\n");
  4645. + }
  4646. +
  4647. + return ret;
  4648. +}
  4649. +
  4650. +static void __exit bcm_dmaman_drv_exit(void)
  4651. +{
  4652. + platform_driver_unregister(&bcm_dmaman_driver);
  4653. +}
  4654. +
  4655. +module_init(bcm_dmaman_drv_init);
  4656. +module_exit(bcm_dmaman_drv_exit);
  4657. +
  4658. +module_param(dmachans, int, 0644);
  4659. +
  4660. +MODULE_AUTHOR("Gray Girling <grayg@broadcom.com>");
  4661. +MODULE_DESCRIPTION("DMA channel manager driver");
  4662. +MODULE_LICENSE("GPL");
  4663. +
  4664. +MODULE_PARM_DESC(dmachans, "Bitmap of DMA channels available to the ARM");
  4665. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/arm_control.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h
  4666. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/arm_control.h 1970-01-01 01:00:00.000000000 +0100
  4667. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_control.h 2014-06-11 21:03:19.000000000 +0200
  4668. @@ -0,0 +1,419 @@
  4669. +/*
  4670. + * linux/arch/arm/mach-bcm2708/arm_control.h
  4671. + *
  4672. + * Copyright (C) 2010 Broadcom
  4673. + *
  4674. + * This program is free software; you can redistribute it and/or modify
  4675. + * it under the terms of the GNU General Public License as published by
  4676. + * the Free Software Foundation; either version 2 of the License, or
  4677. + * (at your option) any later version.
  4678. + *
  4679. + * This program is distributed in the hope that it will be useful,
  4680. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  4681. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4682. + * GNU General Public License for more details.
  4683. + *
  4684. + * You should have received a copy of the GNU General Public License
  4685. + * along with this program; if not, write to the Free Software
  4686. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  4687. + */
  4688. +
  4689. +#ifndef __BCM2708_ARM_CONTROL_H
  4690. +#define __BCM2708_ARM_CONTROL_H
  4691. +
  4692. +/*
  4693. + * Definitions and addresses for the ARM CONTROL logic
  4694. + * This file is manually generated.
  4695. + */
  4696. +
  4697. +#define ARM_BASE 0x7E00B000
  4698. +
  4699. +/* Basic configuration */
  4700. +#define ARM_CONTROL0 HW_REGISTER_RW(ARM_BASE+0x000)
  4701. +#define ARM_C0_SIZ128M 0x00000000
  4702. +#define ARM_C0_SIZ256M 0x00000001
  4703. +#define ARM_C0_SIZ512M 0x00000002
  4704. +#define ARM_C0_SIZ1G 0x00000003
  4705. +#define ARM_C0_BRESP0 0x00000000
  4706. +#define ARM_C0_BRESP1 0x00000004
  4707. +#define ARM_C0_BRESP2 0x00000008
  4708. +#define ARM_C0_BOOTHI 0x00000010
  4709. +#define ARM_C0_UNUSED05 0x00000020 /* free */
  4710. +#define ARM_C0_FULLPERI 0x00000040
  4711. +#define ARM_C0_UNUSED78 0x00000180 /* free */
  4712. +#define ARM_C0_JTAGMASK 0x00000E00
  4713. +#define ARM_C0_JTAGOFF 0x00000000
  4714. +#define ARM_C0_JTAGBASH 0x00000800 /* Debug on GPIO off */
  4715. +#define ARM_C0_JTAGGPIO 0x00000C00 /* Debug on GPIO on */
  4716. +#define ARM_C0_APROTMSK 0x0000F000
  4717. +#define ARM_C0_DBG0SYNC 0x00010000 /* VPU0 halt sync */
  4718. +#define ARM_C0_DBG1SYNC 0x00020000 /* VPU1 halt sync */
  4719. +#define ARM_C0_SWDBGREQ 0x00040000 /* HW debug request */
  4720. +#define ARM_C0_PASSHALT 0x00080000 /* ARM halt passed to debugger */
  4721. +#define ARM_C0_PRIO_PER 0x00F00000 /* per priority mask */
  4722. +#define ARM_C0_PRIO_L2 0x0F000000
  4723. +#define ARM_C0_PRIO_UC 0xF0000000
  4724. +
  4725. +#define ARM_C0_APROTPASS 0x0000A000 /* Translate 1:1 */
  4726. +#define ARM_C0_APROTUSER 0x00000000 /* Only user mode */
  4727. +#define ARM_C0_APROTSYST 0x0000F000 /* Only system mode */
  4728. +
  4729. +
  4730. +#define ARM_CONTROL1 HW_REGISTER_RW(ARM_BASE+0x440)
  4731. +#define ARM_C1_TIMER 0x00000001 /* re-route timer IRQ to VC */
  4732. +#define ARM_C1_MAIL 0x00000002 /* re-route Mail IRQ to VC */
  4733. +#define ARM_C1_BELL0 0x00000004 /* re-route Doorbell 0 to VC */
  4734. +#define ARM_C1_BELL1 0x00000008 /* re-route Doorbell 1 to VC */
  4735. +#define ARM_C1_PERSON 0x00000100 /* peripherals on */
  4736. +#define ARM_C1_REQSTOP 0x00000200 /* ASYNC bridge request stop */
  4737. +
  4738. +#define ARM_STATUS HW_REGISTER_RW(ARM_BASE+0x444)
  4739. +#define ARM_S_ACKSTOP 0x80000000 /* Bridge stopped */
  4740. +#define ARM_S_READPEND 0x000003FF /* pending reads counter */
  4741. +#define ARM_S_WRITPEND 0x000FFC00 /* pending writes counter */
  4742. +
  4743. +#define ARM_ERRHALT HW_REGISTER_RW(ARM_BASE+0x448)
  4744. +#define ARM_EH_PERIBURST 0x00000001 /* Burst write seen on peri bus */
  4745. +#define ARM_EH_ILLADDRS1 0x00000002 /* Address bits 25-27 error */
  4746. +#define ARM_EH_ILLADDRS2 0x00000004 /* Address bits 31-28 error */
  4747. +#define ARM_EH_VPU0HALT 0x00000008 /* VPU0 halted & in debug mode */
  4748. +#define ARM_EH_VPU1HALT 0x00000010 /* VPU1 halted & in debug mode */
  4749. +#define ARM_EH_ARMHALT 0x00000020 /* ARM in halted debug mode */
  4750. +
  4751. +#define ARM_ID_SECURE HW_REGISTER_RW(ARM_BASE+0x00C)
  4752. +#define ARM_ID HW_REGISTER_RW(ARM_BASE+0x44C)
  4753. +#define ARM_IDVAL 0x364D5241
  4754. +
  4755. +/* Translation memory */
  4756. +#define ARM_TRANSLATE HW_REGISTER_RW(ARM_BASE+0x100)
  4757. +/* 32 locations: 0x100.. 0x17F */
  4758. +/* 32 spare means we CAN go to 64 pages.... */
  4759. +
  4760. +
  4761. +/* Interrupts */
  4762. +#define ARM_IRQ_PEND0 HW_REGISTER_RW(ARM_BASE+0x200) /* Top IRQ bits */
  4763. +#define ARM_I0_TIMER 0x00000001 /* timer IRQ */
  4764. +#define ARM_I0_MAIL 0x00000002 /* Mail IRQ */
  4765. +#define ARM_I0_BELL0 0x00000004 /* Doorbell 0 */
  4766. +#define ARM_I0_BELL1 0x00000008 /* Doorbell 1 */
  4767. +#define ARM_I0_BANK1 0x00000100 /* Bank1 IRQ */
  4768. +#define ARM_I0_BANK2 0x00000200 /* Bank2 IRQ */
  4769. +
  4770. +#define ARM_IRQ_PEND1 HW_REGISTER_RW(ARM_BASE+0x204) /* All bank1 IRQ bits */
  4771. +/* todo: all I1_interrupt sources */
  4772. +#define ARM_IRQ_PEND2 HW_REGISTER_RW(ARM_BASE+0x208) /* All bank2 IRQ bits */
  4773. +/* todo: all I2_interrupt sources */
  4774. +
  4775. +#define ARM_IRQ_FAST HW_REGISTER_RW(ARM_BASE+0x20C) /* FIQ control */
  4776. +#define ARM_IF_INDEX 0x0000007F /* FIQ select */
  4777. +#define ARM_IF_ENABLE 0x00000080 /* FIQ enable */
  4778. +#define ARM_IF_VCMASK 0x0000003F /* FIQ = (index from VC source) */
  4779. +#define ARM_IF_TIMER 0x00000040 /* FIQ = ARM timer */
  4780. +#define ARM_IF_MAIL 0x00000041 /* FIQ = ARM Mail */
  4781. +#define ARM_IF_BELL0 0x00000042 /* FIQ = ARM Doorbell 0 */
  4782. +#define ARM_IF_BELL1 0x00000043 /* FIQ = ARM Doorbell 1 */
  4783. +#define ARM_IF_VP0HALT 0x00000044 /* FIQ = VPU0 Halt seen */
  4784. +#define ARM_IF_VP1HALT 0x00000045 /* FIQ = VPU1 Halt seen */
  4785. +#define ARM_IF_ILLEGAL 0x00000046 /* FIQ = Illegal access seen */
  4786. +
  4787. +#define ARM_IRQ_ENBL1 HW_REGISTER_RW(ARM_BASE+0x210) /* Bank1 enable bits */
  4788. +#define ARM_IRQ_ENBL2 HW_REGISTER_RW(ARM_BASE+0x214) /* Bank2 enable bits */
  4789. +#define ARM_IRQ_ENBL3 HW_REGISTER_RW(ARM_BASE+0x218) /* ARM irqs enable bits */
  4790. +#define ARM_IRQ_DIBL1 HW_REGISTER_RW(ARM_BASE+0x21C) /* Bank1 disable bits */
  4791. +#define ARM_IRQ_DIBL2 HW_REGISTER_RW(ARM_BASE+0x220) /* Bank2 disable bits */
  4792. +#define ARM_IRQ_DIBL3 HW_REGISTER_RW(ARM_BASE+0x224) /* ARM irqs disable bits */
  4793. +#define ARM_IE_TIMER 0x00000001 /* Timer IRQ */
  4794. +#define ARM_IE_MAIL 0x00000002 /* Mail IRQ */
  4795. +#define ARM_IE_BELL0 0x00000004 /* Doorbell 0 */
  4796. +#define ARM_IE_BELL1 0x00000008 /* Doorbell 1 */
  4797. +#define ARM_IE_VP0HALT 0x00000010 /* VPU0 Halt */
  4798. +#define ARM_IE_VP1HALT 0x00000020 /* VPU1 Halt */
  4799. +#define ARM_IE_ILLEGAL 0x00000040 /* Illegal access seen */
  4800. +
  4801. +/* Timer */
  4802. +/* For reg. fields see sp804 spec. */
  4803. +#define ARM_T_LOAD HW_REGISTER_RW(ARM_BASE+0x400)
  4804. +#define ARM_T_VALUE HW_REGISTER_RW(ARM_BASE+0x404)
  4805. +#define ARM_T_CONTROL HW_REGISTER_RW(ARM_BASE+0x408)
  4806. +#define ARM_T_IRQCNTL HW_REGISTER_RW(ARM_BASE+0x40C)
  4807. +#define ARM_T_RAWIRQ HW_REGISTER_RW(ARM_BASE+0x410)
  4808. +#define ARM_T_MSKIRQ HW_REGISTER_RW(ARM_BASE+0x414)
  4809. +#define ARM_T_RELOAD HW_REGISTER_RW(ARM_BASE+0x418)
  4810. +#define ARM_T_PREDIV HW_REGISTER_RW(ARM_BASE+0x41c)
  4811. +#define ARM_T_FREECNT HW_REGISTER_RW(ARM_BASE+0x420)
  4812. +
  4813. +#define TIMER_CTRL_ONESHOT (1 << 0)
  4814. +#define TIMER_CTRL_32BIT (1 << 1)
  4815. +#define TIMER_CTRL_DIV1 (0 << 2)
  4816. +#define TIMER_CTRL_DIV16 (1 << 2)
  4817. +#define TIMER_CTRL_DIV256 (2 << 2)
  4818. +#define TIMER_CTRL_IE (1 << 5)
  4819. +#define TIMER_CTRL_PERIODIC (1 << 6)
  4820. +#define TIMER_CTRL_ENABLE (1 << 7)
  4821. +#define TIMER_CTRL_DBGHALT (1 << 8)
  4822. +#define TIMER_CTRL_ENAFREE (1 << 9)
  4823. +#define TIMER_CTRL_FREEDIV_SHIFT 16)
  4824. +#define TIMER_CTRL_FREEDIV_MASK 0xff
  4825. +
  4826. +/* Semaphores, Doorbells, Mailboxes */
  4827. +#define ARM_SBM_OWN0 (ARM_BASE+0x800)
  4828. +#define ARM_SBM_OWN1 (ARM_BASE+0x900)
  4829. +#define ARM_SBM_OWN2 (ARM_BASE+0xA00)
  4830. +#define ARM_SBM_OWN3 (ARM_BASE+0xB00)
  4831. +
  4832. +/* MAILBOXES
  4833. + * Register flags are common across all
  4834. + * owner registers. See end of this section
  4835. + *
  4836. + * Semaphores, Doorbells, Mailboxes Owner 0
  4837. + *
  4838. + */
  4839. +
  4840. +#define ARM_0_SEMS HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4841. +#define ARM_0_SEM0 HW_REGISTER_RW(ARM_SBM_OWN0+0x00)
  4842. +#define ARM_0_SEM1 HW_REGISTER_RW(ARM_SBM_OWN0+0x04)
  4843. +#define ARM_0_SEM2 HW_REGISTER_RW(ARM_SBM_OWN0+0x08)
  4844. +#define ARM_0_SEM3 HW_REGISTER_RW(ARM_SBM_OWN0+0x0C)
  4845. +#define ARM_0_SEM4 HW_REGISTER_RW(ARM_SBM_OWN0+0x10)
  4846. +#define ARM_0_SEM5 HW_REGISTER_RW(ARM_SBM_OWN0+0x14)
  4847. +#define ARM_0_SEM6 HW_REGISTER_RW(ARM_SBM_OWN0+0x18)
  4848. +#define ARM_0_SEM7 HW_REGISTER_RW(ARM_SBM_OWN0+0x1C)
  4849. +#define ARM_0_BELL0 HW_REGISTER_RW(ARM_SBM_OWN0+0x40)
  4850. +#define ARM_0_BELL1 HW_REGISTER_RW(ARM_SBM_OWN0+0x44)
  4851. +#define ARM_0_BELL2 HW_REGISTER_RW(ARM_SBM_OWN0+0x48)
  4852. +#define ARM_0_BELL3 HW_REGISTER_RW(ARM_SBM_OWN0+0x4C)
  4853. +/* MAILBOX 0 access in Owner 0 area */
  4854. +/* Some addresses should ONLY be used by owner 0 */
  4855. +#define ARM_0_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) */
  4856. +#define ARM_0_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN0+0x80) /* .. 0x8C (4 locations) Normal read */
  4857. +#define ARM_0_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN0+0x90) /* none-pop read */
  4858. +#define ARM_0_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN0+0x94) /* Sender read (only LS 2 bits) */
  4859. +#define ARM_0_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN0+0x98) /* Status read */
  4860. +#define ARM_0_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0x9C) /* Config read/write */
  4861. +/* MAILBOX 1 access in Owner 0 area */
  4862. +/* Owner 0 should only WRITE to this mailbox */
  4863. +#define ARM_0_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) /* .. 0xAC (4 locations) */
  4864. +/*#define ARM_0_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN0+0xA0) */ /* DO NOT USE THIS !!!!! */
  4865. +/*#define ARM_0_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN0+0xB0) */ /* DO NOT USE THIS !!!!! */
  4866. +/*#define ARM_0_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN0+0xB4) */ /* DO NOT USE THIS !!!!! */
  4867. +#define ARM_0_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN0+0xB8) /* Status read */
  4868. +/*#define ARM_0_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN0+0xBC) */ /* DO NOT USE THIS !!!!! */
  4869. +/* General SEM, BELL, MAIL config/status */
  4870. +#define ARM_0_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE0) /* semaphore clear/debug register */
  4871. +#define ARM_0_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN0+0xE4) /* Doorbells clear/debug register */
  4872. +#define ARM_0_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xF8) /* ALL interrupts */
  4873. +#define ARM_0_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN0+0xFC) /* IRQS pending for owner 0 */
  4874. +
  4875. +/* Semaphores, Doorbells, Mailboxes Owner 1 */
  4876. +#define ARM_1_SEMS HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4877. +#define ARM_1_SEM0 HW_REGISTER_RW(ARM_SBM_OWN1+0x00)
  4878. +#define ARM_1_SEM1 HW_REGISTER_RW(ARM_SBM_OWN1+0x04)
  4879. +#define ARM_1_SEM2 HW_REGISTER_RW(ARM_SBM_OWN1+0x08)
  4880. +#define ARM_1_SEM3 HW_REGISTER_RW(ARM_SBM_OWN1+0x0C)
  4881. +#define ARM_1_SEM4 HW_REGISTER_RW(ARM_SBM_OWN1+0x10)
  4882. +#define ARM_1_SEM5 HW_REGISTER_RW(ARM_SBM_OWN1+0x14)
  4883. +#define ARM_1_SEM6 HW_REGISTER_RW(ARM_SBM_OWN1+0x18)
  4884. +#define ARM_1_SEM7 HW_REGISTER_RW(ARM_SBM_OWN1+0x1C)
  4885. +#define ARM_1_BELL0 HW_REGISTER_RW(ARM_SBM_OWN1+0x40)
  4886. +#define ARM_1_BELL1 HW_REGISTER_RW(ARM_SBM_OWN1+0x44)
  4887. +#define ARM_1_BELL2 HW_REGISTER_RW(ARM_SBM_OWN1+0x48)
  4888. +#define ARM_1_BELL3 HW_REGISTER_RW(ARM_SBM_OWN1+0x4C)
  4889. +/* MAILBOX 0 access in Owner 0 area */
  4890. +/* Owner 1 should only WRITE to this mailbox */
  4891. +#define ARM_1_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0x80) /* .. 0x8C (4 locations) */
  4892. +/*#define ARM_1_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN1+0x80) */ /* DO NOT USE THIS !!!!! */
  4893. +/*#define ARM_1_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN1+0x90) */ /* DO NOT USE THIS !!!!! */
  4894. +/*#define ARM_1_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN1+0x94) */ /* DO NOT USE THIS !!!!! */
  4895. +#define ARM_1_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN1+0x98) /* Status read */
  4896. +/*#define ARM_1_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0x9C) */ /* DO NOT USE THIS !!!!! */
  4897. +/* MAILBOX 1 access in Owner 0 area */
  4898. +#define ARM_1_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) */
  4899. +#define ARM_1_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN1+0xA0) /* .. 0xAC (4 locations) Normal read */
  4900. +#define ARM_1_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN1+0xB0) /* none-pop read */
  4901. +#define ARM_1_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN1+0xB4) /* Sender read (only LS 2 bits) */
  4902. +#define ARM_1_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN1+0xB8) /* Status read */
  4903. +#define ARM_1_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN1+0xBC)
  4904. +/* General SEM, BELL, MAIL config/status */
  4905. +#define ARM_1_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE0) /* semaphore clear/debug register */
  4906. +#define ARM_1_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN1+0xE4) /* Doorbells clear/debug register */
  4907. +#define ARM_1_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xFC) /* IRQS pending for owner 1 */
  4908. +#define ARM_1_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN1+0xF8) /* ALL interrupts */
  4909. +
  4910. +/* Semaphores, Doorbells, Mailboxes Owner 2 */
  4911. +#define ARM_2_SEMS HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4912. +#define ARM_2_SEM0 HW_REGISTER_RW(ARM_SBM_OWN2+0x00)
  4913. +#define ARM_2_SEM1 HW_REGISTER_RW(ARM_SBM_OWN2+0x04)
  4914. +#define ARM_2_SEM2 HW_REGISTER_RW(ARM_SBM_OWN2+0x08)
  4915. +#define ARM_2_SEM3 HW_REGISTER_RW(ARM_SBM_OWN2+0x0C)
  4916. +#define ARM_2_SEM4 HW_REGISTER_RW(ARM_SBM_OWN2+0x10)
  4917. +#define ARM_2_SEM5 HW_REGISTER_RW(ARM_SBM_OWN2+0x14)
  4918. +#define ARM_2_SEM6 HW_REGISTER_RW(ARM_SBM_OWN2+0x18)
  4919. +#define ARM_2_SEM7 HW_REGISTER_RW(ARM_SBM_OWN2+0x1C)
  4920. +#define ARM_2_BELL0 HW_REGISTER_RW(ARM_SBM_OWN2+0x40)
  4921. +#define ARM_2_BELL1 HW_REGISTER_RW(ARM_SBM_OWN2+0x44)
  4922. +#define ARM_2_BELL2 HW_REGISTER_RW(ARM_SBM_OWN2+0x48)
  4923. +#define ARM_2_BELL3 HW_REGISTER_RW(ARM_SBM_OWN2+0x4C)
  4924. +/* MAILBOX 0 access in Owner 2 area */
  4925. +/* Owner 2 should only WRITE to this mailbox */
  4926. +#define ARM_2_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0x80) /* .. 0x8C (4 locations) */
  4927. +/*#define ARM_2_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN2+0x80) */ /* DO NOT USE THIS !!!!! */
  4928. +/*#define ARM_2_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN2+0x90) */ /* DO NOT USE THIS !!!!! */
  4929. +/*#define ARM_2_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN2+0x94) */ /* DO NOT USE THIS !!!!! */
  4930. +#define ARM_2_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN2+0x98) /* Status read */
  4931. +/*#define ARM_2_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0x9C) */ /* DO NOT USE THIS !!!!! */
  4932. +/* MAILBOX 1 access in Owner 2 area */
  4933. +/* Owner 2 should only WRITE to this mailbox */
  4934. +#define ARM_2_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) /* .. 0xAC (4 locations) */
  4935. +/*#define ARM_2_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN2+0xA0) */ /* DO NOT USE THIS !!!!! */
  4936. +/*#define ARM_2_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN2+0xB0) */ /* DO NOT USE THIS !!!!! */
  4937. +/*#define ARM_2_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN2+0xB4) */ /* DO NOT USE THIS !!!!! */
  4938. +#define ARM_2_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN2+0xB8) /* Status read */
  4939. +/*#define ARM_2_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN2+0xBC) */ /* DO NOT USE THIS !!!!! */
  4940. +/* General SEM, BELL, MAIL config/status */
  4941. +#define ARM_2_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE0) /* semaphore clear/debug register */
  4942. +#define ARM_2_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN2+0xE4) /* Doorbells clear/debug register */
  4943. +#define ARM_2_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xFC) /* IRQS pending for owner 2 */
  4944. +#define ARM_2_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN2+0xF8) /* ALL interrupts */
  4945. +
  4946. +/* Semaphores, Doorbells, Mailboxes Owner 3 */
  4947. +#define ARM_3_SEMS HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4948. +#define ARM_3_SEM0 HW_REGISTER_RW(ARM_SBM_OWN3+0x00)
  4949. +#define ARM_3_SEM1 HW_REGISTER_RW(ARM_SBM_OWN3+0x04)
  4950. +#define ARM_3_SEM2 HW_REGISTER_RW(ARM_SBM_OWN3+0x08)
  4951. +#define ARM_3_SEM3 HW_REGISTER_RW(ARM_SBM_OWN3+0x0C)
  4952. +#define ARM_3_SEM4 HW_REGISTER_RW(ARM_SBM_OWN3+0x10)
  4953. +#define ARM_3_SEM5 HW_REGISTER_RW(ARM_SBM_OWN3+0x14)
  4954. +#define ARM_3_SEM6 HW_REGISTER_RW(ARM_SBM_OWN3+0x18)
  4955. +#define ARM_3_SEM7 HW_REGISTER_RW(ARM_SBM_OWN3+0x1C)
  4956. +#define ARM_3_BELL0 HW_REGISTER_RW(ARM_SBM_OWN3+0x40)
  4957. +#define ARM_3_BELL1 HW_REGISTER_RW(ARM_SBM_OWN3+0x44)
  4958. +#define ARM_3_BELL2 HW_REGISTER_RW(ARM_SBM_OWN3+0x48)
  4959. +#define ARM_3_BELL3 HW_REGISTER_RW(ARM_SBM_OWN3+0x4C)
  4960. +/* MAILBOX 0 access in Owner 3 area */
  4961. +/* Owner 3 should only WRITE to this mailbox */
  4962. +#define ARM_3_MAIL0_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0x80) /* .. 0x8C (4 locations) */
  4963. +/*#define ARM_3_MAIL0_RD HW_REGISTER_RW(ARM_SBM_OWN3+0x80) */ /* DO NOT USE THIS !!!!! */
  4964. +/*#define ARM_3_MAIL0_POL HW_REGISTER_RW(ARM_SBM_OWN3+0x90) */ /* DO NOT USE THIS !!!!! */
  4965. +/*#define ARM_3_MAIL0_SND HW_REGISTER_RW(ARM_SBM_OWN3+0x94) */ /* DO NOT USE THIS !!!!! */
  4966. +#define ARM_3_MAIL0_STA HW_REGISTER_RW(ARM_SBM_OWN3+0x98) /* Status read */
  4967. +/*#define ARM_3_MAIL0_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0x9C) */ /* DO NOT USE THIS !!!!! */
  4968. +/* MAILBOX 1 access in Owner 3 area */
  4969. +/* Owner 3 should only WRITE to this mailbox */
  4970. +#define ARM_3_MAIL1_WRT HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) /* .. 0xAC (4 locations) */
  4971. +/*#define ARM_3_MAIL1_RD HW_REGISTER_RW(ARM_SBM_OWN3+0xA0) */ /* DO NOT USE THIS !!!!! */
  4972. +/*#define ARM_3_MAIL1_POL HW_REGISTER_RW(ARM_SBM_OWN3+0xB0) */ /* DO NOT USE THIS !!!!! */
  4973. +/*#define ARM_3_MAIL1_SND HW_REGISTER_RW(ARM_SBM_OWN3+0xB4) */ /* DO NOT USE THIS !!!!! */
  4974. +#define ARM_3_MAIL1_STA HW_REGISTER_RW(ARM_SBM_OWN3+0xB8) /* Status read */
  4975. +/*#define ARM_3_MAIL1_CNF HW_REGISTER_RW(ARM_SBM_OWN3+0xBC) */ /* DO NOT USE THIS !!!!! */
  4976. +/* General SEM, BELL, MAIL config/status */
  4977. +#define ARM_3_SEMCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE0) /* semaphore clear/debug register */
  4978. +#define ARM_3_BELLCLRDBG HW_REGISTER_RW(ARM_SBM_OWN3+0xE4) /* Doorbells clear/debug register */
  4979. +#define ARM_3_MY_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xFC) /* IRQS pending for owner 3 */
  4980. +#define ARM_3_ALL_IRQS HW_REGISTER_RW(ARM_SBM_OWN3+0xF8) /* ALL interrupts */
  4981. +
  4982. +
  4983. +
  4984. +/* Mailbox flags. Valid for all owners */
  4985. +
  4986. +/* Mailbox status register (...0x98) */
  4987. +#define ARM_MS_FULL 0x80000000
  4988. +#define ARM_MS_EMPTY 0x40000000
  4989. +#define ARM_MS_LEVEL 0x400000FF /* Max. value depdnds on mailbox depth parameter */
  4990. +
  4991. +/* MAILBOX config/status register (...0x9C) */
  4992. +/* ANY write to this register clears the error bits! */
  4993. +#define ARM_MC_IHAVEDATAIRQEN 0x00000001 /* mailbox irq enable: has data */
  4994. +#define ARM_MC_IHAVESPACEIRQEN 0x00000002 /* mailbox irq enable: has space */
  4995. +#define ARM_MC_OPPISEMPTYIRQEN 0x00000004 /* mailbox irq enable: Opp. is empty */
  4996. +#define ARM_MC_MAIL_CLEAR 0x00000008 /* mailbox clear write 1, then 0 */
  4997. +#define ARM_MC_IHAVEDATAIRQPEND 0x00000010 /* mailbox irq pending: has space */
  4998. +#define ARM_MC_IHAVESPACEIRQPEND 0x00000020 /* mailbox irq pending: Opp. is empty */
  4999. +#define ARM_MC_OPPISEMPTYIRQPEND 0x00000040 /* mailbox irq pending */
  5000. +/* Bit 7 is unused */
  5001. +#define ARM_MC_ERRNOOWN 0x00000100 /* error : none owner read from mailbox */
  5002. +#define ARM_MC_ERROVERFLW 0x00000200 /* error : write to fill mailbox */
  5003. +#define ARM_MC_ERRUNDRFLW 0x00000400 /* error : read from empty mailbox */
  5004. +
  5005. +/* Semaphore clear/debug register (...0xE0) */
  5006. +#define ARM_SD_OWN0 0x00000003 /* Owner of sem 0 */
  5007. +#define ARM_SD_OWN1 0x0000000C /* Owner of sem 1 */
  5008. +#define ARM_SD_OWN2 0x00000030 /* Owner of sem 2 */
  5009. +#define ARM_SD_OWN3 0x000000C0 /* Owner of sem 3 */
  5010. +#define ARM_SD_OWN4 0x00000300 /* Owner of sem 4 */
  5011. +#define ARM_SD_OWN5 0x00000C00 /* Owner of sem 5 */
  5012. +#define ARM_SD_OWN6 0x00003000 /* Owner of sem 6 */
  5013. +#define ARM_SD_OWN7 0x0000C000 /* Owner of sem 7 */
  5014. +#define ARM_SD_SEM0 0x00010000 /* Status of sem 0 */
  5015. +#define ARM_SD_SEM1 0x00020000 /* Status of sem 1 */
  5016. +#define ARM_SD_SEM2 0x00040000 /* Status of sem 2 */
  5017. +#define ARM_SD_SEM3 0x00080000 /* Status of sem 3 */
  5018. +#define ARM_SD_SEM4 0x00100000 /* Status of sem 4 */
  5019. +#define ARM_SD_SEM5 0x00200000 /* Status of sem 5 */
  5020. +#define ARM_SD_SEM6 0x00400000 /* Status of sem 6 */
  5021. +#define ARM_SD_SEM7 0x00800000 /* Status of sem 7 */
  5022. +
  5023. +/* Doorbells clear/debug register (...0xE4) */
  5024. +#define ARM_BD_OWN0 0x00000003 /* Owner of doorbell 0 */
  5025. +#define ARM_BD_OWN1 0x0000000C /* Owner of doorbell 1 */
  5026. +#define ARM_BD_OWN2 0x00000030 /* Owner of doorbell 2 */
  5027. +#define ARM_BD_OWN3 0x000000C0 /* Owner of doorbell 3 */
  5028. +#define ARM_BD_BELL0 0x00000100 /* Status of doorbell 0 */
  5029. +#define ARM_BD_BELL1 0x00000200 /* Status of doorbell 1 */
  5030. +#define ARM_BD_BELL2 0x00000400 /* Status of doorbell 2 */
  5031. +#define ARM_BD_BELL3 0x00000800 /* Status of doorbell 3 */
  5032. +
  5033. +/* MY IRQS register (...0xF8) */
  5034. +#define ARM_MYIRQ_BELL 0x00000001 /* This owner has a doorbell IRQ */
  5035. +#define ARM_MYIRQ_MAIL 0x00000002 /* This owner has a mailbox IRQ */
  5036. +
  5037. +/* ALL IRQS register (...0xF8) */
  5038. +#define ARM_AIS_BELL0 0x00000001 /* Doorbell 0 IRQ pending */
  5039. +#define ARM_AIS_BELL1 0x00000002 /* Doorbell 1 IRQ pending */
  5040. +#define ARM_AIS_BELL2 0x00000004 /* Doorbell 2 IRQ pending */
  5041. +#define ARM_AIS_BELL3 0x00000008 /* Doorbell 3 IRQ pending */
  5042. +#define ARM_AIS0_HAVEDATA 0x00000010 /* MAIL 0 has data IRQ pending */
  5043. +#define ARM_AIS0_HAVESPAC 0x00000020 /* MAIL 0 has space IRQ pending */
  5044. +#define ARM_AIS0_OPPEMPTY 0x00000040 /* MAIL 0 opposite is empty IRQ */
  5045. +#define ARM_AIS1_HAVEDATA 0x00000080 /* MAIL 1 has data IRQ pending */
  5046. +#define ARM_AIS1_HAVESPAC 0x00000100 /* MAIL 1 has space IRQ pending */
  5047. +#define ARM_AIS1_OPPEMPTY 0x00000200 /* MAIL 1 opposite is empty IRQ */
  5048. +/* Note that bell-0, bell-1 and MAIL0 IRQ go only to the ARM */
  5049. +/* Whilst that bell-2, bell-3 and MAIL1 IRQ go only to the VC */
  5050. +/* */
  5051. +/* ARM JTAG BASH */
  5052. +/* */
  5053. +#define AJB_BASE 0x7e2000c0
  5054. +
  5055. +#define AJBCONF HW_REGISTER_RW(AJB_BASE+0x00)
  5056. +#define AJB_BITS0 0x000000
  5057. +#define AJB_BITS4 0x000004
  5058. +#define AJB_BITS8 0x000008
  5059. +#define AJB_BITS12 0x00000C
  5060. +#define AJB_BITS16 0x000010
  5061. +#define AJB_BITS20 0x000014
  5062. +#define AJB_BITS24 0x000018
  5063. +#define AJB_BITS28 0x00001C
  5064. +#define AJB_BITS32 0x000020
  5065. +#define AJB_BITS34 0x000022
  5066. +#define AJB_OUT_MS 0x000040
  5067. +#define AJB_OUT_LS 0x000000
  5068. +#define AJB_INV_CLK 0x000080
  5069. +#define AJB_D0_RISE 0x000100
  5070. +#define AJB_D0_FALL 0x000000
  5071. +#define AJB_D1_RISE 0x000200
  5072. +#define AJB_D1_FALL 0x000000
  5073. +#define AJB_IN_RISE 0x000400
  5074. +#define AJB_IN_FALL 0x000000
  5075. +#define AJB_ENABLE 0x000800
  5076. +#define AJB_HOLD0 0x000000
  5077. +#define AJB_HOLD1 0x001000
  5078. +#define AJB_HOLD2 0x002000
  5079. +#define AJB_HOLD3 0x003000
  5080. +#define AJB_RESETN 0x004000
  5081. +#define AJB_CLKSHFT 16
  5082. +#define AJB_BUSY 0x80000000
  5083. +#define AJBTMS HW_REGISTER_RW(AJB_BASE+0x04)
  5084. +#define AJBTDI HW_REGISTER_RW(AJB_BASE+0x08)
  5085. +#define AJBTDO HW_REGISTER_RW(AJB_BASE+0x0c)
  5086. +
  5087. +#endif
  5088. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/arm_power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5089. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/arm_power.h 1970-01-01 01:00:00.000000000 +0100
  5090. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/arm_power.h 2014-06-11 21:03:19.000000000 +0200
  5091. @@ -0,0 +1,60 @@
  5092. +/*
  5093. + * linux/arch/arm/mach-bcm2708/include/mach/arm_power.h
  5094. + *
  5095. + * Copyright (C) 2010 Broadcom
  5096. + *
  5097. + * This program is free software; you can redistribute it and/or modify
  5098. + * it under the terms of the GNU General Public License as published by
  5099. + * the Free Software Foundation; either version 2 of the License, or
  5100. + * (at your option) any later version.
  5101. + *
  5102. + * This program is distributed in the hope that it will be useful,
  5103. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5104. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5105. + * GNU General Public License for more details.
  5106. + *
  5107. + * You should have received a copy of the GNU General Public License
  5108. + * along with this program; if not, write to the Free Software
  5109. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5110. + */
  5111. +
  5112. +#ifndef _ARM_POWER_H
  5113. +#define _ARM_POWER_H
  5114. +
  5115. +/* Use meaningful names on each side */
  5116. +#ifdef __VIDEOCORE__
  5117. +#define PREFIX(x) ARM_##x
  5118. +#else
  5119. +#define PREFIX(x) BCM_##x
  5120. +#endif
  5121. +
  5122. +enum {
  5123. + PREFIX(POWER_SDCARD_BIT),
  5124. + PREFIX(POWER_UART_BIT),
  5125. + PREFIX(POWER_MINIUART_BIT),
  5126. + PREFIX(POWER_USB_BIT),
  5127. + PREFIX(POWER_I2C0_BIT),
  5128. + PREFIX(POWER_I2C1_BIT),
  5129. + PREFIX(POWER_I2C2_BIT),
  5130. + PREFIX(POWER_SPI_BIT),
  5131. + PREFIX(POWER_CCP2TX_BIT),
  5132. +
  5133. + PREFIX(POWER_MAX)
  5134. +};
  5135. +
  5136. +enum {
  5137. + PREFIX(POWER_SDCARD) = (1 << PREFIX(POWER_SDCARD_BIT)),
  5138. + PREFIX(POWER_UART) = (1 << PREFIX(POWER_UART_BIT)),
  5139. + PREFIX(POWER_MINIUART) = (1 << PREFIX(POWER_MINIUART_BIT)),
  5140. + PREFIX(POWER_USB) = (1 << PREFIX(POWER_USB_BIT)),
  5141. + PREFIX(POWER_I2C0) = (1 << PREFIX(POWER_I2C0_BIT)),
  5142. + PREFIX(POWER_I2C1_MASK) = (1 << PREFIX(POWER_I2C1_BIT)),
  5143. + PREFIX(POWER_I2C2_MASK) = (1 << PREFIX(POWER_I2C2_BIT)),
  5144. + PREFIX(POWER_SPI_MASK) = (1 << PREFIX(POWER_SPI_BIT)),
  5145. + PREFIX(POWER_CCP2TX_MASK) = (1 << PREFIX(POWER_CCP2TX_BIT)),
  5146. +
  5147. + PREFIX(POWER_MASK) = (1 << PREFIX(POWER_MAX)) - 1,
  5148. + PREFIX(POWER_NONE) = 0
  5149. +};
  5150. +
  5151. +#endif
  5152. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/clkdev.h linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h
  5153. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/clkdev.h 1970-01-01 01:00:00.000000000 +0100
  5154. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/clkdev.h 2014-06-11 21:03:19.000000000 +0200
  5155. @@ -0,0 +1,7 @@
  5156. +#ifndef __ASM_MACH_CLKDEV_H
  5157. +#define __ASM_MACH_CLKDEV_H
  5158. +
  5159. +#define __clk_get(clk) ({ 1; })
  5160. +#define __clk_put(clk) do { } while (0)
  5161. +
  5162. +#endif
  5163. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/debug-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5164. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/debug-macro.S 1970-01-01 01:00:00.000000000 +0100
  5165. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/debug-macro.S 2014-06-11 21:03:19.000000000 +0200
  5166. @@ -0,0 +1,22 @@
  5167. +/* arch/arm/mach-bcm2708/include/mach/debug-macro.S
  5168. + *
  5169. + * Debugging macro include header
  5170. + *
  5171. + * Copyright (C) 2010 Broadcom
  5172. + * Copyright (C) 1994-1999 Russell King
  5173. + * Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
  5174. + *
  5175. + * This program is free software; you can redistribute it and/or modify
  5176. + * it under the terms of the GNU General Public License version 2 as
  5177. + * published by the Free Software Foundation.
  5178. + *
  5179. +*/
  5180. +
  5181. +#include <mach/platform.h>
  5182. +
  5183. + .macro addruart, rp, rv, tmp
  5184. + ldr \rp, =UART0_BASE
  5185. + ldr \rv, =IO_ADDRESS(UART0_BASE)
  5186. + .endm
  5187. +
  5188. +#include <debug/pl01x.S>
  5189. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/dma.h linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h
  5190. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/dma.h 1970-01-01 01:00:00.000000000 +0100
  5191. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/dma.h 2014-06-11 21:03:19.000000000 +0200
  5192. @@ -0,0 +1,90 @@
  5193. +/*
  5194. + * linux/arch/arm/mach-bcm2708/include/mach/dma.h
  5195. + *
  5196. + * Copyright (C) 2010 Broadcom
  5197. + *
  5198. + * This program is free software; you can redistribute it and/or modify
  5199. + * it under the terms of the GNU General Public License version 2 as
  5200. + * published by the Free Software Foundation.
  5201. + */
  5202. +
  5203. +
  5204. +#ifndef _MACH_BCM2708_DMA_H
  5205. +#define _MACH_BCM2708_DMA_H
  5206. +
  5207. +#define BCM_DMAMAN_DRIVER_NAME "bcm2708_dma"
  5208. +
  5209. +/* DMA CS Control and Status bits */
  5210. +#define BCM2708_DMA_ACTIVE (1 << 0)
  5211. +#define BCM2708_DMA_INT (1 << 2)
  5212. +#define BCM2708_DMA_ISPAUSED (1 << 4) /* Pause requested or not active */
  5213. +#define BCM2708_DMA_ISHELD (1 << 5) /* Is held by DREQ flow control */
  5214. +#define BCM2708_DMA_ERR (1 << 8)
  5215. +#define BCM2708_DMA_ABORT (1 << 30) /* stop current CB, go to next, WO */
  5216. +#define BCM2708_DMA_RESET (1 << 31) /* WO, self clearing */
  5217. +
  5218. +/* DMA control block "info" field bits */
  5219. +#define BCM2708_DMA_INT_EN (1 << 0)
  5220. +#define BCM2708_DMA_TDMODE (1 << 1)
  5221. +#define BCM2708_DMA_WAIT_RESP (1 << 3)
  5222. +#define BCM2708_DMA_D_INC (1 << 4)
  5223. +#define BCM2708_DMA_D_WIDTH (1 << 5)
  5224. +#define BCM2708_DMA_D_DREQ (1 << 6)
  5225. +#define BCM2708_DMA_S_INC (1 << 8)
  5226. +#define BCM2708_DMA_S_WIDTH (1 << 9)
  5227. +#define BCM2708_DMA_S_DREQ (1 << 10)
  5228. +
  5229. +#define BCM2708_DMA_BURST(x) (((x)&0xf) << 12)
  5230. +#define BCM2708_DMA_PER_MAP(x) ((x) << 16)
  5231. +#define BCM2708_DMA_WAITS(x) (((x)&0x1f) << 21)
  5232. +
  5233. +#define BCM2708_DMA_DREQ_EMMC 11
  5234. +#define BCM2708_DMA_DREQ_SDHOST 13
  5235. +
  5236. +#define BCM2708_DMA_CS 0x00 /* Control and Status */
  5237. +#define BCM2708_DMA_ADDR 0x04
  5238. +/* the current control block appears in the following registers - read only */
  5239. +#define BCM2708_DMA_INFO 0x08
  5240. +#define BCM2708_DMA_SOURCE_AD 0x0c
  5241. +#define BCM2708_DMA_DEST_AD 0x10
  5242. +#define BCM2708_DMA_NEXTCB 0x1C
  5243. +#define BCM2708_DMA_DEBUG 0x20
  5244. +
  5245. +#define BCM2708_DMA4_CS (BCM2708_DMA_CHAN(4)+BCM2708_DMA_CS)
  5246. +#define BCM2708_DMA4_ADDR (BCM2708_DMA_CHAN(4)+BCM2708_DMA_ADDR)
  5247. +
  5248. +#define BCM2708_DMA_TDMODE_LEN(w, h) ((h) << 16 | (w))
  5249. +
  5250. +struct bcm2708_dma_cb {
  5251. + unsigned long info;
  5252. + unsigned long src;
  5253. + unsigned long dst;
  5254. + unsigned long length;
  5255. + unsigned long stride;
  5256. + unsigned long next;
  5257. + unsigned long pad[2];
  5258. +};
  5259. +struct scatterlist;
  5260. +
  5261. +extern int bcm_sg_suitable_for_dma(struct scatterlist *sg_ptr, int sg_len);
  5262. +extern void bcm_dma_start(void __iomem *dma_chan_base,
  5263. + dma_addr_t control_block);
  5264. +extern void bcm_dma_wait_idle(void __iomem *dma_chan_base);
  5265. +extern bool bcm_dma_is_busy(void __iomem *dma_chan_base);
  5266. +extern int /*rc*/ bcm_dma_abort(void __iomem *dma_chan_base);
  5267. +
  5268. +/* When listing features we can ask for when allocating DMA channels give
  5269. + those with higher priority smaller ordinal numbers */
  5270. +#define BCM_DMA_FEATURE_FAST_ORD 0
  5271. +#define BCM_DMA_FEATURE_BULK_ORD 1
  5272. +#define BCM_DMA_FEATURE_FAST (1<<BCM_DMA_FEATURE_FAST_ORD)
  5273. +#define BCM_DMA_FEATURE_BULK (1<<BCM_DMA_FEATURE_BULK_ORD)
  5274. +#define BCM_DMA_FEATURE_COUNT 2
  5275. +
  5276. +/* return channel no or -ve error */
  5277. +extern int bcm_dma_chan_alloc(unsigned preferred_feature_set,
  5278. + void __iomem **out_dma_base, int *out_dma_irq);
  5279. +extern int bcm_dma_chan_free(int channel);
  5280. +
  5281. +
  5282. +#endif /* _MACH_BCM2708_DMA_H */
  5283. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/entry-macro.S linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5284. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/entry-macro.S 1970-01-01 01:00:00.000000000 +0100
  5285. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/entry-macro.S 2014-06-11 21:03:19.000000000 +0200
  5286. @@ -0,0 +1,69 @@
  5287. +/*
  5288. + * arch/arm/mach-bcm2708/include/mach/entry-macro.S
  5289. + *
  5290. + * Low-level IRQ helper macros for BCM2708 platforms
  5291. + *
  5292. + * Copyright (C) 2010 Broadcom
  5293. + *
  5294. + * This program is free software; you can redistribute it and/or modify
  5295. + * it under the terms of the GNU General Public License as published by
  5296. + * the Free Software Foundation; either version 2 of the License, or
  5297. + * (at your option) any later version.
  5298. + *
  5299. + * This program is distributed in the hope that it will be useful,
  5300. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5301. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5302. + * GNU General Public License for more details.
  5303. + *
  5304. + * You should have received a copy of the GNU General Public License
  5305. + * along with this program; if not, write to the Free Software
  5306. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5307. + */
  5308. +#include <mach/hardware.h>
  5309. +
  5310. + .macro disable_fiq
  5311. + .endm
  5312. +
  5313. + .macro get_irqnr_preamble, base, tmp
  5314. + ldr \base, =IO_ADDRESS(ARMCTRL_IC_BASE)
  5315. + .endm
  5316. +
  5317. + .macro arch_ret_to_user, tmp1, tmp2
  5318. + .endm
  5319. +
  5320. + .macro get_irqnr_and_base, irqnr, irqstat, base, tmp
  5321. + /* get masked status */
  5322. + ldr \irqstat, [\base, #(ARM_IRQ_PEND0 - ARMCTRL_IC_BASE)]
  5323. + mov \irqnr, #(ARM_IRQ0_BASE + 31)
  5324. + and \tmp, \irqstat, #0x300 @ save bits 8 and 9
  5325. + /* clear bits 8 and 9, and test */
  5326. + bics \irqstat, \irqstat, #0x300
  5327. + bne 1010f
  5328. +
  5329. + tst \tmp, #0x100
  5330. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND1 - ARMCTRL_IC_BASE)]
  5331. + movne \irqnr, #(ARM_IRQ1_BASE + 31)
  5332. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5333. + bicne \irqstat, #((1<<7) | (1<<9) | (1<<10))
  5334. + bicne \irqstat, #((1<<18) | (1<<19))
  5335. + bne 1010f
  5336. +
  5337. + tst \tmp, #0x200
  5338. + ldrne \irqstat, [\base, #(ARM_IRQ_PEND2 - ARMCTRL_IC_BASE)]
  5339. + movne \irqnr, #(ARM_IRQ2_BASE + 31)
  5340. + @ Mask out the interrupts also present in PEND0 - see SW-5809
  5341. + bicne \irqstat, #((1<<21) | (1<<22) | (1<<23) | (1<<24) | (1<<25))
  5342. + bicne \irqstat, #((1<<30))
  5343. + beq 1020f
  5344. +
  5345. +1010:
  5346. + @ For non-zero x, LSB(x) = 31 - CLZ(x^(x-1))
  5347. + @ N.B. CLZ is an ARM5 instruction.
  5348. + sub \tmp, \irqstat, #1
  5349. + eor \irqstat, \irqstat, \tmp
  5350. + clz \tmp, \irqstat
  5351. + sub \irqnr, \tmp
  5352. +
  5353. +1020: @ EQ will be set if no irqs pending
  5354. +
  5355. + .endm
  5356. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/frc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h
  5357. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/frc.h 1970-01-01 01:00:00.000000000 +0100
  5358. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/frc.h 2014-06-11 21:03:19.000000000 +0200
  5359. @@ -0,0 +1,38 @@
  5360. +/*
  5361. + * arch/arm/mach-bcm2708/include/mach/timex.h
  5362. + *
  5363. + * BCM2708 free running counter (timer)
  5364. + *
  5365. + * Copyright (C) 2010 Broadcom
  5366. + *
  5367. + * This program is free software; you can redistribute it and/or modify
  5368. + * it under the terms of the GNU General Public License as published by
  5369. + * the Free Software Foundation; either version 2 of the License, or
  5370. + * (at your option) any later version.
  5371. + *
  5372. + * This program is distributed in the hope that it will be useful,
  5373. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5374. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5375. + * GNU General Public License for more details.
  5376. + *
  5377. + * You should have received a copy of the GNU General Public License
  5378. + * along with this program; if not, write to the Free Software
  5379. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5380. + */
  5381. +
  5382. +#ifndef _MACH_FRC_H
  5383. +#define _MACH_FRC_H
  5384. +
  5385. +#define FRC_TICK_RATE (1000000)
  5386. +
  5387. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5388. + (slightly faster than frc_clock_ticks63()
  5389. + */
  5390. +extern unsigned long frc_clock_ticks32(void);
  5391. +
  5392. +/*! Free running counter incrementing at the CLOCK_TICK_RATE
  5393. + * Note - top bit should be ignored (see cnt32_to_63)
  5394. + */
  5395. +extern unsigned long long frc_clock_ticks63(void);
  5396. +
  5397. +#endif
  5398. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/gpio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h
  5399. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/gpio.h 1970-01-01 01:00:00.000000000 +0100
  5400. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/gpio.h 2014-06-11 21:03:19.000000000 +0200
  5401. @@ -0,0 +1,17 @@
  5402. +/*
  5403. + * arch/arm/mach-bcm2708/include/mach/gpio.h
  5404. + *
  5405. + * This file is licensed under the terms of the GNU General Public
  5406. + * License version 2. This program is licensed "as is" without any
  5407. + * warranty of any kind, whether express or implied.
  5408. + */
  5409. +
  5410. +#ifndef __ASM_ARCH_GPIO_H
  5411. +#define __ASM_ARCH_GPIO_H
  5412. +
  5413. +#define BCM2708_NR_GPIOS 54 // number of gpio lines
  5414. +
  5415. +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
  5416. +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
  5417. +
  5418. +#endif
  5419. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/hardware.h linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h
  5420. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/hardware.h 1970-01-01 01:00:00.000000000 +0100
  5421. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/hardware.h 2014-06-11 21:03:19.000000000 +0200
  5422. @@ -0,0 +1,28 @@
  5423. +/*
  5424. + * arch/arm/mach-bcm2708/include/mach/hardware.h
  5425. + *
  5426. + * This file contains the hardware definitions of the BCM2708 devices.
  5427. + *
  5428. + * Copyright (C) 2010 Broadcom
  5429. + *
  5430. + * This program is free software; you can redistribute it and/or modify
  5431. + * it under the terms of the GNU General Public License as published by
  5432. + * the Free Software Foundation; either version 2 of the License, or
  5433. + * (at your option) any later version.
  5434. + *
  5435. + * This program is distributed in the hope that it will be useful,
  5436. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5437. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5438. + * GNU General Public License for more details.
  5439. + *
  5440. + * You should have received a copy of the GNU General Public License
  5441. + * along with this program; if not, write to the Free Software
  5442. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5443. + */
  5444. +#ifndef __ASM_ARCH_HARDWARE_H
  5445. +#define __ASM_ARCH_HARDWARE_H
  5446. +
  5447. +#include <asm/sizes.h>
  5448. +#include <mach/platform.h>
  5449. +
  5450. +#endif
  5451. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/io.h linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h
  5452. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/io.h 1970-01-01 01:00:00.000000000 +0100
  5453. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/io.h 2014-06-11 21:03:19.000000000 +0200
  5454. @@ -0,0 +1,27 @@
  5455. +/*
  5456. + * arch/arm/mach-bcm2708/include/mach/io.h
  5457. + *
  5458. + * Copyright (C) 2003 ARM Limited
  5459. + *
  5460. + * This program is free software; you can redistribute it and/or modify
  5461. + * it under the terms of the GNU General Public License as published by
  5462. + * the Free Software Foundation; either version 2 of the License, or
  5463. + * (at your option) any later version.
  5464. + *
  5465. + * This program is distributed in the hope that it will be useful,
  5466. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5467. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5468. + * GNU General Public License for more details.
  5469. + *
  5470. + * You should have received a copy of the GNU General Public License
  5471. + * along with this program; if not, write to the Free Software
  5472. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5473. + */
  5474. +#ifndef __ASM_ARM_ARCH_IO_H
  5475. +#define __ASM_ARM_ARCH_IO_H
  5476. +
  5477. +#define IO_SPACE_LIMIT 0xffffffff
  5478. +
  5479. +#define __io(a) __typesafe_io(a)
  5480. +
  5481. +#endif
  5482. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/irqs.h linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h
  5483. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/irqs.h 1970-01-01 01:00:00.000000000 +0100
  5484. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/irqs.h 2014-06-11 21:03:19.000000000 +0200
  5485. @@ -0,0 +1,197 @@
  5486. +/*
  5487. + * arch/arm/mach-bcm2708/include/mach/irqs.h
  5488. + *
  5489. + * Copyright (C) 2010 Broadcom
  5490. + * Copyright (C) 2003 ARM Limited
  5491. + * Copyright (C) 2000 Deep Blue Solutions Ltd.
  5492. + *
  5493. + * This program is free software; you can redistribute it and/or modify
  5494. + * it under the terms of the GNU General Public License as published by
  5495. + * the Free Software Foundation; either version 2 of the License, or
  5496. + * (at your option) any later version.
  5497. + *
  5498. + * This program is distributed in the hope that it will be useful,
  5499. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5500. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5501. + * GNU General Public License for more details.
  5502. + *
  5503. + * You should have received a copy of the GNU General Public License
  5504. + * along with this program; if not, write to the Free Software
  5505. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5506. + */
  5507. +
  5508. +#ifndef _BCM2708_IRQS_H_
  5509. +#define _BCM2708_IRQS_H_
  5510. +
  5511. +#include <mach/platform.h>
  5512. +
  5513. +/*
  5514. + * IRQ interrupts definitions are the same as the INT definitions
  5515. + * held within platform.h
  5516. + */
  5517. +#define IRQ_ARMCTRL_START 0
  5518. +#define IRQ_TIMER0 (IRQ_ARMCTRL_START + INTERRUPT_TIMER0)
  5519. +#define IRQ_TIMER1 (IRQ_ARMCTRL_START + INTERRUPT_TIMER1)
  5520. +#define IRQ_TIMER2 (IRQ_ARMCTRL_START + INTERRUPT_TIMER2)
  5521. +#define IRQ_TIMER3 (IRQ_ARMCTRL_START + INTERRUPT_TIMER3)
  5522. +#define IRQ_CODEC0 (IRQ_ARMCTRL_START + INTERRUPT_CODEC0)
  5523. +#define IRQ_CODEC1 (IRQ_ARMCTRL_START + INTERRUPT_CODEC1)
  5524. +#define IRQ_CODEC2 (IRQ_ARMCTRL_START + INTERRUPT_CODEC2)
  5525. +#define IRQ_JPEG (IRQ_ARMCTRL_START + INTERRUPT_JPEG)
  5526. +#define IRQ_ISP (IRQ_ARMCTRL_START + INTERRUPT_ISP)
  5527. +#define IRQ_USB (IRQ_ARMCTRL_START + INTERRUPT_USB)
  5528. +#define IRQ_3D (IRQ_ARMCTRL_START + INTERRUPT_3D)
  5529. +#define IRQ_TRANSPOSER (IRQ_ARMCTRL_START + INTERRUPT_TRANSPOSER)
  5530. +#define IRQ_MULTICORESYNC0 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC0)
  5531. +#define IRQ_MULTICORESYNC1 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC1)
  5532. +#define IRQ_MULTICORESYNC2 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC2)
  5533. +#define IRQ_MULTICORESYNC3 (IRQ_ARMCTRL_START + INTERRUPT_MULTICORESYNC3)
  5534. +#define IRQ_DMA0 (IRQ_ARMCTRL_START + INTERRUPT_DMA0)
  5535. +#define IRQ_DMA1 (IRQ_ARMCTRL_START + INTERRUPT_DMA1)
  5536. +#define IRQ_DMA2 (IRQ_ARMCTRL_START + INTERRUPT_DMA2)
  5537. +#define IRQ_DMA3 (IRQ_ARMCTRL_START + INTERRUPT_DMA3)
  5538. +#define IRQ_DMA4 (IRQ_ARMCTRL_START + INTERRUPT_DMA4)
  5539. +#define IRQ_DMA5 (IRQ_ARMCTRL_START + INTERRUPT_DMA5)
  5540. +#define IRQ_DMA6 (IRQ_ARMCTRL_START + INTERRUPT_DMA6)
  5541. +#define IRQ_DMA7 (IRQ_ARMCTRL_START + INTERRUPT_DMA7)
  5542. +#define IRQ_DMA8 (IRQ_ARMCTRL_START + INTERRUPT_DMA8)
  5543. +#define IRQ_DMA9 (IRQ_ARMCTRL_START + INTERRUPT_DMA9)
  5544. +#define IRQ_DMA10 (IRQ_ARMCTRL_START + INTERRUPT_DMA10)
  5545. +#define IRQ_DMA11 (IRQ_ARMCTRL_START + INTERRUPT_DMA11)
  5546. +#define IRQ_DMA12 (IRQ_ARMCTRL_START + INTERRUPT_DMA12)
  5547. +#define IRQ_AUX (IRQ_ARMCTRL_START + INTERRUPT_AUX)
  5548. +#define IRQ_ARM (IRQ_ARMCTRL_START + INTERRUPT_ARM)
  5549. +#define IRQ_VPUDMA (IRQ_ARMCTRL_START + INTERRUPT_VPUDMA)
  5550. +#define IRQ_HOSTPORT (IRQ_ARMCTRL_START + INTERRUPT_HOSTPORT)
  5551. +#define IRQ_VIDEOSCALER (IRQ_ARMCTRL_START + INTERRUPT_VIDEOSCALER)
  5552. +#define IRQ_CCP2TX (IRQ_ARMCTRL_START + INTERRUPT_CCP2TX)
  5553. +#define IRQ_SDC (IRQ_ARMCTRL_START + INTERRUPT_SDC)
  5554. +#define IRQ_DSI0 (IRQ_ARMCTRL_START + INTERRUPT_DSI0)
  5555. +#define IRQ_AVE (IRQ_ARMCTRL_START + INTERRUPT_AVE)
  5556. +#define IRQ_CAM0 (IRQ_ARMCTRL_START + INTERRUPT_CAM0)
  5557. +#define IRQ_CAM1 (IRQ_ARMCTRL_START + INTERRUPT_CAM1)
  5558. +#define IRQ_HDMI0 (IRQ_ARMCTRL_START + INTERRUPT_HDMI0)
  5559. +#define IRQ_HDMI1 (IRQ_ARMCTRL_START + INTERRUPT_HDMI1)
  5560. +#define IRQ_PIXELVALVE1 (IRQ_ARMCTRL_START + INTERRUPT_PIXELVALVE1)
  5561. +#define IRQ_I2CSPISLV (IRQ_ARMCTRL_START + INTERRUPT_I2CSPISLV)
  5562. +#define IRQ_DSI1 (IRQ_ARMCTRL_START + INTERRUPT_DSI1)
  5563. +#define IRQ_PWA0 (IRQ_ARMCTRL_START + INTERRUPT_PWA0)
  5564. +#define IRQ_PWA1 (IRQ_ARMCTRL_START + INTERRUPT_PWA1)
  5565. +#define IRQ_CPR (IRQ_ARMCTRL_START + INTERRUPT_CPR)
  5566. +#define IRQ_SMI (IRQ_ARMCTRL_START + INTERRUPT_SMI)
  5567. +#define IRQ_GPIO0 (IRQ_ARMCTRL_START + INTERRUPT_GPIO0)
  5568. +#define IRQ_GPIO1 (IRQ_ARMCTRL_START + INTERRUPT_GPIO1)
  5569. +#define IRQ_GPIO2 (IRQ_ARMCTRL_START + INTERRUPT_GPIO2)
  5570. +#define IRQ_GPIO3 (IRQ_ARMCTRL_START + INTERRUPT_GPIO3)
  5571. +#define IRQ_I2C (IRQ_ARMCTRL_START + INTERRUPT_I2C)
  5572. +#define IRQ_SPI (IRQ_ARMCTRL_START + INTERRUPT_SPI)
  5573. +#define IRQ_I2SPCM (IRQ_ARMCTRL_START + INTERRUPT_I2SPCM)
  5574. +#define IRQ_SDIO (IRQ_ARMCTRL_START + INTERRUPT_SDIO)
  5575. +#define IRQ_UART (IRQ_ARMCTRL_START + INTERRUPT_UART)
  5576. +#define IRQ_SLIMBUS (IRQ_ARMCTRL_START + INTERRUPT_SLIMBUS)
  5577. +#define IRQ_VEC (IRQ_ARMCTRL_START + INTERRUPT_VEC)
  5578. +#define IRQ_CPG (IRQ_ARMCTRL_START + INTERRUPT_CPG)
  5579. +#define IRQ_RNG (IRQ_ARMCTRL_START + INTERRUPT_RNG)
  5580. +#define IRQ_ARASANSDIO (IRQ_ARMCTRL_START + INTERRUPT_ARASANSDIO)
  5581. +#define IRQ_AVSPMON (IRQ_ARMCTRL_START + INTERRUPT_AVSPMON)
  5582. +
  5583. +#define IRQ_ARM_TIMER (IRQ_ARMCTRL_START + INTERRUPT_ARM_TIMER)
  5584. +#define IRQ_ARM_MAILBOX (IRQ_ARMCTRL_START + INTERRUPT_ARM_MAILBOX)
  5585. +#define IRQ_ARM_DOORBELL_0 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_0)
  5586. +#define IRQ_ARM_DOORBELL_1 (IRQ_ARMCTRL_START + INTERRUPT_ARM_DOORBELL_1)
  5587. +#define IRQ_VPU0_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU0_HALTED)
  5588. +#define IRQ_VPU1_HALTED (IRQ_ARMCTRL_START + INTERRUPT_VPU1_HALTED)
  5589. +#define IRQ_ILLEGAL_TYPE0 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE0)
  5590. +#define IRQ_ILLEGAL_TYPE1 (IRQ_ARMCTRL_START + INTERRUPT_ILLEGAL_TYPE1)
  5591. +#define IRQ_PENDING1 (IRQ_ARMCTRL_START + INTERRUPT_PENDING1)
  5592. +#define IRQ_PENDING2 (IRQ_ARMCTRL_START + INTERRUPT_PENDING2)
  5593. +
  5594. +#define FIQ_START HARD_IRQS
  5595. +
  5596. +/*
  5597. + * FIQ interrupts definitions are the same as the INT definitions.
  5598. + */
  5599. +#define FIQ_TIMER0 (FIQ_START+INTERRUPT_TIMER0)
  5600. +#define FIQ_TIMER1 (FIQ_START+INTERRUPT_TIMER1)
  5601. +#define FIQ_TIMER2 (FIQ_START+INTERRUPT_TIMER2)
  5602. +#define FIQ_TIMER3 (FIQ_START+INTERRUPT_TIMER3)
  5603. +#define FIQ_CODEC0 (FIQ_START+INTERRUPT_CODEC0)
  5604. +#define FIQ_CODEC1 (FIQ_START+INTERRUPT_CODEC1)
  5605. +#define FIQ_CODEC2 (FIQ_START+INTERRUPT_CODEC2)
  5606. +#define FIQ_JPEG (FIQ_START+INTERRUPT_JPEG)
  5607. +#define FIQ_ISP (FIQ_START+INTERRUPT_ISP)
  5608. +#define FIQ_USB (FIQ_START+INTERRUPT_USB)
  5609. +#define FIQ_3D (FIQ_START+INTERRUPT_3D)
  5610. +#define FIQ_TRANSPOSER (FIQ_START+INTERRUPT_TRANSPOSER)
  5611. +#define FIQ_MULTICORESYNC0 (FIQ_START+INTERRUPT_MULTICORESYNC0)
  5612. +#define FIQ_MULTICORESYNC1 (FIQ_START+INTERRUPT_MULTICORESYNC1)
  5613. +#define FIQ_MULTICORESYNC2 (FIQ_START+INTERRUPT_MULTICORESYNC2)
  5614. +#define FIQ_MULTICORESYNC3 (FIQ_START+INTERRUPT_MULTICORESYNC3)
  5615. +#define FIQ_DMA0 (FIQ_START+INTERRUPT_DMA0)
  5616. +#define FIQ_DMA1 (FIQ_START+INTERRUPT_DMA1)
  5617. +#define FIQ_DMA2 (FIQ_START+INTERRUPT_DMA2)
  5618. +#define FIQ_DMA3 (FIQ_START+INTERRUPT_DMA3)
  5619. +#define FIQ_DMA4 (FIQ_START+INTERRUPT_DMA4)
  5620. +#define FIQ_DMA5 (FIQ_START+INTERRUPT_DMA5)
  5621. +#define FIQ_DMA6 (FIQ_START+INTERRUPT_DMA6)
  5622. +#define FIQ_DMA7 (FIQ_START+INTERRUPT_DMA7)
  5623. +#define FIQ_DMA8 (FIQ_START+INTERRUPT_DMA8)
  5624. +#define FIQ_DMA9 (FIQ_START+INTERRUPT_DMA9)
  5625. +#define FIQ_DMA10 (FIQ_START+INTERRUPT_DMA10)
  5626. +#define FIQ_DMA11 (FIQ_START+INTERRUPT_DMA11)
  5627. +#define FIQ_DMA12 (FIQ_START+INTERRUPT_DMA12)
  5628. +#define FIQ_AUX (FIQ_START+INTERRUPT_AUX)
  5629. +#define FIQ_ARM (FIQ_START+INTERRUPT_ARM)
  5630. +#define FIQ_VPUDMA (FIQ_START+INTERRUPT_VPUDMA)
  5631. +#define FIQ_HOSTPORT (FIQ_START+INTERRUPT_HOSTPORT)
  5632. +#define FIQ_VIDEOSCALER (FIQ_START+INTERRUPT_VIDEOSCALER)
  5633. +#define FIQ_CCP2TX (FIQ_START+INTERRUPT_CCP2TX)
  5634. +#define FIQ_SDC (FIQ_START+INTERRUPT_SDC)
  5635. +#define FIQ_DSI0 (FIQ_START+INTERRUPT_DSI0)
  5636. +#define FIQ_AVE (FIQ_START+INTERRUPT_AVE)
  5637. +#define FIQ_CAM0 (FIQ_START+INTERRUPT_CAM0)
  5638. +#define FIQ_CAM1 (FIQ_START+INTERRUPT_CAM1)
  5639. +#define FIQ_HDMI0 (FIQ_START+INTERRUPT_HDMI0)
  5640. +#define FIQ_HDMI1 (FIQ_START+INTERRUPT_HDMI1)
  5641. +#define FIQ_PIXELVALVE1 (FIQ_START+INTERRUPT_PIXELVALVE1)
  5642. +#define FIQ_I2CSPISLV (FIQ_START+INTERRUPT_I2CSPISLV)
  5643. +#define FIQ_DSI1 (FIQ_START+INTERRUPT_DSI1)
  5644. +#define FIQ_PWA0 (FIQ_START+INTERRUPT_PWA0)
  5645. +#define FIQ_PWA1 (FIQ_START+INTERRUPT_PWA1)
  5646. +#define FIQ_CPR (FIQ_START+INTERRUPT_CPR)
  5647. +#define FIQ_SMI (FIQ_START+INTERRUPT_SMI)
  5648. +#define FIQ_GPIO0 (FIQ_START+INTERRUPT_GPIO0)
  5649. +#define FIQ_GPIO1 (FIQ_START+INTERRUPT_GPIO1)
  5650. +#define FIQ_GPIO2 (FIQ_START+INTERRUPT_GPIO2)
  5651. +#define FIQ_GPIO3 (FIQ_START+INTERRUPT_GPIO3)
  5652. +#define FIQ_I2C (FIQ_START+INTERRUPT_I2C)
  5653. +#define FIQ_SPI (FIQ_START+INTERRUPT_SPI)
  5654. +#define FIQ_I2SPCM (FIQ_START+INTERRUPT_I2SPCM)
  5655. +#define FIQ_SDIO (FIQ_START+INTERRUPT_SDIO)
  5656. +#define FIQ_UART (FIQ_START+INTERRUPT_UART)
  5657. +#define FIQ_SLIMBUS (FIQ_START+INTERRUPT_SLIMBUS)
  5658. +#define FIQ_VEC (FIQ_START+INTERRUPT_VEC)
  5659. +#define FIQ_CPG (FIQ_START+INTERRUPT_CPG)
  5660. +#define FIQ_RNG (FIQ_START+INTERRUPT_RNG)
  5661. +#define FIQ_ARASANSDIO (FIQ_START+INTERRUPT_ARASANSDIO)
  5662. +#define FIQ_AVSPMON (FIQ_START+INTERRUPT_AVSPMON)
  5663. +
  5664. +#define FIQ_ARM_TIMER (FIQ_START+INTERRUPT_ARM_TIMER)
  5665. +#define FIQ_ARM_MAILBOX (FIQ_START+INTERRUPT_ARM_MAILBOX)
  5666. +#define FIQ_ARM_DOORBELL_0 (FIQ_START+INTERRUPT_ARM_DOORBELL_0)
  5667. +#define FIQ_ARM_DOORBELL_1 (FIQ_START+INTERRUPT_ARM_DOORBELL_1)
  5668. +#define FIQ_VPU0_HALTED (FIQ_START+INTERRUPT_VPU0_HALTED)
  5669. +#define FIQ_VPU1_HALTED (FIQ_START+INTERRUPT_VPU1_HALTED)
  5670. +#define FIQ_ILLEGAL_TYPE0 (FIQ_START+INTERRUPT_ILLEGAL_TYPE0)
  5671. +#define FIQ_ILLEGAL_TYPE1 (FIQ_START+INTERRUPT_ILLEGAL_TYPE1)
  5672. +#define FIQ_PENDING1 (FIQ_START+INTERRUPT_PENDING1)
  5673. +#define FIQ_PENDING2 (FIQ_START+INTERRUPT_PENDING2)
  5674. +
  5675. +#define HARD_IRQS (64 + 21)
  5676. +#define FIQ_IRQS (64 + 21)
  5677. +#define GPIO_IRQ_START (HARD_IRQS + FIQ_IRQS)
  5678. +#define GPIO_IRQS (32*5)
  5679. +#define SPARE_IRQS (64)
  5680. +#define NR_IRQS (HARD_IRQS+FIQ_IRQS+GPIO_IRQS+SPARE_IRQS)
  5681. +
  5682. +#endif /* _BCM2708_IRQS_H_ */
  5683. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/memory.h linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h
  5684. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/memory.h 1970-01-01 01:00:00.000000000 +0100
  5685. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/memory.h 2014-06-11 21:03:19.000000000 +0200
  5686. @@ -0,0 +1,57 @@
  5687. +/*
  5688. + * arch/arm/mach-bcm2708/include/mach/memory.h
  5689. + *
  5690. + * Copyright (C) 2010 Broadcom
  5691. + *
  5692. + * This program is free software; you can redistribute it and/or modify
  5693. + * it under the terms of the GNU General Public License as published by
  5694. + * the Free Software Foundation; either version 2 of the License, or
  5695. + * (at your option) any later version.
  5696. + *
  5697. + * This program is distributed in the hope that it will be useful,
  5698. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5699. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5700. + * GNU General Public License for more details.
  5701. + *
  5702. + * You should have received a copy of the GNU General Public License
  5703. + * along with this program; if not, write to the Free Software
  5704. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5705. + */
  5706. +#ifndef __ASM_ARCH_MEMORY_H
  5707. +#define __ASM_ARCH_MEMORY_H
  5708. +
  5709. +/* Memory overview:
  5710. +
  5711. + [ARMcore] <--virtual addr-->
  5712. + [ARMmmu] <--physical addr-->
  5713. + [GERTmap] <--bus add-->
  5714. + [VCperiph]
  5715. +
  5716. +*/
  5717. +
  5718. +/*
  5719. + * Physical DRAM offset.
  5720. + */
  5721. +#define PLAT_PHYS_OFFSET UL(0x00000000)
  5722. +#define VC_ARMMEM_OFFSET UL(0x00000000) /* offset in VC of ARM memory */
  5723. +
  5724. +#ifdef CONFIG_BCM2708_NOL2CACHE
  5725. + #define _REAL_BUS_OFFSET UL(0xC0000000) /* don't use L1 or L2 caches */
  5726. +#else
  5727. + #define _REAL_BUS_OFFSET UL(0x40000000) /* use L2 cache */
  5728. +#endif
  5729. +
  5730. +/* We're using the memory at 64M in the VideoCore for Linux - this adjustment
  5731. + * will provide the offset into this area as well as setting the bits that
  5732. + * stop the L1 and L2 cache from being used
  5733. + *
  5734. + * WARNING: this only works because the ARM is given memory at a fixed location
  5735. + * (ARMMEM_OFFSET)
  5736. + */
  5737. +#define BUS_OFFSET (VC_ARMMEM_OFFSET + _REAL_BUS_OFFSET)
  5738. +#define __virt_to_bus(x) ((x) + (BUS_OFFSET - PAGE_OFFSET))
  5739. +#define __bus_to_virt(x) ((x) - (BUS_OFFSET - PAGE_OFFSET))
  5740. +#define __pfn_to_bus(x) (__pfn_to_phys(x) + (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5741. +#define __bus_to_pfn(x) __phys_to_pfn((x) - (BUS_OFFSET - PLAT_PHYS_OFFSET))
  5742. +
  5743. +#endif
  5744. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/platform.h linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h
  5745. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/platform.h 1970-01-01 01:00:00.000000000 +0100
  5746. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/platform.h 2014-06-11 21:03:19.000000000 +0200
  5747. @@ -0,0 +1,228 @@
  5748. +/*
  5749. + * arch/arm/mach-bcm2708/include/mach/platform.h
  5750. + *
  5751. + * Copyright (C) 2010 Broadcom
  5752. + *
  5753. + * This program is free software; you can redistribute it and/or modify
  5754. + * it under the terms of the GNU General Public License as published by
  5755. + * the Free Software Foundation; either version 2 of the License, or
  5756. + * (at your option) any later version.
  5757. + *
  5758. + * This program is distributed in the hope that it will be useful,
  5759. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5760. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5761. + * GNU General Public License for more details.
  5762. + *
  5763. + * You should have received a copy of the GNU General Public License
  5764. + * along with this program; if not, write to the Free Software
  5765. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  5766. + */
  5767. +
  5768. +#ifndef _BCM2708_PLATFORM_H
  5769. +#define _BCM2708_PLATFORM_H
  5770. +
  5771. +
  5772. +/* macros to get at IO space when running virtually */
  5773. +#define IO_ADDRESS(x) (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
  5774. +
  5775. +#define __io_address(n) IOMEM(IO_ADDRESS(n))
  5776. +
  5777. +
  5778. +/*
  5779. + * SDRAM
  5780. + */
  5781. +#define BCM2708_SDRAM_BASE 0x00000000
  5782. +
  5783. +/*
  5784. + * Logic expansion modules
  5785. + *
  5786. + */
  5787. +
  5788. +
  5789. +/* ------------------------------------------------------------------------
  5790. + * BCM2708 ARMCTRL Registers
  5791. + * ------------------------------------------------------------------------
  5792. + */
  5793. +
  5794. +#define HW_REGISTER_RW(addr) (addr)
  5795. +#define HW_REGISTER_RO(addr) (addr)
  5796. +
  5797. +#include "arm_control.h"
  5798. +#undef ARM_BASE
  5799. +
  5800. +/*
  5801. + * Definitions and addresses for the ARM CONTROL logic
  5802. + * This file is manually generated.
  5803. + */
  5804. +
  5805. +#define BCM2708_PERI_BASE 0x20000000
  5806. +#define IC0_BASE (BCM2708_PERI_BASE + 0x2000)
  5807. +#define ST_BASE (BCM2708_PERI_BASE + 0x3000) /* System Timer */
  5808. +#define MPHI_BASE (BCM2708_PERI_BASE + 0x6000) /* Message -based Parallel Host Interface */
  5809. +#define DMA_BASE (BCM2708_PERI_BASE + 0x7000) /* DMA controller */
  5810. +#define ARM_BASE (BCM2708_PERI_BASE + 0xB000) /* BCM2708 ARM control block */
  5811. +#define PM_BASE (BCM2708_PERI_BASE + 0x100000) /* Power Management, Reset controller and Watchdog registers */
  5812. +#define PCM_CLOCK_BASE (BCM2708_PERI_BASE + 0x101098) /* PCM Clock */
  5813. +#define RNG_BASE (BCM2708_PERI_BASE + 0x104000) /* Hardware RNG */
  5814. +#define GPIO_BASE (BCM2708_PERI_BASE + 0x200000) /* GPIO */
  5815. +#define UART0_BASE (BCM2708_PERI_BASE + 0x201000) /* Uart 0 */
  5816. +#define MMCI0_BASE (BCM2708_PERI_BASE + 0x202000) /* MMC interface */
  5817. +#define I2S_BASE (BCM2708_PERI_BASE + 0x203000) /* I2S */
  5818. +#define SPI0_BASE (BCM2708_PERI_BASE + 0x204000) /* SPI0 */
  5819. +#define BSC0_BASE (BCM2708_PERI_BASE + 0x205000) /* BSC0 I2C/TWI */
  5820. +#define UART1_BASE (BCM2708_PERI_BASE + 0x215000) /* Uart 1 */
  5821. +#define EMMC_BASE (BCM2708_PERI_BASE + 0x300000) /* eMMC interface */
  5822. +#define SMI_BASE (BCM2708_PERI_BASE + 0x600000) /* SMI */
  5823. +#define BSC1_BASE (BCM2708_PERI_BASE + 0x804000) /* BSC1 I2C/TWI */
  5824. +#define USB_BASE (BCM2708_PERI_BASE + 0x980000) /* DTC_OTG USB controller */
  5825. +#define MCORE_BASE (BCM2708_PERI_BASE + 0x0000) /* Fake frame buffer device (actually the multicore sync block*/
  5826. +
  5827. +#define ARMCTRL_BASE (ARM_BASE + 0x000)
  5828. +#define ARMCTRL_IC_BASE (ARM_BASE + 0x200) /* ARM interrupt controller */
  5829. +#define ARMCTRL_TIMER0_1_BASE (ARM_BASE + 0x400) /* Timer 0 and 1 */
  5830. +#define ARMCTRL_0_SBM_BASE (ARM_BASE + 0x800) /* User 0 (ARM)'s Semaphores Doorbells and Mailboxes */
  5831. +
  5832. +
  5833. +/*
  5834. + * Interrupt assignments
  5835. + */
  5836. +
  5837. +#define ARM_IRQ1_BASE 0
  5838. +#define INTERRUPT_TIMER0 (ARM_IRQ1_BASE + 0)
  5839. +#define INTERRUPT_TIMER1 (ARM_IRQ1_BASE + 1)
  5840. +#define INTERRUPT_TIMER2 (ARM_IRQ1_BASE + 2)
  5841. +#define INTERRUPT_TIMER3 (ARM_IRQ1_BASE + 3)
  5842. +#define INTERRUPT_CODEC0 (ARM_IRQ1_BASE + 4)
  5843. +#define INTERRUPT_CODEC1 (ARM_IRQ1_BASE + 5)
  5844. +#define INTERRUPT_CODEC2 (ARM_IRQ1_BASE + 6)
  5845. +#define INTERRUPT_VC_JPEG (ARM_IRQ1_BASE + 7)
  5846. +#define INTERRUPT_ISP (ARM_IRQ1_BASE + 8)
  5847. +#define INTERRUPT_VC_USB (ARM_IRQ1_BASE + 9)
  5848. +#define INTERRUPT_VC_3D (ARM_IRQ1_BASE + 10)
  5849. +#define INTERRUPT_TRANSPOSER (ARM_IRQ1_BASE + 11)
  5850. +#define INTERRUPT_MULTICORESYNC0 (ARM_IRQ1_BASE + 12)
  5851. +#define INTERRUPT_MULTICORESYNC1 (ARM_IRQ1_BASE + 13)
  5852. +#define INTERRUPT_MULTICORESYNC2 (ARM_IRQ1_BASE + 14)
  5853. +#define INTERRUPT_MULTICORESYNC3 (ARM_IRQ1_BASE + 15)
  5854. +#define INTERRUPT_DMA0 (ARM_IRQ1_BASE + 16)
  5855. +#define INTERRUPT_DMA1 (ARM_IRQ1_BASE + 17)
  5856. +#define INTERRUPT_VC_DMA2 (ARM_IRQ1_BASE + 18)
  5857. +#define INTERRUPT_VC_DMA3 (ARM_IRQ1_BASE + 19)
  5858. +#define INTERRUPT_DMA4 (ARM_IRQ1_BASE + 20)
  5859. +#define INTERRUPT_DMA5 (ARM_IRQ1_BASE + 21)
  5860. +#define INTERRUPT_DMA6 (ARM_IRQ1_BASE + 22)
  5861. +#define INTERRUPT_DMA7 (ARM_IRQ1_BASE + 23)
  5862. +#define INTERRUPT_DMA8 (ARM_IRQ1_BASE + 24)
  5863. +#define INTERRUPT_DMA9 (ARM_IRQ1_BASE + 25)
  5864. +#define INTERRUPT_DMA10 (ARM_IRQ1_BASE + 26)
  5865. +#define INTERRUPT_DMA11 (ARM_IRQ1_BASE + 27)
  5866. +#define INTERRUPT_DMA12 (ARM_IRQ1_BASE + 28)
  5867. +#define INTERRUPT_AUX (ARM_IRQ1_BASE + 29)
  5868. +#define INTERRUPT_ARM (ARM_IRQ1_BASE + 30)
  5869. +#define INTERRUPT_VPUDMA (ARM_IRQ1_BASE + 31)
  5870. +
  5871. +#define ARM_IRQ2_BASE 32
  5872. +#define INTERRUPT_HOSTPORT (ARM_IRQ2_BASE + 0)
  5873. +#define INTERRUPT_VIDEOSCALER (ARM_IRQ2_BASE + 1)
  5874. +#define INTERRUPT_CCP2TX (ARM_IRQ2_BASE + 2)
  5875. +#define INTERRUPT_SDC (ARM_IRQ2_BASE + 3)
  5876. +#define INTERRUPT_DSI0 (ARM_IRQ2_BASE + 4)
  5877. +#define INTERRUPT_AVE (ARM_IRQ2_BASE + 5)
  5878. +#define INTERRUPT_CAM0 (ARM_IRQ2_BASE + 6)
  5879. +#define INTERRUPT_CAM1 (ARM_IRQ2_BASE + 7)
  5880. +#define INTERRUPT_HDMI0 (ARM_IRQ2_BASE + 8)
  5881. +#define INTERRUPT_HDMI1 (ARM_IRQ2_BASE + 9)
  5882. +#define INTERRUPT_PIXELVALVE1 (ARM_IRQ2_BASE + 10)
  5883. +#define INTERRUPT_I2CSPISLV (ARM_IRQ2_BASE + 11)
  5884. +#define INTERRUPT_DSI1 (ARM_IRQ2_BASE + 12)
  5885. +#define INTERRUPT_PWA0 (ARM_IRQ2_BASE + 13)
  5886. +#define INTERRUPT_PWA1 (ARM_IRQ2_BASE + 14)
  5887. +#define INTERRUPT_CPR (ARM_IRQ2_BASE + 15)
  5888. +#define INTERRUPT_SMI (ARM_IRQ2_BASE + 16)
  5889. +#define INTERRUPT_GPIO0 (ARM_IRQ2_BASE + 17)
  5890. +#define INTERRUPT_GPIO1 (ARM_IRQ2_BASE + 18)
  5891. +#define INTERRUPT_GPIO2 (ARM_IRQ2_BASE + 19)
  5892. +#define INTERRUPT_GPIO3 (ARM_IRQ2_BASE + 20)
  5893. +#define INTERRUPT_VC_I2C (ARM_IRQ2_BASE + 21)
  5894. +#define INTERRUPT_VC_SPI (ARM_IRQ2_BASE + 22)
  5895. +#define INTERRUPT_VC_I2SPCM (ARM_IRQ2_BASE + 23)
  5896. +#define INTERRUPT_VC_SDIO (ARM_IRQ2_BASE + 24)
  5897. +#define INTERRUPT_VC_UART (ARM_IRQ2_BASE + 25)
  5898. +#define INTERRUPT_SLIMBUS (ARM_IRQ2_BASE + 26)
  5899. +#define INTERRUPT_VEC (ARM_IRQ2_BASE + 27)
  5900. +#define INTERRUPT_CPG (ARM_IRQ2_BASE + 28)
  5901. +#define INTERRUPT_RNG (ARM_IRQ2_BASE + 29)
  5902. +#define INTERRUPT_VC_ARASANSDIO (ARM_IRQ2_BASE + 30)
  5903. +#define INTERRUPT_AVSPMON (ARM_IRQ2_BASE + 31)
  5904. +
  5905. +#define ARM_IRQ0_BASE 64
  5906. +#define INTERRUPT_ARM_TIMER (ARM_IRQ0_BASE + 0)
  5907. +#define INTERRUPT_ARM_MAILBOX (ARM_IRQ0_BASE + 1)
  5908. +#define INTERRUPT_ARM_DOORBELL_0 (ARM_IRQ0_BASE + 2)
  5909. +#define INTERRUPT_ARM_DOORBELL_1 (ARM_IRQ0_BASE + 3)
  5910. +#define INTERRUPT_VPU0_HALTED (ARM_IRQ0_BASE + 4)
  5911. +#define INTERRUPT_VPU1_HALTED (ARM_IRQ0_BASE + 5)
  5912. +#define INTERRUPT_ILLEGAL_TYPE0 (ARM_IRQ0_BASE + 6)
  5913. +#define INTERRUPT_ILLEGAL_TYPE1 (ARM_IRQ0_BASE + 7)
  5914. +#define INTERRUPT_PENDING1 (ARM_IRQ0_BASE + 8)
  5915. +#define INTERRUPT_PENDING2 (ARM_IRQ0_BASE + 9)
  5916. +#define INTERRUPT_JPEG (ARM_IRQ0_BASE + 10)
  5917. +#define INTERRUPT_USB (ARM_IRQ0_BASE + 11)
  5918. +#define INTERRUPT_3D (ARM_IRQ0_BASE + 12)
  5919. +#define INTERRUPT_DMA2 (ARM_IRQ0_BASE + 13)
  5920. +#define INTERRUPT_DMA3 (ARM_IRQ0_BASE + 14)
  5921. +#define INTERRUPT_I2C (ARM_IRQ0_BASE + 15)
  5922. +#define INTERRUPT_SPI (ARM_IRQ0_BASE + 16)
  5923. +#define INTERRUPT_I2SPCM (ARM_IRQ0_BASE + 17)
  5924. +#define INTERRUPT_SDIO (ARM_IRQ0_BASE + 18)
  5925. +#define INTERRUPT_UART (ARM_IRQ0_BASE + 19)
  5926. +#define INTERRUPT_ARASANSDIO (ARM_IRQ0_BASE + 20)
  5927. +
  5928. +#define MAXIRQNUM (32 + 32 + 20)
  5929. +#define MAXFIQNUM (32 + 32 + 20)
  5930. +
  5931. +#define MAX_TIMER 2
  5932. +#define MAX_PERIOD 699050
  5933. +#define TICKS_PER_uSEC 1
  5934. +
  5935. +/*
  5936. + * These are useconds NOT ticks.
  5937. + *
  5938. + */
  5939. +#define mSEC_1 1000
  5940. +#define mSEC_5 (mSEC_1 * 5)
  5941. +#define mSEC_10 (mSEC_1 * 10)
  5942. +#define mSEC_25 (mSEC_1 * 25)
  5943. +#define SEC_1 (mSEC_1 * 1000)
  5944. +
  5945. +/*
  5946. + * Watchdog
  5947. + */
  5948. +#define PM_RSTC (PM_BASE+0x1c)
  5949. +#define PM_RSTS (PM_BASE+0x20)
  5950. +#define PM_WDOG (PM_BASE+0x24)
  5951. +
  5952. +#define PM_WDOG_RESET 0000000000
  5953. +#define PM_PASSWORD 0x5a000000
  5954. +#define PM_WDOG_TIME_SET 0x000fffff
  5955. +#define PM_RSTC_WRCFG_CLR 0xffffffcf
  5956. +#define PM_RSTC_WRCFG_SET 0x00000030
  5957. +#define PM_RSTC_WRCFG_FULL_RESET 0x00000020
  5958. +#define PM_RSTC_RESET 0x00000102
  5959. +
  5960. +#define PM_RSTS_HADPOR_SET 0x00001000
  5961. +#define PM_RSTS_HADSRH_SET 0x00000400
  5962. +#define PM_RSTS_HADSRF_SET 0x00000200
  5963. +#define PM_RSTS_HADSRQ_SET 0x00000100
  5964. +#define PM_RSTS_HADWRH_SET 0x00000040
  5965. +#define PM_RSTS_HADWRF_SET 0x00000020
  5966. +#define PM_RSTS_HADWRQ_SET 0x00000010
  5967. +#define PM_RSTS_HADDRH_SET 0x00000004
  5968. +#define PM_RSTS_HADDRF_SET 0x00000002
  5969. +#define PM_RSTS_HADDRQ_SET 0x00000001
  5970. +
  5971. +#define UART0_CLOCK 3000000
  5972. +
  5973. +#endif
  5974. +
  5975. +/* END */
  5976. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/power.h linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h
  5977. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/power.h 1970-01-01 01:00:00.000000000 +0100
  5978. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/power.h 2014-06-11 21:03:19.000000000 +0200
  5979. @@ -0,0 +1,26 @@
  5980. +/*
  5981. + * linux/arch/arm/mach-bcm2708/power.h
  5982. + *
  5983. + * Copyright (C) 2010 Broadcom
  5984. + *
  5985. + * This program is free software; you can redistribute it and/or modify
  5986. + * it under the terms of the GNU General Public License version 2 as
  5987. + * published by the Free Software Foundation.
  5988. + *
  5989. + * This device provides a shared mechanism for controlling the power to
  5990. + * VideoCore subsystems.
  5991. + */
  5992. +
  5993. +#ifndef _MACH_BCM2708_POWER_H
  5994. +#define _MACH_BCM2708_POWER_H
  5995. +
  5996. +#include <linux/types.h>
  5997. +#include <mach/arm_power.h>
  5998. +
  5999. +typedef unsigned int BCM_POWER_HANDLE_T;
  6000. +
  6001. +extern int bcm_power_open(BCM_POWER_HANDLE_T *handle);
  6002. +extern int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request);
  6003. +extern int bcm_power_close(BCM_POWER_HANDLE_T handle);
  6004. +
  6005. +#endif
  6006. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/system.h linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h
  6007. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/system.h 1970-01-01 01:00:00.000000000 +0100
  6008. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/system.h 2014-06-11 21:03:19.000000000 +0200
  6009. @@ -0,0 +1,38 @@
  6010. +/*
  6011. + * arch/arm/mach-bcm2708/include/mach/system.h
  6012. + *
  6013. + * Copyright (C) 2010 Broadcom
  6014. + * Copyright (C) 2003 ARM Limited
  6015. + * Copyright (C) 2000 Deep Blue Solutions Ltd
  6016. + *
  6017. + * This program is free software; you can redistribute it and/or modify
  6018. + * it under the terms of the GNU General Public License as published by
  6019. + * the Free Software Foundation; either version 2 of the License, or
  6020. + * (at your option) any later version.
  6021. + *
  6022. + * This program is distributed in the hope that it will be useful,
  6023. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6024. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6025. + * GNU General Public License for more details.
  6026. + *
  6027. + * You should have received a copy of the GNU General Public License
  6028. + * along with this program; if not, write to the Free Software
  6029. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6030. + */
  6031. +#ifndef __ASM_ARCH_SYSTEM_H
  6032. +#define __ASM_ARCH_SYSTEM_H
  6033. +
  6034. +#include <linux/io.h>
  6035. +#include <mach/hardware.h>
  6036. +#include <mach/platform.h>
  6037. +
  6038. +static inline void arch_idle(void)
  6039. +{
  6040. + /*
  6041. + * This should do all the clock switching
  6042. + * and wait for interrupt tricks
  6043. + */
  6044. + cpu_do_idle();
  6045. +}
  6046. +
  6047. +#endif
  6048. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/timex.h linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h
  6049. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/timex.h 1970-01-01 01:00:00.000000000 +0100
  6050. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/timex.h 2014-06-11 21:03:19.000000000 +0200
  6051. @@ -0,0 +1,23 @@
  6052. +/*
  6053. + * arch/arm/mach-bcm2708/include/mach/timex.h
  6054. + *
  6055. + * BCM2708 sysem clock frequency
  6056. + *
  6057. + * Copyright (C) 2010 Broadcom
  6058. + *
  6059. + * This program is free software; you can redistribute it and/or modify
  6060. + * it under the terms of the GNU General Public License as published by
  6061. + * the Free Software Foundation; either version 2 of the License, or
  6062. + * (at your option) any later version.
  6063. + *
  6064. + * This program is distributed in the hope that it will be useful,
  6065. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6066. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6067. + * GNU General Public License for more details.
  6068. + *
  6069. + * You should have received a copy of the GNU General Public License
  6070. + * along with this program; if not, write to the Free Software
  6071. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6072. + */
  6073. +
  6074. +#define CLOCK_TICK_RATE (1000000)
  6075. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/uncompress.h linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h
  6076. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/uncompress.h 1970-01-01 01:00:00.000000000 +0100
  6077. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/uncompress.h 2014-06-11 21:03:19.000000000 +0200
  6078. @@ -0,0 +1,84 @@
  6079. +/*
  6080. + * arch/arm/mach-bcn2708/include/mach/uncompress.h
  6081. + *
  6082. + * Copyright (C) 2010 Broadcom
  6083. + * Copyright (C) 2003 ARM Limited
  6084. + *
  6085. + * This program is free software; you can redistribute it and/or modify
  6086. + * it under the terms of the GNU General Public License as published by
  6087. + * the Free Software Foundation; either version 2 of the License, or
  6088. + * (at your option) any later version.
  6089. + *
  6090. + * This program is distributed in the hope that it will be useful,
  6091. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6092. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6093. + * GNU General Public License for more details.
  6094. + *
  6095. + * You should have received a copy of the GNU General Public License
  6096. + * along with this program; if not, write to the Free Software
  6097. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6098. + */
  6099. +
  6100. +#include <linux/io.h>
  6101. +#include <linux/amba/serial.h>
  6102. +#include <mach/hardware.h>
  6103. +
  6104. +#define UART_BAUD 115200
  6105. +
  6106. +#define BCM2708_UART_DR __io(UART0_BASE + UART01x_DR)
  6107. +#define BCM2708_UART_FR __io(UART0_BASE + UART01x_FR)
  6108. +#define BCM2708_UART_IBRD __io(UART0_BASE + UART011_IBRD)
  6109. +#define BCM2708_UART_FBRD __io(UART0_BASE + UART011_FBRD)
  6110. +#define BCM2708_UART_LCRH __io(UART0_BASE + UART011_LCRH)
  6111. +#define BCM2708_UART_CR __io(UART0_BASE + UART011_CR)
  6112. +
  6113. +/*
  6114. + * This does not append a newline
  6115. + */
  6116. +static inline void putc(int c)
  6117. +{
  6118. + while (__raw_readl(BCM2708_UART_FR) & UART01x_FR_TXFF)
  6119. + barrier();
  6120. +
  6121. + __raw_writel(c, BCM2708_UART_DR);
  6122. +}
  6123. +
  6124. +static inline void flush(void)
  6125. +{
  6126. + int fr;
  6127. +
  6128. + do {
  6129. + fr = __raw_readl(BCM2708_UART_FR);
  6130. + barrier();
  6131. + } while ((fr & (UART011_FR_TXFE | UART01x_FR_BUSY)) != UART011_FR_TXFE);
  6132. +}
  6133. +
  6134. +static inline void arch_decomp_setup(void)
  6135. +{
  6136. + int temp, div, rem, frac;
  6137. +
  6138. + temp = 16 * UART_BAUD;
  6139. + div = UART0_CLOCK / temp;
  6140. + rem = UART0_CLOCK % temp;
  6141. + temp = (8 * rem) / UART_BAUD;
  6142. + frac = (temp >> 1) + (temp & 1);
  6143. +
  6144. + /* Make sure the UART is disabled before we start */
  6145. + __raw_writel(0, BCM2708_UART_CR);
  6146. +
  6147. + /* Set the baud rate */
  6148. + __raw_writel(div, BCM2708_UART_IBRD);
  6149. + __raw_writel(frac, BCM2708_UART_FBRD);
  6150. +
  6151. + /* Set the UART to 8n1, FIFO enabled */
  6152. + __raw_writel(UART01x_LCRH_WLEN_8 | UART01x_LCRH_FEN, BCM2708_UART_LCRH);
  6153. +
  6154. + /* Enable the UART */
  6155. + __raw_writel(UART01x_CR_UARTEN | UART011_CR_TXE | UART011_CR_RXE,
  6156. + BCM2708_UART_CR);
  6157. +}
  6158. +
  6159. +/*
  6160. + * nothing to do
  6161. + */
  6162. +#define arch_decomp_wdog()
  6163. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/vcio.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h
  6164. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/vcio.h 1970-01-01 01:00:00.000000000 +0100
  6165. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vcio.h 2014-06-11 21:03:19.000000000 +0200
  6166. @@ -0,0 +1,141 @@
  6167. +/*
  6168. + * arch/arm/mach-bcm2708/include/mach/vcio.h
  6169. + *
  6170. + * Copyright (C) 2010 Broadcom
  6171. + *
  6172. + * This program is free software; you can redistribute it and/or modify
  6173. + * it under the terms of the GNU General Public License as published by
  6174. + * the Free Software Foundation; either version 2 of the License, or
  6175. + * (at your option) any later version.
  6176. + *
  6177. + * This program is distributed in the hope that it will be useful,
  6178. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6179. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6180. + * GNU General Public License for more details.
  6181. + *
  6182. + * You should have received a copy of the GNU General Public License
  6183. + * along with this program; if not, write to the Free Software
  6184. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6185. + */
  6186. +#ifndef _MACH_BCM2708_VCIO_H
  6187. +#define _MACH_BCM2708_VCIO_H
  6188. +
  6189. +/* Routines to handle I/O via the VideoCore "ARM control" registers
  6190. + * (semaphores, doorbells, mailboxes)
  6191. + */
  6192. +
  6193. +#define BCM_VCIO_DRIVER_NAME "bcm2708_vcio"
  6194. +
  6195. +/* Constants shared with the ARM identifying separate mailbox channels */
  6196. +#define MBOX_CHAN_POWER 0 /* for use by the power management interface */
  6197. +#define MBOX_CHAN_FB 1 /* for use by the frame buffer */
  6198. +#define MBOX_CHAN_VCHIQ 3 /* for use by the VCHIQ interface */
  6199. +#define MBOX_CHAN_PROPERTY 8 /* for use by the property channel */
  6200. +#define MBOX_CHAN_COUNT 9
  6201. +
  6202. +/* Mailbox property tags */
  6203. +enum {
  6204. + VCMSG_PROPERTY_END = 0x00000000,
  6205. + VCMSG_GET_FIRMWARE_REVISION = 0x00000001,
  6206. + VCMSG_GET_BOARD_MODEL = 0x00010001,
  6207. + VCMSG_GET_BOARD_REVISION = 0x00020002,
  6208. + VCMSG_GET_BOARD_MAC_ADDRESS = 0x00020003,
  6209. + VCMSG_GET_BOARD_SERIAL = 0x00020004,
  6210. + VCMSG_GET_ARM_MEMORY = 0x00020005,
  6211. + VCMSG_GET_VC_MEMORY = 0x00020006,
  6212. + VCMSG_GET_CLOCKS = 0x00020007,
  6213. + VCMSG_GET_COMMAND_LINE = 0x00050001,
  6214. + VCMSG_GET_DMA_CHANNELS = 0x00060001,
  6215. + VCMSG_GET_POWER_STATE = 0x00020001,
  6216. + VCMSG_GET_TIMING = 0x00020002,
  6217. + VCMSG_SET_POWER_STATE = 0x00028001,
  6218. + VCMSG_GET_CLOCK_STATE = 0x00030001,
  6219. + VCMSG_SET_CLOCK_STATE = 0x00038001,
  6220. + VCMSG_GET_CLOCK_RATE = 0x00030002,
  6221. + VCMSG_SET_CLOCK_RATE = 0x00038002,
  6222. + VCMSG_GET_VOLTAGE = 0x00030003,
  6223. + VCMSG_SET_VOLTAGE = 0x00038003,
  6224. + VCMSG_GET_MAX_CLOCK = 0x00030004,
  6225. + VCMSG_GET_MAX_VOLTAGE = 0x00030005,
  6226. + VCMSG_GET_TEMPERATURE = 0x00030006,
  6227. + VCMSG_GET_MIN_CLOCK = 0x00030007,
  6228. + VCMSG_GET_MIN_VOLTAGE = 0x00030008,
  6229. + VCMSG_GET_TURBO = 0x00030009,
  6230. + VCMSG_SET_TURBO = 0x00038009,
  6231. + VCMSG_SET_ALLOCATE_BUFFER = 0x00040001,
  6232. + VCMSG_SET_RELEASE_BUFFER = 0x00048001,
  6233. + VCMSG_SET_BLANK_SCREEN = 0x00040002,
  6234. + VCMSG_TST_BLANK_SCREEN = 0x00044002,
  6235. + VCMSG_GET_PHYSICAL_WIDTH_HEIGHT = 0x00040003,
  6236. + VCMSG_TST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
  6237. + VCMSG_SET_PHYSICAL_WIDTH_HEIGHT = 0x00048003,
  6238. + VCMSG_GET_VIRTUAL_WIDTH_HEIGHT = 0x00040004,
  6239. + VCMSG_TST_VIRTUAL_WIDTH_HEIGHT = 0x00044004,
  6240. + VCMSG_SET_VIRTUAL_WIDTH_HEIGHT = 0x00048004,
  6241. + VCMSG_GET_DEPTH = 0x00040005,
  6242. + VCMSG_TST_DEPTH = 0x00044005,
  6243. + VCMSG_SET_DEPTH = 0x00048005,
  6244. + VCMSG_GET_PIXEL_ORDER = 0x00040006,
  6245. + VCMSG_TST_PIXEL_ORDER = 0x00044006,
  6246. + VCMSG_SET_PIXEL_ORDER = 0x00048006,
  6247. + VCMSG_GET_ALPHA_MODE = 0x00040007,
  6248. + VCMSG_TST_ALPHA_MODE = 0x00044007,
  6249. + VCMSG_SET_ALPHA_MODE = 0x00048007,
  6250. + VCMSG_GET_PITCH = 0x00040008,
  6251. + VCMSG_TST_PITCH = 0x00044008,
  6252. + VCMSG_SET_PITCH = 0x00048008,
  6253. + VCMSG_GET_VIRTUAL_OFFSET = 0x00040009,
  6254. + VCMSG_TST_VIRTUAL_OFFSET = 0x00044009,
  6255. + VCMSG_SET_VIRTUAL_OFFSET = 0x00048009,
  6256. + VCMSG_GET_OVERSCAN = 0x0004000a,
  6257. + VCMSG_TST_OVERSCAN = 0x0004400a,
  6258. + VCMSG_SET_OVERSCAN = 0x0004800a,
  6259. + VCMSG_GET_PALETTE = 0x0004000b,
  6260. + VCMSG_TST_PALETTE = 0x0004400b,
  6261. + VCMSG_SET_PALETTE = 0x0004800b,
  6262. + VCMSG_GET_LAYER = 0x0004000c,
  6263. + VCMSG_TST_LAYER = 0x0004400c,
  6264. + VCMSG_SET_LAYER = 0x0004800c,
  6265. + VCMSG_GET_TRANSFORM = 0x0004000d,
  6266. + VCMSG_TST_TRANSFORM = 0x0004400d,
  6267. + VCMSG_SET_TRANSFORM = 0x0004800d,
  6268. +};
  6269. +
  6270. +extern int /*rc*/ bcm_mailbox_read(unsigned chan, uint32_t *data28);
  6271. +extern int /*rc*/ bcm_mailbox_write(unsigned chan, uint32_t data28);
  6272. +extern int /*rc*/ bcm_mailbox_property(void *data, int size);
  6273. +
  6274. +#include <linux/ioctl.h>
  6275. +
  6276. +/*
  6277. + * The major device number. We can't rely on dynamic
  6278. + * registration any more, because ioctls need to know
  6279. + * it.
  6280. + */
  6281. +#define MAJOR_NUM 100
  6282. +
  6283. +/*
  6284. + * Set the message of the device driver
  6285. + */
  6286. +#define IOCTL_MBOX_PROPERTY _IOWR(MAJOR_NUM, 0, char *)
  6287. +/*
  6288. + * _IOWR means that we're creating an ioctl command
  6289. + * number for passing information from a user process
  6290. + * to the kernel module and from the kernel module to user process
  6291. + *
  6292. + * The first arguments, MAJOR_NUM, is the major device
  6293. + * number we're using.
  6294. + *
  6295. + * The second argument is the number of the command
  6296. + * (there could be several with different meanings).
  6297. + *
  6298. + * The third argument is the type we want to get from
  6299. + * the process to the kernel.
  6300. + */
  6301. +
  6302. +/*
  6303. + * The name of the device file
  6304. + */
  6305. +#define DEVICE_FILE_NAME "char_dev"
  6306. +
  6307. +#endif
  6308. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/vc_mem.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h
  6309. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/vc_mem.h 1970-01-01 01:00:00.000000000 +0100
  6310. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vc_mem.h 2014-06-11 21:03:19.000000000 +0200
  6311. @@ -0,0 +1,35 @@
  6312. +/*****************************************************************************
  6313. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  6314. +*
  6315. +* Unless you and Broadcom execute a separate written software license
  6316. +* agreement governing use of this software, this software is licensed to you
  6317. +* under the terms of the GNU General Public License version 2, available at
  6318. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  6319. +*
  6320. +* Notwithstanding the above, under no circumstances may you combine this
  6321. +* software in any way with any other Broadcom software provided under a
  6322. +* license other than the GPL, without Broadcom's express prior written
  6323. +* consent.
  6324. +*****************************************************************************/
  6325. +
  6326. +#if !defined( VC_MEM_H )
  6327. +#define VC_MEM_H
  6328. +
  6329. +#include <linux/ioctl.h>
  6330. +
  6331. +#define VC_MEM_IOC_MAGIC 'v'
  6332. +
  6333. +#define VC_MEM_IOC_MEM_PHYS_ADDR _IOR( VC_MEM_IOC_MAGIC, 0, unsigned long )
  6334. +#define VC_MEM_IOC_MEM_SIZE _IOR( VC_MEM_IOC_MAGIC, 1, unsigned int )
  6335. +#define VC_MEM_IOC_MEM_BASE _IOR( VC_MEM_IOC_MAGIC, 2, unsigned int )
  6336. +#define VC_MEM_IOC_MEM_LOAD _IOR( VC_MEM_IOC_MAGIC, 3, unsigned int )
  6337. +
  6338. +#if defined( __KERNEL__ )
  6339. +#define VC_MEM_TO_ARM_ADDR_MASK 0x3FFFFFFF
  6340. +
  6341. +extern unsigned long mm_vc_mem_phys_addr;
  6342. +extern unsigned int mm_vc_mem_size;
  6343. +extern int vc_mem_get_current_size( void );
  6344. +#endif
  6345. +
  6346. +#endif /* VC_MEM_H */
  6347. diff -Nur linux-3.15/arch/arm/mach-bcm2708/include/mach/vmalloc.h linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6348. --- linux-3.15/arch/arm/mach-bcm2708/include/mach/vmalloc.h 1970-01-01 01:00:00.000000000 +0100
  6349. +++ linux-rpi/arch/arm/mach-bcm2708/include/mach/vmalloc.h 2014-06-11 21:03:19.000000000 +0200
  6350. @@ -0,0 +1,20 @@
  6351. +/*
  6352. + * arch/arm/mach-bcm2708/include/mach/vmalloc.h
  6353. + *
  6354. + * Copyright (C) 2010 Broadcom
  6355. + *
  6356. + * This program is free software; you can redistribute it and/or modify
  6357. + * it under the terms of the GNU General Public License as published by
  6358. + * the Free Software Foundation; either version 2 of the License, or
  6359. + * (at your option) any later version.
  6360. + *
  6361. + * This program is distributed in the hope that it will be useful,
  6362. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  6363. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  6364. + * GNU General Public License for more details.
  6365. + *
  6366. + * You should have received a copy of the GNU General Public License
  6367. + * along with this program; if not, write to the Free Software
  6368. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  6369. + */
  6370. +#define VMALLOC_END (0xe8000000)
  6371. diff -Nur linux-3.15/arch/arm/mach-bcm2708/Kconfig linux-rpi/arch/arm/mach-bcm2708/Kconfig
  6372. --- linux-3.15/arch/arm/mach-bcm2708/Kconfig 1970-01-01 01:00:00.000000000 +0100
  6373. +++ linux-rpi/arch/arm/mach-bcm2708/Kconfig 2014-06-11 21:03:19.000000000 +0200
  6374. @@ -0,0 +1,41 @@
  6375. +menu "Broadcom BCM2708 Implementations"
  6376. + depends on ARCH_BCM2708
  6377. +
  6378. +config MACH_BCM2708
  6379. + bool "Broadcom BCM2708 Development Platform"
  6380. + select NEED_MACH_MEMORY_H
  6381. + select NEED_MACH_IO_H
  6382. + select CPU_V6
  6383. + help
  6384. + Include support for the Broadcom(R) BCM2708 platform.
  6385. +
  6386. +config BCM2708_GPIO
  6387. + bool "BCM2708 gpio support"
  6388. + depends on MACH_BCM2708
  6389. + select ARCH_REQUIRE_GPIOLIB
  6390. + default y
  6391. + help
  6392. + Include support for the Broadcom(R) BCM2708 gpio.
  6393. +
  6394. +config BCM2708_VCMEM
  6395. + bool "Videocore Memory"
  6396. + depends on MACH_BCM2708
  6397. + default y
  6398. + help
  6399. + Helper for videocore memory access and total size allocation.
  6400. +
  6401. +config BCM2708_NOL2CACHE
  6402. + bool "Videocore L2 cache disable"
  6403. + depends on MACH_BCM2708
  6404. + default n
  6405. + help
  6406. + Do not allow ARM to use GPU's L2 cache. Requires disable_l2cache in config.txt.
  6407. +
  6408. +config BCM2708_SPIDEV
  6409. + bool "Bind spidev to SPI0 master"
  6410. + depends on MACH_BCM2708
  6411. + depends on SPI
  6412. + default y
  6413. + help
  6414. + Binds spidev driver to the SPI0 master
  6415. +endmenu
  6416. diff -Nur linux-3.15/arch/arm/mach-bcm2708/Makefile linux-rpi/arch/arm/mach-bcm2708/Makefile
  6417. --- linux-3.15/arch/arm/mach-bcm2708/Makefile 1970-01-01 01:00:00.000000000 +0100
  6418. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile 2014-06-11 21:03:19.000000000 +0200
  6419. @@ -0,0 +1,7 @@
  6420. +#
  6421. +# Makefile for the linux kernel.
  6422. +#
  6423. +
  6424. +obj-$(CONFIG_MACH_BCM2708) += clock.o bcm2708.o armctrl.o vcio.o power.o dma.o
  6425. +obj-$(CONFIG_BCM2708_GPIO) += bcm2708_gpio.o
  6426. +obj-$(CONFIG_BCM2708_VCMEM) += vc_mem.o
  6427. diff -Nur linux-3.15/arch/arm/mach-bcm2708/Makefile.boot linux-rpi/arch/arm/mach-bcm2708/Makefile.boot
  6428. --- linux-3.15/arch/arm/mach-bcm2708/Makefile.boot 1970-01-01 01:00:00.000000000 +0100
  6429. +++ linux-rpi/arch/arm/mach-bcm2708/Makefile.boot 2014-06-11 21:03:19.000000000 +0200
  6430. @@ -0,0 +1,3 @@
  6431. + zreladdr-y := 0x00008000
  6432. +params_phys-y := 0x00000100
  6433. +initrd_phys-y := 0x00800000
  6434. diff -Nur linux-3.15/arch/arm/mach-bcm2708/power.c linux-rpi/arch/arm/mach-bcm2708/power.c
  6435. --- linux-3.15/arch/arm/mach-bcm2708/power.c 1970-01-01 01:00:00.000000000 +0100
  6436. +++ linux-rpi/arch/arm/mach-bcm2708/power.c 2014-06-11 21:03:19.000000000 +0200
  6437. @@ -0,0 +1,194 @@
  6438. +/*
  6439. + * linux/arch/arm/mach-bcm2708/power.c
  6440. + *
  6441. + * Copyright (C) 2010 Broadcom
  6442. + *
  6443. + * This program is free software; you can redistribute it and/or modify
  6444. + * it under the terms of the GNU General Public License version 2 as
  6445. + * published by the Free Software Foundation.
  6446. + *
  6447. + * This device provides a shared mechanism for controlling the power to
  6448. + * VideoCore subsystems.
  6449. + */
  6450. +
  6451. +#include <linux/module.h>
  6452. +#include <linux/semaphore.h>
  6453. +#include <linux/bug.h>
  6454. +#include <mach/power.h>
  6455. +#include <mach/vcio.h>
  6456. +#include <mach/arm_power.h>
  6457. +
  6458. +#define DRIVER_NAME "bcm2708_power"
  6459. +
  6460. +#define BCM_POWER_MAXCLIENTS 4
  6461. +#define BCM_POWER_NOCLIENT (1<<31)
  6462. +
  6463. +/* Some drivers expect there devices to be permanently powered */
  6464. +#define BCM_POWER_ALWAYS_ON (BCM_POWER_USB)
  6465. +
  6466. +#if 1
  6467. +#define DPRINTK printk
  6468. +#else
  6469. +#define DPRINTK if (0) printk
  6470. +#endif
  6471. +
  6472. +struct state_struct {
  6473. + uint32_t global_request;
  6474. + uint32_t client_request[BCM_POWER_MAXCLIENTS];
  6475. + struct semaphore client_mutex;
  6476. + struct semaphore mutex;
  6477. +} g_state;
  6478. +
  6479. +int bcm_power_open(BCM_POWER_HANDLE_T *handle)
  6480. +{
  6481. + BCM_POWER_HANDLE_T i;
  6482. + int ret = -EBUSY;
  6483. +
  6484. + down(&g_state.client_mutex);
  6485. +
  6486. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6487. + if (g_state.client_request[i] == BCM_POWER_NOCLIENT) {
  6488. + g_state.client_request[i] = BCM_POWER_NONE;
  6489. + *handle = i;
  6490. + ret = 0;
  6491. + break;
  6492. + }
  6493. + }
  6494. +
  6495. + up(&g_state.client_mutex);
  6496. +
  6497. + DPRINTK("bcm_power_open() -> %d\n", *handle);
  6498. +
  6499. + return ret;
  6500. +}
  6501. +EXPORT_SYMBOL_GPL(bcm_power_open);
  6502. +
  6503. +int bcm_power_request(BCM_POWER_HANDLE_T handle, uint32_t request)
  6504. +{
  6505. + int rc = 0;
  6506. +
  6507. + DPRINTK("bcm_power_request(%d, %x)\n", handle, request);
  6508. +
  6509. + if ((handle < BCM_POWER_MAXCLIENTS) &&
  6510. + (g_state.client_request[handle] != BCM_POWER_NOCLIENT)) {
  6511. + if (down_interruptible(&g_state.mutex) != 0) {
  6512. + DPRINTK("bcm_power_request -> interrupted\n");
  6513. + return -EINTR;
  6514. + }
  6515. +
  6516. + if (request != g_state.client_request[handle]) {
  6517. + uint32_t others_request = 0;
  6518. + uint32_t global_request;
  6519. + BCM_POWER_HANDLE_T i;
  6520. +
  6521. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++) {
  6522. + if (i != handle)
  6523. + others_request |=
  6524. + g_state.client_request[i];
  6525. + }
  6526. + others_request &= ~BCM_POWER_NOCLIENT;
  6527. +
  6528. + global_request = request | others_request;
  6529. + if (global_request != g_state.global_request) {
  6530. + uint32_t actual;
  6531. +
  6532. + /* Send a request to VideoCore */
  6533. + bcm_mailbox_write(MBOX_CHAN_POWER,
  6534. + global_request << 4);
  6535. +
  6536. + /* Wait for a response during power-up */
  6537. + if (global_request & ~g_state.global_request) {
  6538. + rc = bcm_mailbox_read(MBOX_CHAN_POWER,
  6539. + &actual);
  6540. + DPRINTK
  6541. + ("bcm_mailbox_read -> %08x, %d\n",
  6542. + actual, rc);
  6543. + actual >>= 4;
  6544. + } else {
  6545. + rc = 0;
  6546. + actual = global_request;
  6547. + }
  6548. +
  6549. + if (rc == 0) {
  6550. + if (actual != global_request) {
  6551. + printk(KERN_ERR
  6552. + "%s: prev global %x, new global %x, actual %x, request %x, others_request %x\n",
  6553. + __func__,
  6554. + g_state.global_request,
  6555. + global_request, actual, request, others_request);
  6556. + /* A failure */
  6557. + BUG_ON((others_request & actual)
  6558. + != others_request);
  6559. + request &= actual;
  6560. + rc = -EIO;
  6561. + }
  6562. +
  6563. + g_state.global_request = actual;
  6564. + g_state.client_request[handle] =
  6565. + request;
  6566. + }
  6567. + }
  6568. + }
  6569. + up(&g_state.mutex);
  6570. + } else {
  6571. + rc = -EINVAL;
  6572. + }
  6573. + DPRINTK("bcm_power_request -> %d\n", rc);
  6574. + return rc;
  6575. +}
  6576. +EXPORT_SYMBOL_GPL(bcm_power_request);
  6577. +
  6578. +int bcm_power_close(BCM_POWER_HANDLE_T handle)
  6579. +{
  6580. + int rc;
  6581. +
  6582. + DPRINTK("bcm_power_close(%d)\n", handle);
  6583. +
  6584. + rc = bcm_power_request(handle, BCM_POWER_NONE);
  6585. + if (rc == 0)
  6586. + g_state.client_request[handle] = BCM_POWER_NOCLIENT;
  6587. +
  6588. + return rc;
  6589. +}
  6590. +EXPORT_SYMBOL_GPL(bcm_power_close);
  6591. +
  6592. +static int __init bcm_power_init(void)
  6593. +{
  6594. +#if defined(BCM_POWER_ALWAYS_ON)
  6595. + BCM_POWER_HANDLE_T always_on_handle;
  6596. +#endif
  6597. + int rc = 0;
  6598. + int i;
  6599. +
  6600. + printk(KERN_INFO "bcm_power: Broadcom power driver\n");
  6601. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6602. +
  6603. + for (i = 0; i < BCM_POWER_MAXCLIENTS; i++)
  6604. + g_state.client_request[i] = BCM_POWER_NOCLIENT;
  6605. +
  6606. + sema_init(&g_state.client_mutex, 1);
  6607. + sema_init(&g_state.mutex, 1);
  6608. +
  6609. + g_state.global_request = 0;
  6610. +
  6611. +#if defined(BCM_POWER_ALWAYS_ON)
  6612. + if (BCM_POWER_ALWAYS_ON) {
  6613. + bcm_power_open(&always_on_handle);
  6614. + bcm_power_request(always_on_handle, BCM_POWER_ALWAYS_ON);
  6615. + }
  6616. +#endif
  6617. +
  6618. + return rc;
  6619. +}
  6620. +
  6621. +static void __exit bcm_power_exit(void)
  6622. +{
  6623. + bcm_mailbox_write(MBOX_CHAN_POWER, 0);
  6624. +}
  6625. +
  6626. +arch_initcall(bcm_power_init); /* Initialize early */
  6627. +module_exit(bcm_power_exit);
  6628. +
  6629. +MODULE_AUTHOR("Phil Elwell");
  6630. +MODULE_DESCRIPTION("Interface to BCM2708 power management");
  6631. +MODULE_LICENSE("GPL");
  6632. diff -Nur linux-3.15/arch/arm/mach-bcm2708/vcio.c linux-rpi/arch/arm/mach-bcm2708/vcio.c
  6633. --- linux-3.15/arch/arm/mach-bcm2708/vcio.c 1970-01-01 01:00:00.000000000 +0100
  6634. +++ linux-rpi/arch/arm/mach-bcm2708/vcio.c 2014-06-11 21:03:19.000000000 +0200
  6635. @@ -0,0 +1,474 @@
  6636. +/*
  6637. + * linux/arch/arm/mach-bcm2708/vcio.c
  6638. + *
  6639. + * Copyright (C) 2010 Broadcom
  6640. + *
  6641. + * This program is free software; you can redistribute it and/or modify
  6642. + * it under the terms of the GNU General Public License version 2 as
  6643. + * published by the Free Software Foundation.
  6644. + *
  6645. + * This device provides a shared mechanism for writing to the mailboxes,
  6646. + * semaphores, doorbells etc. that are shared between the ARM and the
  6647. + * VideoCore processor
  6648. + */
  6649. +
  6650. +#if defined(CONFIG_SERIAL_BCM_MBOX_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  6651. +#define SUPPORT_SYSRQ
  6652. +#endif
  6653. +
  6654. +#include <linux/module.h>
  6655. +#include <linux/console.h>
  6656. +#include <linux/serial_core.h>
  6657. +#include <linux/serial.h>
  6658. +#include <linux/errno.h>
  6659. +#include <linux/device.h>
  6660. +#include <linux/init.h>
  6661. +#include <linux/mm.h>
  6662. +#include <linux/dma-mapping.h>
  6663. +#include <linux/platform_device.h>
  6664. +#include <linux/sysrq.h>
  6665. +#include <linux/delay.h>
  6666. +#include <linux/slab.h>
  6667. +#include <linux/interrupt.h>
  6668. +#include <linux/irq.h>
  6669. +
  6670. +#include <linux/io.h>
  6671. +
  6672. +#include <mach/vcio.h>
  6673. +#include <mach/platform.h>
  6674. +
  6675. +#include <asm/uaccess.h>
  6676. +
  6677. +
  6678. +#define DRIVER_NAME BCM_VCIO_DRIVER_NAME
  6679. +
  6680. +/* ----------------------------------------------------------------------
  6681. + * Mailbox
  6682. + * -------------------------------------------------------------------- */
  6683. +
  6684. +/* offsets from a mail box base address */
  6685. +#define MAIL_WRT 0x00 /* write - and next 4 words */
  6686. +#define MAIL_RD 0x00 /* read - and next 4 words */
  6687. +#define MAIL_POL 0x10 /* read without popping the fifo */
  6688. +#define MAIL_SND 0x14 /* sender ID (bottom two bits) */
  6689. +#define MAIL_STA 0x18 /* status */
  6690. +#define MAIL_CNF 0x1C /* configuration */
  6691. +
  6692. +#define MBOX_MSG(chan, data28) (((data28) & ~0xf) | ((chan) & 0xf))
  6693. +#define MBOX_MSG_LSB(chan, data28) (((data28) << 4) | ((chan) & 0xf))
  6694. +#define MBOX_CHAN(msg) ((msg) & 0xf)
  6695. +#define MBOX_DATA28(msg) ((msg) & ~0xf)
  6696. +#define MBOX_DATA28_LSB(msg) (((uint32_t)msg) >> 4)
  6697. +
  6698. +#define MBOX_MAGIC 0xd0d0c0de
  6699. +
  6700. +struct vc_mailbox {
  6701. + struct device *dev; /* parent device */
  6702. + void __iomem *status;
  6703. + void __iomem *config;
  6704. + void __iomem *read;
  6705. + void __iomem *write;
  6706. + uint32_t msg[MBOX_CHAN_COUNT];
  6707. + struct semaphore sema[MBOX_CHAN_COUNT];
  6708. + uint32_t magic;
  6709. +};
  6710. +
  6711. +static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
  6712. + uint32_t addr_mbox)
  6713. +{
  6714. + int i;
  6715. +
  6716. + mbox_out->dev = dev;
  6717. + mbox_out->status = __io_address(addr_mbox + MAIL_STA);
  6718. + mbox_out->config = __io_address(addr_mbox + MAIL_CNF);
  6719. + mbox_out->read = __io_address(addr_mbox + MAIL_RD);
  6720. + /* Write to the other mailbox */
  6721. + mbox_out->write =
  6722. + __io_address((addr_mbox ^ ARM_0_MAIL0_WRT ^ ARM_0_MAIL1_WRT) +
  6723. + MAIL_WRT);
  6724. +
  6725. + for (i = 0; i < MBOX_CHAN_COUNT; i++) {
  6726. + mbox_out->msg[i] = 0;
  6727. + sema_init(&mbox_out->sema[i], 0);
  6728. + }
  6729. +
  6730. + /* Enable the interrupt on data reception */
  6731. + writel(ARM_MC_IHAVEDATAIRQEN, mbox_out->config);
  6732. +
  6733. + mbox_out->magic = MBOX_MAGIC;
  6734. +}
  6735. +
  6736. +static int mbox_write(struct vc_mailbox *mbox, unsigned chan, uint32_t data28)
  6737. +{
  6738. + int rc;
  6739. +
  6740. + if (mbox->magic != MBOX_MAGIC)
  6741. + rc = -EINVAL;
  6742. + else {
  6743. + /* wait for the mailbox FIFO to have some space in it */
  6744. + while (0 != (readl(mbox->status) & ARM_MS_FULL))
  6745. + cpu_relax();
  6746. +
  6747. + writel(MBOX_MSG(chan, data28), mbox->write);
  6748. + rc = 0;
  6749. + }
  6750. + return rc;
  6751. +}
  6752. +
  6753. +static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
  6754. +{
  6755. + int rc;
  6756. +
  6757. + if (mbox->magic != MBOX_MAGIC)
  6758. + rc = -EINVAL;
  6759. + else {
  6760. + down(&mbox->sema[chan]);
  6761. + *data28 = MBOX_DATA28(mbox->msg[chan]);
  6762. + mbox->msg[chan] = 0;
  6763. + rc = 0;
  6764. + }
  6765. + return rc;
  6766. +}
  6767. +
  6768. +static irqreturn_t mbox_irq(int irq, void *dev_id)
  6769. +{
  6770. + /* wait for the mailbox FIFO to have some data in it */
  6771. + struct vc_mailbox *mbox = (struct vc_mailbox *) dev_id;
  6772. + int status = readl(mbox->status);
  6773. + int ret = IRQ_NONE;
  6774. +
  6775. + while (!(status & ARM_MS_EMPTY)) {
  6776. + uint32_t msg = readl(mbox->read);
  6777. + int chan = MBOX_CHAN(msg);
  6778. + if (chan < MBOX_CHAN_COUNT) {
  6779. + if (mbox->msg[chan]) {
  6780. + /* Overflow */
  6781. + printk(KERN_ERR DRIVER_NAME
  6782. + ": mbox chan %d overflow - drop %08x\n",
  6783. + chan, msg);
  6784. + } else {
  6785. + mbox->msg[chan] = (msg | 0xf);
  6786. + up(&mbox->sema[chan]);
  6787. + }
  6788. + } else {
  6789. + printk(KERN_ERR DRIVER_NAME
  6790. + ": invalid channel selector (msg %08x)\n", msg);
  6791. + }
  6792. + ret = IRQ_HANDLED;
  6793. + status = readl(mbox->status);
  6794. + }
  6795. + return ret;
  6796. +}
  6797. +
  6798. +static struct irqaction mbox_irqaction = {
  6799. + .name = "ARM Mailbox IRQ",
  6800. + .flags = IRQF_DISABLED | IRQF_IRQPOLL,
  6801. + .handler = mbox_irq,
  6802. +};
  6803. +
  6804. +/* ----------------------------------------------------------------------
  6805. + * Mailbox Methods
  6806. + * -------------------------------------------------------------------- */
  6807. +
  6808. +static struct device *mbox_dev; /* we assume there's only one! */
  6809. +
  6810. +static int dev_mbox_write(struct device *dev, unsigned chan, uint32_t data28)
  6811. +{
  6812. + int rc;
  6813. +
  6814. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6815. + device_lock(dev);
  6816. + rc = mbox_write(mailbox, chan, data28);
  6817. + device_unlock(dev);
  6818. +
  6819. + return rc;
  6820. +}
  6821. +
  6822. +static int dev_mbox_read(struct device *dev, unsigned chan, uint32_t *data28)
  6823. +{
  6824. + int rc;
  6825. +
  6826. + struct vc_mailbox *mailbox = dev_get_drvdata(dev);
  6827. + device_lock(dev);
  6828. + rc = mbox_read(mailbox, chan, data28);
  6829. + device_unlock(dev);
  6830. +
  6831. + return rc;
  6832. +}
  6833. +
  6834. +extern int bcm_mailbox_write(unsigned chan, uint32_t data28)
  6835. +{
  6836. + if (mbox_dev)
  6837. + return dev_mbox_write(mbox_dev, chan, data28);
  6838. + else
  6839. + return -ENODEV;
  6840. +}
  6841. +EXPORT_SYMBOL_GPL(bcm_mailbox_write);
  6842. +
  6843. +extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
  6844. +{
  6845. + if (mbox_dev)
  6846. + return dev_mbox_read(mbox_dev, chan, data28);
  6847. + else
  6848. + return -ENODEV;
  6849. +}
  6850. +EXPORT_SYMBOL_GPL(bcm_mailbox_read);
  6851. +
  6852. +static void dev_mbox_register(const char *dev_name, struct device *dev)
  6853. +{
  6854. + mbox_dev = dev;
  6855. +}
  6856. +
  6857. +static int mbox_copy_from_user(void *dst, const void *src, int size)
  6858. +{
  6859. + if ( (uint32_t)src < TASK_SIZE)
  6860. + {
  6861. + return copy_from_user(dst, src, size);
  6862. + }
  6863. + else
  6864. + {
  6865. + memcpy( dst, src, size );
  6866. + return 0;
  6867. + }
  6868. +}
  6869. +
  6870. +static int mbox_copy_to_user(void *dst, const void *src, int size)
  6871. +{
  6872. + if ( (uint32_t)dst < TASK_SIZE)
  6873. + {
  6874. + return copy_to_user(dst, src, size);
  6875. + }
  6876. + else
  6877. + {
  6878. + memcpy( dst, src, size );
  6879. + return 0;
  6880. + }
  6881. +}
  6882. +
  6883. +static DEFINE_MUTEX(mailbox_lock);
  6884. +extern int bcm_mailbox_property(void *data, int size)
  6885. +{
  6886. + uint32_t success;
  6887. + dma_addr_t mem_bus; /* the memory address accessed from videocore */
  6888. + void *mem_kern; /* the memory address accessed from driver */
  6889. + int s = 0;
  6890. +
  6891. + mutex_lock(&mailbox_lock);
  6892. + /* allocate some memory for the messages communicating with GPU */
  6893. + mem_kern = dma_alloc_coherent(NULL, PAGE_ALIGN(size), &mem_bus, GFP_ATOMIC);
  6894. + if (mem_kern) {
  6895. + /* create the message */
  6896. + mbox_copy_from_user(mem_kern, data, size);
  6897. +
  6898. + /* send the message */
  6899. + wmb();
  6900. + s = bcm_mailbox_write(MBOX_CHAN_PROPERTY, (uint32_t)mem_bus);
  6901. + if (s == 0) {
  6902. + s = bcm_mailbox_read(MBOX_CHAN_PROPERTY, &success);
  6903. + }
  6904. + if (s == 0) {
  6905. + /* copy the response */
  6906. + rmb();
  6907. + mbox_copy_to_user(data, mem_kern, size);
  6908. + }
  6909. + dma_free_coherent(NULL, PAGE_ALIGN(size), mem_kern, mem_bus);
  6910. + } else {
  6911. + s = -ENOMEM;
  6912. + }
  6913. + if (s != 0)
  6914. + printk(KERN_ERR DRIVER_NAME ": %s failed (%d)\n", __func__, s);
  6915. +
  6916. + mutex_unlock(&mailbox_lock);
  6917. + return s;
  6918. +}
  6919. +EXPORT_SYMBOL_GPL(bcm_mailbox_property);
  6920. +
  6921. +/* ----------------------------------------------------------------------
  6922. + * Platform Device for Mailbox
  6923. + * -------------------------------------------------------------------- */
  6924. +
  6925. +/*
  6926. + * Is the device open right now? Used to prevent
  6927. + * concurent access into the same device
  6928. + */
  6929. +static int Device_Open = 0;
  6930. +
  6931. +/*
  6932. + * This is called whenever a process attempts to open the device file
  6933. + */
  6934. +static int device_open(struct inode *inode, struct file *file)
  6935. +{
  6936. + /*
  6937. + * We don't want to talk to two processes at the same time
  6938. + */
  6939. + if (Device_Open)
  6940. + return -EBUSY;
  6941. +
  6942. + Device_Open++;
  6943. + /*
  6944. + * Initialize the message
  6945. + */
  6946. + try_module_get(THIS_MODULE);
  6947. + return 0;
  6948. +}
  6949. +
  6950. +static int device_release(struct inode *inode, struct file *file)
  6951. +{
  6952. + /*
  6953. + * We're now ready for our next caller
  6954. + */
  6955. + Device_Open--;
  6956. +
  6957. + module_put(THIS_MODULE);
  6958. + return 0;
  6959. +}
  6960. +
  6961. +/*
  6962. + * This function is called whenever a process tries to do an ioctl on our
  6963. + * device file. We get two extra parameters (additional to the inode and file
  6964. + * structures, which all device functions get): the number of the ioctl called
  6965. + * and the parameter given to the ioctl function.
  6966. + *
  6967. + * If the ioctl is write or read/write (meaning output is returned to the
  6968. + * calling process), the ioctl call returns the output of this function.
  6969. + *
  6970. + */
  6971. +static long device_ioctl(struct file *file, /* see include/linux/fs.h */
  6972. + unsigned int ioctl_num, /* number and param for ioctl */
  6973. + unsigned long ioctl_param)
  6974. +{
  6975. + unsigned size;
  6976. + /*
  6977. + * Switch according to the ioctl called
  6978. + */
  6979. + switch (ioctl_num) {
  6980. + case IOCTL_MBOX_PROPERTY:
  6981. + /*
  6982. + * Receive a pointer to a message (in user space) and set that
  6983. + * to be the device's message. Get the parameter given to
  6984. + * ioctl by the process.
  6985. + */
  6986. + mbox_copy_from_user(&size, (void *)ioctl_param, sizeof size);
  6987. + return bcm_mailbox_property((void *)ioctl_param, size);
  6988. + break;
  6989. + default:
  6990. + printk(KERN_ERR DRIVER_NAME "unknown ioctl: %d\n", ioctl_num);
  6991. + return -EINVAL;
  6992. + }
  6993. +
  6994. + return 0;
  6995. +}
  6996. +
  6997. +/* Module Declarations */
  6998. +
  6999. +/*
  7000. + * This structure will hold the functions to be called
  7001. + * when a process does something to the device we
  7002. + * created. Since a pointer to this structure is kept in
  7003. + * the devices table, it can't be local to
  7004. + * init_module. NULL is for unimplemented functios.
  7005. + */
  7006. +struct file_operations fops = {
  7007. + .unlocked_ioctl = device_ioctl,
  7008. + .open = device_open,
  7009. + .release = device_release, /* a.k.a. close */
  7010. +};
  7011. +
  7012. +static int bcm_vcio_probe(struct platform_device *pdev)
  7013. +{
  7014. + int ret = 0;
  7015. + struct vc_mailbox *mailbox;
  7016. +
  7017. + mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
  7018. + if (NULL == mailbox) {
  7019. + printk(KERN_ERR DRIVER_NAME ": failed to allocate "
  7020. + "mailbox memory\n");
  7021. + ret = -ENOMEM;
  7022. + } else {
  7023. + struct resource *res;
  7024. +
  7025. + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  7026. + if (res == NULL) {
  7027. + printk(KERN_ERR DRIVER_NAME ": failed to obtain memory "
  7028. + "resource\n");
  7029. + ret = -ENODEV;
  7030. + kfree(mailbox);
  7031. + } else {
  7032. + /* should be based on the registers from res really */
  7033. + mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
  7034. +
  7035. + platform_set_drvdata(pdev, mailbox);
  7036. + dev_mbox_register(DRIVER_NAME, &pdev->dev);
  7037. +
  7038. + mbox_irqaction.dev_id = mailbox;
  7039. + setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
  7040. + printk(KERN_INFO DRIVER_NAME ": mailbox at %p\n",
  7041. + __io_address(ARM_0_MAIL0_RD));
  7042. + }
  7043. + }
  7044. +
  7045. + if (ret == 0) {
  7046. + /*
  7047. + * Register the character device
  7048. + */
  7049. + ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
  7050. +
  7051. + /*
  7052. + * Negative values signify an error
  7053. + */
  7054. + if (ret < 0) {
  7055. + printk(KERN_ERR DRIVER_NAME
  7056. + "Failed registering the character device %d\n", ret);
  7057. + return ret;
  7058. + }
  7059. + }
  7060. + return ret;
  7061. +}
  7062. +
  7063. +static int bcm_vcio_remove(struct platform_device *pdev)
  7064. +{
  7065. + struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
  7066. +
  7067. + platform_set_drvdata(pdev, NULL);
  7068. + kfree(mailbox);
  7069. +
  7070. + return 0;
  7071. +}
  7072. +
  7073. +static struct platform_driver bcm_mbox_driver = {
  7074. + .probe = bcm_vcio_probe,
  7075. + .remove = bcm_vcio_remove,
  7076. +
  7077. + .driver = {
  7078. + .name = DRIVER_NAME,
  7079. + .owner = THIS_MODULE,
  7080. + },
  7081. +};
  7082. +
  7083. +static int __init bcm_mbox_init(void)
  7084. +{
  7085. + int ret;
  7086. +
  7087. + printk(KERN_INFO "mailbox: Broadcom VideoCore Mailbox driver\n");
  7088. +
  7089. + ret = platform_driver_register(&bcm_mbox_driver);
  7090. + if (ret != 0) {
  7091. + printk(KERN_ERR DRIVER_NAME ": failed to register "
  7092. + "on platform\n");
  7093. + }
  7094. +
  7095. + return ret;
  7096. +}
  7097. +
  7098. +static void __exit bcm_mbox_exit(void)
  7099. +{
  7100. + platform_driver_unregister(&bcm_mbox_driver);
  7101. +}
  7102. +
  7103. +arch_initcall(bcm_mbox_init); /* Initialize early */
  7104. +module_exit(bcm_mbox_exit);
  7105. +
  7106. +MODULE_AUTHOR("Gray Girling");
  7107. +MODULE_DESCRIPTION("ARM I/O to VideoCore processor");
  7108. +MODULE_LICENSE("GPL");
  7109. +MODULE_ALIAS("platform:bcm-mbox");
  7110. diff -Nur linux-3.15/arch/arm/mach-bcm2708/vc_mem.c linux-rpi/arch/arm/mach-bcm2708/vc_mem.c
  7111. --- linux-3.15/arch/arm/mach-bcm2708/vc_mem.c 1970-01-01 01:00:00.000000000 +0100
  7112. +++ linux-rpi/arch/arm/mach-bcm2708/vc_mem.c 2014-06-11 21:03:19.000000000 +0200
  7113. @@ -0,0 +1,432 @@
  7114. +/*****************************************************************************
  7115. +* Copyright 2010 - 2011 Broadcom Corporation. All rights reserved.
  7116. +*
  7117. +* Unless you and Broadcom execute a separate written software license
  7118. +* agreement governing use of this software, this software is licensed to you
  7119. +* under the terms of the GNU General Public License version 2, available at
  7120. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  7121. +*
  7122. +* Notwithstanding the above, under no circumstances may you combine this
  7123. +* software in any way with any other Broadcom software provided under a
  7124. +* license other than the GPL, without Broadcom's express prior written
  7125. +* consent.
  7126. +*****************************************************************************/
  7127. +
  7128. +#include <linux/kernel.h>
  7129. +#include <linux/module.h>
  7130. +#include <linux/fs.h>
  7131. +#include <linux/device.h>
  7132. +#include <linux/cdev.h>
  7133. +#include <linux/mm.h>
  7134. +#include <linux/slab.h>
  7135. +#include <linux/debugfs.h>
  7136. +#include <asm/uaccess.h>
  7137. +#include <linux/dma-mapping.h>
  7138. +
  7139. +#ifdef CONFIG_ARCH_KONA
  7140. +#include <chal/chal_ipc.h>
  7141. +#elif CONFIG_ARCH_BCM2708
  7142. +#else
  7143. +#include <csp/chal_ipc.h>
  7144. +#endif
  7145. +
  7146. +#include "mach/vc_mem.h"
  7147. +#include <mach/vcio.h>
  7148. +
  7149. +#define DRIVER_NAME "vc-mem"
  7150. +
  7151. +// Device (/dev) related variables
  7152. +static dev_t vc_mem_devnum = 0;
  7153. +static struct class *vc_mem_class = NULL;
  7154. +static struct cdev vc_mem_cdev;
  7155. +static int vc_mem_inited = 0;
  7156. +
  7157. +#ifdef CONFIG_DEBUG_FS
  7158. +static struct dentry *vc_mem_debugfs_entry;
  7159. +#endif
  7160. +
  7161. +/*
  7162. + * Videocore memory addresses and size
  7163. + *
  7164. + * Drivers that wish to know the videocore memory addresses and sizes should
  7165. + * use these variables instead of the MM_IO_BASE and MM_ADDR_IO defines in
  7166. + * headers. This allows the other drivers to not be tied down to a a certain
  7167. + * address/size at compile time.
  7168. + *
  7169. + * In the future, the goal is to have the videocore memory virtual address and
  7170. + * size be calculated at boot time rather than at compile time. The decision of
  7171. + * where the videocore memory resides and its size would be in the hands of the
  7172. + * bootloader (and/or kernel). When that happens, the values of these variables
  7173. + * would be calculated and assigned in the init function.
  7174. + */
  7175. +// in the 2835 VC in mapped above ARM, but ARM has full access to VC space
  7176. +unsigned long mm_vc_mem_phys_addr = 0x00000000;
  7177. +unsigned int mm_vc_mem_size = 0;
  7178. +unsigned int mm_vc_mem_base = 0;
  7179. +
  7180. +EXPORT_SYMBOL(mm_vc_mem_phys_addr);
  7181. +EXPORT_SYMBOL(mm_vc_mem_size);
  7182. +EXPORT_SYMBOL(mm_vc_mem_base);
  7183. +
  7184. +static uint phys_addr = 0;
  7185. +static uint mem_size = 0;
  7186. +static uint mem_base = 0;
  7187. +
  7188. +
  7189. +/****************************************************************************
  7190. +*
  7191. +* vc_mem_open
  7192. +*
  7193. +***************************************************************************/
  7194. +
  7195. +static int
  7196. +vc_mem_open(struct inode *inode, struct file *file)
  7197. +{
  7198. + (void) inode;
  7199. + (void) file;
  7200. +
  7201. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7202. +
  7203. + return 0;
  7204. +}
  7205. +
  7206. +/****************************************************************************
  7207. +*
  7208. +* vc_mem_release
  7209. +*
  7210. +***************************************************************************/
  7211. +
  7212. +static int
  7213. +vc_mem_release(struct inode *inode, struct file *file)
  7214. +{
  7215. + (void) inode;
  7216. + (void) file;
  7217. +
  7218. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7219. +
  7220. + return 0;
  7221. +}
  7222. +
  7223. +/****************************************************************************
  7224. +*
  7225. +* vc_mem_get_size
  7226. +*
  7227. +***************************************************************************/
  7228. +
  7229. +static void
  7230. +vc_mem_get_size(void)
  7231. +{
  7232. +}
  7233. +
  7234. +/****************************************************************************
  7235. +*
  7236. +* vc_mem_get_base
  7237. +*
  7238. +***************************************************************************/
  7239. +
  7240. +static void
  7241. +vc_mem_get_base(void)
  7242. +{
  7243. +}
  7244. +
  7245. +/****************************************************************************
  7246. +*
  7247. +* vc_mem_get_current_size
  7248. +*
  7249. +***************************************************************************/
  7250. +
  7251. +int
  7252. +vc_mem_get_current_size(void)
  7253. +{
  7254. + return mm_vc_mem_size;
  7255. +}
  7256. +
  7257. +EXPORT_SYMBOL_GPL(vc_mem_get_current_size);
  7258. +
  7259. +/****************************************************************************
  7260. +*
  7261. +* vc_mem_ioctl
  7262. +*
  7263. +***************************************************************************/
  7264. +
  7265. +static long
  7266. +vc_mem_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7267. +{
  7268. + int rc = 0;
  7269. +
  7270. + (void) cmd;
  7271. + (void) arg;
  7272. +
  7273. + pr_debug("%s: called file = 0x%p\n", __func__, file);
  7274. +
  7275. + switch (cmd) {
  7276. + case VC_MEM_IOC_MEM_PHYS_ADDR:
  7277. + {
  7278. + pr_debug("%s: VC_MEM_IOC_MEM_PHYS_ADDR=0x%p\n",
  7279. + __func__, (void *) mm_vc_mem_phys_addr);
  7280. +
  7281. + if (copy_to_user((void *) arg, &mm_vc_mem_phys_addr,
  7282. + sizeof (mm_vc_mem_phys_addr)) != 0) {
  7283. + rc = -EFAULT;
  7284. + }
  7285. + break;
  7286. + }
  7287. + case VC_MEM_IOC_MEM_SIZE:
  7288. + {
  7289. + // Get the videocore memory size first
  7290. + vc_mem_get_size();
  7291. +
  7292. + pr_debug("%s: VC_MEM_IOC_MEM_SIZE=%u\n", __func__,
  7293. + mm_vc_mem_size);
  7294. +
  7295. + if (copy_to_user((void *) arg, &mm_vc_mem_size,
  7296. + sizeof (mm_vc_mem_size)) != 0) {
  7297. + rc = -EFAULT;
  7298. + }
  7299. + break;
  7300. + }
  7301. + case VC_MEM_IOC_MEM_BASE:
  7302. + {
  7303. + // Get the videocore memory base
  7304. + vc_mem_get_base();
  7305. +
  7306. + pr_debug("%s: VC_MEM_IOC_MEM_BASE=%u\n", __func__,
  7307. + mm_vc_mem_base);
  7308. +
  7309. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7310. + sizeof (mm_vc_mem_base)) != 0) {
  7311. + rc = -EFAULT;
  7312. + }
  7313. + break;
  7314. + }
  7315. + case VC_MEM_IOC_MEM_LOAD:
  7316. + {
  7317. + // Get the videocore memory base
  7318. + vc_mem_get_base();
  7319. +
  7320. + pr_debug("%s: VC_MEM_IOC_MEM_LOAD=%u\n", __func__,
  7321. + mm_vc_mem_base);
  7322. +
  7323. + if (copy_to_user((void *) arg, &mm_vc_mem_base,
  7324. + sizeof (mm_vc_mem_base)) != 0) {
  7325. + rc = -EFAULT;
  7326. + }
  7327. + break;
  7328. + }
  7329. + default:
  7330. + {
  7331. + return -ENOTTY;
  7332. + }
  7333. + }
  7334. + pr_debug("%s: file = 0x%p returning %d\n", __func__, file, rc);
  7335. +
  7336. + return rc;
  7337. +}
  7338. +
  7339. +/****************************************************************************
  7340. +*
  7341. +* vc_mem_mmap
  7342. +*
  7343. +***************************************************************************/
  7344. +
  7345. +static int
  7346. +vc_mem_mmap(struct file *filp, struct vm_area_struct *vma)
  7347. +{
  7348. + int rc = 0;
  7349. + unsigned long length = vma->vm_end - vma->vm_start;
  7350. + unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  7351. +
  7352. + pr_debug("%s: vm_start = 0x%08lx vm_end = 0x%08lx vm_pgoff = 0x%08lx\n",
  7353. + __func__, (long) vma->vm_start, (long) vma->vm_end,
  7354. + (long) vma->vm_pgoff);
  7355. +
  7356. + if (offset + length > mm_vc_mem_size) {
  7357. + pr_err("%s: length %ld is too big\n", __func__, length);
  7358. + return -EINVAL;
  7359. + }
  7360. + // Do not cache the memory map
  7361. + vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
  7362. +
  7363. + rc = remap_pfn_range(vma, vma->vm_start,
  7364. + (mm_vc_mem_phys_addr >> PAGE_SHIFT) +
  7365. + vma->vm_pgoff, length, vma->vm_page_prot);
  7366. + if (rc != 0) {
  7367. + pr_err("%s: remap_pfn_range failed (rc=%d)\n", __func__, rc);
  7368. + }
  7369. +
  7370. + return rc;
  7371. +}
  7372. +
  7373. +/****************************************************************************
  7374. +*
  7375. +* File Operations for the driver.
  7376. +*
  7377. +***************************************************************************/
  7378. +
  7379. +static const struct file_operations vc_mem_fops = {
  7380. + .owner = THIS_MODULE,
  7381. + .open = vc_mem_open,
  7382. + .release = vc_mem_release,
  7383. + .unlocked_ioctl = vc_mem_ioctl,
  7384. + .mmap = vc_mem_mmap,
  7385. +};
  7386. +
  7387. +#ifdef CONFIG_DEBUG_FS
  7388. +static void vc_mem_debugfs_deinit(void)
  7389. +{
  7390. + debugfs_remove_recursive(vc_mem_debugfs_entry);
  7391. + vc_mem_debugfs_entry = NULL;
  7392. +}
  7393. +
  7394. +
  7395. +static int vc_mem_debugfs_init(
  7396. + struct device *dev)
  7397. +{
  7398. + vc_mem_debugfs_entry = debugfs_create_dir(DRIVER_NAME, NULL);
  7399. + if (!vc_mem_debugfs_entry) {
  7400. + dev_warn(dev, "could not create debugfs entry\n");
  7401. + return -EFAULT;
  7402. + }
  7403. +
  7404. + if (!debugfs_create_x32("vc_mem_phys_addr",
  7405. + 0444,
  7406. + vc_mem_debugfs_entry,
  7407. + (u32 *)&mm_vc_mem_phys_addr)) {
  7408. + dev_warn(dev, "%s:could not create vc_mem_phys entry\n",
  7409. + __func__);
  7410. + goto fail;
  7411. + }
  7412. +
  7413. + if (!debugfs_create_x32("vc_mem_size",
  7414. + 0444,
  7415. + vc_mem_debugfs_entry,
  7416. + (u32 *)&mm_vc_mem_size)) {
  7417. + dev_warn(dev, "%s:could not create vc_mem_size entry\n",
  7418. + __func__);
  7419. + goto fail;
  7420. + }
  7421. +
  7422. + if (!debugfs_create_x32("vc_mem_base",
  7423. + 0444,
  7424. + vc_mem_debugfs_entry,
  7425. + (u32 *)&mm_vc_mem_base)) {
  7426. + dev_warn(dev, "%s:could not create vc_mem_base entry\n",
  7427. + __func__);
  7428. + goto fail;
  7429. + }
  7430. +
  7431. + return 0;
  7432. +
  7433. +fail:
  7434. + vc_mem_debugfs_deinit();
  7435. + return -EFAULT;
  7436. +}
  7437. +
  7438. +#endif /* CONFIG_DEBUG_FS */
  7439. +
  7440. +
  7441. +/****************************************************************************
  7442. +*
  7443. +* vc_mem_init
  7444. +*
  7445. +***************************************************************************/
  7446. +
  7447. +static int __init
  7448. +vc_mem_init(void)
  7449. +{
  7450. + int rc = -EFAULT;
  7451. + struct device *dev;
  7452. +
  7453. + pr_debug("%s: called\n", __func__);
  7454. +
  7455. + mm_vc_mem_phys_addr = phys_addr;
  7456. + mm_vc_mem_size = mem_size;
  7457. + mm_vc_mem_base = mem_base;
  7458. +
  7459. + vc_mem_get_size();
  7460. +
  7461. + pr_info("vc-mem: phys_addr:0x%08lx mem_base=0x%08x mem_size:0x%08x(%u MiB)\n",
  7462. + mm_vc_mem_phys_addr, mm_vc_mem_base, mm_vc_mem_size, mm_vc_mem_size / (1024 * 1024));
  7463. +
  7464. + if ((rc = alloc_chrdev_region(&vc_mem_devnum, 0, 1, DRIVER_NAME)) < 0) {
  7465. + pr_err("%s: alloc_chrdev_region failed (rc=%d)\n",
  7466. + __func__, rc);
  7467. + goto out_err;
  7468. + }
  7469. +
  7470. + cdev_init(&vc_mem_cdev, &vc_mem_fops);
  7471. + if ((rc = cdev_add(&vc_mem_cdev, vc_mem_devnum, 1)) != 0) {
  7472. + pr_err("%s: cdev_add failed (rc=%d)\n", __func__, rc);
  7473. + goto out_unregister;
  7474. + }
  7475. +
  7476. + vc_mem_class = class_create(THIS_MODULE, DRIVER_NAME);
  7477. + if (IS_ERR(vc_mem_class)) {
  7478. + rc = PTR_ERR(vc_mem_class);
  7479. + pr_err("%s: class_create failed (rc=%d)\n", __func__, rc);
  7480. + goto out_cdev_del;
  7481. + }
  7482. +
  7483. + dev = device_create(vc_mem_class, NULL, vc_mem_devnum, NULL,
  7484. + DRIVER_NAME);
  7485. + if (IS_ERR(dev)) {
  7486. + rc = PTR_ERR(dev);
  7487. + pr_err("%s: device_create failed (rc=%d)\n", __func__, rc);
  7488. + goto out_class_destroy;
  7489. + }
  7490. +
  7491. +#ifdef CONFIG_DEBUG_FS
  7492. + /* don't fail if the debug entries cannot be created */
  7493. + vc_mem_debugfs_init(dev);
  7494. +#endif
  7495. +
  7496. + vc_mem_inited = 1;
  7497. + return 0;
  7498. +
  7499. + device_destroy(vc_mem_class, vc_mem_devnum);
  7500. +
  7501. + out_class_destroy:
  7502. + class_destroy(vc_mem_class);
  7503. + vc_mem_class = NULL;
  7504. +
  7505. + out_cdev_del:
  7506. + cdev_del(&vc_mem_cdev);
  7507. +
  7508. + out_unregister:
  7509. + unregister_chrdev_region(vc_mem_devnum, 1);
  7510. +
  7511. + out_err:
  7512. + return -1;
  7513. +}
  7514. +
  7515. +/****************************************************************************
  7516. +*
  7517. +* vc_mem_exit
  7518. +*
  7519. +***************************************************************************/
  7520. +
  7521. +static void __exit
  7522. +vc_mem_exit(void)
  7523. +{
  7524. + pr_debug("%s: called\n", __func__);
  7525. +
  7526. + if (vc_mem_inited) {
  7527. +#if CONFIG_DEBUG_FS
  7528. + vc_mem_debugfs_deinit();
  7529. +#endif
  7530. + device_destroy(vc_mem_class, vc_mem_devnum);
  7531. + class_destroy(vc_mem_class);
  7532. + cdev_del(&vc_mem_cdev);
  7533. + unregister_chrdev_region(vc_mem_devnum, 1);
  7534. + }
  7535. +}
  7536. +
  7537. +module_init(vc_mem_init);
  7538. +module_exit(vc_mem_exit);
  7539. +MODULE_LICENSE("GPL");
  7540. +MODULE_AUTHOR("Broadcom Corporation");
  7541. +
  7542. +module_param(phys_addr, uint, 0644);
  7543. +module_param(mem_size, uint, 0644);
  7544. +module_param(mem_base, uint, 0644);
  7545. +
  7546. diff -Nur linux-3.15/arch/arm/Makefile linux-rpi/arch/arm/Makefile
  7547. --- linux-3.15/arch/arm/Makefile 2014-06-08 20:19:54.000000000 +0200
  7548. +++ linux-rpi/arch/arm/Makefile 2014-06-11 21:05:18.000000000 +0200
  7549. @@ -143,6 +143,7 @@
  7550. # by CONFIG_* macro name.
  7551. machine-$(CONFIG_ARCH_AT91) += at91
  7552. machine-$(CONFIG_ARCH_BCM) += bcm
  7553. +machine-$(CONFIG_ARCH_BCM2708) += bcm2708
  7554. machine-$(CONFIG_ARCH_BERLIN) += berlin
  7555. machine-$(CONFIG_ARCH_CLPS711X) += clps711x
  7556. machine-$(CONFIG_ARCH_CNS3XXX) += cns3xxx
  7557. diff -Nur linux-3.15/arch/arm/mm/Kconfig linux-rpi/arch/arm/mm/Kconfig
  7558. --- linux-3.15/arch/arm/mm/Kconfig 2014-06-08 20:19:54.000000000 +0200
  7559. +++ linux-rpi/arch/arm/mm/Kconfig 2014-06-11 21:05:18.000000000 +0200
  7560. @@ -358,7 +358,7 @@
  7561. # ARMv6
  7562. config CPU_V6
  7563. - bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX
  7564. + bool "Support ARM V6 processor" if ARCH_INTEGRATOR || MACH_REALVIEW_EB || MACH_REALVIEW_PBX || MACH_BCM2708
  7565. select CPU_32v6
  7566. select CPU_ABRT_EV6
  7567. select CPU_CACHE_V6
  7568. diff -Nur linux-3.15/arch/arm/mm/proc-v6.S linux-rpi/arch/arm/mm/proc-v6.S
  7569. --- linux-3.15/arch/arm/mm/proc-v6.S 2014-06-08 20:19:54.000000000 +0200
  7570. +++ linux-rpi/arch/arm/mm/proc-v6.S 2014-06-11 21:05:18.000000000 +0200
  7571. @@ -73,10 +73,19 @@
  7572. *
  7573. * IRQs are already disabled.
  7574. */
  7575. +
  7576. +/* See jira SW-5991 for details of this workaround */
  7577. ENTRY(cpu_v6_do_idle)
  7578. - mov r1, #0
  7579. - mcr p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7580. - mcr p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7581. + .align 5
  7582. + mov r1, #2
  7583. +1: subs r1, #1
  7584. + nop
  7585. + mcreq p15, 0, r1, c7, c10, 4 @ DWB - WFI may enter a low-power mode
  7586. + mcreq p15, 0, r1, c7, c0, 4 @ wait for interrupt
  7587. + nop
  7588. + nop
  7589. + nop
  7590. + bne 1b
  7591. mov pc, lr
  7592. ENTRY(cpu_v6_dcache_clean_area)
  7593. diff -Nur linux-3.15/arch/arm/tools/mach-types linux-rpi/arch/arm/tools/mach-types
  7594. --- linux-3.15/arch/arm/tools/mach-types 2014-06-08 20:19:54.000000000 +0200
  7595. +++ linux-rpi/arch/arm/tools/mach-types 2014-06-11 21:03:20.000000000 +0200
  7596. @@ -522,6 +522,7 @@
  7597. prima2_evb MACH_PRIMA2_EVB PRIMA2_EVB 3103
  7598. paz00 MACH_PAZ00 PAZ00 3128
  7599. acmenetusfoxg20 MACH_ACMENETUSFOXG20 ACMENETUSFOXG20 3129
  7600. +bcm2708 MACH_BCM2708 BCM2708 3138
  7601. ag5evm MACH_AG5EVM AG5EVM 3189
  7602. ics_if_voip MACH_ICS_IF_VOIP ICS_IF_VOIP 3206
  7603. wlf_cragg_6410 MACH_WLF_CRAGG_6410 WLF_CRAGG_6410 3207
  7604. diff -Nur linux-3.15/Documentation/video4linux/bcm2835-v4l2.txt linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt
  7605. --- linux-3.15/Documentation/video4linux/bcm2835-v4l2.txt 1970-01-01 01:00:00.000000000 +0100
  7606. +++ linux-rpi/Documentation/video4linux/bcm2835-v4l2.txt 2014-06-11 21:03:19.000000000 +0200
  7607. @@ -0,0 +1,60 @@
  7608. +
  7609. +BCM2835 (aka Raspberry Pi) V4L2 driver
  7610. +======================================
  7611. +
  7612. +1. Copyright
  7613. +============
  7614. +
  7615. +Copyright © 2013 Raspberry Pi (Trading) Ltd.
  7616. +
  7617. +2. License
  7618. +==========
  7619. +
  7620. +This program is free software; you can redistribute it and/or modify
  7621. +it under the terms of the GNU General Public License as published by
  7622. +the Free Software Foundation; either version 2 of the License, or
  7623. +(at your option) any later version.
  7624. +
  7625. +This program is distributed in the hope that it will be useful,
  7626. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  7627. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  7628. +GNU General Public License for more details.
  7629. +
  7630. +You should have received a copy of the GNU General Public License
  7631. +along with this program; if not, write to the Free Software
  7632. +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  7633. +
  7634. +3. Quick Start
  7635. +==============
  7636. +
  7637. +You need a version 1.0 or later of v4l2-ctl, available from:
  7638. + git://git.linuxtv.org/v4l-utils.git
  7639. +
  7640. +$ sudo modprobe bcm2835-v4l2
  7641. +
  7642. +Turn on the overlay:
  7643. +
  7644. +$ v4l2-ctl --overlay=1
  7645. +
  7646. +Turn off the overlay:
  7647. +
  7648. +$ v4l2-ctl --overlay=0
  7649. +
  7650. +Set the capture format for video:
  7651. +
  7652. +$ v4l2-ctl --set-fmt-video=width=1920,height=1088,pixelformat=4
  7653. +
  7654. +(Note: 1088 not 1080).
  7655. +
  7656. +Capture:
  7657. +
  7658. +$ v4l2-ctl --stream-mmap=3 --stream-count=100 --stream-to=somefile.h264
  7659. +
  7660. +Stills capture:
  7661. +
  7662. +$ v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3
  7663. +$ v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=somefile.jpg
  7664. +
  7665. +List of available formats:
  7666. +
  7667. +$ v4l2-ctl --list-formats
  7668. diff -Nur linux-3.15/drivers/char/broadcom/Kconfig linux-rpi/drivers/char/broadcom/Kconfig
  7669. --- linux-3.15/drivers/char/broadcom/Kconfig 1970-01-01 01:00:00.000000000 +0100
  7670. +++ linux-rpi/drivers/char/broadcom/Kconfig 2014-06-11 21:03:22.000000000 +0200
  7671. @@ -0,0 +1,16 @@
  7672. +#
  7673. +# Broadcom char driver config
  7674. +#
  7675. +
  7676. +menuconfig BRCM_CHAR_DRIVERS
  7677. + bool "Broadcom Char Drivers"
  7678. + help
  7679. + Broadcom's char drivers
  7680. +
  7681. +config BCM_VC_CMA
  7682. + bool "Videocore CMA"
  7683. + depends on CMA && BRCM_CHAR_DRIVERS && BCM2708_VCHIQ
  7684. + default n
  7685. + help
  7686. + Helper for videocore CMA access.
  7687. +
  7688. diff -Nur linux-3.15/drivers/char/broadcom/Makefile linux-rpi/drivers/char/broadcom/Makefile
  7689. --- linux-3.15/drivers/char/broadcom/Makefile 1970-01-01 01:00:00.000000000 +0100
  7690. +++ linux-rpi/drivers/char/broadcom/Makefile 2014-06-11 21:03:22.000000000 +0200
  7691. @@ -0,0 +1 @@
  7692. +obj-$(CONFIG_BCM_VC_CMA) += vc_cma/
  7693. diff -Nur linux-3.15/drivers/char/broadcom/vc_cma/Makefile linux-rpi/drivers/char/broadcom/vc_cma/Makefile
  7694. --- linux-3.15/drivers/char/broadcom/vc_cma/Makefile 1970-01-01 01:00:00.000000000 +0100
  7695. +++ linux-rpi/drivers/char/broadcom/vc_cma/Makefile 2014-06-11 21:03:22.000000000 +0200
  7696. @@ -0,0 +1,14 @@
  7697. +ccflags-y += -Wall -Wstrict-prototypes -Wno-trigraphs
  7698. +ccflags-y += -Werror
  7699. +ccflags-y += -Iinclude/linux/broadcom
  7700. +ccflags-y += -Idrivers/misc/vc04_services
  7701. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchi
  7702. +ccflags-y += -Idrivers/misc/vc04_services/interface/vchiq_arm
  7703. +
  7704. +ccflags-y += -D__KERNEL__
  7705. +ccflags-y += -D__linux__
  7706. +ccflags-y += -Werror
  7707. +
  7708. +obj-$(CONFIG_BCM_VC_CMA) += vc-cma.o
  7709. +
  7710. +vc-cma-objs := vc_cma.o
  7711. diff -Nur linux-3.15/drivers/char/broadcom/vc_cma/vc_cma.c linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c
  7712. --- linux-3.15/drivers/char/broadcom/vc_cma/vc_cma.c 1970-01-01 01:00:00.000000000 +0100
  7713. +++ linux-rpi/drivers/char/broadcom/vc_cma/vc_cma.c 2014-06-11 21:03:22.000000000 +0200
  7714. @@ -0,0 +1,1143 @@
  7715. +/**
  7716. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  7717. + *
  7718. + * Redistribution and use in source and binary forms, with or without
  7719. + * modification, are permitted provided that the following conditions
  7720. + * are met:
  7721. + * 1. Redistributions of source code must retain the above copyright
  7722. + * notice, this list of conditions, and the following disclaimer,
  7723. + * without modification.
  7724. + * 2. Redistributions in binary form must reproduce the above copyright
  7725. + * notice, this list of conditions and the following disclaimer in the
  7726. + * documentation and/or other materials provided with the distribution.
  7727. + * 3. The names of the above-listed copyright holders may not be used
  7728. + * to endorse or promote products derived from this software without
  7729. + * specific prior written permission.
  7730. + *
  7731. + * ALTERNATIVELY, this software may be distributed under the terms of the
  7732. + * GNU General Public License ("GPL") version 2, as published by the Free
  7733. + * Software Foundation.
  7734. + *
  7735. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  7736. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  7737. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  7738. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  7739. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  7740. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  7741. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  7742. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  7743. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  7744. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  7745. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7746. + */
  7747. +
  7748. +#include <linux/kernel.h>
  7749. +#include <linux/module.h>
  7750. +#include <linux/kthread.h>
  7751. +#include <linux/fs.h>
  7752. +#include <linux/device.h>
  7753. +#include <linux/cdev.h>
  7754. +#include <linux/mm.h>
  7755. +#include <linux/proc_fs.h>
  7756. +#include <linux/seq_file.h>
  7757. +#include <linux/dma-mapping.h>
  7758. +#include <linux/dma-contiguous.h>
  7759. +#include <linux/platform_device.h>
  7760. +#include <linux/uaccess.h>
  7761. +#include <asm/cacheflush.h>
  7762. +
  7763. +#include "vc_cma.h"
  7764. +
  7765. +#include "vchiq_util.h"
  7766. +#include "vchiq_connected.h"
  7767. +//#include "debug_sym.h"
  7768. +//#include "vc_mem.h"
  7769. +
  7770. +#define DRIVER_NAME "vc-cma"
  7771. +
  7772. +#define LOG_DBG(fmt, ...) \
  7773. + if (vc_cma_debug) \
  7774. + printk(KERN_INFO fmt "\n", ##__VA_ARGS__)
  7775. +#define LOG_ERR(fmt, ...) \
  7776. + printk(KERN_ERR fmt "\n", ##__VA_ARGS__)
  7777. +
  7778. +#define VC_CMA_FOURCC VCHIQ_MAKE_FOURCC('C', 'M', 'A', ' ')
  7779. +#define VC_CMA_VERSION 2
  7780. +
  7781. +#define VC_CMA_CHUNK_ORDER 6 /* 256K */
  7782. +#define VC_CMA_CHUNK_SIZE (4096 << VC_CMA_CHUNK_ORDER)
  7783. +#define VC_CMA_MAX_PARAMS_PER_MSG \
  7784. + ((VCHIQ_MAX_MSG_SIZE - sizeof(unsigned short))/sizeof(unsigned short))
  7785. +#define VC_CMA_RESERVE_COUNT_MAX 16
  7786. +
  7787. +#define PAGES_PER_CHUNK (VC_CMA_CHUNK_SIZE / PAGE_SIZE)
  7788. +
  7789. +#define VCADDR_TO_PHYSADDR(vcaddr) (mm_vc_mem_phys_addr + vcaddr)
  7790. +
  7791. +#define loud_error(...) \
  7792. + LOG_ERR("===== " __VA_ARGS__)
  7793. +
  7794. +enum {
  7795. + VC_CMA_MSG_QUIT,
  7796. + VC_CMA_MSG_OPEN,
  7797. + VC_CMA_MSG_TICK,
  7798. + VC_CMA_MSG_ALLOC, /* chunk count */
  7799. + VC_CMA_MSG_FREE, /* chunk, chunk, ... */
  7800. + VC_CMA_MSG_ALLOCATED, /* chunk, chunk, ... */
  7801. + VC_CMA_MSG_REQUEST_ALLOC, /* chunk count */
  7802. + VC_CMA_MSG_REQUEST_FREE, /* chunk count */
  7803. + VC_CMA_MSG_RESERVE, /* bytes lo, bytes hi */
  7804. + VC_CMA_MSG_UPDATE_RESERVE,
  7805. + VC_CMA_MSG_MAX
  7806. +};
  7807. +
  7808. +struct cma_msg {
  7809. + unsigned short type;
  7810. + unsigned short params[VC_CMA_MAX_PARAMS_PER_MSG];
  7811. +};
  7812. +
  7813. +struct vc_cma_reserve_user {
  7814. + unsigned int pid;
  7815. + unsigned int reserve;
  7816. +};
  7817. +
  7818. +/* Device (/dev) related variables */
  7819. +static dev_t vc_cma_devnum;
  7820. +static struct class *vc_cma_class;
  7821. +static struct cdev vc_cma_cdev;
  7822. +static int vc_cma_inited;
  7823. +static int vc_cma_debug;
  7824. +
  7825. +/* Proc entry */
  7826. +static struct proc_dir_entry *vc_cma_proc_entry;
  7827. +
  7828. +phys_addr_t vc_cma_base;
  7829. +struct page *vc_cma_base_page;
  7830. +unsigned int vc_cma_size;
  7831. +EXPORT_SYMBOL(vc_cma_size);
  7832. +unsigned int vc_cma_initial;
  7833. +unsigned int vc_cma_chunks;
  7834. +unsigned int vc_cma_chunks_used;
  7835. +unsigned int vc_cma_chunks_reserved;
  7836. +
  7837. +static int in_loud_error;
  7838. +
  7839. +unsigned int vc_cma_reserve_total;
  7840. +unsigned int vc_cma_reserve_count;
  7841. +struct vc_cma_reserve_user vc_cma_reserve_users[VC_CMA_RESERVE_COUNT_MAX];
  7842. +static DEFINE_SEMAPHORE(vc_cma_reserve_mutex);
  7843. +static DEFINE_SEMAPHORE(vc_cma_worker_queue_push_mutex);
  7844. +
  7845. +static u64 vc_cma_dma_mask = DMA_BIT_MASK(32);
  7846. +static struct platform_device vc_cma_device = {
  7847. + .name = "vc-cma",
  7848. + .id = 0,
  7849. + .dev = {
  7850. + .dma_mask = &vc_cma_dma_mask,
  7851. + .coherent_dma_mask = DMA_BIT_MASK(32),
  7852. + },
  7853. +};
  7854. +
  7855. +static VCHIQ_INSTANCE_T cma_instance;
  7856. +static VCHIQ_SERVICE_HANDLE_T cma_service;
  7857. +static VCHIU_QUEUE_T cma_msg_queue;
  7858. +static struct task_struct *cma_worker;
  7859. +
  7860. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid);
  7861. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply);
  7862. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  7863. + VCHIQ_HEADER_T * header,
  7864. + VCHIQ_SERVICE_HANDLE_T service,
  7865. + void *bulk_userdata);
  7866. +static void send_vc_msg(unsigned short type,
  7867. + unsigned short param1, unsigned short param2);
  7868. +static bool send_worker_msg(VCHIQ_HEADER_T * msg);
  7869. +
  7870. +static int early_vc_cma_mem(char *p)
  7871. +{
  7872. + unsigned int new_size;
  7873. + printk(KERN_NOTICE "early_vc_cma_mem(%s)", p);
  7874. + vc_cma_size = memparse(p, &p);
  7875. + vc_cma_initial = vc_cma_size;
  7876. + if (*p == '/')
  7877. + vc_cma_size = memparse(p + 1, &p);
  7878. + if (*p == '@')
  7879. + vc_cma_base = memparse(p + 1, &p);
  7880. +
  7881. + new_size = (vc_cma_size - ((-vc_cma_base) & (VC_CMA_CHUNK_SIZE - 1)))
  7882. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7883. + if (new_size > vc_cma_size)
  7884. + vc_cma_size = 0;
  7885. + vc_cma_initial = (vc_cma_initial + VC_CMA_CHUNK_SIZE - 1)
  7886. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7887. + if (vc_cma_initial > vc_cma_size)
  7888. + vc_cma_initial = vc_cma_size;
  7889. + vc_cma_base = (vc_cma_base + VC_CMA_CHUNK_SIZE - 1)
  7890. + & ~(VC_CMA_CHUNK_SIZE - 1);
  7891. +
  7892. + printk(KERN_NOTICE " -> initial %x, size %x, base %x", vc_cma_initial,
  7893. + vc_cma_size, (unsigned int)vc_cma_base);
  7894. +
  7895. + return 0;
  7896. +}
  7897. +
  7898. +early_param("vc-cma-mem", early_vc_cma_mem);
  7899. +
  7900. +void vc_cma_early_init(void)
  7901. +{
  7902. + LOG_DBG("vc_cma_early_init - vc_cma_chunks = %d", vc_cma_chunks);
  7903. + if (vc_cma_size) {
  7904. + int rc = platform_device_register(&vc_cma_device);
  7905. + LOG_DBG("platform_device_register -> %d", rc);
  7906. + }
  7907. +}
  7908. +
  7909. +void vc_cma_reserve(void)
  7910. +{
  7911. + /* if vc_cma_size is set, then declare vc CMA area of the same
  7912. + * size from the end of memory
  7913. + */
  7914. + if (vc_cma_size) {
  7915. + if (dma_declare_contiguous(NULL /*&vc_cma_device.dev*/, vc_cma_size,
  7916. + vc_cma_base, 0) == 0) {
  7917. + } else {
  7918. + LOG_ERR("vc_cma: dma_declare_contiguous(%x,%x) failed",
  7919. + vc_cma_size, (unsigned int)vc_cma_base);
  7920. + vc_cma_size = 0;
  7921. + }
  7922. + }
  7923. + vc_cma_chunks = vc_cma_size / VC_CMA_CHUNK_SIZE;
  7924. +}
  7925. +
  7926. +/****************************************************************************
  7927. +*
  7928. +* vc_cma_open
  7929. +*
  7930. +***************************************************************************/
  7931. +
  7932. +static int vc_cma_open(struct inode *inode, struct file *file)
  7933. +{
  7934. + (void)inode;
  7935. + (void)file;
  7936. +
  7937. + return 0;
  7938. +}
  7939. +
  7940. +/****************************************************************************
  7941. +*
  7942. +* vc_cma_release
  7943. +*
  7944. +***************************************************************************/
  7945. +
  7946. +static int vc_cma_release(struct inode *inode, struct file *file)
  7947. +{
  7948. + (void)inode;
  7949. + (void)file;
  7950. +
  7951. + vc_cma_set_reserve(0, current->tgid);
  7952. +
  7953. + return 0;
  7954. +}
  7955. +
  7956. +/****************************************************************************
  7957. +*
  7958. +* vc_cma_ioctl
  7959. +*
  7960. +***************************************************************************/
  7961. +
  7962. +static long vc_cma_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  7963. +{
  7964. + int rc = 0;
  7965. +
  7966. + (void)cmd;
  7967. + (void)arg;
  7968. +
  7969. + switch (cmd) {
  7970. + case VC_CMA_IOC_RESERVE:
  7971. + rc = vc_cma_set_reserve((unsigned int)arg, current->tgid);
  7972. + if (rc >= 0)
  7973. + rc = 0;
  7974. + break;
  7975. + default:
  7976. + LOG_ERR("vc-cma: Unknown ioctl %x", cmd);
  7977. + return -ENOTTY;
  7978. + }
  7979. +
  7980. + return rc;
  7981. +}
  7982. +
  7983. +/****************************************************************************
  7984. +*
  7985. +* File Operations for the driver.
  7986. +*
  7987. +***************************************************************************/
  7988. +
  7989. +static const struct file_operations vc_cma_fops = {
  7990. + .owner = THIS_MODULE,
  7991. + .open = vc_cma_open,
  7992. + .release = vc_cma_release,
  7993. + .unlocked_ioctl = vc_cma_ioctl,
  7994. +};
  7995. +
  7996. +/****************************************************************************
  7997. +*
  7998. +* vc_cma_proc_open
  7999. +*
  8000. +***************************************************************************/
  8001. +
  8002. +static int vc_cma_show_info(struct seq_file *m, void *v)
  8003. +{
  8004. + int i;
  8005. +
  8006. + seq_printf(m, "Videocore CMA:\n");
  8007. + seq_printf(m, " Base : %08x\n", (unsigned int)vc_cma_base);
  8008. + seq_printf(m, " Length : %08x\n", vc_cma_size);
  8009. + seq_printf(m, " Initial : %08x\n", vc_cma_initial);
  8010. + seq_printf(m, " Chunk size : %08x\n", VC_CMA_CHUNK_SIZE);
  8011. + seq_printf(m, " Chunks : %4d (%d bytes)\n",
  8012. + (int)vc_cma_chunks,
  8013. + (int)(vc_cma_chunks * VC_CMA_CHUNK_SIZE));
  8014. + seq_printf(m, " Used : %4d (%d bytes)\n",
  8015. + (int)vc_cma_chunks_used,
  8016. + (int)(vc_cma_chunks_used * VC_CMA_CHUNK_SIZE));
  8017. + seq_printf(m, " Reserved : %4d (%d bytes)\n",
  8018. + (unsigned int)vc_cma_chunks_reserved,
  8019. + (int)(vc_cma_chunks_reserved * VC_CMA_CHUNK_SIZE));
  8020. +
  8021. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8022. + struct vc_cma_reserve_user *user = &vc_cma_reserve_users[i];
  8023. + seq_printf(m, " PID %5d: %d bytes\n", user->pid,
  8024. + user->reserve);
  8025. + }
  8026. +
  8027. + seq_printf(m, "\n");
  8028. +
  8029. + return 0;
  8030. +}
  8031. +
  8032. +static int vc_cma_proc_open(struct inode *inode, struct file *file)
  8033. +{
  8034. + return single_open(file, vc_cma_show_info, NULL);
  8035. +}
  8036. +
  8037. +/****************************************************************************
  8038. +*
  8039. +* vc_cma_proc_write
  8040. +*
  8041. +***************************************************************************/
  8042. +
  8043. +static int vc_cma_proc_write(struct file *file,
  8044. + const char __user *buffer,
  8045. + size_t size, loff_t *ppos)
  8046. +{
  8047. + int rc = -EFAULT;
  8048. + char input_str[20];
  8049. +
  8050. + memset(input_str, 0, sizeof(input_str));
  8051. +
  8052. + if (size > sizeof(input_str)) {
  8053. + LOG_ERR("%s: input string length too long", __func__);
  8054. + goto out;
  8055. + }
  8056. +
  8057. + if (copy_from_user(input_str, buffer, size - 1)) {
  8058. + LOG_ERR("%s: failed to get input string", __func__);
  8059. + goto out;
  8060. + }
  8061. +#define ALLOC_STR "alloc"
  8062. +#define FREE_STR "free"
  8063. +#define DEBUG_STR "debug"
  8064. +#define RESERVE_STR "reserve"
  8065. + if (strncmp(input_str, ALLOC_STR, strlen(ALLOC_STR)) == 0) {
  8066. + int size;
  8067. + char *p = input_str + strlen(ALLOC_STR);
  8068. +
  8069. + while (*p == ' ')
  8070. + p++;
  8071. + size = memparse(p, NULL);
  8072. + LOG_ERR("/proc/vc-cma: alloc %d", size);
  8073. + if (size)
  8074. + send_vc_msg(VC_CMA_MSG_REQUEST_FREE,
  8075. + size / VC_CMA_CHUNK_SIZE, 0);
  8076. + else
  8077. + LOG_ERR("invalid size '%s'", p);
  8078. + rc = size;
  8079. + } else if (strncmp(input_str, FREE_STR, strlen(FREE_STR)) == 0) {
  8080. + int size;
  8081. + char *p = input_str + strlen(FREE_STR);
  8082. +
  8083. + while (*p == ' ')
  8084. + p++;
  8085. + size = memparse(p, NULL);
  8086. + LOG_ERR("/proc/vc-cma: free %d", size);
  8087. + if (size)
  8088. + send_vc_msg(VC_CMA_MSG_REQUEST_ALLOC,
  8089. + size / VC_CMA_CHUNK_SIZE, 0);
  8090. + else
  8091. + LOG_ERR("invalid size '%s'", p);
  8092. + rc = size;
  8093. + } else if (strncmp(input_str, DEBUG_STR, strlen(DEBUG_STR)) == 0) {
  8094. + char *p = input_str + strlen(DEBUG_STR);
  8095. + while (*p == ' ')
  8096. + p++;
  8097. + if ((strcmp(p, "on") == 0) || (strcmp(p, "1") == 0))
  8098. + vc_cma_debug = 1;
  8099. + else if ((strcmp(p, "off") == 0) || (strcmp(p, "0") == 0))
  8100. + vc_cma_debug = 0;
  8101. + LOG_ERR("/proc/vc-cma: debug %s", vc_cma_debug ? "on" : "off");
  8102. + rc = size;
  8103. + } else if (strncmp(input_str, RESERVE_STR, strlen(RESERVE_STR)) == 0) {
  8104. + int size;
  8105. + int reserved;
  8106. + char *p = input_str + strlen(RESERVE_STR);
  8107. + while (*p == ' ')
  8108. + p++;
  8109. + size = memparse(p, NULL);
  8110. +
  8111. + reserved = vc_cma_set_reserve(size, current->tgid);
  8112. + rc = (reserved >= 0) ? size : reserved;
  8113. + }
  8114. +
  8115. +out:
  8116. + return rc;
  8117. +}
  8118. +
  8119. +/****************************************************************************
  8120. +*
  8121. +* File Operations for /proc interface.
  8122. +*
  8123. +***************************************************************************/
  8124. +
  8125. +static const struct file_operations vc_cma_proc_fops = {
  8126. + .open = vc_cma_proc_open,
  8127. + .read = seq_read,
  8128. + .write = vc_cma_proc_write,
  8129. + .llseek = seq_lseek,
  8130. + .release = single_release
  8131. +};
  8132. +
  8133. +static int vc_cma_set_reserve(unsigned int reserve, unsigned int pid)
  8134. +{
  8135. + struct vc_cma_reserve_user *user = NULL;
  8136. + int delta = 0;
  8137. + int i;
  8138. +
  8139. + if (down_interruptible(&vc_cma_reserve_mutex))
  8140. + return -ERESTARTSYS;
  8141. +
  8142. + for (i = 0; i < vc_cma_reserve_count; i++) {
  8143. + if (pid == vc_cma_reserve_users[i].pid) {
  8144. + user = &vc_cma_reserve_users[i];
  8145. + delta = reserve - user->reserve;
  8146. + if (reserve)
  8147. + user->reserve = reserve;
  8148. + else {
  8149. + /* Remove this entry by copying downwards */
  8150. + while ((i + 1) < vc_cma_reserve_count) {
  8151. + user[0].pid = user[1].pid;
  8152. + user[0].reserve = user[1].reserve;
  8153. + user++;
  8154. + i++;
  8155. + }
  8156. + vc_cma_reserve_count--;
  8157. + user = NULL;
  8158. + }
  8159. + break;
  8160. + }
  8161. + }
  8162. +
  8163. + if (reserve && !user) {
  8164. + if (vc_cma_reserve_count == VC_CMA_RESERVE_COUNT_MAX) {
  8165. + LOG_ERR("vc-cma: Too many reservations - "
  8166. + "increase CMA_RESERVE_COUNT_MAX");
  8167. + up(&vc_cma_reserve_mutex);
  8168. + return -EBUSY;
  8169. + }
  8170. + user = &vc_cma_reserve_users[vc_cma_reserve_count];
  8171. + user->pid = pid;
  8172. + user->reserve = reserve;
  8173. + delta = reserve;
  8174. + vc_cma_reserve_count++;
  8175. + }
  8176. +
  8177. + vc_cma_reserve_total += delta;
  8178. +
  8179. + send_vc_msg(VC_CMA_MSG_RESERVE,
  8180. + vc_cma_reserve_total & 0xffff, vc_cma_reserve_total >> 16);
  8181. +
  8182. + send_worker_msg((VCHIQ_HEADER_T *) VC_CMA_MSG_UPDATE_RESERVE);
  8183. +
  8184. + LOG_DBG("/proc/vc-cma: reserve %d (PID %d) - total %u",
  8185. + reserve, pid, vc_cma_reserve_total);
  8186. +
  8187. + up(&vc_cma_reserve_mutex);
  8188. +
  8189. + return vc_cma_reserve_total;
  8190. +}
  8191. +
  8192. +static VCHIQ_STATUS_T cma_service_callback(VCHIQ_REASON_T reason,
  8193. + VCHIQ_HEADER_T * header,
  8194. + VCHIQ_SERVICE_HANDLE_T service,
  8195. + void *bulk_userdata)
  8196. +{
  8197. + switch (reason) {
  8198. + case VCHIQ_MESSAGE_AVAILABLE:
  8199. + if (!send_worker_msg(header))
  8200. + return VCHIQ_RETRY;
  8201. + break;
  8202. + case VCHIQ_SERVICE_CLOSED:
  8203. + LOG_DBG("CMA service closed");
  8204. + break;
  8205. + default:
  8206. + LOG_ERR("Unexpected CMA callback reason %d", reason);
  8207. + break;
  8208. + }
  8209. + return VCHIQ_SUCCESS;
  8210. +}
  8211. +
  8212. +static void send_vc_msg(unsigned short type,
  8213. + unsigned short param1, unsigned short param2)
  8214. +{
  8215. + unsigned short msg[] = { type, param1, param2 };
  8216. + VCHIQ_ELEMENT_T elem = { &msg, sizeof(msg) };
  8217. + VCHIQ_STATUS_T ret;
  8218. + vchiq_use_service(cma_service);
  8219. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8220. + vchiq_release_service(cma_service);
  8221. + if (ret != VCHIQ_SUCCESS)
  8222. + LOG_ERR("vchiq_queue_message returned %x", ret);
  8223. +}
  8224. +
  8225. +static bool send_worker_msg(VCHIQ_HEADER_T * msg)
  8226. +{
  8227. + if (down_interruptible(&vc_cma_worker_queue_push_mutex))
  8228. + return false;
  8229. + vchiu_queue_push(&cma_msg_queue, msg);
  8230. + up(&vc_cma_worker_queue_push_mutex);
  8231. + return true;
  8232. +}
  8233. +
  8234. +static int vc_cma_alloc_chunks(int num_chunks, struct cma_msg *reply)
  8235. +{
  8236. + int i;
  8237. + for (i = 0; i < num_chunks; i++) {
  8238. + struct page *chunk;
  8239. + unsigned int chunk_num;
  8240. + uint8_t *chunk_addr;
  8241. + size_t chunk_size = PAGES_PER_CHUNK << PAGE_SHIFT;
  8242. +
  8243. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8244. + PAGES_PER_CHUNK,
  8245. + VC_CMA_CHUNK_ORDER);
  8246. + if (!chunk)
  8247. + break;
  8248. +
  8249. + chunk_addr = page_address(chunk);
  8250. + dmac_flush_range(chunk_addr, chunk_addr + chunk_size);
  8251. + outer_inv_range(__pa(chunk_addr), __pa(chunk_addr) +
  8252. + chunk_size);
  8253. +
  8254. + chunk_num =
  8255. + (page_to_phys(chunk) - vc_cma_base) / VC_CMA_CHUNK_SIZE;
  8256. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8257. + VC_CMA_CHUNK_SIZE) != 0);
  8258. + if (chunk_num >= vc_cma_chunks) {
  8259. + LOG_ERR("%s: ===============================",
  8260. + __func__);
  8261. + LOG_ERR("%s: chunk phys %x, vc_cma %x-%x - "
  8262. + "bad SPARSEMEM configuration?",
  8263. + __func__, (unsigned int)page_to_phys(chunk),
  8264. + vc_cma_base, vc_cma_base + vc_cma_size - 1);
  8265. + LOG_ERR("%s: dev->cma_area = %p\n", __func__,
  8266. + (void*)0/*vc_cma_device.dev.cma_area*/);
  8267. + LOG_ERR("%s: ===============================",
  8268. + __func__);
  8269. + break;
  8270. + }
  8271. + reply->params[i] = chunk_num;
  8272. + vc_cma_chunks_used++;
  8273. + }
  8274. +
  8275. + if (i < num_chunks) {
  8276. + LOG_ERR("%s: dma_alloc_from_contiguous failed "
  8277. + "for %x bytes (alloc %d of %d, %d free)",
  8278. + __func__, VC_CMA_CHUNK_SIZE, i,
  8279. + num_chunks, vc_cma_chunks - vc_cma_chunks_used);
  8280. + num_chunks = i;
  8281. + }
  8282. +
  8283. + LOG_DBG("CMA allocated %d chunks -> %d used",
  8284. + num_chunks, vc_cma_chunks_used);
  8285. + reply->type = VC_CMA_MSG_ALLOCATED;
  8286. +
  8287. + {
  8288. + VCHIQ_ELEMENT_T elem = {
  8289. + reply,
  8290. + offsetof(struct cma_msg, params[0]) +
  8291. + num_chunks * sizeof(reply->params[0])
  8292. + };
  8293. + VCHIQ_STATUS_T ret;
  8294. + vchiq_use_service(cma_service);
  8295. + ret = vchiq_queue_message(cma_service, &elem, 1);
  8296. + vchiq_release_service(cma_service);
  8297. + if (ret != VCHIQ_SUCCESS)
  8298. + LOG_ERR("vchiq_queue_message return " "%x", ret);
  8299. + }
  8300. +
  8301. + return num_chunks;
  8302. +}
  8303. +
  8304. +static int cma_worker_proc(void *param)
  8305. +{
  8306. + static struct cma_msg reply;
  8307. + (void)param;
  8308. +
  8309. + while (1) {
  8310. + VCHIQ_HEADER_T *msg;
  8311. + static struct cma_msg msg_copy;
  8312. + struct cma_msg *cma_msg = &msg_copy;
  8313. + int type, msg_size;
  8314. +
  8315. + msg = vchiu_queue_pop(&cma_msg_queue);
  8316. + if ((unsigned int)msg >= VC_CMA_MSG_MAX) {
  8317. + msg_size = msg->size;
  8318. + memcpy(&msg_copy, msg->data, msg_size);
  8319. + type = cma_msg->type;
  8320. + vchiq_release_message(cma_service, msg);
  8321. + } else {
  8322. + msg_size = 0;
  8323. + type = (int)msg;
  8324. + if (type == VC_CMA_MSG_QUIT)
  8325. + break;
  8326. + else if (type == VC_CMA_MSG_UPDATE_RESERVE) {
  8327. + msg = NULL;
  8328. + cma_msg = NULL;
  8329. + } else {
  8330. + BUG();
  8331. + continue;
  8332. + }
  8333. + }
  8334. +
  8335. + switch (type) {
  8336. + case VC_CMA_MSG_ALLOC:{
  8337. + int num_chunks, free_chunks;
  8338. + num_chunks = cma_msg->params[0];
  8339. + free_chunks =
  8340. + vc_cma_chunks - vc_cma_chunks_used;
  8341. + LOG_DBG("CMA_MSG_ALLOC(%d chunks)", num_chunks);
  8342. + if (num_chunks > VC_CMA_MAX_PARAMS_PER_MSG) {
  8343. + LOG_ERR
  8344. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8345. + "exceeds VC_CMA_MAX_PARAMS_PER_MSG (%d)",
  8346. + num_chunks,
  8347. + VC_CMA_MAX_PARAMS_PER_MSG);
  8348. + num_chunks = VC_CMA_MAX_PARAMS_PER_MSG;
  8349. + }
  8350. +
  8351. + if (num_chunks > free_chunks) {
  8352. + LOG_ERR
  8353. + ("CMA_MSG_ALLOC - chunk count (%d) "
  8354. + "exceeds free chunks (%d)",
  8355. + num_chunks, free_chunks);
  8356. + num_chunks = free_chunks;
  8357. + }
  8358. +
  8359. + vc_cma_alloc_chunks(num_chunks, &reply);
  8360. + }
  8361. + break;
  8362. +
  8363. + case VC_CMA_MSG_FREE:{
  8364. + int chunk_count =
  8365. + (msg_size -
  8366. + offsetof(struct cma_msg,
  8367. + params)) /
  8368. + sizeof(cma_msg->params[0]);
  8369. + int i;
  8370. + BUG_ON(chunk_count <= 0);
  8371. +
  8372. + LOG_DBG("CMA_MSG_FREE(%d chunks - %x, ...)",
  8373. + chunk_count, cma_msg->params[0]);
  8374. + for (i = 0; i < chunk_count; i++) {
  8375. + int chunk_num = cma_msg->params[i];
  8376. + struct page *page = vc_cma_base_page +
  8377. + chunk_num * PAGES_PER_CHUNK;
  8378. + if (chunk_num >= vc_cma_chunks) {
  8379. + LOG_ERR
  8380. + ("CMA_MSG_FREE - chunk %d of %d"
  8381. + " (value %x) exceeds maximum "
  8382. + "(%x)", i, chunk_count,
  8383. + chunk_num,
  8384. + vc_cma_chunks - 1);
  8385. + break;
  8386. + }
  8387. +
  8388. + if (!dma_release_from_contiguous
  8389. + (NULL /*&vc_cma_device.dev*/, page,
  8390. + PAGES_PER_CHUNK)) {
  8391. + LOG_ERR
  8392. + ("CMA_MSG_FREE - failed to "
  8393. + "release chunk %d (phys %x, "
  8394. + "page %x)", chunk_num,
  8395. + page_to_phys(page),
  8396. + (unsigned int)page);
  8397. + }
  8398. + vc_cma_chunks_used--;
  8399. + }
  8400. + LOG_DBG("CMA released %d chunks -> %d used",
  8401. + i, vc_cma_chunks_used);
  8402. + }
  8403. + break;
  8404. +
  8405. + case VC_CMA_MSG_UPDATE_RESERVE:{
  8406. + int chunks_needed =
  8407. + ((vc_cma_reserve_total + VC_CMA_CHUNK_SIZE -
  8408. + 1)
  8409. + / VC_CMA_CHUNK_SIZE) -
  8410. + vc_cma_chunks_reserved;
  8411. +
  8412. + LOG_DBG
  8413. + ("CMA_MSG_UPDATE_RESERVE(%d chunks needed)",
  8414. + chunks_needed);
  8415. +
  8416. + /* Cap the reservations to what is available */
  8417. + if (chunks_needed > 0) {
  8418. + if (chunks_needed >
  8419. + (vc_cma_chunks -
  8420. + vc_cma_chunks_used))
  8421. + chunks_needed =
  8422. + (vc_cma_chunks -
  8423. + vc_cma_chunks_used);
  8424. +
  8425. + chunks_needed =
  8426. + vc_cma_alloc_chunks(chunks_needed,
  8427. + &reply);
  8428. + }
  8429. +
  8430. + LOG_DBG
  8431. + ("CMA_MSG_UPDATE_RESERVE(%d chunks allocated)",
  8432. + chunks_needed);
  8433. + vc_cma_chunks_reserved += chunks_needed;
  8434. + }
  8435. + break;
  8436. +
  8437. + default:
  8438. + LOG_ERR("unexpected msg type %d", type);
  8439. + break;
  8440. + }
  8441. + }
  8442. +
  8443. + LOG_DBG("quitting...");
  8444. + return 0;
  8445. +}
  8446. +
  8447. +/****************************************************************************
  8448. +*
  8449. +* vc_cma_connected_init
  8450. +*
  8451. +* This function is called once the videocore has been connected.
  8452. +*
  8453. +***************************************************************************/
  8454. +
  8455. +static void vc_cma_connected_init(void)
  8456. +{
  8457. + VCHIQ_SERVICE_PARAMS_T service_params;
  8458. +
  8459. + LOG_DBG("vc_cma_connected_init");
  8460. +
  8461. + if (!vchiu_queue_init(&cma_msg_queue, 16)) {
  8462. + LOG_ERR("could not create CMA msg queue");
  8463. + goto fail_queue;
  8464. + }
  8465. +
  8466. + if (vchiq_initialise(&cma_instance) != VCHIQ_SUCCESS)
  8467. + goto fail_vchiq_init;
  8468. +
  8469. + vchiq_connect(cma_instance);
  8470. +
  8471. + service_params.fourcc = VC_CMA_FOURCC;
  8472. + service_params.callback = cma_service_callback;
  8473. + service_params.userdata = NULL;
  8474. + service_params.version = VC_CMA_VERSION;
  8475. + service_params.version_min = VC_CMA_VERSION;
  8476. +
  8477. + if (vchiq_open_service(cma_instance, &service_params,
  8478. + &cma_service) != VCHIQ_SUCCESS) {
  8479. + LOG_ERR("failed to open service - already in use?");
  8480. + goto fail_vchiq_open;
  8481. + }
  8482. +
  8483. + vchiq_release_service(cma_service);
  8484. +
  8485. + cma_worker = kthread_create(cma_worker_proc, NULL, "cma_worker");
  8486. + if (!cma_worker) {
  8487. + LOG_ERR("could not create CMA worker thread");
  8488. + goto fail_worker;
  8489. + }
  8490. + set_user_nice(cma_worker, -20);
  8491. + wake_up_process(cma_worker);
  8492. +
  8493. + return;
  8494. +
  8495. +fail_worker:
  8496. + vchiq_close_service(cma_service);
  8497. +fail_vchiq_open:
  8498. + vchiq_shutdown(cma_instance);
  8499. +fail_vchiq_init:
  8500. + vchiu_queue_delete(&cma_msg_queue);
  8501. +fail_queue:
  8502. + return;
  8503. +}
  8504. +
  8505. +void
  8506. +loud_error_header(void)
  8507. +{
  8508. + if (in_loud_error)
  8509. + return;
  8510. +
  8511. + LOG_ERR("============================================================"
  8512. + "================");
  8513. + LOG_ERR("============================================================"
  8514. + "================");
  8515. + LOG_ERR("=====");
  8516. +
  8517. + in_loud_error = 1;
  8518. +}
  8519. +
  8520. +void
  8521. +loud_error_footer(void)
  8522. +{
  8523. + if (!in_loud_error)
  8524. + return;
  8525. +
  8526. + LOG_ERR("=====");
  8527. + LOG_ERR("============================================================"
  8528. + "================");
  8529. + LOG_ERR("============================================================"
  8530. + "================");
  8531. +
  8532. + in_loud_error = 0;
  8533. +}
  8534. +
  8535. +#if 1
  8536. +static int check_cma_config(void) { return 1; }
  8537. +#else
  8538. +static int
  8539. +read_vc_debug_var(VC_MEM_ACCESS_HANDLE_T handle,
  8540. + const char *symbol,
  8541. + void *buf, size_t bufsize)
  8542. +{
  8543. + VC_MEM_ADDR_T vcMemAddr;
  8544. + size_t vcMemSize;
  8545. + uint8_t *mapAddr;
  8546. + off_t vcMapAddr;
  8547. +
  8548. + if (!LookupVideoCoreSymbol(handle, symbol,
  8549. + &vcMemAddr,
  8550. + &vcMemSize)) {
  8551. + loud_error_header();
  8552. + loud_error(
  8553. + "failed to find VC symbol \"%s\".",
  8554. + symbol);
  8555. + loud_error_footer();
  8556. + return 0;
  8557. + }
  8558. +
  8559. + if (vcMemSize != bufsize) {
  8560. + loud_error_header();
  8561. + loud_error(
  8562. + "VC symbol \"%s\" is the wrong size.",
  8563. + symbol);
  8564. + loud_error_footer();
  8565. + return 0;
  8566. + }
  8567. +
  8568. + vcMapAddr = (off_t)vcMemAddr & VC_MEM_TO_ARM_ADDR_MASK;
  8569. + vcMapAddr += mm_vc_mem_phys_addr;
  8570. + mapAddr = ioremap_nocache(vcMapAddr, vcMemSize);
  8571. + if (mapAddr == 0) {
  8572. + loud_error_header();
  8573. + loud_error(
  8574. + "failed to ioremap \"%s\" @ 0x%x "
  8575. + "(phys: 0x%x, size: %u).",
  8576. + symbol,
  8577. + (unsigned int)vcMapAddr,
  8578. + (unsigned int)vcMemAddr,
  8579. + (unsigned int)vcMemSize);
  8580. + loud_error_footer();
  8581. + return 0;
  8582. + }
  8583. +
  8584. + memcpy(buf, mapAddr, bufsize);
  8585. + iounmap(mapAddr);
  8586. +
  8587. + return 1;
  8588. +}
  8589. +
  8590. +
  8591. +static int
  8592. +check_cma_config(void)
  8593. +{
  8594. + VC_MEM_ACCESS_HANDLE_T mem_hndl;
  8595. + VC_MEM_ADDR_T mempool_start;
  8596. + VC_MEM_ADDR_T mempool_end;
  8597. + VC_MEM_ADDR_T mempool_offline_start;
  8598. + VC_MEM_ADDR_T mempool_offline_end;
  8599. + VC_MEM_ADDR_T cam_alloc_base;
  8600. + VC_MEM_ADDR_T cam_alloc_size;
  8601. + VC_MEM_ADDR_T cam_alloc_end;
  8602. + int success = 0;
  8603. +
  8604. + if (OpenVideoCoreMemory(&mem_hndl) != 0)
  8605. + goto out;
  8606. +
  8607. + /* Read the relevant VideoCore variables */
  8608. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_START",
  8609. + &mempool_start,
  8610. + sizeof(mempool_start)))
  8611. + goto close;
  8612. +
  8613. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_END",
  8614. + &mempool_end,
  8615. + sizeof(mempool_end)))
  8616. + goto close;
  8617. +
  8618. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_START",
  8619. + &mempool_offline_start,
  8620. + sizeof(mempool_offline_start)))
  8621. + goto close;
  8622. +
  8623. + if (!read_vc_debug_var(mem_hndl, "__MEMPOOL_OFFLINE_END",
  8624. + &mempool_offline_end,
  8625. + sizeof(mempool_offline_end)))
  8626. + goto close;
  8627. +
  8628. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_base",
  8629. + &cam_alloc_base,
  8630. + sizeof(cam_alloc_base)))
  8631. + goto close;
  8632. +
  8633. + if (!read_vc_debug_var(mem_hndl, "cam_alloc_size",
  8634. + &cam_alloc_size,
  8635. + sizeof(cam_alloc_size)))
  8636. + goto close;
  8637. +
  8638. + cam_alloc_end = cam_alloc_base + cam_alloc_size;
  8639. +
  8640. + success = 1;
  8641. +
  8642. + /* Now the sanity checks */
  8643. + if (!mempool_offline_start)
  8644. + mempool_offline_start = mempool_start;
  8645. + if (!mempool_offline_end)
  8646. + mempool_offline_end = mempool_end;
  8647. +
  8648. + if (VCADDR_TO_PHYSADDR(mempool_offline_start) != vc_cma_base) {
  8649. + loud_error_header();
  8650. + loud_error(
  8651. + "__MEMPOOL_OFFLINE_START(%x -> %lx) doesn't match "
  8652. + "vc_cma_base(%x)",
  8653. + mempool_offline_start,
  8654. + VCADDR_TO_PHYSADDR(mempool_offline_start),
  8655. + vc_cma_base);
  8656. + success = 0;
  8657. + }
  8658. +
  8659. + if (VCADDR_TO_PHYSADDR(mempool_offline_end) !=
  8660. + (vc_cma_base + vc_cma_size)) {
  8661. + loud_error_header();
  8662. + loud_error(
  8663. + "__MEMPOOL_OFFLINE_END(%x -> %lx) doesn't match "
  8664. + "vc_cma_base(%x) + vc_cma_size(%x) = %x",
  8665. + mempool_offline_start,
  8666. + VCADDR_TO_PHYSADDR(mempool_offline_end),
  8667. + vc_cma_base, vc_cma_size, vc_cma_base + vc_cma_size);
  8668. + success = 0;
  8669. + }
  8670. +
  8671. + if (mempool_end < mempool_start) {
  8672. + loud_error_header();
  8673. + loud_error(
  8674. + "__MEMPOOL_END(%x) must not be before "
  8675. + "__MEMPOOL_START(%x)",
  8676. + mempool_end,
  8677. + mempool_start);
  8678. + success = 0;
  8679. + }
  8680. +
  8681. + if (mempool_offline_end < mempool_offline_start) {
  8682. + loud_error_header();
  8683. + loud_error(
  8684. + "__MEMPOOL_OFFLINE_END(%x) must not be before "
  8685. + "__MEMPOOL_OFFLINE_START(%x)",
  8686. + mempool_offline_end,
  8687. + mempool_offline_start);
  8688. + success = 0;
  8689. + }
  8690. +
  8691. + if (mempool_offline_start < mempool_start) {
  8692. + loud_error_header();
  8693. + loud_error(
  8694. + "__MEMPOOL_OFFLINE_START(%x) must not be before "
  8695. + "__MEMPOOL_START(%x)",
  8696. + mempool_offline_start,
  8697. + mempool_start);
  8698. + success = 0;
  8699. + }
  8700. +
  8701. + if (mempool_offline_end > mempool_end) {
  8702. + loud_error_header();
  8703. + loud_error(
  8704. + "__MEMPOOL_OFFLINE_END(%x) must not be after "
  8705. + "__MEMPOOL_END(%x)",
  8706. + mempool_offline_end,
  8707. + mempool_end);
  8708. + success = 0;
  8709. + }
  8710. +
  8711. + if ((cam_alloc_base < mempool_end) &&
  8712. + (cam_alloc_end > mempool_start)) {
  8713. + loud_error_header();
  8714. + loud_error(
  8715. + "cam_alloc pool(%x-%x) overlaps "
  8716. + "mempool(%x-%x)",
  8717. + cam_alloc_base, cam_alloc_end,
  8718. + mempool_start, mempool_end);
  8719. + success = 0;
  8720. + }
  8721. +
  8722. + loud_error_footer();
  8723. +
  8724. +close:
  8725. + CloseVideoCoreMemory(mem_hndl);
  8726. +
  8727. +out:
  8728. + return success;
  8729. +}
  8730. +#endif
  8731. +
  8732. +static int vc_cma_init(void)
  8733. +{
  8734. + int rc = -EFAULT;
  8735. + struct device *dev;
  8736. +
  8737. + if (!check_cma_config())
  8738. + goto out_release;
  8739. +
  8740. + printk(KERN_INFO "vc-cma: Videocore CMA driver\n");
  8741. + printk(KERN_INFO "vc-cma: vc_cma_base = 0x%08x\n", vc_cma_base);
  8742. + printk(KERN_INFO "vc-cma: vc_cma_size = 0x%08x (%u MiB)\n",
  8743. + vc_cma_size, vc_cma_size / (1024 * 1024));
  8744. + printk(KERN_INFO "vc-cma: vc_cma_initial = 0x%08x (%u MiB)\n",
  8745. + vc_cma_initial, vc_cma_initial / (1024 * 1024));
  8746. +
  8747. + vc_cma_base_page = phys_to_page(vc_cma_base);
  8748. +
  8749. + if (vc_cma_chunks) {
  8750. + int chunks_needed = vc_cma_initial / VC_CMA_CHUNK_SIZE;
  8751. +
  8752. + for (vc_cma_chunks_used = 0;
  8753. + vc_cma_chunks_used < chunks_needed; vc_cma_chunks_used++) {
  8754. + struct page *chunk;
  8755. + chunk = dma_alloc_from_contiguous(NULL /*&vc_cma_device.dev*/,
  8756. + PAGES_PER_CHUNK,
  8757. + VC_CMA_CHUNK_ORDER);
  8758. + if (!chunk)
  8759. + break;
  8760. + BUG_ON(((page_to_phys(chunk) - vc_cma_base) %
  8761. + VC_CMA_CHUNK_SIZE) != 0);
  8762. + }
  8763. + if (vc_cma_chunks_used != chunks_needed) {
  8764. + LOG_ERR("%s: dma_alloc_from_contiguous failed (%d "
  8765. + "bytes, allocation %d of %d)",
  8766. + __func__, VC_CMA_CHUNK_SIZE,
  8767. + vc_cma_chunks_used, chunks_needed);
  8768. + goto out_release;
  8769. + }
  8770. +
  8771. + vchiq_add_connected_callback(vc_cma_connected_init);
  8772. + }
  8773. +
  8774. + rc = alloc_chrdev_region(&vc_cma_devnum, 0, 1, DRIVER_NAME);
  8775. + if (rc < 0) {
  8776. + LOG_ERR("%s: alloc_chrdev_region failed (rc=%d)", __func__, rc);
  8777. + goto out_release;
  8778. + }
  8779. +
  8780. + cdev_init(&vc_cma_cdev, &vc_cma_fops);
  8781. + rc = cdev_add(&vc_cma_cdev, vc_cma_devnum, 1);
  8782. + if (rc != 0) {
  8783. + LOG_ERR("%s: cdev_add failed (rc=%d)", __func__, rc);
  8784. + goto out_unregister;
  8785. + }
  8786. +
  8787. + vc_cma_class = class_create(THIS_MODULE, DRIVER_NAME);
  8788. + if (IS_ERR(vc_cma_class)) {
  8789. + rc = PTR_ERR(vc_cma_class);
  8790. + LOG_ERR("%s: class_create failed (rc=%d)", __func__, rc);
  8791. + goto out_cdev_del;
  8792. + }
  8793. +
  8794. + dev = device_create(vc_cma_class, NULL, vc_cma_devnum, NULL,
  8795. + DRIVER_NAME);
  8796. + if (IS_ERR(dev)) {
  8797. + rc = PTR_ERR(dev);
  8798. + LOG_ERR("%s: device_create failed (rc=%d)", __func__, rc);
  8799. + goto out_class_destroy;
  8800. + }
  8801. +
  8802. + vc_cma_proc_entry = proc_create(DRIVER_NAME, 0444, NULL, &vc_cma_proc_fops);
  8803. + if (vc_cma_proc_entry == NULL) {
  8804. + rc = -EFAULT;
  8805. + LOG_ERR("%s: proc_create failed", __func__);
  8806. + goto out_device_destroy;
  8807. + }
  8808. +
  8809. + vc_cma_inited = 1;
  8810. + return 0;
  8811. +
  8812. +out_device_destroy:
  8813. + device_destroy(vc_cma_class, vc_cma_devnum);
  8814. +
  8815. +out_class_destroy:
  8816. + class_destroy(vc_cma_class);
  8817. + vc_cma_class = NULL;
  8818. +
  8819. +out_cdev_del:
  8820. + cdev_del(&vc_cma_cdev);
  8821. +
  8822. +out_unregister:
  8823. + unregister_chrdev_region(vc_cma_devnum, 1);
  8824. +
  8825. +out_release:
  8826. + /* It is tempting to try to clean up by calling
  8827. + dma_release_from_contiguous for all allocated chunks, but it isn't
  8828. + a very safe thing to do. If vc_cma_initial is non-zero it is because
  8829. + VideoCore is already using that memory, so giving it back to Linux
  8830. + is likely to be fatal.
  8831. + */
  8832. + return -1;
  8833. +}
  8834. +
  8835. +/****************************************************************************
  8836. +*
  8837. +* vc_cma_exit
  8838. +*
  8839. +***************************************************************************/
  8840. +
  8841. +static void __exit vc_cma_exit(void)
  8842. +{
  8843. + LOG_DBG("%s: called", __func__);
  8844. +
  8845. + if (vc_cma_inited) {
  8846. + remove_proc_entry(DRIVER_NAME, NULL);
  8847. + device_destroy(vc_cma_class, vc_cma_devnum);
  8848. + class_destroy(vc_cma_class);
  8849. + cdev_del(&vc_cma_cdev);
  8850. + unregister_chrdev_region(vc_cma_devnum, 1);
  8851. + }
  8852. +}
  8853. +
  8854. +module_init(vc_cma_init);
  8855. +module_exit(vc_cma_exit);
  8856. +MODULE_LICENSE("GPL");
  8857. +MODULE_AUTHOR("Broadcom Corporation");
  8858. diff -Nur linux-3.15/drivers/char/hw_random/bcm2708-rng.c linux-rpi/drivers/char/hw_random/bcm2708-rng.c
  8859. --- linux-3.15/drivers/char/hw_random/bcm2708-rng.c 1970-01-01 01:00:00.000000000 +0100
  8860. +++ linux-rpi/drivers/char/hw_random/bcm2708-rng.c 2014-06-11 21:05:19.000000000 +0200
  8861. @@ -0,0 +1,118 @@
  8862. +/**
  8863. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  8864. + *
  8865. + * Redistribution and use in source and binary forms, with or without
  8866. + * modification, are permitted provided that the following conditions
  8867. + * are met:
  8868. + * 1. Redistributions of source code must retain the above copyright
  8869. + * notice, this list of conditions, and the following disclaimer,
  8870. + * without modification.
  8871. + * 2. Redistributions in binary form must reproduce the above copyright
  8872. + * notice, this list of conditions and the following disclaimer in the
  8873. + * documentation and/or other materials provided with the distribution.
  8874. + * 3. The names of the above-listed copyright holders may not be used
  8875. + * to endorse or promote products derived from this software without
  8876. + * specific prior written permission.
  8877. + *
  8878. + * ALTERNATIVELY, this software may be distributed under the terms of the
  8879. + * GNU General Public License ("GPL") version 2, as published by the Free
  8880. + * Software Foundation.
  8881. + *
  8882. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  8883. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  8884. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  8885. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  8886. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  8887. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  8888. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  8889. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  8890. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  8891. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  8892. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  8893. + */
  8894. +
  8895. +#include <linux/kernel.h>
  8896. +#include <linux/module.h>
  8897. +#include <linux/init.h>
  8898. +#include <linux/hw_random.h>
  8899. +#include <linux/printk.h>
  8900. +
  8901. +#include <asm/io.h>
  8902. +#include <mach/hardware.h>
  8903. +#include <mach/platform.h>
  8904. +
  8905. +#define RNG_CTRL (0x0)
  8906. +#define RNG_STATUS (0x4)
  8907. +#define RNG_DATA (0x8)
  8908. +#define RNG_FF_THRESHOLD (0xc)
  8909. +
  8910. +/* enable rng */
  8911. +#define RNG_RBGEN 0x1
  8912. +/* double speed, less random mode */
  8913. +#define RNG_RBG2X 0x2
  8914. +
  8915. +/* the initial numbers generated are "less random" so will be discarded */
  8916. +#define RNG_WARMUP_COUNT 0x40000
  8917. +
  8918. +static int bcm2708_rng_data_read(struct hwrng *rng, u32 *buffer)
  8919. +{
  8920. + void __iomem *rng_base = (void __iomem *)rng->priv;
  8921. + unsigned words;
  8922. + /* wait for a random number to be in fifo */
  8923. + do {
  8924. + words = __raw_readl(rng_base + RNG_STATUS)>>24;
  8925. + }
  8926. + while (words == 0);
  8927. + /* read the random number */
  8928. + *buffer = __raw_readl(rng_base + RNG_DATA);
  8929. + return 4;
  8930. +}
  8931. +
  8932. +static struct hwrng bcm2708_rng_ops = {
  8933. + .name = "bcm2708",
  8934. + .data_read = bcm2708_rng_data_read,
  8935. +};
  8936. +
  8937. +static int __init bcm2708_rng_init(void)
  8938. +{
  8939. + void __iomem *rng_base;
  8940. + int err;
  8941. +
  8942. + /* map peripheral */
  8943. + rng_base = ioremap(RNG_BASE, 0x10);
  8944. + pr_info("bcm2708_rng_init=%p\n", rng_base);
  8945. + if (!rng_base) {
  8946. + pr_err("bcm2708_rng_init failed to ioremap\n");
  8947. + return -ENOMEM;
  8948. + }
  8949. + bcm2708_rng_ops.priv = (unsigned long)rng_base;
  8950. +
  8951. + /* set warm-up count & enable */
  8952. + __raw_writel(RNG_WARMUP_COUNT, rng_base + RNG_STATUS);
  8953. + __raw_writel(RNG_RBGEN, rng_base + RNG_CTRL);
  8954. +
  8955. + /* register driver */
  8956. + err = hwrng_register(&bcm2708_rng_ops);
  8957. + if (err) {
  8958. + pr_err("bcm2708_rng_init hwrng_register()=%d\n", err);
  8959. + iounmap(rng_base);
  8960. + }
  8961. + return err;
  8962. +}
  8963. +
  8964. +static void __exit bcm2708_rng_exit(void)
  8965. +{
  8966. + void __iomem *rng_base = (void __iomem *)bcm2708_rng_ops.priv;
  8967. + pr_info("bcm2708_rng_exit\n");
  8968. + /* disable rng hardware */
  8969. + __raw_writel(0, rng_base + RNG_CTRL);
  8970. + /* unregister driver */
  8971. + hwrng_unregister(&bcm2708_rng_ops);
  8972. + iounmap(rng_base);
  8973. +}
  8974. +
  8975. +module_init(bcm2708_rng_init);
  8976. +module_exit(bcm2708_rng_exit);
  8977. +
  8978. +MODULE_DESCRIPTION("BCM2708 H/W Random Number Generator (RNG) driver");
  8979. +MODULE_LICENSE("GPL and additional rights");
  8980. diff -Nur linux-3.15/drivers/char/hw_random/Kconfig linux-rpi/drivers/char/hw_random/Kconfig
  8981. --- linux-3.15/drivers/char/hw_random/Kconfig 2014-06-08 20:19:54.000000000 +0200
  8982. +++ linux-rpi/drivers/char/hw_random/Kconfig 2014-06-11 21:05:19.000000000 +0200
  8983. @@ -341,6 +341,17 @@
  8984. If unsure, say Y.
  8985. +config HW_RANDOM_BCM2708
  8986. + tristate "BCM2708 generic true random number generator support"
  8987. + depends on HW_RANDOM && ARCH_BCM2708
  8988. + ---help---
  8989. + This driver provides the kernel-side support for the BCM2708 hardware.
  8990. +
  8991. + To compile this driver as a module, choose M here: the
  8992. + module will be called bcm2708-rng.
  8993. +
  8994. + If unsure, say N.
  8995. +
  8996. config HW_RANDOM_MSM
  8997. tristate "Qualcomm SoCs Random Number Generator support"
  8998. depends on HW_RANDOM && ARCH_QCOM
  8999. diff -Nur linux-3.15/drivers/char/hw_random/Makefile linux-rpi/drivers/char/hw_random/Makefile
  9000. --- linux-3.15/drivers/char/hw_random/Makefile 2014-06-08 20:19:54.000000000 +0200
  9001. +++ linux-rpi/drivers/char/hw_random/Makefile 2014-06-11 21:05:19.000000000 +0200
  9002. @@ -29,4 +29,5 @@
  9003. obj-$(CONFIG_HW_RANDOM_EXYNOS) += exynos-rng.o
  9004. obj-$(CONFIG_HW_RANDOM_TPM) += tpm-rng.o
  9005. obj-$(CONFIG_HW_RANDOM_BCM2835) += bcm2835-rng.o
  9006. +obj-$(CONFIG_HW_RANDOM_BCM2708) += bcm2708-rng.o
  9007. obj-$(CONFIG_HW_RANDOM_MSM) += msm-rng.o
  9008. diff -Nur linux-3.15/drivers/char/Kconfig linux-rpi/drivers/char/Kconfig
  9009. --- linux-3.15/drivers/char/Kconfig 2014-06-08 20:19:54.000000000 +0200
  9010. +++ linux-rpi/drivers/char/Kconfig 2014-06-11 21:05:19.000000000 +0200
  9011. @@ -581,6 +581,8 @@
  9012. source "drivers/s390/char/Kconfig"
  9013. +source "drivers/char/broadcom/Kconfig"
  9014. +
  9015. config MSM_SMD_PKT
  9016. bool "Enable device interface for some SMD packet ports"
  9017. default n
  9018. diff -Nur linux-3.15/drivers/char/Makefile linux-rpi/drivers/char/Makefile
  9019. --- linux-3.15/drivers/char/Makefile 2014-06-08 20:19:54.000000000 +0200
  9020. +++ linux-rpi/drivers/char/Makefile 2014-06-11 21:05:19.000000000 +0200
  9021. @@ -61,3 +61,5 @@
  9022. js-rtc-y = rtc.o
  9023. obj-$(CONFIG_TILE_SROM) += tile-srom.o
  9024. +
  9025. +obj-$(CONFIG_BRCM_CHAR_DRIVERS) += broadcom/
  9026. diff -Nur linux-3.15/drivers/cpufreq/bcm2835-cpufreq.c linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c
  9027. --- linux-3.15/drivers/cpufreq/bcm2835-cpufreq.c 1970-01-01 01:00:00.000000000 +0100
  9028. +++ linux-rpi/drivers/cpufreq/bcm2835-cpufreq.c 2014-06-11 21:03:22.000000000 +0200
  9029. @@ -0,0 +1,239 @@
  9030. +/*****************************************************************************
  9031. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9032. +*
  9033. +* Unless you and Broadcom execute a separate written software license
  9034. +* agreement governing use of this software, this software is licensed to you
  9035. +* under the terms of the GNU General Public License version 2, available at
  9036. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9037. +*
  9038. +* Notwithstanding the above, under no circumstances may you combine this
  9039. +* software in any way with any other Broadcom software provided under a
  9040. +* license other than the GPL, without Broadcom's express prior written
  9041. +* consent.
  9042. +*****************************************************************************/
  9043. +
  9044. +/*****************************************************************************
  9045. +* FILENAME: bcm2835-cpufreq.h
  9046. +* DESCRIPTION: This driver dynamically manages the CPU Frequency of the ARM
  9047. +* processor. Messages are sent to Videocore either setting or requesting the
  9048. +* frequency of the ARM in order to match an appropiate frequency to the current
  9049. +* usage of the processor. The policy which selects the frequency to use is
  9050. +* defined in the kernel .config file, but can be changed during runtime.
  9051. +*****************************************************************************/
  9052. +
  9053. +/* ---------- INCLUDES ---------- */
  9054. +#include <linux/kernel.h>
  9055. +#include <linux/init.h>
  9056. +#include <linux/module.h>
  9057. +#include <linux/cpufreq.h>
  9058. +#include <mach/vcio.h>
  9059. +
  9060. +/* ---------- DEFINES ---------- */
  9061. +/*#define CPUFREQ_DEBUG_ENABLE*/ /* enable debugging */
  9062. +#define MODULE_NAME "bcm2835-cpufreq"
  9063. +
  9064. +#define VCMSG_ID_ARM_CLOCK 0x000000003 /* Clock/Voltage ID's */
  9065. +
  9066. +/* debug printk macros */
  9067. +#ifdef CPUFREQ_DEBUG_ENABLE
  9068. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9069. +#else
  9070. +#define print_debug(fmt,...)
  9071. +#endif
  9072. +#define print_err(fmt,...) pr_err("%s:%s:%d: "fmt, MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9073. +#define print_info(fmt,...) pr_info("%s: "fmt, MODULE_NAME, ##__VA_ARGS__)
  9074. +
  9075. +/* tag part of the message */
  9076. +struct vc_msg_tag {
  9077. + uint32_t tag_id; /* the message id */
  9078. + uint32_t buffer_size; /* size of the buffer (which in this case is always 8 bytes) */
  9079. + uint32_t data_size; /* amount of data being sent or received */
  9080. + uint32_t dev_id; /* the ID of the clock/voltage to get or set */
  9081. + uint32_t val; /* the value (e.g. rate (in Hz)) to set */
  9082. +};
  9083. +
  9084. +/* message structure to be sent to videocore */
  9085. +struct vc_msg {
  9086. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9087. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9088. + struct vc_msg_tag tag; /* the tag structure above to make */
  9089. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9090. +};
  9091. +
  9092. +/* ---------- GLOBALS ---------- */
  9093. +static struct cpufreq_driver bcm2835_cpufreq_driver; /* the cpufreq driver global */
  9094. +
  9095. +/*
  9096. + ===============================================
  9097. + clk_rate either gets or sets the clock rates.
  9098. + ===============================================
  9099. +*/
  9100. +static uint32_t bcm2835_cpufreq_set_clock(int cur_rate, int arm_rate)
  9101. +{
  9102. + int s, actual_rate=0;
  9103. + struct vc_msg msg;
  9104. +
  9105. + /* wipe all previous message data */
  9106. + memset(&msg, 0, sizeof msg);
  9107. +
  9108. + msg.msg_size = sizeof msg;
  9109. +
  9110. + msg.tag.tag_id = VCMSG_SET_CLOCK_RATE;
  9111. + msg.tag.buffer_size = 8;
  9112. + msg.tag.data_size = 8; /* we're sending the clock ID and the new rates which is a total of 2 words */
  9113. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9114. + msg.tag.val = arm_rate * 1000;
  9115. +
  9116. + /* send the message */
  9117. + s = bcm_mailbox_property(&msg, sizeof msg);
  9118. +
  9119. + /* check if it was all ok and return the rate in KHz */
  9120. + if (s == 0 && (msg.request_code & 0x80000000))
  9121. + actual_rate = msg.tag.val/1000;
  9122. +
  9123. + print_debug("Setting new frequency = %d -> %d (actual %d)\n", cur_rate, arm_rate, actual_rate);
  9124. + return actual_rate;
  9125. +}
  9126. +
  9127. +static uint32_t bcm2835_cpufreq_get_clock(int tag)
  9128. +{
  9129. + int s;
  9130. + int arm_rate = 0;
  9131. + struct vc_msg msg;
  9132. +
  9133. + /* wipe all previous message data */
  9134. + memset(&msg, 0, sizeof msg);
  9135. +
  9136. + msg.msg_size = sizeof msg;
  9137. + msg.tag.tag_id = tag;
  9138. + msg.tag.buffer_size = 8;
  9139. + msg.tag.data_size = 4; /* we're just sending the clock ID which is one word long */
  9140. + msg.tag.dev_id = VCMSG_ID_ARM_CLOCK;
  9141. +
  9142. + /* send the message */
  9143. + s = bcm_mailbox_property(&msg, sizeof msg);
  9144. +
  9145. + /* check if it was all ok and return the rate in KHz */
  9146. + if (s == 0 && (msg.request_code & 0x80000000))
  9147. + arm_rate = msg.tag.val/1000;
  9148. +
  9149. + print_debug("%s frequency = %d\n",
  9150. + tag == VCMSG_GET_CLOCK_RATE ? "Current":
  9151. + tag == VCMSG_GET_MIN_CLOCK ? "Min":
  9152. + tag == VCMSG_GET_MAX_CLOCK ? "Max":
  9153. + "Unexpected", arm_rate);
  9154. +
  9155. + return arm_rate;
  9156. +}
  9157. +
  9158. +/*
  9159. + ====================================================
  9160. + Module Initialisation registers the cpufreq driver
  9161. + ====================================================
  9162. +*/
  9163. +static int __init bcm2835_cpufreq_module_init(void)
  9164. +{
  9165. + print_debug("IN\n");
  9166. + return cpufreq_register_driver(&bcm2835_cpufreq_driver);
  9167. +}
  9168. +
  9169. +/*
  9170. + =============
  9171. + Module exit
  9172. + =============
  9173. +*/
  9174. +static void __exit bcm2835_cpufreq_module_exit(void)
  9175. +{
  9176. + print_debug("IN\n");
  9177. + cpufreq_unregister_driver(&bcm2835_cpufreq_driver);
  9178. + return;
  9179. +}
  9180. +
  9181. +/*
  9182. + ==============================================================
  9183. + Initialisation function sets up the CPU policy for first use
  9184. + ==============================================================
  9185. +*/
  9186. +static int bcm2835_cpufreq_driver_init(struct cpufreq_policy *policy)
  9187. +{
  9188. + /* measured value of how long it takes to change frequency */
  9189. + policy->cpuinfo.transition_latency = 355000; /* ns */
  9190. +
  9191. + /* now find out what the maximum and minimum frequencies are */
  9192. + policy->min = policy->cpuinfo.min_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MIN_CLOCK);
  9193. + policy->max = policy->cpuinfo.max_freq = bcm2835_cpufreq_get_clock(VCMSG_GET_MAX_CLOCK);
  9194. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9195. +
  9196. + print_info("min=%d max=%d cur=%d\n", policy->min, policy->max, policy->cur);
  9197. + return 0;
  9198. +}
  9199. +
  9200. +/*
  9201. + =================================================================================
  9202. + Target function chooses the most appropriate frequency from the table to enable
  9203. + =================================================================================
  9204. +*/
  9205. +
  9206. +static int bcm2835_cpufreq_driver_target(struct cpufreq_policy *policy, unsigned int target_freq, unsigned int relation)
  9207. +{
  9208. + unsigned int target = target_freq;
  9209. +#ifdef CPUFREQ_DEBUG_ENABLE
  9210. + unsigned int cur = policy->cur;
  9211. +#endif
  9212. + print_debug("%s: min=%d max=%d cur=%d target=%d\n",policy->governor->name,policy->min,policy->max,policy->cur,target_freq);
  9213. +
  9214. + /* if we are above min and using ondemand, then just use max */
  9215. + if (strcmp("ondemand", policy->governor->name)==0 && target > policy->min)
  9216. + target = policy->max;
  9217. + /* if the frequency is the same, just quit */
  9218. + if (target == policy->cur)
  9219. + return 0;
  9220. +
  9221. + /* otherwise were good to set the clock frequency */
  9222. + policy->cur = bcm2835_cpufreq_set_clock(policy->cur, target);
  9223. +
  9224. + if (!policy->cur)
  9225. + {
  9226. + print_err("Error occurred setting a new frequency (%d)!\n", target);
  9227. + policy->cur = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9228. + return -EINVAL;
  9229. + }
  9230. + print_debug("Freq %d->%d (min=%d max=%d target=%d request=%d)\n", cur, policy->cur, policy->min, policy->max, target_freq, target);
  9231. + return 0;
  9232. +}
  9233. +
  9234. +static unsigned int bcm2835_cpufreq_driver_get(unsigned int cpu)
  9235. +{
  9236. + unsigned int actual_rate = bcm2835_cpufreq_get_clock(VCMSG_GET_CLOCK_RATE);
  9237. + print_debug("cpu=%d\n", actual_rate);
  9238. + return actual_rate;
  9239. +}
  9240. +
  9241. +/*
  9242. + =================================================================================
  9243. + Verify ensures that when a policy is changed, it is suitable for the CPU to use
  9244. + =================================================================================
  9245. +*/
  9246. +
  9247. +static int bcm2835_cpufreq_driver_verify(struct cpufreq_policy *policy)
  9248. +{
  9249. + print_info("switching to governor %s\n", policy->governor->name);
  9250. + return 0;
  9251. +}
  9252. +
  9253. +
  9254. +/* the CPUFreq driver */
  9255. +static struct cpufreq_driver bcm2835_cpufreq_driver = {
  9256. + .name = "BCM2835 CPUFreq",
  9257. + .init = bcm2835_cpufreq_driver_init,
  9258. + .verify = bcm2835_cpufreq_driver_verify,
  9259. + .target = bcm2835_cpufreq_driver_target,
  9260. + .get = bcm2835_cpufreq_driver_get
  9261. +};
  9262. +
  9263. +MODULE_AUTHOR("Dorian Peake and Dom Cobley");
  9264. +MODULE_DESCRIPTION("CPU frequency driver for BCM2835 chip");
  9265. +MODULE_LICENSE("GPL");
  9266. +
  9267. +module_init(bcm2835_cpufreq_module_init);
  9268. +module_exit(bcm2835_cpufreq_module_exit);
  9269. diff -Nur linux-3.15/drivers/cpufreq/Kconfig.arm linux-rpi/drivers/cpufreq/Kconfig.arm
  9270. --- linux-3.15/drivers/cpufreq/Kconfig.arm 2014-06-08 20:19:54.000000000 +0200
  9271. +++ linux-rpi/drivers/cpufreq/Kconfig.arm 2014-06-11 21:05:19.000000000 +0200
  9272. @@ -240,6 +240,14 @@
  9273. help
  9274. This adds the CPUFreq driver support for SPEAr SOCs.
  9275. +config ARM_BCM2835_CPUFREQ
  9276. + bool "BCM2835 Driver"
  9277. + default y
  9278. + help
  9279. + This adds the CPUFreq driver for BCM2835
  9280. +
  9281. + If in doubt, say N.
  9282. +
  9283. config ARM_TEGRA_CPUFREQ
  9284. bool "TEGRA CPUFreq support"
  9285. depends on ARCH_TEGRA
  9286. diff -Nur linux-3.15/drivers/cpufreq/Makefile linux-rpi/drivers/cpufreq/Makefile
  9287. --- linux-3.15/drivers/cpufreq/Makefile 2014-06-08 20:19:54.000000000 +0200
  9288. +++ linux-rpi/drivers/cpufreq/Makefile 2014-06-11 21:05:19.000000000 +0200
  9289. @@ -73,6 +73,7 @@
  9290. obj-$(CONFIG_ARM_SA1100_CPUFREQ) += sa1100-cpufreq.o
  9291. obj-$(CONFIG_ARM_SA1110_CPUFREQ) += sa1110-cpufreq.o
  9292. obj-$(CONFIG_ARM_SPEAR_CPUFREQ) += spear-cpufreq.o
  9293. +obj-$(CONFIG_ARM_BCM2835_CPUFREQ) += bcm2835-cpufreq.o
  9294. obj-$(CONFIG_ARM_TEGRA_CPUFREQ) += tegra-cpufreq.o
  9295. obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
  9296. diff -Nur linux-3.15/drivers/dma/bcm2708-dmaengine.c linux-rpi/drivers/dma/bcm2708-dmaengine.c
  9297. --- linux-3.15/drivers/dma/bcm2708-dmaengine.c 1970-01-01 01:00:00.000000000 +0100
  9298. +++ linux-rpi/drivers/dma/bcm2708-dmaengine.c 2014-06-11 21:05:19.000000000 +0200
  9299. @@ -0,0 +1,588 @@
  9300. +/*
  9301. + * BCM2708 DMA engine support
  9302. + *
  9303. + * This driver only supports cyclic DMA transfers
  9304. + * as needed for the I2S module.
  9305. + *
  9306. + * Author: Florian Meier <florian.meier@koalo.de>
  9307. + * Copyright 2013
  9308. + *
  9309. + * Based on
  9310. + * OMAP DMAengine support by Russell King
  9311. + *
  9312. + * BCM2708 DMA Driver
  9313. + * Copyright (C) 2010 Broadcom
  9314. + *
  9315. + * Raspberry Pi PCM I2S ALSA Driver
  9316. + * Copyright (c) by Phil Poole 2013
  9317. + *
  9318. + * MARVELL MMP Peripheral DMA Driver
  9319. + * Copyright 2012 Marvell International Ltd.
  9320. + *
  9321. + * This program is free software; you can redistribute it and/or modify
  9322. + * it under the terms of the GNU General Public License as published by
  9323. + * the Free Software Foundation; either version 2 of the License, or
  9324. + * (at your option) any later version.
  9325. + *
  9326. + * This program is distributed in the hope that it will be useful,
  9327. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9328. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9329. + * GNU General Public License for more details.
  9330. + */
  9331. +#include <linux/dmaengine.h>
  9332. +#include <linux/dma-mapping.h>
  9333. +#include <linux/err.h>
  9334. +#include <linux/init.h>
  9335. +#include <linux/interrupt.h>
  9336. +#include <linux/list.h>
  9337. +#include <linux/module.h>
  9338. +#include <linux/platform_device.h>
  9339. +#include <linux/slab.h>
  9340. +#include <linux/io.h>
  9341. +#include <linux/spinlock.h>
  9342. +#include <linux/irq.h>
  9343. +
  9344. +#include "virt-dma.h"
  9345. +
  9346. +#include <mach/dma.h>
  9347. +#include <mach/irqs.h>
  9348. +
  9349. +struct bcm2708_dmadev {
  9350. + struct dma_device ddev;
  9351. + spinlock_t lock;
  9352. + void __iomem *base;
  9353. + struct device_dma_parameters dma_parms;
  9354. +};
  9355. +
  9356. +struct bcm2708_chan {
  9357. + struct virt_dma_chan vc;
  9358. + struct list_head node;
  9359. +
  9360. + struct dma_slave_config cfg;
  9361. + bool cyclic;
  9362. +
  9363. + int ch;
  9364. + struct bcm2708_desc *desc;
  9365. +
  9366. + void __iomem *chan_base;
  9367. + int irq_number;
  9368. +};
  9369. +
  9370. +struct bcm2708_desc {
  9371. + struct virt_dma_desc vd;
  9372. + enum dma_transfer_direction dir;
  9373. +
  9374. + unsigned int control_block_size;
  9375. + struct bcm2708_dma_cb *control_block_base;
  9376. + dma_addr_t control_block_base_phys;
  9377. +
  9378. + unsigned frames;
  9379. + size_t size;
  9380. +};
  9381. +
  9382. +#define BCM2708_DMA_DATA_TYPE_S8 1
  9383. +#define BCM2708_DMA_DATA_TYPE_S16 2
  9384. +#define BCM2708_DMA_DATA_TYPE_S32 4
  9385. +#define BCM2708_DMA_DATA_TYPE_S128 16
  9386. +
  9387. +static inline struct bcm2708_dmadev *to_bcm2708_dma_dev(struct dma_device *d)
  9388. +{
  9389. + return container_of(d, struct bcm2708_dmadev, ddev);
  9390. +}
  9391. +
  9392. +static inline struct bcm2708_chan *to_bcm2708_dma_chan(struct dma_chan *c)
  9393. +{
  9394. + return container_of(c, struct bcm2708_chan, vc.chan);
  9395. +}
  9396. +
  9397. +static inline struct bcm2708_desc *to_bcm2708_dma_desc(
  9398. + struct dma_async_tx_descriptor *t)
  9399. +{
  9400. + return container_of(t, struct bcm2708_desc, vd.tx);
  9401. +}
  9402. +
  9403. +static void bcm2708_dma_desc_free(struct virt_dma_desc *vd)
  9404. +{
  9405. + struct bcm2708_desc *desc = container_of(vd, struct bcm2708_desc, vd);
  9406. + dma_free_coherent(desc->vd.tx.chan->device->dev,
  9407. + desc->control_block_size,
  9408. + desc->control_block_base,
  9409. + desc->control_block_base_phys);
  9410. + kfree(desc);
  9411. +}
  9412. +
  9413. +static void bcm2708_dma_start_desc(struct bcm2708_chan *c)
  9414. +{
  9415. + struct virt_dma_desc *vd = vchan_next_desc(&c->vc);
  9416. + struct bcm2708_desc *d;
  9417. +
  9418. + if (!vd) {
  9419. + c->desc = NULL;
  9420. + return;
  9421. + }
  9422. +
  9423. + list_del(&vd->node);
  9424. +
  9425. + c->desc = d = to_bcm2708_dma_desc(&vd->tx);
  9426. +
  9427. + bcm_dma_start(c->chan_base, d->control_block_base_phys);
  9428. +}
  9429. +
  9430. +static irqreturn_t bcm2708_dma_callback(int irq, void *data)
  9431. +{
  9432. + struct bcm2708_chan *c = data;
  9433. + struct bcm2708_desc *d;
  9434. + unsigned long flags;
  9435. +
  9436. + spin_lock_irqsave(&c->vc.lock, flags);
  9437. +
  9438. + /* Acknowledge interrupt */
  9439. + writel(BCM2708_DMA_INT, c->chan_base + BCM2708_DMA_CS);
  9440. +
  9441. + d = c->desc;
  9442. +
  9443. + if (d) {
  9444. + /* TODO Only works for cyclic DMA */
  9445. + vchan_cyclic_callback(&d->vd);
  9446. + }
  9447. +
  9448. + /* Keep the DMA engine running */
  9449. + dsb(); /* ARM synchronization barrier */
  9450. + writel(BCM2708_DMA_ACTIVE, c->chan_base + BCM2708_DMA_CS);
  9451. +
  9452. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9453. +
  9454. + return IRQ_HANDLED;
  9455. +}
  9456. +
  9457. +static int bcm2708_dma_alloc_chan_resources(struct dma_chan *chan)
  9458. +{
  9459. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9460. +
  9461. + return request_irq(c->irq_number,
  9462. + bcm2708_dma_callback, 0, "DMA IRQ", c);
  9463. +}
  9464. +
  9465. +static void bcm2708_dma_free_chan_resources(struct dma_chan *chan)
  9466. +{
  9467. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9468. +
  9469. + vchan_free_chan_resources(&c->vc);
  9470. + free_irq(c->irq_number, c);
  9471. +
  9472. + dev_dbg(c->vc.chan.device->dev, "Freeing DMA channel %u\n", c->ch);
  9473. +}
  9474. +
  9475. +static size_t bcm2708_dma_desc_size(struct bcm2708_desc *d)
  9476. +{
  9477. + return d->size;
  9478. +}
  9479. +
  9480. +static size_t bcm2708_dma_desc_size_pos(struct bcm2708_desc *d, dma_addr_t addr)
  9481. +{
  9482. + unsigned i;
  9483. + size_t size;
  9484. +
  9485. + for (size = i = 0; i < d->frames; i++) {
  9486. + struct bcm2708_dma_cb *control_block =
  9487. + &d->control_block_base[i];
  9488. + size_t this_size = control_block->length;
  9489. + dma_addr_t dma;
  9490. +
  9491. + if (d->dir == DMA_DEV_TO_MEM)
  9492. + dma = control_block->dst;
  9493. + else
  9494. + dma = control_block->src;
  9495. +
  9496. + if (size)
  9497. + size += this_size;
  9498. + else if (addr >= dma && addr < dma + this_size)
  9499. + size += dma + this_size - addr;
  9500. + }
  9501. +
  9502. + return size;
  9503. +}
  9504. +
  9505. +static enum dma_status bcm2708_dma_tx_status(struct dma_chan *chan,
  9506. + dma_cookie_t cookie, struct dma_tx_state *txstate)
  9507. +{
  9508. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9509. + struct virt_dma_desc *vd;
  9510. + enum dma_status ret;
  9511. + unsigned long flags;
  9512. +
  9513. + ret = dma_cookie_status(chan, cookie, txstate);
  9514. + if (ret == DMA_COMPLETE || !txstate)
  9515. + return ret;
  9516. +
  9517. + spin_lock_irqsave(&c->vc.lock, flags);
  9518. + vd = vchan_find_desc(&c->vc, cookie);
  9519. + if (vd) {
  9520. + txstate->residue =
  9521. + bcm2708_dma_desc_size(to_bcm2708_dma_desc(&vd->tx));
  9522. + } else if (c->desc && c->desc->vd.tx.cookie == cookie) {
  9523. + struct bcm2708_desc *d = c->desc;
  9524. + dma_addr_t pos;
  9525. +
  9526. + if (d->dir == DMA_MEM_TO_DEV)
  9527. + pos = readl(c->chan_base + BCM2708_DMA_SOURCE_AD);
  9528. + else if (d->dir == DMA_DEV_TO_MEM)
  9529. + pos = readl(c->chan_base + BCM2708_DMA_DEST_AD);
  9530. + else
  9531. + pos = 0;
  9532. +
  9533. + txstate->residue = bcm2708_dma_desc_size_pos(d, pos);
  9534. + } else {
  9535. + txstate->residue = 0;
  9536. + }
  9537. +
  9538. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9539. +
  9540. + return ret;
  9541. +}
  9542. +
  9543. +static void bcm2708_dma_issue_pending(struct dma_chan *chan)
  9544. +{
  9545. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9546. + unsigned long flags;
  9547. +
  9548. + c->cyclic = true; /* Nothing else is implemented */
  9549. +
  9550. + spin_lock_irqsave(&c->vc.lock, flags);
  9551. + if (vchan_issue_pending(&c->vc) && !c->desc)
  9552. + bcm2708_dma_start_desc(c);
  9553. +
  9554. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9555. +}
  9556. +
  9557. +static struct dma_async_tx_descriptor *bcm2708_dma_prep_dma_cyclic(
  9558. + struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
  9559. + size_t period_len, enum dma_transfer_direction direction,
  9560. + unsigned long flags, void *context)
  9561. +{
  9562. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9563. + enum dma_slave_buswidth dev_width;
  9564. + struct bcm2708_desc *d;
  9565. + dma_addr_t dev_addr;
  9566. + unsigned es, sync_type;
  9567. + unsigned frame;
  9568. +
  9569. + /* Grab configuration */
  9570. + if (direction == DMA_DEV_TO_MEM) {
  9571. + dev_addr = c->cfg.src_addr;
  9572. + dev_width = c->cfg.src_addr_width;
  9573. + sync_type = BCM2708_DMA_S_DREQ;
  9574. + } else if (direction == DMA_MEM_TO_DEV) {
  9575. + dev_addr = c->cfg.dst_addr;
  9576. + dev_width = c->cfg.dst_addr_width;
  9577. + sync_type = BCM2708_DMA_D_DREQ;
  9578. + } else {
  9579. + dev_err(chan->device->dev, "%s: bad direction?\n", __func__);
  9580. + return NULL;
  9581. + }
  9582. +
  9583. + /* Bus width translates to the element size (ES) */
  9584. + switch (dev_width) {
  9585. + case DMA_SLAVE_BUSWIDTH_4_BYTES:
  9586. + es = BCM2708_DMA_DATA_TYPE_S32;
  9587. + break;
  9588. + default:
  9589. + return NULL;
  9590. + }
  9591. +
  9592. + /* Now allocate and setup the descriptor. */
  9593. + d = kzalloc(sizeof(*d), GFP_NOWAIT);
  9594. + if (!d)
  9595. + return NULL;
  9596. +
  9597. + d->dir = direction;
  9598. + d->frames = buf_len / period_len;
  9599. +
  9600. + /* Allocate memory for control blocks */
  9601. + d->control_block_size = d->frames * sizeof(struct bcm2708_dma_cb);
  9602. + d->control_block_base = dma_zalloc_coherent(chan->device->dev,
  9603. + d->control_block_size, &d->control_block_base_phys,
  9604. + GFP_NOWAIT);
  9605. +
  9606. + if (!d->control_block_base) {
  9607. + kfree(d);
  9608. + return NULL;
  9609. + }
  9610. +
  9611. + /*
  9612. + * Iterate over all frames, create a control block
  9613. + * for each frame and link them together.
  9614. + */
  9615. + for (frame = 0; frame < d->frames; frame++) {
  9616. + struct bcm2708_dma_cb *control_block =
  9617. + &d->control_block_base[frame];
  9618. +
  9619. + /* Setup adresses */
  9620. + if (d->dir == DMA_DEV_TO_MEM) {
  9621. + control_block->info = BCM2708_DMA_D_INC;
  9622. + control_block->src = dev_addr;
  9623. + control_block->dst = buf_addr + frame * period_len;
  9624. + } else {
  9625. + control_block->info = BCM2708_DMA_S_INC;
  9626. + control_block->src = buf_addr + frame * period_len;
  9627. + control_block->dst = dev_addr;
  9628. + }
  9629. +
  9630. + /* Enable interrupt */
  9631. + control_block->info |= BCM2708_DMA_INT_EN;
  9632. +
  9633. + /* Setup synchronization */
  9634. + if (sync_type != 0)
  9635. + control_block->info |= sync_type;
  9636. +
  9637. + /* Setup DREQ channel */
  9638. + if (c->cfg.slave_id != 0)
  9639. + control_block->info |=
  9640. + BCM2708_DMA_PER_MAP(c->cfg.slave_id);
  9641. +
  9642. + /* Length of a frame */
  9643. + control_block->length = period_len;
  9644. + d->size += control_block->length;
  9645. +
  9646. + /*
  9647. + * Next block is the next frame.
  9648. + * This DMA engine driver currently only supports cyclic DMA.
  9649. + * Therefore, wrap around at number of frames.
  9650. + */
  9651. + control_block->next = d->control_block_base_phys +
  9652. + sizeof(struct bcm2708_dma_cb)
  9653. + * ((frame + 1) % d->frames);
  9654. + }
  9655. +
  9656. + return vchan_tx_prep(&c->vc, &d->vd, flags);
  9657. +}
  9658. +
  9659. +static int bcm2708_dma_slave_config(struct bcm2708_chan *c,
  9660. + struct dma_slave_config *cfg)
  9661. +{
  9662. + if ((cfg->direction == DMA_DEV_TO_MEM &&
  9663. + cfg->src_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9664. + (cfg->direction == DMA_MEM_TO_DEV &&
  9665. + cfg->dst_addr_width != DMA_SLAVE_BUSWIDTH_4_BYTES) ||
  9666. + !is_slave_direction(cfg->direction)) {
  9667. + return -EINVAL;
  9668. + }
  9669. +
  9670. + c->cfg = *cfg;
  9671. +
  9672. + return 0;
  9673. +}
  9674. +
  9675. +static int bcm2708_dma_terminate_all(struct bcm2708_chan *c)
  9676. +{
  9677. + struct bcm2708_dmadev *d = to_bcm2708_dma_dev(c->vc.chan.device);
  9678. + unsigned long flags;
  9679. + int timeout = 10000;
  9680. + LIST_HEAD(head);
  9681. +
  9682. + spin_lock_irqsave(&c->vc.lock, flags);
  9683. +
  9684. + /* Prevent this channel being scheduled */
  9685. + spin_lock(&d->lock);
  9686. + list_del_init(&c->node);
  9687. + spin_unlock(&d->lock);
  9688. +
  9689. + /*
  9690. + * Stop DMA activity: we assume the callback will not be called
  9691. + * after bcm_dma_abort() returns (even if it does, it will see
  9692. + * c->desc is NULL and exit.)
  9693. + */
  9694. + if (c->desc) {
  9695. + c->desc = NULL;
  9696. + bcm_dma_abort(c->chan_base);
  9697. +
  9698. + /* Wait for stopping */
  9699. + while (timeout > 0) {
  9700. + timeout--;
  9701. + if (!(readl(c->chan_base + BCM2708_DMA_CS) &
  9702. + BCM2708_DMA_ACTIVE))
  9703. + break;
  9704. +
  9705. + cpu_relax();
  9706. + }
  9707. +
  9708. + if (timeout <= 0)
  9709. + dev_err(d->ddev.dev, "DMA transfer could not be terminated\n");
  9710. + }
  9711. +
  9712. + vchan_get_all_descriptors(&c->vc, &head);
  9713. + spin_unlock_irqrestore(&c->vc.lock, flags);
  9714. + vchan_dma_desc_free_list(&c->vc, &head);
  9715. +
  9716. + return 0;
  9717. +}
  9718. +
  9719. +static int bcm2708_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  9720. + unsigned long arg)
  9721. +{
  9722. + struct bcm2708_chan *c = to_bcm2708_dma_chan(chan);
  9723. +
  9724. + switch (cmd) {
  9725. + case DMA_SLAVE_CONFIG:
  9726. + return bcm2708_dma_slave_config(c,
  9727. + (struct dma_slave_config *)arg);
  9728. +
  9729. + case DMA_TERMINATE_ALL:
  9730. + return bcm2708_dma_terminate_all(c);
  9731. +
  9732. + default:
  9733. + return -ENXIO;
  9734. + }
  9735. +}
  9736. +
  9737. +static int bcm2708_dma_chan_init(struct bcm2708_dmadev *d, void __iomem* chan_base,
  9738. + int chan_id, int irq)
  9739. +{
  9740. + struct bcm2708_chan *c;
  9741. +
  9742. + c = devm_kzalloc(d->ddev.dev, sizeof(*c), GFP_KERNEL);
  9743. + if (!c)
  9744. + return -ENOMEM;
  9745. +
  9746. + c->vc.desc_free = bcm2708_dma_desc_free;
  9747. + vchan_init(&c->vc, &d->ddev);
  9748. + INIT_LIST_HEAD(&c->node);
  9749. +
  9750. + d->ddev.chancnt++;
  9751. +
  9752. + c->chan_base = chan_base;
  9753. + c->ch = chan_id;
  9754. + c->irq_number = irq;
  9755. +
  9756. + return 0;
  9757. +}
  9758. +
  9759. +static void bcm2708_dma_free(struct bcm2708_dmadev *od)
  9760. +{
  9761. + while (!list_empty(&od->ddev.channels)) {
  9762. + struct bcm2708_chan *c = list_first_entry(&od->ddev.channels,
  9763. + struct bcm2708_chan, vc.chan.device_node);
  9764. +
  9765. + list_del(&c->vc.chan.device_node);
  9766. + tasklet_kill(&c->vc.task);
  9767. + }
  9768. +}
  9769. +
  9770. +static int bcm2708_dma_probe(struct platform_device *pdev)
  9771. +{
  9772. + struct bcm2708_dmadev *od;
  9773. + int rc, i;
  9774. +
  9775. + if (!pdev->dev.dma_mask)
  9776. + pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
  9777. +
  9778. + rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
  9779. + if (rc)
  9780. + return rc;
  9781. + dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
  9782. +
  9783. + od = devm_kzalloc(&pdev->dev, sizeof(*od), GFP_KERNEL);
  9784. + if (!od)
  9785. + return -ENOMEM;
  9786. +
  9787. + pdev->dev.dma_parms = &od->dma_parms;
  9788. + dma_set_max_seg_size(&pdev->dev, 0x3FFFFFFF);
  9789. +
  9790. + dma_cap_set(DMA_SLAVE, od->ddev.cap_mask);
  9791. + dma_cap_set(DMA_CYCLIC, od->ddev.cap_mask);
  9792. + od->ddev.device_alloc_chan_resources = bcm2708_dma_alloc_chan_resources;
  9793. + od->ddev.device_free_chan_resources = bcm2708_dma_free_chan_resources;
  9794. + od->ddev.device_tx_status = bcm2708_dma_tx_status;
  9795. + od->ddev.device_issue_pending = bcm2708_dma_issue_pending;
  9796. + od->ddev.device_prep_dma_cyclic = bcm2708_dma_prep_dma_cyclic;
  9797. + od->ddev.device_control = bcm2708_dma_control;
  9798. + od->ddev.dev = &pdev->dev;
  9799. + INIT_LIST_HEAD(&od->ddev.channels);
  9800. + spin_lock_init(&od->lock);
  9801. +
  9802. + platform_set_drvdata(pdev, od);
  9803. +
  9804. + for (i = 0; i < 16; i++) {
  9805. + void __iomem* chan_base;
  9806. + int chan_id, irq;
  9807. +
  9808. + chan_id = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  9809. + &chan_base,
  9810. + &irq);
  9811. +
  9812. + if (chan_id < 0)
  9813. + break;
  9814. +
  9815. + rc = bcm2708_dma_chan_init(od, chan_base, chan_id, irq);
  9816. + if (rc) {
  9817. + bcm2708_dma_free(od);
  9818. + return rc;
  9819. + }
  9820. + }
  9821. +
  9822. + rc = dma_async_device_register(&od->ddev);
  9823. + if (rc) {
  9824. + dev_err(&pdev->dev,
  9825. + "Failed to register slave DMA engine device: %d\n", rc);
  9826. + bcm2708_dma_free(od);
  9827. + return rc;
  9828. + }
  9829. +
  9830. + dev_dbg(&pdev->dev, "Load BCM2708 DMA engine driver\n");
  9831. +
  9832. + return rc;
  9833. +}
  9834. +
  9835. +static int bcm2708_dma_remove(struct platform_device *pdev)
  9836. +{
  9837. + struct bcm2708_dmadev *od = platform_get_drvdata(pdev);
  9838. +
  9839. + dma_async_device_unregister(&od->ddev);
  9840. + bcm2708_dma_free(od);
  9841. +
  9842. + return 0;
  9843. +}
  9844. +
  9845. +static struct platform_driver bcm2708_dma_driver = {
  9846. + .probe = bcm2708_dma_probe,
  9847. + .remove = bcm2708_dma_remove,
  9848. + .driver = {
  9849. + .name = "bcm2708-dmaengine",
  9850. + .owner = THIS_MODULE,
  9851. + },
  9852. +};
  9853. +
  9854. +static struct platform_device *pdev;
  9855. +
  9856. +static const struct platform_device_info bcm2708_dma_dev_info = {
  9857. + .name = "bcm2708-dmaengine",
  9858. + .id = -1,
  9859. +};
  9860. +
  9861. +static int bcm2708_dma_init(void)
  9862. +{
  9863. + int rc = platform_driver_register(&bcm2708_dma_driver);
  9864. +
  9865. + if (rc == 0) {
  9866. + pdev = platform_device_register_full(&bcm2708_dma_dev_info);
  9867. + if (IS_ERR(pdev)) {
  9868. + platform_driver_unregister(&bcm2708_dma_driver);
  9869. + rc = PTR_ERR(pdev);
  9870. + }
  9871. + }
  9872. +
  9873. + return rc;
  9874. +}
  9875. +subsys_initcall(bcm2708_dma_init);
  9876. +
  9877. +static void __exit bcm2708_dma_exit(void)
  9878. +{
  9879. + platform_device_unregister(pdev);
  9880. + platform_driver_unregister(&bcm2708_dma_driver);
  9881. +}
  9882. +module_exit(bcm2708_dma_exit);
  9883. +
  9884. +MODULE_ALIAS("platform:bcm2708-dma");
  9885. +MODULE_DESCRIPTION("BCM2708 DMA engine driver");
  9886. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  9887. +MODULE_LICENSE("GPL v2");
  9888. diff -Nur linux-3.15/drivers/dma/Kconfig linux-rpi/drivers/dma/Kconfig
  9889. --- linux-3.15/drivers/dma/Kconfig 2014-06-08 20:19:54.000000000 +0200
  9890. +++ linux-rpi/drivers/dma/Kconfig 2014-06-11 21:05:19.000000000 +0200
  9891. @@ -312,6 +312,12 @@
  9892. select DMA_ENGINE
  9893. select DMA_VIRTUAL_CHANNELS
  9894. +config DMA_BCM2708
  9895. + tristate "BCM2708 DMA engine support"
  9896. + depends on MACH_BCM2708
  9897. + select DMA_ENGINE
  9898. + select DMA_VIRTUAL_CHANNELS
  9899. +
  9900. config TI_CPPI41
  9901. tristate "AM33xx CPPI41 DMA support"
  9902. depends on ARCH_OMAP
  9903. diff -Nur linux-3.15/drivers/dma/Makefile linux-rpi/drivers/dma/Makefile
  9904. --- linux-3.15/drivers/dma/Makefile 2014-06-08 20:19:54.000000000 +0200
  9905. +++ linux-rpi/drivers/dma/Makefile 2014-06-11 21:05:19.000000000 +0200
  9906. @@ -39,6 +39,7 @@
  9907. obj-$(CONFIG_MMP_TDMA) += mmp_tdma.o
  9908. obj-$(CONFIG_DMA_OMAP) += omap-dma.o
  9909. obj-$(CONFIG_DMA_BCM2835) += bcm2835-dma.o
  9910. +obj-$(CONFIG_DMA_BCM2708) += bcm2708-dmaengine.o
  9911. obj-$(CONFIG_MMP_PDMA) += mmp_pdma.o
  9912. obj-$(CONFIG_DMA_JZ4740) += dma-jz4740.o
  9913. obj-$(CONFIG_TI_CPPI41) += cppi41.o
  9914. diff -Nur linux-3.15/drivers/hwmon/bcm2835-hwmon.c linux-rpi/drivers/hwmon/bcm2835-hwmon.c
  9915. --- linux-3.15/drivers/hwmon/bcm2835-hwmon.c 1970-01-01 01:00:00.000000000 +0100
  9916. +++ linux-rpi/drivers/hwmon/bcm2835-hwmon.c 2014-06-11 21:03:30.000000000 +0200
  9917. @@ -0,0 +1,219 @@
  9918. +/*****************************************************************************
  9919. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  9920. +*
  9921. +* Unless you and Broadcom execute a separate written software license
  9922. +* agreement governing use of this software, this software is licensed to you
  9923. +* under the terms of the GNU General Public License version 2, available at
  9924. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  9925. +*
  9926. +* Notwithstanding the above, under no circumstances may you combine this
  9927. +* software in any way with any other Broadcom software provided under a
  9928. +* license other than the GPL, without Broadcom's express prior written
  9929. +* consent.
  9930. +*****************************************************************************/
  9931. +
  9932. +#include <linux/kernel.h>
  9933. +#include <linux/module.h>
  9934. +#include <linux/init.h>
  9935. +#include <linux/hwmon.h>
  9936. +#include <linux/hwmon-sysfs.h>
  9937. +#include <linux/platform_device.h>
  9938. +#include <linux/sysfs.h>
  9939. +#include <mach/vcio.h>
  9940. +#include <linux/slab.h>
  9941. +#include <linux/err.h>
  9942. +
  9943. +#define MODULE_NAME "bcm2835_hwmon"
  9944. +
  9945. +/*#define HWMON_DEBUG_ENABLE*/
  9946. +
  9947. +#ifdef HWMON_DEBUG_ENABLE
  9948. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  9949. +#else
  9950. +#define print_debug(fmt,...)
  9951. +#endif
  9952. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  9953. +#define print_info(fmt,...) printk(KERN_INFO "%s: "fmt"\n", MODULE_NAME, ##__VA_ARGS__)
  9954. +
  9955. +#define VC_TAG_GET_TEMP 0x00030006
  9956. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  9957. +
  9958. +/* --- STRUCTS --- */
  9959. +struct bcm2835_hwmon_data {
  9960. + struct device *hwmon_dev;
  9961. +};
  9962. +
  9963. +/* tag part of the message */
  9964. +struct vc_msg_tag {
  9965. + uint32_t tag_id; /* the tag ID for the temperature */
  9966. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  9967. + uint32_t request_code; /* identifies message as a request (should be 0) */
  9968. + uint32_t id; /* extra ID field (should be 0) */
  9969. + uint32_t val; /* returned value of the temperature */
  9970. +};
  9971. +
  9972. +/* message structure to be sent to videocore */
  9973. +struct vc_msg {
  9974. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  9975. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  9976. + struct vc_msg_tag tag; /* the tag structure above to make */
  9977. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  9978. +};
  9979. +
  9980. +typedef enum {
  9981. + TEMP,
  9982. + MAX_TEMP,
  9983. +} temp_type;
  9984. +
  9985. +/* --- PROTOTYPES --- */
  9986. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf);
  9987. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf);
  9988. +
  9989. +/* --- GLOBALS --- */
  9990. +
  9991. +static struct bcm2835_hwmon_data *bcm2835_data;
  9992. +static struct platform_driver bcm2835_hwmon_driver;
  9993. +
  9994. +static SENSOR_DEVICE_ATTR(name, S_IRUGO,bcm2835_get_name,NULL,0);
  9995. +static SENSOR_DEVICE_ATTR(temp1_input,S_IRUGO,bcm2835_get_temp,NULL,TEMP);
  9996. +static SENSOR_DEVICE_ATTR(temp1_max,S_IRUGO,bcm2835_get_temp,NULL,MAX_TEMP);
  9997. +
  9998. +static struct attribute* bcm2835_attributes[] = {
  9999. + &sensor_dev_attr_name.dev_attr.attr,
  10000. + &sensor_dev_attr_temp1_input.dev_attr.attr,
  10001. + &sensor_dev_attr_temp1_max.dev_attr.attr,
  10002. + NULL,
  10003. +};
  10004. +
  10005. +static struct attribute_group bcm2835_attr_group = {
  10006. + .attrs = bcm2835_attributes,
  10007. +};
  10008. +
  10009. +/* --- FUNCTIONS --- */
  10010. +
  10011. +static ssize_t bcm2835_get_name(struct device *dev, struct device_attribute *attr, char *buf)
  10012. +{
  10013. + return sprintf(buf,"bcm2835_hwmon\n");
  10014. +}
  10015. +
  10016. +static ssize_t bcm2835_get_temp(struct device *dev, struct device_attribute *attr, char *buf)
  10017. +{
  10018. + struct vc_msg msg;
  10019. + int result;
  10020. + uint temp = 0;
  10021. + int index = ((struct sensor_device_attribute*)to_sensor_dev_attr(attr))->index;
  10022. +
  10023. + print_debug("IN");
  10024. +
  10025. + /* wipe all previous message data */
  10026. + memset(&msg, 0, sizeof msg);
  10027. +
  10028. + /* determine the message type */
  10029. + if(index == TEMP)
  10030. + msg.tag.tag_id = VC_TAG_GET_TEMP;
  10031. + else if (index == MAX_TEMP)
  10032. + msg.tag.tag_id = VC_TAG_GET_MAX_TEMP;
  10033. + else
  10034. + {
  10035. + print_debug("Unknown temperature message!");
  10036. + return -EINVAL;
  10037. + }
  10038. +
  10039. + msg.msg_size = sizeof msg;
  10040. + msg.tag.buffer_size = 8;
  10041. +
  10042. + /* send the message */
  10043. + result = bcm_mailbox_property(&msg, sizeof msg);
  10044. +
  10045. + /* check if it was all ok and return the rate in milli degrees C */
  10046. + if (result == 0 && (msg.request_code & 0x80000000))
  10047. + temp = (uint)msg.tag.val;
  10048. + #ifdef HWMON_DEBUG_ENABLE
  10049. + else
  10050. + print_debug("Failed to get temperature!");
  10051. + #endif
  10052. + print_debug("Got temperature as %u",temp);
  10053. + print_debug("OUT");
  10054. + return sprintf(buf, "%u\n", temp);
  10055. +}
  10056. +
  10057. +
  10058. +static int bcm2835_hwmon_probe(struct platform_device *pdev)
  10059. +{
  10060. + int err;
  10061. +
  10062. + print_debug("IN");
  10063. + print_debug("HWMON Driver has been probed!");
  10064. +
  10065. + /* check that the device isn't null!*/
  10066. + if(pdev == NULL)
  10067. + {
  10068. + print_debug("Platform device is empty!");
  10069. + return -ENODEV;
  10070. + }
  10071. +
  10072. + /* allocate memory for neccessary data */
  10073. + bcm2835_data = kzalloc(sizeof(struct bcm2835_hwmon_data),GFP_KERNEL);
  10074. + if(!bcm2835_data)
  10075. + {
  10076. + print_debug("Unable to allocate memory for hwmon data!");
  10077. + err = -ENOMEM;
  10078. + goto kzalloc_error;
  10079. + }
  10080. +
  10081. + /* create the sysfs files */
  10082. + if(sysfs_create_group(&pdev->dev.kobj, &bcm2835_attr_group))
  10083. + {
  10084. + print_debug("Unable to create sysfs files!");
  10085. + err = -EFAULT;
  10086. + goto sysfs_error;
  10087. + }
  10088. +
  10089. + /* register the hwmon device */
  10090. + bcm2835_data->hwmon_dev = hwmon_device_register(&pdev->dev);
  10091. + if (IS_ERR(bcm2835_data->hwmon_dev))
  10092. + {
  10093. + err = PTR_ERR(bcm2835_data->hwmon_dev);
  10094. + goto hwmon_error;
  10095. + }
  10096. + print_debug("OUT");
  10097. + return 0;
  10098. +
  10099. + /* error goto's */
  10100. + hwmon_error:
  10101. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10102. +
  10103. + sysfs_error:
  10104. + kfree(bcm2835_data);
  10105. +
  10106. + kzalloc_error:
  10107. +
  10108. + return err;
  10109. +
  10110. +}
  10111. +
  10112. +static int bcm2835_hwmon_remove(struct platform_device *pdev)
  10113. +{
  10114. + print_debug("IN");
  10115. + hwmon_device_unregister(bcm2835_data->hwmon_dev);
  10116. +
  10117. + sysfs_remove_group(&pdev->dev.kobj, &bcm2835_attr_group);
  10118. + print_debug("OUT");
  10119. + return 0;
  10120. +}
  10121. +
  10122. +/* Hwmon Driver */
  10123. +static struct platform_driver bcm2835_hwmon_driver = {
  10124. + .probe = bcm2835_hwmon_probe,
  10125. + .remove = bcm2835_hwmon_remove,
  10126. + .driver = {
  10127. + .name = "bcm2835_hwmon",
  10128. + .owner = THIS_MODULE,
  10129. + },
  10130. +};
  10131. +
  10132. +MODULE_LICENSE("GPL");
  10133. +MODULE_AUTHOR("Dorian Peake");
  10134. +MODULE_DESCRIPTION("HW Monitor driver for bcm2835 chip");
  10135. +
  10136. +module_platform_driver(bcm2835_hwmon_driver);
  10137. diff -Nur linux-3.15/drivers/hwmon/Kconfig linux-rpi/drivers/hwmon/Kconfig
  10138. --- linux-3.15/drivers/hwmon/Kconfig 2014-06-08 20:19:54.000000000 +0200
  10139. +++ linux-rpi/drivers/hwmon/Kconfig 2014-06-11 21:05:19.000000000 +0200
  10140. @@ -1602,6 +1602,16 @@
  10141. This driver provides support for the Ultra45 workstation environmental
  10142. sensors.
  10143. +config SENSORS_BCM2835
  10144. + depends on THERMAL_BCM2835=n
  10145. + tristate "Broadcom BCM2835 HWMON Driver"
  10146. + help
  10147. + If you say yes here you get support for the hardware
  10148. + monitoring features of the BCM2835 Chip
  10149. +
  10150. + This driver can also be built as a module. If so, the module
  10151. + will be called bcm2835-hwmon.
  10152. +
  10153. if ACPI
  10154. comment "ACPI drivers"
  10155. diff -Nur linux-3.15/drivers/hwmon/Makefile linux-rpi/drivers/hwmon/Makefile
  10156. --- linux-3.15/drivers/hwmon/Makefile 2014-06-08 20:19:54.000000000 +0200
  10157. +++ linux-rpi/drivers/hwmon/Makefile 2014-06-11 21:05:19.000000000 +0200
  10158. @@ -146,6 +146,7 @@
  10159. obj-$(CONFIG_SENSORS_W83L786NG) += w83l786ng.o
  10160. obj-$(CONFIG_SENSORS_WM831X) += wm831x-hwmon.o
  10161. obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
  10162. +obj-$(CONFIG_SENSORS_BCM2835) += bcm2835-hwmon.o
  10163. obj-$(CONFIG_PMBUS) += pmbus/
  10164. diff -Nur linux-3.15/drivers/i2c/busses/i2c-bcm2708.c linux-rpi/drivers/i2c/busses/i2c-bcm2708.c
  10165. --- linux-3.15/drivers/i2c/busses/i2c-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  10166. +++ linux-rpi/drivers/i2c/busses/i2c-bcm2708.c 2014-06-11 21:05:19.000000000 +0200
  10167. @@ -0,0 +1,448 @@
  10168. +/*
  10169. + * Driver for Broadcom BCM2708 BSC Controllers
  10170. + *
  10171. + * Copyright (C) 2012 Chris Boot & Frank Buss
  10172. + *
  10173. + * This driver is inspired by:
  10174. + * i2c-ocores.c, by Peter Korsgaard <jacmet@sunsite.dk>
  10175. + *
  10176. + * This program is free software; you can redistribute it and/or modify
  10177. + * it under the terms of the GNU General Public License as published by
  10178. + * the Free Software Foundation; either version 2 of the License, or
  10179. + * (at your option) any later version.
  10180. + *
  10181. + * This program is distributed in the hope that it will be useful,
  10182. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10183. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10184. + * GNU General Public License for more details.
  10185. + *
  10186. + * You should have received a copy of the GNU General Public License
  10187. + * along with this program; if not, write to the Free Software
  10188. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  10189. + */
  10190. +
  10191. +#include <linux/kernel.h>
  10192. +#include <linux/module.h>
  10193. +#include <linux/spinlock.h>
  10194. +#include <linux/clk.h>
  10195. +#include <linux/err.h>
  10196. +#include <linux/platform_device.h>
  10197. +#include <linux/io.h>
  10198. +#include <linux/slab.h>
  10199. +#include <linux/i2c.h>
  10200. +#include <linux/interrupt.h>
  10201. +#include <linux/sched.h>
  10202. +#include <linux/wait.h>
  10203. +
  10204. +/* BSC register offsets */
  10205. +#define BSC_C 0x00
  10206. +#define BSC_S 0x04
  10207. +#define BSC_DLEN 0x08
  10208. +#define BSC_A 0x0c
  10209. +#define BSC_FIFO 0x10
  10210. +#define BSC_DIV 0x14
  10211. +#define BSC_DEL 0x18
  10212. +#define BSC_CLKT 0x1c
  10213. +
  10214. +/* Bitfields in BSC_C */
  10215. +#define BSC_C_I2CEN 0x00008000
  10216. +#define BSC_C_INTR 0x00000400
  10217. +#define BSC_C_INTT 0x00000200
  10218. +#define BSC_C_INTD 0x00000100
  10219. +#define BSC_C_ST 0x00000080
  10220. +#define BSC_C_CLEAR_1 0x00000020
  10221. +#define BSC_C_CLEAR_2 0x00000010
  10222. +#define BSC_C_READ 0x00000001
  10223. +
  10224. +/* Bitfields in BSC_S */
  10225. +#define BSC_S_CLKT 0x00000200
  10226. +#define BSC_S_ERR 0x00000100
  10227. +#define BSC_S_RXF 0x00000080
  10228. +#define BSC_S_TXE 0x00000040
  10229. +#define BSC_S_RXD 0x00000020
  10230. +#define BSC_S_TXD 0x00000010
  10231. +#define BSC_S_RXR 0x00000008
  10232. +#define BSC_S_TXW 0x00000004
  10233. +#define BSC_S_DONE 0x00000002
  10234. +#define BSC_S_TA 0x00000001
  10235. +
  10236. +#define I2C_TIMEOUT_MS 150
  10237. +
  10238. +#define DRV_NAME "bcm2708_i2c"
  10239. +
  10240. +static unsigned int baudrate = CONFIG_I2C_BCM2708_BAUDRATE;
  10241. +module_param(baudrate, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
  10242. +MODULE_PARM_DESC(baudrate, "The I2C baudrate");
  10243. +
  10244. +static bool combined = false;
  10245. +module_param(combined, bool, 0644);
  10246. +MODULE_PARM_DESC(combined, "Use combined transactions");
  10247. +
  10248. +struct bcm2708_i2c {
  10249. + struct i2c_adapter adapter;
  10250. +
  10251. + spinlock_t lock;
  10252. + void __iomem *base;
  10253. + int irq;
  10254. + struct clk *clk;
  10255. +
  10256. + struct completion done;
  10257. +
  10258. + struct i2c_msg *msg;
  10259. + int pos;
  10260. + int nmsgs;
  10261. + bool error;
  10262. +};
  10263. +
  10264. +/*
  10265. + * This function sets the ALT mode on the I2C pins so that we can use them with
  10266. + * the BSC hardware.
  10267. + *
  10268. + * FIXME: This is a hack. Use pinmux / pinctrl.
  10269. + */
  10270. +static void bcm2708_i2c_init_pinmode(int id)
  10271. +{
  10272. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  10273. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  10274. +
  10275. + int pin;
  10276. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  10277. +
  10278. + BUG_ON(id != 0 && id != 1);
  10279. + /* BSC0 is on GPIO 0 & 1, BSC1 is on GPIO 2 & 3 */
  10280. + for (pin = id*2+0; pin <= id*2+1; pin++) {
  10281. +printk("bcm2708_i2c_init_pinmode(%d,%d)\n", id, pin);
  10282. + INP_GPIO(pin); /* set mode to GPIO input first */
  10283. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  10284. + }
  10285. +
  10286. + iounmap(gpio);
  10287. +
  10288. +#undef INP_GPIO
  10289. +#undef SET_GPIO_ALT
  10290. +}
  10291. +
  10292. +static inline u32 bcm2708_rd(struct bcm2708_i2c *bi, unsigned reg)
  10293. +{
  10294. + return readl(bi->base + reg);
  10295. +}
  10296. +
  10297. +static inline void bcm2708_wr(struct bcm2708_i2c *bi, unsigned reg, u32 val)
  10298. +{
  10299. + writel(val, bi->base + reg);
  10300. +}
  10301. +
  10302. +static inline void bcm2708_bsc_reset(struct bcm2708_i2c *bi)
  10303. +{
  10304. + bcm2708_wr(bi, BSC_C, 0);
  10305. + bcm2708_wr(bi, BSC_S, BSC_S_CLKT | BSC_S_ERR | BSC_S_DONE);
  10306. +}
  10307. +
  10308. +static inline void bcm2708_bsc_fifo_drain(struct bcm2708_i2c *bi)
  10309. +{
  10310. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_RXD) && (bi->pos < bi->msg->len))
  10311. + bi->msg->buf[bi->pos++] = bcm2708_rd(bi, BSC_FIFO);
  10312. +}
  10313. +
  10314. +static inline void bcm2708_bsc_fifo_fill(struct bcm2708_i2c *bi)
  10315. +{
  10316. + while ((bcm2708_rd(bi, BSC_S) & BSC_S_TXD) && (bi->pos < bi->msg->len))
  10317. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10318. +}
  10319. +
  10320. +static inline void bcm2708_bsc_setup(struct bcm2708_i2c *bi)
  10321. +{
  10322. + unsigned long bus_hz;
  10323. + u32 cdiv, s;
  10324. + u32 c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_ST | BSC_C_CLEAR_1;
  10325. +
  10326. + bus_hz = clk_get_rate(bi->clk);
  10327. + cdiv = bus_hz / baudrate;
  10328. + if (cdiv > 0xffff)
  10329. + cdiv = 0xffff;
  10330. +
  10331. + if (bi->msg->flags & I2C_M_RD)
  10332. + c |= BSC_C_INTR | BSC_C_READ;
  10333. + else
  10334. + c |= BSC_C_INTT;
  10335. +
  10336. + bcm2708_wr(bi, BSC_DIV, cdiv);
  10337. + bcm2708_wr(bi, BSC_A, bi->msg->addr);
  10338. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10339. + if (combined)
  10340. + {
  10341. + /* Do the next two messages meet combined transaction criteria?
  10342. + - Current message is a write, next message is a read
  10343. + - Both messages to same slave address
  10344. + - Write message can fit inside FIFO (16 bytes or less) */
  10345. + if ( (bi->nmsgs > 1) &&
  10346. + !(bi->msg[0].flags & I2C_M_RD) && (bi->msg[1].flags & I2C_M_RD) &&
  10347. + (bi->msg[0].addr == bi->msg[1].addr) && (bi->msg[0].len <= 16)) {
  10348. + /* Fill FIFO with entire write message (16 byte FIFO) */
  10349. + while (bi->pos < bi->msg->len)
  10350. + bcm2708_wr(bi, BSC_FIFO, bi->msg->buf[bi->pos++]);
  10351. + /* Start write transfer (no interrupts, don't clear FIFO) */
  10352. + bcm2708_wr(bi, BSC_C, BSC_C_I2CEN | BSC_C_ST);
  10353. + /* poll for transfer start bit (should only take 1-20 polls) */
  10354. + do {
  10355. + s = bcm2708_rd(bi, BSC_S);
  10356. + } while (!(s & (BSC_S_TA | BSC_S_ERR | BSC_S_CLKT | BSC_S_DONE)));
  10357. + /* Send next read message before the write transfer finishes. */
  10358. + bi->nmsgs--;
  10359. + bi->msg++;
  10360. + bi->pos = 0;
  10361. + bcm2708_wr(bi, BSC_DLEN, bi->msg->len);
  10362. + c = BSC_C_I2CEN | BSC_C_INTD | BSC_C_INTR | BSC_C_ST | BSC_C_READ;
  10363. + }
  10364. + }
  10365. + bcm2708_wr(bi, BSC_C, c);
  10366. +}
  10367. +
  10368. +static irqreturn_t bcm2708_i2c_interrupt(int irq, void *dev_id)
  10369. +{
  10370. + struct bcm2708_i2c *bi = dev_id;
  10371. + bool handled = true;
  10372. + u32 s;
  10373. +
  10374. + spin_lock(&bi->lock);
  10375. +
  10376. + /* we may see camera interrupts on the "other" I2C channel
  10377. + Just return if we've not sent anything */
  10378. + if (!bi->nmsgs || !bi->msg )
  10379. + goto early_exit;
  10380. +
  10381. + s = bcm2708_rd(bi, BSC_S);
  10382. +
  10383. + if (s & (BSC_S_CLKT | BSC_S_ERR)) {
  10384. + bcm2708_bsc_reset(bi);
  10385. + bi->error = true;
  10386. +
  10387. + /* wake up our bh */
  10388. + complete(&bi->done);
  10389. + } else if (s & BSC_S_DONE) {
  10390. + bi->nmsgs--;
  10391. +
  10392. + if (bi->msg->flags & I2C_M_RD)
  10393. + bcm2708_bsc_fifo_drain(bi);
  10394. +
  10395. + bcm2708_bsc_reset(bi);
  10396. +
  10397. + if (bi->nmsgs) {
  10398. + /* advance to next message */
  10399. + bi->msg++;
  10400. + bi->pos = 0;
  10401. + bcm2708_bsc_setup(bi);
  10402. + } else {
  10403. + /* wake up our bh */
  10404. + complete(&bi->done);
  10405. + }
  10406. + } else if (s & BSC_S_TXW) {
  10407. + bcm2708_bsc_fifo_fill(bi);
  10408. + } else if (s & BSC_S_RXR) {
  10409. + bcm2708_bsc_fifo_drain(bi);
  10410. + } else {
  10411. + handled = false;
  10412. + }
  10413. +
  10414. +early_exit:
  10415. + spin_unlock(&bi->lock);
  10416. +
  10417. + return handled ? IRQ_HANDLED : IRQ_NONE;
  10418. +}
  10419. +
  10420. +static int bcm2708_i2c_master_xfer(struct i2c_adapter *adap,
  10421. + struct i2c_msg *msgs, int num)
  10422. +{
  10423. + struct bcm2708_i2c *bi = adap->algo_data;
  10424. + unsigned long flags;
  10425. + int ret;
  10426. +
  10427. + spin_lock_irqsave(&bi->lock, flags);
  10428. +
  10429. + reinit_completion(&bi->done);
  10430. + bi->msg = msgs;
  10431. + bi->pos = 0;
  10432. + bi->nmsgs = num;
  10433. + bi->error = false;
  10434. +
  10435. + spin_unlock_irqrestore(&bi->lock, flags);
  10436. +
  10437. + bcm2708_bsc_setup(bi);
  10438. +
  10439. + ret = wait_for_completion_timeout(&bi->done,
  10440. + msecs_to_jiffies(I2C_TIMEOUT_MS));
  10441. + if (ret == 0) {
  10442. + dev_err(&adap->dev, "transfer timed out\n");
  10443. + spin_lock_irqsave(&bi->lock, flags);
  10444. + bcm2708_bsc_reset(bi);
  10445. + spin_unlock_irqrestore(&bi->lock, flags);
  10446. + return -ETIMEDOUT;
  10447. + }
  10448. +
  10449. + return bi->error ? -EIO : num;
  10450. +}
  10451. +
  10452. +static u32 bcm2708_i2c_functionality(struct i2c_adapter *adap)
  10453. +{
  10454. + return I2C_FUNC_I2C | /*I2C_FUNC_10BIT_ADDR |*/ I2C_FUNC_SMBUS_EMUL;
  10455. +}
  10456. +
  10457. +static struct i2c_algorithm bcm2708_i2c_algorithm = {
  10458. + .master_xfer = bcm2708_i2c_master_xfer,
  10459. + .functionality = bcm2708_i2c_functionality,
  10460. +};
  10461. +
  10462. +static int bcm2708_i2c_probe(struct platform_device *pdev)
  10463. +{
  10464. + struct resource *regs;
  10465. + int irq, err = -ENOMEM;
  10466. + struct clk *clk;
  10467. + struct bcm2708_i2c *bi;
  10468. + struct i2c_adapter *adap;
  10469. + unsigned long bus_hz;
  10470. + u32 cdiv;
  10471. +
  10472. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  10473. + if (!regs) {
  10474. + dev_err(&pdev->dev, "could not get IO memory\n");
  10475. + return -ENXIO;
  10476. + }
  10477. +
  10478. + irq = platform_get_irq(pdev, 0);
  10479. + if (irq < 0) {
  10480. + dev_err(&pdev->dev, "could not get IRQ\n");
  10481. + return irq;
  10482. + }
  10483. +
  10484. + clk = clk_get(&pdev->dev, NULL);
  10485. + if (IS_ERR(clk)) {
  10486. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  10487. + return PTR_ERR(clk);
  10488. + }
  10489. +
  10490. + bcm2708_i2c_init_pinmode(pdev->id);
  10491. +
  10492. + bi = kzalloc(sizeof(*bi), GFP_KERNEL);
  10493. + if (!bi)
  10494. + goto out_clk_put;
  10495. +
  10496. + platform_set_drvdata(pdev, bi);
  10497. +
  10498. + adap = &bi->adapter;
  10499. + adap->class = I2C_CLASS_HWMON | I2C_CLASS_DDC;
  10500. + adap->algo = &bcm2708_i2c_algorithm;
  10501. + adap->algo_data = bi;
  10502. + adap->dev.parent = &pdev->dev;
  10503. + adap->nr = pdev->id;
  10504. + strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  10505. +
  10506. + switch (pdev->id) {
  10507. + case 0:
  10508. + adap->class = I2C_CLASS_HWMON;
  10509. + break;
  10510. + case 1:
  10511. + adap->class = I2C_CLASS_DDC;
  10512. + break;
  10513. + default:
  10514. + dev_err(&pdev->dev, "can only bind to BSC 0 or 1\n");
  10515. + err = -ENXIO;
  10516. + goto out_free_bi;
  10517. + }
  10518. +
  10519. + spin_lock_init(&bi->lock);
  10520. + init_completion(&bi->done);
  10521. +
  10522. + bi->base = ioremap(regs->start, resource_size(regs));
  10523. + if (!bi->base) {
  10524. + dev_err(&pdev->dev, "could not remap memory\n");
  10525. + goto out_free_bi;
  10526. + }
  10527. +
  10528. + bi->irq = irq;
  10529. + bi->clk = clk;
  10530. +
  10531. + err = request_irq(irq, bcm2708_i2c_interrupt, IRQF_SHARED,
  10532. + dev_name(&pdev->dev), bi);
  10533. + if (err) {
  10534. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  10535. + goto out_iounmap;
  10536. + }
  10537. +
  10538. + bcm2708_bsc_reset(bi);
  10539. +
  10540. + err = i2c_add_numbered_adapter(adap);
  10541. + if (err < 0) {
  10542. + dev_err(&pdev->dev, "could not add I2C adapter: %d\n", err);
  10543. + goto out_free_irq;
  10544. + }
  10545. +
  10546. + bus_hz = clk_get_rate(bi->clk);
  10547. + cdiv = bus_hz / baudrate;
  10548. + if (cdiv > 0xffff) {
  10549. + cdiv = 0xffff;
  10550. + baudrate = bus_hz / cdiv;
  10551. + }
  10552. +
  10553. + dev_info(&pdev->dev, "BSC%d Controller at 0x%08lx (irq %d) (baudrate %d)\n",
  10554. + pdev->id, (unsigned long)regs->start, irq, baudrate);
  10555. +
  10556. + return 0;
  10557. +
  10558. +out_free_irq:
  10559. + free_irq(bi->irq, bi);
  10560. +out_iounmap:
  10561. + iounmap(bi->base);
  10562. +out_free_bi:
  10563. + kfree(bi);
  10564. +out_clk_put:
  10565. + clk_put(clk);
  10566. + return err;
  10567. +}
  10568. +
  10569. +static int bcm2708_i2c_remove(struct platform_device *pdev)
  10570. +{
  10571. + struct bcm2708_i2c *bi = platform_get_drvdata(pdev);
  10572. +
  10573. + platform_set_drvdata(pdev, NULL);
  10574. +
  10575. + i2c_del_adapter(&bi->adapter);
  10576. + free_irq(bi->irq, bi);
  10577. + iounmap(bi->base);
  10578. + clk_disable(bi->clk);
  10579. + clk_put(bi->clk);
  10580. + kfree(bi);
  10581. +
  10582. + return 0;
  10583. +}
  10584. +
  10585. +static struct platform_driver bcm2708_i2c_driver = {
  10586. + .driver = {
  10587. + .name = DRV_NAME,
  10588. + .owner = THIS_MODULE,
  10589. + },
  10590. + .probe = bcm2708_i2c_probe,
  10591. + .remove = bcm2708_i2c_remove,
  10592. +};
  10593. +
  10594. +// module_platform_driver(bcm2708_i2c_driver);
  10595. +
  10596. +
  10597. +static int __init bcm2708_i2c_init(void)
  10598. +{
  10599. + return platform_driver_register(&bcm2708_i2c_driver);
  10600. +}
  10601. +
  10602. +static void __exit bcm2708_i2c_exit(void)
  10603. +{
  10604. + platform_driver_unregister(&bcm2708_i2c_driver);
  10605. +}
  10606. +
  10607. +module_init(bcm2708_i2c_init);
  10608. +module_exit(bcm2708_i2c_exit);
  10609. +
  10610. +
  10611. +
  10612. +MODULE_DESCRIPTION("BSC controller driver for Broadcom BCM2708");
  10613. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  10614. +MODULE_LICENSE("GPL v2");
  10615. +MODULE_ALIAS("platform:" DRV_NAME);
  10616. diff -Nur linux-3.15/drivers/i2c/busses/Kconfig linux-rpi/drivers/i2c/busses/Kconfig
  10617. --- linux-3.15/drivers/i2c/busses/Kconfig 2014-06-08 20:19:54.000000000 +0200
  10618. +++ linux-rpi/drivers/i2c/busses/Kconfig 2014-06-11 21:05:19.000000000 +0200
  10619. @@ -348,6 +348,25 @@
  10620. This support is also available as a module. If so, the module
  10621. will be called i2c-bcm2835.
  10622. +config I2C_BCM2708
  10623. + tristate "BCM2708 BSC"
  10624. + depends on MACH_BCM2708
  10625. + help
  10626. + Enabling this option will add BSC (Broadcom Serial Controller)
  10627. + support for the BCM2708. BSC is a Broadcom proprietary bus compatible
  10628. + with I2C/TWI/SMBus.
  10629. +
  10630. +config I2C_BCM2708_BAUDRATE
  10631. + prompt "BCM2708 I2C baudrate"
  10632. + depends on I2C_BCM2708
  10633. + int
  10634. + default 100000
  10635. + help
  10636. + Set the I2C baudrate. This will alter the default value. A
  10637. + different baudrate can be set by using a module parameter as well. If
  10638. + no parameter is provided when loading, this is the value that will be
  10639. + used.
  10640. +
  10641. config I2C_BCM_KONA
  10642. tristate "BCM Kona I2C adapter"
  10643. depends on ARCH_BCM_MOBILE
  10644. diff -Nur linux-3.15/drivers/i2c/busses/Makefile linux-rpi/drivers/i2c/busses/Makefile
  10645. --- linux-3.15/drivers/i2c/busses/Makefile 2014-06-08 20:19:54.000000000 +0200
  10646. +++ linux-rpi/drivers/i2c/busses/Makefile 2014-06-11 21:05:19.000000000 +0200
  10647. @@ -32,6 +32,7 @@
  10648. obj-$(CONFIG_I2C_AT91) += i2c-at91.o
  10649. obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  10650. obj-$(CONFIG_I2C_BCM2835) += i2c-bcm2835.o
  10651. +obj-$(CONFIG_I2C_BCM2708) += i2c-bcm2708.o
  10652. obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
  10653. obj-$(CONFIG_I2C_CADENCE) += i2c-cadence.o
  10654. obj-$(CONFIG_I2C_CBUS_GPIO) += i2c-cbus-gpio.o
  10655. diff -Nur linux-3.15/drivers/media/platform/bcm2835/bcm2835-camera.c linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c
  10656. --- linux-3.15/drivers/media/platform/bcm2835/bcm2835-camera.c 1970-01-01 01:00:00.000000000 +0100
  10657. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.c 2014-06-11 21:05:19.000000000 +0200
  10658. @@ -0,0 +1,1827 @@
  10659. +/*
  10660. + * Broadcom BM2835 V4L2 driver
  10661. + *
  10662. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  10663. + *
  10664. + * This file is subject to the terms and conditions of the GNU General Public
  10665. + * License. See the file COPYING in the main directory of this archive
  10666. + * for more details.
  10667. + *
  10668. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  10669. + * Dave Stevenson <dsteve@broadcom.com>
  10670. + * Simon Mellor <simellor@broadcom.com>
  10671. + * Luke Diamand <luked@broadcom.com>
  10672. + */
  10673. +
  10674. +#include <linux/errno.h>
  10675. +#include <linux/kernel.h>
  10676. +#include <linux/module.h>
  10677. +#include <linux/slab.h>
  10678. +#include <media/videobuf2-vmalloc.h>
  10679. +#include <media/videobuf2-dma-contig.h>
  10680. +#include <media/v4l2-device.h>
  10681. +#include <media/v4l2-ioctl.h>
  10682. +#include <media/v4l2-ctrls.h>
  10683. +#include <media/v4l2-fh.h>
  10684. +#include <media/v4l2-event.h>
  10685. +#include <media/v4l2-common.h>
  10686. +#include <linux/delay.h>
  10687. +
  10688. +#include "mmal-common.h"
  10689. +#include "mmal-encodings.h"
  10690. +#include "mmal-vchiq.h"
  10691. +#include "mmal-msg.h"
  10692. +#include "mmal-parameters.h"
  10693. +#include "bcm2835-camera.h"
  10694. +
  10695. +#define BM2835_MMAL_VERSION "0.0.2"
  10696. +#define BM2835_MMAL_MODULE_NAME "bcm2835-v4l2"
  10697. +#define MIN_WIDTH 16
  10698. +#define MIN_HEIGHT 16
  10699. +#define MAX_WIDTH 2592
  10700. +#define MAX_HEIGHT 1944
  10701. +#define MIN_BUFFER_SIZE (80*1024)
  10702. +
  10703. +#define MAX_VIDEO_MODE_WIDTH 1280
  10704. +#define MAX_VIDEO_MODE_HEIGHT 720
  10705. +
  10706. +MODULE_DESCRIPTION("Broadcom 2835 MMAL video capture");
  10707. +MODULE_AUTHOR("Vincent Sanders");
  10708. +MODULE_LICENSE("GPL");
  10709. +MODULE_VERSION(BM2835_MMAL_VERSION);
  10710. +
  10711. +int bcm2835_v4l2_debug;
  10712. +module_param_named(debug, bcm2835_v4l2_debug, int, 0644);
  10713. +MODULE_PARM_DESC(bcm2835_v4l2_debug, "Debug level 0-2");
  10714. +
  10715. +int max_video_width = MAX_VIDEO_MODE_WIDTH;
  10716. +int max_video_height = MAX_VIDEO_MODE_HEIGHT;
  10717. +module_param(max_video_width, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  10718. +MODULE_PARM_DESC(max_video_width, "Threshold for video mode");
  10719. +module_param(max_video_height, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  10720. +MODULE_PARM_DESC(max_video_height, "Threshold for video mode");
  10721. +
  10722. +/* Gstreamer bug https://bugzilla.gnome.org/show_bug.cgi?id=726521
  10723. + * v4l2src does bad (and actually wrong) things when the vidioc_enum_framesizes
  10724. + * function says type V4L2_FRMSIZE_TYPE_STEPWISE, which we do by default.
  10725. + * It's happier if we just don't say anything at all, when it then
  10726. + * sets up a load of defaults that it thinks might work.
  10727. + * If gst_v4l2src_is_broken is non-zero, then we remove the function from
  10728. + * our function table list (actually switch to an alternate set, but same
  10729. + * result).
  10730. + */
  10731. +int gst_v4l2src_is_broken = 0;
  10732. +module_param(gst_v4l2src_is_broken, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
  10733. +MODULE_PARM_DESC(gst_v4l2src_is_broken, "If non-zero, enable workaround for Gstreamer");
  10734. +
  10735. +static struct bm2835_mmal_dev *gdev; /* global device data */
  10736. +
  10737. +#define FPS_MIN 1
  10738. +#define FPS_MAX 90
  10739. +
  10740. +/* timeperframe: min/max and default */
  10741. +static const struct v4l2_fract
  10742. + tpf_min = {.numerator = 1, .denominator = FPS_MAX},
  10743. + tpf_max = {.numerator = 1, .denominator = FPS_MIN},
  10744. + tpf_default = {.numerator = 1000, .denominator = 30000};
  10745. +
  10746. +/* video formats */
  10747. +static struct mmal_fmt formats[] = {
  10748. + {
  10749. + .name = "4:2:0, packed YUV",
  10750. + .fourcc = V4L2_PIX_FMT_YUV420,
  10751. + .flags = 0,
  10752. + .mmal = MMAL_ENCODING_I420,
  10753. + .depth = 12,
  10754. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10755. + },
  10756. + {
  10757. + .name = "4:2:2, packed, YUYV",
  10758. + .fourcc = V4L2_PIX_FMT_YUYV,
  10759. + .flags = 0,
  10760. + .mmal = MMAL_ENCODING_YUYV,
  10761. + .depth = 16,
  10762. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10763. + },
  10764. + {
  10765. + .name = "RGB24 (LE)",
  10766. + .fourcc = V4L2_PIX_FMT_RGB24,
  10767. + .flags = 0,
  10768. + .mmal = MMAL_ENCODING_BGR24,
  10769. + .depth = 24,
  10770. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10771. + },
  10772. + {
  10773. + .name = "JPEG",
  10774. + .fourcc = V4L2_PIX_FMT_JPEG,
  10775. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10776. + .mmal = MMAL_ENCODING_JPEG,
  10777. + .depth = 8,
  10778. + .mmal_component = MMAL_COMPONENT_IMAGE_ENCODE,
  10779. + },
  10780. + {
  10781. + .name = "H264",
  10782. + .fourcc = V4L2_PIX_FMT_H264,
  10783. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10784. + .mmal = MMAL_ENCODING_H264,
  10785. + .depth = 8,
  10786. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  10787. + },
  10788. + {
  10789. + .name = "MJPEG",
  10790. + .fourcc = V4L2_PIX_FMT_MJPEG,
  10791. + .flags = V4L2_FMT_FLAG_COMPRESSED,
  10792. + .mmal = MMAL_ENCODING_MJPEG,
  10793. + .depth = 8,
  10794. + .mmal_component = MMAL_COMPONENT_VIDEO_ENCODE,
  10795. + },
  10796. + {
  10797. + .name = "4:2:2, packed, YVYU",
  10798. + .fourcc = V4L2_PIX_FMT_YVYU,
  10799. + .flags = 0,
  10800. + .mmal = MMAL_ENCODING_YVYU,
  10801. + .depth = 16,
  10802. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10803. + },
  10804. + {
  10805. + .name = "4:2:2, packed, VYUY",
  10806. + .fourcc = V4L2_PIX_FMT_VYUY,
  10807. + .flags = 0,
  10808. + .mmal = MMAL_ENCODING_VYUY,
  10809. + .depth = 16,
  10810. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10811. + },
  10812. + {
  10813. + .name = "4:2:2, packed, UYVY",
  10814. + .fourcc = V4L2_PIX_FMT_UYVY,
  10815. + .flags = 0,
  10816. + .mmal = MMAL_ENCODING_UYVY,
  10817. + .depth = 16,
  10818. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10819. + },
  10820. + {
  10821. + .name = "4:2:0, packed, NV12",
  10822. + .fourcc = V4L2_PIX_FMT_NV12,
  10823. + .flags = 0,
  10824. + .mmal = MMAL_ENCODING_NV12,
  10825. + .depth = 12,
  10826. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10827. + },
  10828. + {
  10829. + .name = "RGB24 (BE)",
  10830. + .fourcc = V4L2_PIX_FMT_BGR24,
  10831. + .flags = 0,
  10832. + .mmal = MMAL_ENCODING_RGB24,
  10833. + .depth = 24,
  10834. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10835. + },
  10836. + {
  10837. + .name = "4:2:0, packed YVU",
  10838. + .fourcc = V4L2_PIX_FMT_YVU420,
  10839. + .flags = 0,
  10840. + .mmal = MMAL_ENCODING_YV12,
  10841. + .depth = 12,
  10842. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10843. + },
  10844. + {
  10845. + .name = "4:2:0, packed, NV21",
  10846. + .fourcc = V4L2_PIX_FMT_NV21,
  10847. + .flags = 0,
  10848. + .mmal = MMAL_ENCODING_NV21,
  10849. + .depth = 12,
  10850. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10851. + },
  10852. + {
  10853. + .name = "RGB32 (BE)",
  10854. + .fourcc = V4L2_PIX_FMT_BGR32,
  10855. + .flags = 0,
  10856. + .mmal = MMAL_ENCODING_BGRA,
  10857. + .depth = 32,
  10858. + .mmal_component = MMAL_COMPONENT_CAMERA,
  10859. + },
  10860. +};
  10861. +
  10862. +static struct mmal_fmt *get_format(struct v4l2_format *f)
  10863. +{
  10864. + struct mmal_fmt *fmt;
  10865. + unsigned int k;
  10866. +
  10867. + for (k = 0; k < ARRAY_SIZE(formats); k++) {
  10868. + fmt = &formats[k];
  10869. + if (fmt->fourcc == f->fmt.pix.pixelformat)
  10870. + break;
  10871. + }
  10872. +
  10873. + if (k == ARRAY_SIZE(formats))
  10874. + return NULL;
  10875. +
  10876. + return &formats[k];
  10877. +}
  10878. +
  10879. +/* ------------------------------------------------------------------
  10880. + Videobuf queue operations
  10881. + ------------------------------------------------------------------*/
  10882. +
  10883. +static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
  10884. + unsigned int *nbuffers, unsigned int *nplanes,
  10885. + unsigned int sizes[], void *alloc_ctxs[])
  10886. +{
  10887. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  10888. + unsigned long size;
  10889. +
  10890. + /* refuse queue setup if port is not configured */
  10891. + if (dev->capture.port == NULL) {
  10892. + v4l2_err(&dev->v4l2_dev,
  10893. + "%s: capture port not configured\n", __func__);
  10894. + return -EINVAL;
  10895. + }
  10896. +
  10897. + size = dev->capture.port->current_buffer.size;
  10898. + if (size == 0) {
  10899. + v4l2_err(&dev->v4l2_dev,
  10900. + "%s: capture port buffer size is zero\n", __func__);
  10901. + return -EINVAL;
  10902. + }
  10903. +
  10904. + if (*nbuffers < (dev->capture.port->current_buffer.num + 2))
  10905. + *nbuffers = (dev->capture.port->current_buffer.num + 2);
  10906. +
  10907. + *nplanes = 1;
  10908. +
  10909. + sizes[0] = size;
  10910. +
  10911. + /*
  10912. + * videobuf2-vmalloc allocator is context-less so no need to set
  10913. + * alloc_ctxs array.
  10914. + */
  10915. +
  10916. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10917. + __func__, dev);
  10918. +
  10919. + return 0;
  10920. +}
  10921. +
  10922. +static int buffer_prepare(struct vb2_buffer *vb)
  10923. +{
  10924. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  10925. + unsigned long size;
  10926. +
  10927. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  10928. + __func__, dev);
  10929. +
  10930. + BUG_ON(dev->capture.port == NULL);
  10931. + BUG_ON(dev->capture.fmt == NULL);
  10932. +
  10933. + size = dev->capture.stride * dev->capture.height;
  10934. + if (vb2_plane_size(vb, 0) < size) {
  10935. + v4l2_err(&dev->v4l2_dev,
  10936. + "%s data will not fit into plane (%lu < %lu)\n",
  10937. + __func__, vb2_plane_size(vb, 0), size);
  10938. + return -EINVAL;
  10939. + }
  10940. +
  10941. + return 0;
  10942. +}
  10943. +
  10944. +static inline bool is_capturing(struct bm2835_mmal_dev *dev)
  10945. +{
  10946. + return dev->capture.camera_port ==
  10947. + &dev->
  10948. + component[MMAL_COMPONENT_CAMERA]->output[MMAL_CAMERA_PORT_CAPTURE];
  10949. +}
  10950. +
  10951. +static void buffer_cb(struct vchiq_mmal_instance *instance,
  10952. + struct vchiq_mmal_port *port,
  10953. + int status,
  10954. + struct mmal_buffer *buf,
  10955. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts)
  10956. +{
  10957. + struct bm2835_mmal_dev *dev = port->cb_ctx;
  10958. +
  10959. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  10960. + "%s: status:%d, buf:%p, length:%lu, flags %u, pts %lld\n",
  10961. + __func__, status, buf, length, mmal_flags, pts);
  10962. +
  10963. + if (status != 0) {
  10964. + /* error in transfer */
  10965. + if (buf != NULL) {
  10966. + /* there was a buffer with the error so return it */
  10967. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10968. + }
  10969. + return;
  10970. + } else if (length == 0) {
  10971. + /* stream ended */
  10972. + if (buf != NULL) {
  10973. + /* this should only ever happen if the port is
  10974. + * disabled and there are buffers still queued
  10975. + */
  10976. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
  10977. + pr_debug("Empty buffer");
  10978. + } else if (dev->capture.frame_count) {
  10979. + /* grab another frame */
  10980. + if (is_capturing(dev)) {
  10981. + pr_debug("Grab another frame");
  10982. + vchiq_mmal_port_parameter_set(
  10983. + instance,
  10984. + dev->capture.
  10985. + camera_port,
  10986. + MMAL_PARAMETER_CAPTURE,
  10987. + &dev->capture.
  10988. + frame_count,
  10989. + sizeof(dev->capture.frame_count));
  10990. + }
  10991. + } else {
  10992. + /* signal frame completion */
  10993. + complete(&dev->capture.frame_cmplt);
  10994. + }
  10995. + } else {
  10996. + if (dev->capture.frame_count) {
  10997. + if (dev->capture.vc_start_timestamp != -1 &&
  10998. + pts != 0) {
  10999. + s64 runtime_us = pts -
  11000. + dev->capture.vc_start_timestamp;
  11001. + u32 div = 0;
  11002. + u32 rem = 0;
  11003. +
  11004. + div =
  11005. + div_u64_rem(runtime_us, USEC_PER_SEC, &rem);
  11006. + buf->vb.v4l2_buf.timestamp.tv_sec =
  11007. + dev->capture.kernel_start_ts.tv_sec - 1 +
  11008. + div;
  11009. + buf->vb.v4l2_buf.timestamp.tv_usec =
  11010. + dev->capture.kernel_start_ts.tv_usec + rem;
  11011. +
  11012. + if (buf->vb.v4l2_buf.timestamp.tv_usec >=
  11013. + USEC_PER_SEC) {
  11014. + buf->vb.v4l2_buf.timestamp.tv_sec++;
  11015. + buf->vb.v4l2_buf.timestamp.tv_usec -=
  11016. + USEC_PER_SEC;
  11017. + }
  11018. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11019. + "Convert start time %d.%06d and %llu "
  11020. + "with offset %llu to %d.%06d\n",
  11021. + (int)dev->capture.kernel_start_ts.
  11022. + tv_sec,
  11023. + (int)dev->capture.kernel_start_ts.
  11024. + tv_usec,
  11025. + dev->capture.vc_start_timestamp, pts,
  11026. + (int)buf->vb.v4l2_buf.timestamp.tv_sec,
  11027. + (int)buf->vb.v4l2_buf.timestamp.
  11028. + tv_usec);
  11029. + } else {
  11030. + v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
  11031. + }
  11032. +
  11033. + vb2_set_plane_payload(&buf->vb, 0, length);
  11034. + vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
  11035. +
  11036. + if (mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS &&
  11037. + is_capturing(dev)) {
  11038. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11039. + "Grab another frame as buffer has EOS");
  11040. + vchiq_mmal_port_parameter_set(
  11041. + instance,
  11042. + dev->capture.
  11043. + camera_port,
  11044. + MMAL_PARAMETER_CAPTURE,
  11045. + &dev->capture.
  11046. + frame_count,
  11047. + sizeof(dev->capture.frame_count));
  11048. + }
  11049. + } else {
  11050. + /* signal frame completion */
  11051. + complete(&dev->capture.frame_cmplt);
  11052. + }
  11053. + }
  11054. +}
  11055. +
  11056. +static int enable_camera(struct bm2835_mmal_dev *dev)
  11057. +{
  11058. + int ret;
  11059. + if (!dev->camera_use_count) {
  11060. + ret = vchiq_mmal_component_enable(
  11061. + dev->instance,
  11062. + dev->component[MMAL_COMPONENT_CAMERA]);
  11063. + if (ret < 0) {
  11064. + v4l2_err(&dev->v4l2_dev,
  11065. + "Failed enabling camera, ret %d\n", ret);
  11066. + return -EINVAL;
  11067. + }
  11068. + }
  11069. + dev->camera_use_count++;
  11070. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11071. + &dev->v4l2_dev, "enabled camera (refcount %d)\n",
  11072. + dev->camera_use_count);
  11073. + return 0;
  11074. +}
  11075. +
  11076. +static int disable_camera(struct bm2835_mmal_dev *dev)
  11077. +{
  11078. + int ret;
  11079. + if (!dev->camera_use_count) {
  11080. + v4l2_err(&dev->v4l2_dev,
  11081. + "Disabled the camera when already disabled\n");
  11082. + return -EINVAL;
  11083. + }
  11084. + dev->camera_use_count--;
  11085. + if (!dev->camera_use_count) {
  11086. + unsigned int i = 0xFFFFFFFF;
  11087. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11088. + "Disabling camera\n");
  11089. + ret =
  11090. + vchiq_mmal_component_disable(
  11091. + dev->instance,
  11092. + dev->component[MMAL_COMPONENT_CAMERA]);
  11093. + if (ret < 0) {
  11094. + v4l2_err(&dev->v4l2_dev,
  11095. + "Failed disabling camera, ret %d\n", ret);
  11096. + return -EINVAL;
  11097. + }
  11098. + vchiq_mmal_port_parameter_set(
  11099. + dev->instance,
  11100. + &dev->component[MMAL_COMPONENT_CAMERA]->control,
  11101. + MMAL_PARAMETER_CAMERA_NUM, &i,
  11102. + sizeof(i));
  11103. + }
  11104. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11105. + "Camera refcount now %d\n", dev->camera_use_count);
  11106. + return 0;
  11107. +}
  11108. +
  11109. +static void buffer_queue(struct vb2_buffer *vb)
  11110. +{
  11111. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
  11112. + struct mmal_buffer *buf = container_of(vb, struct mmal_buffer, vb);
  11113. + int ret;
  11114. +
  11115. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11116. + "%s: dev:%p buf:%p\n", __func__, dev, buf);
  11117. +
  11118. + buf->buffer = vb2_plane_vaddr(&buf->vb, 0);
  11119. + buf->buffer_size = vb2_plane_size(&buf->vb, 0);
  11120. +
  11121. + ret = vchiq_mmal_submit_buffer(dev->instance, dev->capture.port, buf);
  11122. + if (ret < 0)
  11123. + v4l2_err(&dev->v4l2_dev, "%s: error submitting buffer\n",
  11124. + __func__);
  11125. +}
  11126. +
  11127. +static int start_streaming(struct vb2_queue *vq, unsigned int count)
  11128. +{
  11129. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11130. + int ret;
  11131. + int parameter_size;
  11132. +
  11133. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11134. + __func__, dev);
  11135. +
  11136. + /* ensure a format has actually been set */
  11137. + if (dev->capture.port == NULL)
  11138. + return -EINVAL;
  11139. +
  11140. + if (enable_camera(dev) < 0) {
  11141. + v4l2_err(&dev->v4l2_dev, "Failed to enable camera\n");
  11142. + return -EINVAL;
  11143. + }
  11144. +
  11145. + /*init_completion(&dev->capture.frame_cmplt); */
  11146. +
  11147. + /* enable frame capture */
  11148. + dev->capture.frame_count = 1;
  11149. +
  11150. + /* if the preview is not already running, wait for a few frames for AGC
  11151. + * to settle down.
  11152. + */
  11153. + if (!dev->component[MMAL_COMPONENT_PREVIEW]->enabled)
  11154. + msleep(300);
  11155. +
  11156. + /* enable the connection from camera to encoder (if applicable) */
  11157. + if (dev->capture.camera_port != dev->capture.port
  11158. + && dev->capture.camera_port) {
  11159. + ret = vchiq_mmal_port_enable(dev->instance,
  11160. + dev->capture.camera_port, NULL);
  11161. + if (ret) {
  11162. + v4l2_err(&dev->v4l2_dev,
  11163. + "Failed to enable encode tunnel - error %d\n",
  11164. + ret);
  11165. + return -1;
  11166. + }
  11167. + }
  11168. +
  11169. + /* Get VC timestamp at this point in time */
  11170. + parameter_size = sizeof(dev->capture.vc_start_timestamp);
  11171. + if (vchiq_mmal_port_parameter_get(dev->instance,
  11172. + dev->capture.camera_port,
  11173. + MMAL_PARAMETER_SYSTEM_TIME,
  11174. + &dev->capture.vc_start_timestamp,
  11175. + &parameter_size)) {
  11176. + v4l2_err(&dev->v4l2_dev,
  11177. + "Failed to get VC start time - update your VC f/w\n");
  11178. +
  11179. + /* Flag to indicate just to rely on kernel timestamps */
  11180. + dev->capture.vc_start_timestamp = -1;
  11181. + } else
  11182. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11183. + "Start time %lld size %d\n",
  11184. + dev->capture.vc_start_timestamp, parameter_size);
  11185. +
  11186. + v4l2_get_timestamp(&dev->capture.kernel_start_ts);
  11187. +
  11188. + /* enable the camera port */
  11189. + dev->capture.port->cb_ctx = dev;
  11190. + ret =
  11191. + vchiq_mmal_port_enable(dev->instance, dev->capture.port, buffer_cb);
  11192. + if (ret) {
  11193. + v4l2_err(&dev->v4l2_dev,
  11194. + "Failed to enable capture port - error %d. "
  11195. + "Disabling camera port again\n", ret);
  11196. +
  11197. + vchiq_mmal_port_disable(dev->instance,
  11198. + dev->capture.camera_port);
  11199. + if (disable_camera(dev) < 0) {
  11200. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11201. + return -EINVAL;
  11202. + }
  11203. + return -1;
  11204. + }
  11205. +
  11206. + /* capture the first frame */
  11207. + vchiq_mmal_port_parameter_set(dev->instance,
  11208. + dev->capture.camera_port,
  11209. + MMAL_PARAMETER_CAPTURE,
  11210. + &dev->capture.frame_count,
  11211. + sizeof(dev->capture.frame_count));
  11212. + return 0;
  11213. +}
  11214. +
  11215. +/* abort streaming and wait for last buffer */
  11216. +static int stop_streaming(struct vb2_queue *vq)
  11217. +{
  11218. + int ret;
  11219. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11220. +
  11221. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "%s: dev:%p\n",
  11222. + __func__, dev);
  11223. +
  11224. + init_completion(&dev->capture.frame_cmplt);
  11225. + dev->capture.frame_count = 0;
  11226. +
  11227. + /* ensure a format has actually been set */
  11228. + if (dev->capture.port == NULL)
  11229. + return -EINVAL;
  11230. +
  11231. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "stopping capturing\n");
  11232. +
  11233. + /* stop capturing frames */
  11234. + vchiq_mmal_port_parameter_set(dev->instance,
  11235. + dev->capture.camera_port,
  11236. + MMAL_PARAMETER_CAPTURE,
  11237. + &dev->capture.frame_count,
  11238. + sizeof(dev->capture.frame_count));
  11239. +
  11240. + /* wait for last frame to complete */
  11241. + ret = wait_for_completion_timeout(&dev->capture.frame_cmplt, HZ);
  11242. + if (ret <= 0)
  11243. + v4l2_err(&dev->v4l2_dev,
  11244. + "error %d waiting for frame completion\n", ret);
  11245. +
  11246. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11247. + "disabling connection\n");
  11248. +
  11249. + /* disable the connection from camera to encoder */
  11250. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.camera_port);
  11251. + if (!ret && dev->capture.camera_port != dev->capture.port) {
  11252. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11253. + "disabling port\n");
  11254. + ret = vchiq_mmal_port_disable(dev->instance, dev->capture.port);
  11255. + } else if (dev->capture.camera_port != dev->capture.port) {
  11256. + v4l2_err(&dev->v4l2_dev, "port_disable failed, error %d\n",
  11257. + ret);
  11258. + }
  11259. +
  11260. + if (disable_camera(dev) < 0) {
  11261. + v4l2_err(&dev->v4l2_dev, "Failed to disable camera");
  11262. + return -EINVAL;
  11263. + }
  11264. +
  11265. + return ret;
  11266. +}
  11267. +
  11268. +static void bm2835_mmal_lock(struct vb2_queue *vq)
  11269. +{
  11270. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11271. + mutex_lock(&dev->mutex);
  11272. +}
  11273. +
  11274. +static void bm2835_mmal_unlock(struct vb2_queue *vq)
  11275. +{
  11276. + struct bm2835_mmal_dev *dev = vb2_get_drv_priv(vq);
  11277. + mutex_unlock(&dev->mutex);
  11278. +}
  11279. +
  11280. +static struct vb2_ops bm2835_mmal_video_qops = {
  11281. + .queue_setup = queue_setup,
  11282. + .buf_prepare = buffer_prepare,
  11283. + .buf_queue = buffer_queue,
  11284. + .start_streaming = start_streaming,
  11285. + .stop_streaming = stop_streaming,
  11286. + .wait_prepare = bm2835_mmal_unlock,
  11287. + .wait_finish = bm2835_mmal_lock,
  11288. +};
  11289. +
  11290. +/* ------------------------------------------------------------------
  11291. + IOCTL operations
  11292. + ------------------------------------------------------------------*/
  11293. +
  11294. +/* overlay ioctl */
  11295. +static int vidioc_enum_fmt_vid_overlay(struct file *file, void *priv,
  11296. + struct v4l2_fmtdesc *f)
  11297. +{
  11298. + struct mmal_fmt *fmt;
  11299. +
  11300. + if (f->index >= ARRAY_SIZE(formats))
  11301. + return -EINVAL;
  11302. +
  11303. + fmt = &formats[f->index];
  11304. +
  11305. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11306. + f->pixelformat = fmt->fourcc;
  11307. + f->flags = fmt->flags;
  11308. +
  11309. + return 0;
  11310. +}
  11311. +
  11312. +static int vidioc_g_fmt_vid_overlay(struct file *file, void *priv,
  11313. + struct v4l2_format *f)
  11314. +{
  11315. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11316. +
  11317. + f->fmt.win = dev->overlay;
  11318. +
  11319. + return 0;
  11320. +}
  11321. +
  11322. +static int vidioc_try_fmt_vid_overlay(struct file *file, void *priv,
  11323. + struct v4l2_format *f)
  11324. +{
  11325. + /* Only support one format so get the current one. */
  11326. + vidioc_g_fmt_vid_overlay(file, priv, f);
  11327. +
  11328. + /* todo: allow the size and/or offset to be changed. */
  11329. + return 0;
  11330. +}
  11331. +
  11332. +static int vidioc_s_fmt_vid_overlay(struct file *file, void *priv,
  11333. + struct v4l2_format *f)
  11334. +{
  11335. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11336. +
  11337. + vidioc_try_fmt_vid_overlay(file, priv, f);
  11338. +
  11339. + dev->overlay = f->fmt.win;
  11340. +
  11341. + /* todo: program the preview port parameters */
  11342. + return 0;
  11343. +}
  11344. +
  11345. +static int vidioc_overlay(struct file *file, void *f, unsigned int on)
  11346. +{
  11347. + int ret;
  11348. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11349. + struct vchiq_mmal_port *src;
  11350. + struct vchiq_mmal_port *dst;
  11351. + struct mmal_parameter_displayregion prev_config = {
  11352. + .set = MMAL_DISPLAY_SET_LAYER | MMAL_DISPLAY_SET_ALPHA |
  11353. + MMAL_DISPLAY_SET_DEST_RECT | MMAL_DISPLAY_SET_FULLSCREEN,
  11354. + .layer = PREVIEW_LAYER,
  11355. + .alpha = 255,
  11356. + .fullscreen = 0,
  11357. + .dest_rect = {
  11358. + .x = dev->overlay.w.left,
  11359. + .y = dev->overlay.w.top,
  11360. + .width = dev->overlay.w.width,
  11361. + .height = dev->overlay.w.height,
  11362. + },
  11363. + };
  11364. +
  11365. + if ((on && dev->component[MMAL_COMPONENT_PREVIEW]->enabled) ||
  11366. + (!on && !dev->component[MMAL_COMPONENT_PREVIEW]->enabled))
  11367. + return 0; /* already in requested state */
  11368. +
  11369. + src =
  11370. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11371. + output[MMAL_CAMERA_PORT_PREVIEW];
  11372. +
  11373. + if (!on) {
  11374. + /* disconnect preview ports and disable component */
  11375. + ret = vchiq_mmal_port_disable(dev->instance, src);
  11376. + if (!ret)
  11377. + ret =
  11378. + vchiq_mmal_port_connect_tunnel(dev->instance, src,
  11379. + NULL);
  11380. + if (ret >= 0)
  11381. + ret = vchiq_mmal_component_disable(
  11382. + dev->instance,
  11383. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11384. +
  11385. + disable_camera(dev);
  11386. + return ret;
  11387. + }
  11388. +
  11389. + /* set preview port format and connect it to output */
  11390. + dst = &dev->component[MMAL_COMPONENT_PREVIEW]->input[0];
  11391. +
  11392. + ret = vchiq_mmal_port_set_format(dev->instance, src);
  11393. + if (ret < 0)
  11394. + goto error;
  11395. +
  11396. + ret = vchiq_mmal_port_parameter_set(dev->instance, dst,
  11397. + MMAL_PARAMETER_DISPLAYREGION,
  11398. + &prev_config, sizeof(prev_config));
  11399. + if (ret < 0)
  11400. + goto error;
  11401. +
  11402. + if (enable_camera(dev) < 0)
  11403. + goto error;
  11404. +
  11405. + ret = vchiq_mmal_component_enable(
  11406. + dev->instance,
  11407. + dev->component[MMAL_COMPONENT_PREVIEW]);
  11408. + if (ret < 0)
  11409. + goto error;
  11410. +
  11411. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev, "connecting %p to %p\n",
  11412. + src, dst);
  11413. + ret = vchiq_mmal_port_connect_tunnel(dev->instance, src, dst);
  11414. + if (!ret)
  11415. + ret = vchiq_mmal_port_enable(dev->instance, src, NULL);
  11416. +error:
  11417. + return ret;
  11418. +}
  11419. +
  11420. +static int vidioc_g_fbuf(struct file *file, void *fh,
  11421. + struct v4l2_framebuffer *a)
  11422. +{
  11423. + /* The video overlay must stay within the framebuffer and can't be
  11424. + positioned independently. */
  11425. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11426. + struct vchiq_mmal_port *preview_port =
  11427. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11428. + output[MMAL_CAMERA_PORT_PREVIEW];
  11429. + a->flags = V4L2_FBUF_FLAG_OVERLAY;
  11430. + a->fmt.width = preview_port->es.video.width;
  11431. + a->fmt.height = preview_port->es.video.height;
  11432. + a->fmt.pixelformat = V4L2_PIX_FMT_YUV420;
  11433. + a->fmt.bytesperline = (preview_port->es.video.width * 3)>>1;
  11434. + a->fmt.sizeimage = (preview_port->es.video.width *
  11435. + preview_port->es.video.height * 3)>>1;
  11436. + a->fmt.colorspace = V4L2_COLORSPACE_JPEG;
  11437. +
  11438. + return 0;
  11439. +}
  11440. +
  11441. +/* input ioctls */
  11442. +static int vidioc_enum_input(struct file *file, void *priv,
  11443. + struct v4l2_input *inp)
  11444. +{
  11445. + /* only a single camera input */
  11446. + if (inp->index != 0)
  11447. + return -EINVAL;
  11448. +
  11449. + inp->type = V4L2_INPUT_TYPE_CAMERA;
  11450. + sprintf(inp->name, "Camera %u", inp->index);
  11451. + return 0;
  11452. +}
  11453. +
  11454. +static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
  11455. +{
  11456. + *i = 0;
  11457. + return 0;
  11458. +}
  11459. +
  11460. +static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
  11461. +{
  11462. + if (i != 0)
  11463. + return -EINVAL;
  11464. +
  11465. + return 0;
  11466. +}
  11467. +
  11468. +/* capture ioctls */
  11469. +static int vidioc_querycap(struct file *file, void *priv,
  11470. + struct v4l2_capability *cap)
  11471. +{
  11472. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11473. + u32 major;
  11474. + u32 minor;
  11475. +
  11476. + vchiq_mmal_version(dev->instance, &major, &minor);
  11477. +
  11478. + strcpy(cap->driver, "bm2835 mmal");
  11479. + snprintf(cap->card, sizeof(cap->card), "mmal service %d.%d",
  11480. + major, minor);
  11481. +
  11482. + snprintf(cap->bus_info, sizeof(cap->bus_info),
  11483. + "platform:%s", dev->v4l2_dev.name);
  11484. + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_OVERLAY |
  11485. + V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
  11486. + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
  11487. +
  11488. + return 0;
  11489. +}
  11490. +
  11491. +static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
  11492. + struct v4l2_fmtdesc *f)
  11493. +{
  11494. + struct mmal_fmt *fmt;
  11495. +
  11496. + if (f->index >= ARRAY_SIZE(formats))
  11497. + return -EINVAL;
  11498. +
  11499. + fmt = &formats[f->index];
  11500. +
  11501. + strlcpy(f->description, fmt->name, sizeof(f->description));
  11502. + f->pixelformat = fmt->fourcc;
  11503. + f->flags = fmt->flags;
  11504. +
  11505. + return 0;
  11506. +}
  11507. +
  11508. +static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
  11509. + struct v4l2_format *f)
  11510. +{
  11511. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11512. +
  11513. + f->fmt.pix.width = dev->capture.width;
  11514. + f->fmt.pix.height = dev->capture.height;
  11515. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11516. + f->fmt.pix.pixelformat = dev->capture.fmt->fourcc;
  11517. + f->fmt.pix.bytesperline = dev->capture.stride;
  11518. + f->fmt.pix.sizeimage = dev->capture.buffersize;
  11519. +
  11520. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  11521. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11522. + else
  11523. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  11524. + f->fmt.pix.priv = 0;
  11525. +
  11526. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11527. + __func__);
  11528. + return 0;
  11529. +}
  11530. +
  11531. +static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
  11532. + struct v4l2_format *f)
  11533. +{
  11534. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11535. + struct mmal_fmt *mfmt;
  11536. +
  11537. + mfmt = get_format(f);
  11538. + if (!mfmt) {
  11539. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11540. + "Fourcc format (0x%08x) unknown.\n",
  11541. + f->fmt.pix.pixelformat);
  11542. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11543. + mfmt = get_format(f);
  11544. + }
  11545. +
  11546. + f->fmt.pix.field = V4L2_FIELD_NONE;
  11547. +
  11548. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11549. + "Clipping/aligning %dx%d format %08X\n",
  11550. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  11551. +
  11552. + v4l_bound_align_image(&f->fmt.pix.width, MIN_WIDTH, MAX_WIDTH, 1,
  11553. + &f->fmt.pix.height, MIN_HEIGHT, MAX_HEIGHT, 1, 0);
  11554. + f->fmt.pix.bytesperline = (f->fmt.pix.width * mfmt->depth)>>3;
  11555. +
  11556. + /* Image buffer has to be padded to allow for alignment, even though
  11557. + * we then remove that padding before delivering the buffer.
  11558. + */
  11559. + f->fmt.pix.sizeimage = ((f->fmt.pix.height+15)&~15) *
  11560. + (((f->fmt.pix.width+31)&~31) * mfmt->depth) >> 3;
  11561. +
  11562. + if ((mfmt->flags & V4L2_FMT_FLAG_COMPRESSED) &&
  11563. + f->fmt.pix.sizeimage < MIN_BUFFER_SIZE)
  11564. + f->fmt.pix.sizeimage = MIN_BUFFER_SIZE;
  11565. +
  11566. + if (dev->capture.fmt->fourcc == V4L2_PIX_FMT_RGB24)
  11567. + f->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
  11568. + else
  11569. + f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
  11570. + f->fmt.pix.priv = 0;
  11571. +
  11572. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11573. + "Now %dx%d format %08X\n",
  11574. + f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.pixelformat);
  11575. +
  11576. + v4l2_dump_pix_format(1, bcm2835_v4l2_debug, &dev->v4l2_dev, &f->fmt.pix,
  11577. + __func__);
  11578. + return 0;
  11579. +}
  11580. +
  11581. +static int mmal_setup_components(struct bm2835_mmal_dev *dev,
  11582. + struct v4l2_format *f)
  11583. +{
  11584. + int ret;
  11585. + struct vchiq_mmal_port *port = NULL, *camera_port = NULL;
  11586. + struct vchiq_mmal_component *encode_component = NULL;
  11587. + struct mmal_fmt *mfmt = get_format(f);
  11588. +
  11589. + BUG_ON(!mfmt);
  11590. +
  11591. + if (dev->capture.encode_component) {
  11592. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11593. + "vid_cap - disconnect previous tunnel\n");
  11594. +
  11595. + /* Disconnect any previous connection */
  11596. + vchiq_mmal_port_connect_tunnel(dev->instance,
  11597. + dev->capture.camera_port, NULL);
  11598. + dev->capture.camera_port = NULL;
  11599. + ret = vchiq_mmal_component_disable(dev->instance,
  11600. + dev->capture.
  11601. + encode_component);
  11602. + if (ret)
  11603. + v4l2_err(&dev->v4l2_dev,
  11604. + "Failed to disable encode component %d\n",
  11605. + ret);
  11606. +
  11607. + dev->capture.encode_component = NULL;
  11608. + }
  11609. + /* format dependant port setup */
  11610. + switch (mfmt->mmal_component) {
  11611. + case MMAL_COMPONENT_CAMERA:
  11612. + /* Make a further decision on port based on resolution */
  11613. + if (f->fmt.pix.width <= max_video_width
  11614. + && f->fmt.pix.height <= max_video_height)
  11615. + camera_port = port =
  11616. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11617. + output[MMAL_CAMERA_PORT_VIDEO];
  11618. + else
  11619. + camera_port = port =
  11620. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11621. + output[MMAL_CAMERA_PORT_CAPTURE];
  11622. + break;
  11623. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11624. + encode_component = dev->component[MMAL_COMPONENT_IMAGE_ENCODE];
  11625. + port = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  11626. + camera_port =
  11627. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11628. + output[MMAL_CAMERA_PORT_CAPTURE];
  11629. + break;
  11630. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11631. + encode_component = dev->component[MMAL_COMPONENT_VIDEO_ENCODE];
  11632. + port = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  11633. + camera_port =
  11634. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11635. + output[MMAL_CAMERA_PORT_VIDEO];
  11636. + break;
  11637. + default:
  11638. + break;
  11639. + }
  11640. +
  11641. + if (!port)
  11642. + return -EINVAL;
  11643. +
  11644. + if (encode_component)
  11645. + camera_port->format.encoding = MMAL_ENCODING_OPAQUE;
  11646. + else
  11647. + camera_port->format.encoding = mfmt->mmal;
  11648. +
  11649. + camera_port->format.encoding_variant = 0;
  11650. + camera_port->es.video.width = f->fmt.pix.width;
  11651. + camera_port->es.video.height = f->fmt.pix.height;
  11652. + camera_port->es.video.crop.x = 0;
  11653. + camera_port->es.video.crop.y = 0;
  11654. + camera_port->es.video.crop.width = f->fmt.pix.width;
  11655. + camera_port->es.video.crop.height = f->fmt.pix.height;
  11656. + camera_port->es.video.frame_rate.num = 0;
  11657. + camera_port->es.video.frame_rate.den = 1;
  11658. + camera_port->es.video.color_space = MMAL_COLOR_SPACE_JPEG_JFIF;
  11659. +
  11660. + ret = vchiq_mmal_port_set_format(dev->instance, camera_port);
  11661. +
  11662. + if (!ret
  11663. + && camera_port ==
  11664. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11665. + output[MMAL_CAMERA_PORT_VIDEO]) {
  11666. + bool overlay_enabled =
  11667. + !!dev->component[MMAL_COMPONENT_PREVIEW]->enabled;
  11668. + struct vchiq_mmal_port *preview_port =
  11669. + &dev->component[MMAL_COMPONENT_CAMERA]->
  11670. + output[MMAL_CAMERA_PORT_PREVIEW];
  11671. + /* Preview and encode ports need to match on resolution */
  11672. + if (overlay_enabled) {
  11673. + /* Need to disable the overlay before we can update
  11674. + * the resolution
  11675. + */
  11676. + ret =
  11677. + vchiq_mmal_port_disable(dev->instance,
  11678. + preview_port);
  11679. + if (!ret)
  11680. + ret =
  11681. + vchiq_mmal_port_connect_tunnel(
  11682. + dev->instance,
  11683. + preview_port,
  11684. + NULL);
  11685. + }
  11686. + preview_port->es.video.width = f->fmt.pix.width;
  11687. + preview_port->es.video.height = f->fmt.pix.height;
  11688. + preview_port->es.video.crop.x = 0;
  11689. + preview_port->es.video.crop.y = 0;
  11690. + preview_port->es.video.crop.width = f->fmt.pix.width;
  11691. + preview_port->es.video.crop.height = f->fmt.pix.height;
  11692. + preview_port->es.video.frame_rate.num =
  11693. + dev->capture.timeperframe.denominator;
  11694. + preview_port->es.video.frame_rate.den =
  11695. + dev->capture.timeperframe.numerator;
  11696. + ret = vchiq_mmal_port_set_format(dev->instance, preview_port);
  11697. + if (overlay_enabled) {
  11698. + ret = vchiq_mmal_port_connect_tunnel(
  11699. + dev->instance,
  11700. + preview_port,
  11701. + &dev->component[MMAL_COMPONENT_PREVIEW]->input[0]);
  11702. + if (!ret)
  11703. + ret = vchiq_mmal_port_enable(dev->instance,
  11704. + preview_port,
  11705. + NULL);
  11706. + }
  11707. + }
  11708. +
  11709. + if (ret) {
  11710. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11711. + "%s failed to set format %dx%d %08X\n", __func__,
  11712. + f->fmt.pix.width, f->fmt.pix.height,
  11713. + f->fmt.pix.pixelformat);
  11714. + /* ensure capture is not going to be tried */
  11715. + dev->capture.port = NULL;
  11716. + } else {
  11717. + if (encode_component) {
  11718. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11719. + "vid_cap - set up encode comp\n");
  11720. +
  11721. + /* configure buffering */
  11722. + camera_port->current_buffer.size =
  11723. + camera_port->recommended_buffer.size;
  11724. + camera_port->current_buffer.num =
  11725. + camera_port->recommended_buffer.num;
  11726. +
  11727. + ret =
  11728. + vchiq_mmal_port_connect_tunnel(
  11729. + dev->instance,
  11730. + camera_port,
  11731. + &encode_component->input[0]);
  11732. + if (ret) {
  11733. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11734. + &dev->v4l2_dev,
  11735. + "%s failed to create connection\n",
  11736. + __func__);
  11737. + /* ensure capture is not going to be tried */
  11738. + dev->capture.port = NULL;
  11739. + } else {
  11740. + port->es.video.width = f->fmt.pix.width;
  11741. + port->es.video.height = f->fmt.pix.height;
  11742. + port->es.video.crop.x = 0;
  11743. + port->es.video.crop.y = 0;
  11744. + port->es.video.crop.width = f->fmt.pix.width;
  11745. + port->es.video.crop.height = f->fmt.pix.height;
  11746. + port->es.video.frame_rate.num =
  11747. + dev->capture.timeperframe.denominator;
  11748. + port->es.video.frame_rate.den =
  11749. + dev->capture.timeperframe.numerator;
  11750. +
  11751. + port->format.encoding = mfmt->mmal;
  11752. + port->format.encoding_variant = 0;
  11753. + /* Set any encoding specific parameters */
  11754. + switch (mfmt->mmal_component) {
  11755. + case MMAL_COMPONENT_VIDEO_ENCODE:
  11756. + port->format.bitrate =
  11757. + dev->capture.encode_bitrate;
  11758. + break;
  11759. + case MMAL_COMPONENT_IMAGE_ENCODE:
  11760. + /* Could set EXIF parameters here */
  11761. + break;
  11762. + default:
  11763. + break;
  11764. + }
  11765. + ret = vchiq_mmal_port_set_format(dev->instance,
  11766. + port);
  11767. + if (ret)
  11768. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11769. + &dev->v4l2_dev,
  11770. + "%s failed to set format %dx%d fmt %08X\n",
  11771. + __func__,
  11772. + f->fmt.pix.width,
  11773. + f->fmt.pix.height,
  11774. + f->fmt.pix.pixelformat
  11775. + );
  11776. + }
  11777. +
  11778. + if (!ret) {
  11779. + ret = vchiq_mmal_component_enable(
  11780. + dev->instance,
  11781. + encode_component);
  11782. + if (ret) {
  11783. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11784. + &dev->v4l2_dev,
  11785. + "%s Failed to enable encode components\n",
  11786. + __func__);
  11787. + }
  11788. + }
  11789. + if (!ret) {
  11790. + /* configure buffering */
  11791. + port->current_buffer.num = 1;
  11792. + port->current_buffer.size =
  11793. + f->fmt.pix.sizeimage;
  11794. + if (port->format.encoding ==
  11795. + MMAL_ENCODING_JPEG) {
  11796. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11797. + &dev->v4l2_dev,
  11798. + "JPG - buf size now %d was %d\n",
  11799. + f->fmt.pix.sizeimage,
  11800. + port->current_buffer.size);
  11801. + port->current_buffer.size =
  11802. + (f->fmt.pix.sizeimage <
  11803. + (100 << 10))
  11804. + ? (100 << 10) : f->fmt.pix.
  11805. + sizeimage;
  11806. + }
  11807. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11808. + &dev->v4l2_dev,
  11809. + "vid_cap - cur_buf.size set to %d\n",
  11810. + f->fmt.pix.sizeimage);
  11811. + port->current_buffer.alignment = 0;
  11812. + }
  11813. + } else {
  11814. + /* configure buffering */
  11815. + camera_port->current_buffer.num = 1;
  11816. + camera_port->current_buffer.size = f->fmt.pix.sizeimage;
  11817. + camera_port->current_buffer.alignment = 0;
  11818. + }
  11819. +
  11820. + if (!ret) {
  11821. + dev->capture.fmt = mfmt;
  11822. + dev->capture.stride = f->fmt.pix.bytesperline;
  11823. + dev->capture.width = camera_port->es.video.crop.width;
  11824. + dev->capture.height = camera_port->es.video.crop.height;
  11825. + dev->capture.buffersize = port->current_buffer.size;
  11826. +
  11827. + /* select port for capture */
  11828. + dev->capture.port = port;
  11829. + dev->capture.camera_port = camera_port;
  11830. + dev->capture.encode_component = encode_component;
  11831. + v4l2_dbg(1, bcm2835_v4l2_debug,
  11832. + &dev->v4l2_dev,
  11833. + "Set dev->capture.fmt %08X, %dx%d, stride %d, size %d",
  11834. + port->format.encoding,
  11835. + dev->capture.width, dev->capture.height,
  11836. + dev->capture.stride, dev->capture.buffersize);
  11837. + }
  11838. + }
  11839. +
  11840. + /* todo: Need to convert the vchiq/mmal error into a v4l2 error. */
  11841. + return ret;
  11842. +}
  11843. +
  11844. +static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
  11845. + struct v4l2_format *f)
  11846. +{
  11847. + int ret;
  11848. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11849. + struct mmal_fmt *mfmt;
  11850. +
  11851. + /* try the format to set valid parameters */
  11852. + ret = vidioc_try_fmt_vid_cap(file, priv, f);
  11853. + if (ret) {
  11854. + v4l2_err(&dev->v4l2_dev,
  11855. + "vid_cap - vidioc_try_fmt_vid_cap failed\n");
  11856. + return ret;
  11857. + }
  11858. +
  11859. + /* if a capture is running refuse to set format */
  11860. + if (vb2_is_busy(&dev->capture.vb_vidq)) {
  11861. + v4l2_info(&dev->v4l2_dev, "%s device busy\n", __func__);
  11862. + return -EBUSY;
  11863. + }
  11864. +
  11865. + /* If the format is unsupported v4l2 says we should switch to
  11866. + * a supported one and not return an error. */
  11867. + mfmt = get_format(f);
  11868. + if (!mfmt) {
  11869. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  11870. + "Fourcc format (0x%08x) unknown.\n",
  11871. + f->fmt.pix.pixelformat);
  11872. + f->fmt.pix.pixelformat = formats[0].fourcc;
  11873. + mfmt = get_format(f);
  11874. + }
  11875. +
  11876. + ret = mmal_setup_components(dev, f);
  11877. + if (ret != 0) {
  11878. + v4l2_err(&dev->v4l2_dev,
  11879. + "%s: failed to setup mmal components: %d\n",
  11880. + __func__, ret);
  11881. + ret = -EINVAL;
  11882. + }
  11883. +
  11884. + return ret;
  11885. +}
  11886. +
  11887. +int vidioc_enum_framesizes(struct file *file, void *fh,
  11888. + struct v4l2_frmsizeenum *fsize)
  11889. +{
  11890. + static const struct v4l2_frmsize_stepwise sizes = {
  11891. + MIN_WIDTH, MAX_WIDTH, 2,
  11892. + MIN_HEIGHT, MAX_HEIGHT, 2
  11893. + };
  11894. + int i;
  11895. +
  11896. + if (fsize->index)
  11897. + return -EINVAL;
  11898. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  11899. + if (formats[i].fourcc == fsize->pixel_format)
  11900. + break;
  11901. + if (i == ARRAY_SIZE(formats))
  11902. + return -EINVAL;
  11903. + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE;
  11904. + fsize->stepwise = sizes;
  11905. + return 0;
  11906. +}
  11907. +
  11908. +/* timeperframe is arbitrary and continous */
  11909. +static int vidioc_enum_frameintervals(struct file *file, void *priv,
  11910. + struct v4l2_frmivalenum *fival)
  11911. +{
  11912. + int i;
  11913. +
  11914. + if (fival->index)
  11915. + return -EINVAL;
  11916. +
  11917. + for (i = 0; i < ARRAY_SIZE(formats); i++)
  11918. + if (formats[i].fourcc == fival->pixel_format)
  11919. + break;
  11920. + if (i == ARRAY_SIZE(formats))
  11921. + return -EINVAL;
  11922. +
  11923. + /* regarding width & height - we support any within range */
  11924. + if (fival->width < MIN_WIDTH || fival->width > MAX_WIDTH ||
  11925. + fival->height < MIN_HEIGHT || fival->height > MAX_HEIGHT)
  11926. + return -EINVAL;
  11927. +
  11928. + fival->type = V4L2_FRMIVAL_TYPE_CONTINUOUS;
  11929. +
  11930. + /* fill in stepwise (step=1.0 is requred by V4L2 spec) */
  11931. + fival->stepwise.min = tpf_min;
  11932. + fival->stepwise.max = tpf_max;
  11933. + fival->stepwise.step = (struct v4l2_fract) {1, 1};
  11934. +
  11935. + return 0;
  11936. +}
  11937. +
  11938. +static int vidioc_g_parm(struct file *file, void *priv,
  11939. + struct v4l2_streamparm *parm)
  11940. +{
  11941. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11942. +
  11943. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11944. + return -EINVAL;
  11945. +
  11946. + parm->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
  11947. + parm->parm.capture.timeperframe = dev->capture.timeperframe;
  11948. + parm->parm.capture.readbuffers = 1;
  11949. + return 0;
  11950. +}
  11951. +
  11952. +#define FRACT_CMP(a, OP, b) \
  11953. + ((u64)(a).numerator * (b).denominator OP \
  11954. + (u64)(b).numerator * (a).denominator)
  11955. +
  11956. +static int vidioc_s_parm(struct file *file, void *priv,
  11957. + struct v4l2_streamparm *parm)
  11958. +{
  11959. + struct bm2835_mmal_dev *dev = video_drvdata(file);
  11960. + struct v4l2_fract tpf;
  11961. + struct mmal_parameter_rational fps_param;
  11962. +
  11963. + if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
  11964. + return -EINVAL;
  11965. +
  11966. + tpf = parm->parm.capture.timeperframe;
  11967. +
  11968. + /* tpf: {*, 0} resets timing; clip to [min, max]*/
  11969. + tpf = tpf.denominator ? tpf : tpf_default;
  11970. + tpf = FRACT_CMP(tpf, <, tpf_min) ? tpf_min : tpf;
  11971. + tpf = FRACT_CMP(tpf, >, tpf_max) ? tpf_max : tpf;
  11972. +
  11973. + dev->capture.timeperframe = tpf;
  11974. + parm->parm.capture.timeperframe = tpf;
  11975. + parm->parm.capture.readbuffers = 1;
  11976. +
  11977. + fps_param.num = 0; /* Select variable fps, and then use
  11978. + * FPS_RANGE to select the actual limits.
  11979. + */
  11980. + fps_param.den = 1;
  11981. + set_framerate_params(dev);
  11982. +
  11983. + return 0;
  11984. +}
  11985. +
  11986. +static const struct v4l2_ioctl_ops camera0_ioctl_ops = {
  11987. + /* overlay */
  11988. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  11989. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  11990. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  11991. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  11992. + .vidioc_overlay = vidioc_overlay,
  11993. + .vidioc_g_fbuf = vidioc_g_fbuf,
  11994. +
  11995. + /* inputs */
  11996. + .vidioc_enum_input = vidioc_enum_input,
  11997. + .vidioc_g_input = vidioc_g_input,
  11998. + .vidioc_s_input = vidioc_s_input,
  11999. +
  12000. + /* capture */
  12001. + .vidioc_querycap = vidioc_querycap,
  12002. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  12003. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  12004. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  12005. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  12006. +
  12007. + /* buffer management */
  12008. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  12009. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  12010. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  12011. + .vidioc_querybuf = vb2_ioctl_querybuf,
  12012. + .vidioc_qbuf = vb2_ioctl_qbuf,
  12013. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  12014. + .vidioc_enum_framesizes = vidioc_enum_framesizes,
  12015. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  12016. + .vidioc_g_parm = vidioc_g_parm,
  12017. + .vidioc_s_parm = vidioc_s_parm,
  12018. + .vidioc_streamon = vb2_ioctl_streamon,
  12019. + .vidioc_streamoff = vb2_ioctl_streamoff,
  12020. +
  12021. + .vidioc_log_status = v4l2_ctrl_log_status,
  12022. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  12023. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  12024. +};
  12025. +
  12026. +static const struct v4l2_ioctl_ops camera0_ioctl_ops_gstreamer = {
  12027. + /* overlay */
  12028. + .vidioc_enum_fmt_vid_overlay = vidioc_enum_fmt_vid_overlay,
  12029. + .vidioc_g_fmt_vid_overlay = vidioc_g_fmt_vid_overlay,
  12030. + .vidioc_try_fmt_vid_overlay = vidioc_try_fmt_vid_overlay,
  12031. + .vidioc_s_fmt_vid_overlay = vidioc_s_fmt_vid_overlay,
  12032. + .vidioc_overlay = vidioc_overlay,
  12033. + .vidioc_g_fbuf = vidioc_g_fbuf,
  12034. +
  12035. + /* inputs */
  12036. + .vidioc_enum_input = vidioc_enum_input,
  12037. + .vidioc_g_input = vidioc_g_input,
  12038. + .vidioc_s_input = vidioc_s_input,
  12039. +
  12040. + /* capture */
  12041. + .vidioc_querycap = vidioc_querycap,
  12042. + .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
  12043. + .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
  12044. + .vidioc_try_fmt_vid_cap = vidioc_try_fmt_vid_cap,
  12045. + .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
  12046. +
  12047. + /* buffer management */
  12048. + .vidioc_reqbufs = vb2_ioctl_reqbufs,
  12049. + .vidioc_create_bufs = vb2_ioctl_create_bufs,
  12050. + .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
  12051. + .vidioc_querybuf = vb2_ioctl_querybuf,
  12052. + .vidioc_qbuf = vb2_ioctl_qbuf,
  12053. + .vidioc_dqbuf = vb2_ioctl_dqbuf,
  12054. + /* Remove this function ptr to fix gstreamer bug
  12055. + .vidioc_enum_framesizes = vidioc_enum_framesizes, */
  12056. + .vidioc_enum_frameintervals = vidioc_enum_frameintervals,
  12057. + .vidioc_g_parm = vidioc_g_parm,
  12058. + .vidioc_s_parm = vidioc_s_parm,
  12059. + .vidioc_streamon = vb2_ioctl_streamon,
  12060. + .vidioc_streamoff = vb2_ioctl_streamoff,
  12061. +
  12062. + .vidioc_log_status = v4l2_ctrl_log_status,
  12063. + .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
  12064. + .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
  12065. +};
  12066. +
  12067. +/* ------------------------------------------------------------------
  12068. + Driver init/finalise
  12069. + ------------------------------------------------------------------*/
  12070. +
  12071. +static const struct v4l2_file_operations camera0_fops = {
  12072. + .owner = THIS_MODULE,
  12073. + .open = v4l2_fh_open,
  12074. + .release = vb2_fop_release,
  12075. + .read = vb2_fop_read,
  12076. + .poll = vb2_fop_poll,
  12077. + .unlocked_ioctl = video_ioctl2, /* V4L2 ioctl handler */
  12078. + .mmap = vb2_fop_mmap,
  12079. +};
  12080. +
  12081. +static struct video_device vdev_template = {
  12082. + .name = "camera0",
  12083. + .fops = &camera0_fops,
  12084. + .ioctl_ops = &camera0_ioctl_ops,
  12085. + .release = video_device_release_empty,
  12086. +};
  12087. +
  12088. +static int set_camera_parameters(struct vchiq_mmal_instance *instance,
  12089. + struct vchiq_mmal_component *camera)
  12090. +{
  12091. + int ret;
  12092. + struct mmal_parameter_camera_config cam_config = {
  12093. + .max_stills_w = MAX_WIDTH,
  12094. + .max_stills_h = MAX_HEIGHT,
  12095. + .stills_yuv422 = 1,
  12096. + .one_shot_stills = 1,
  12097. + .max_preview_video_w = (max_video_width > 1920) ?
  12098. + max_video_width : 1920,
  12099. + .max_preview_video_h = (max_video_height > 1088) ?
  12100. + max_video_height : 1088,
  12101. + .num_preview_video_frames = 3,
  12102. + .stills_capture_circular_buffer_height = 0,
  12103. + .fast_preview_resume = 0,
  12104. + .use_stc_timestamp = MMAL_PARAM_TIMESTAMP_MODE_RAW_STC
  12105. + };
  12106. +
  12107. + ret = vchiq_mmal_port_parameter_set(instance, &camera->control,
  12108. + MMAL_PARAMETER_CAMERA_CONFIG,
  12109. + &cam_config, sizeof(cam_config));
  12110. + return ret;
  12111. +}
  12112. +
  12113. +/* MMAL instance and component init */
  12114. +static int __init mmal_init(struct bm2835_mmal_dev *dev)
  12115. +{
  12116. + int ret;
  12117. + struct mmal_es_format *format;
  12118. + u32 bool_true = 1;
  12119. +
  12120. + ret = vchiq_mmal_init(&dev->instance);
  12121. + if (ret < 0)
  12122. + return ret;
  12123. +
  12124. + /* get the camera component ready */
  12125. + ret = vchiq_mmal_component_init(dev->instance, "ril.camera",
  12126. + &dev->component[MMAL_COMPONENT_CAMERA]);
  12127. + if (ret < 0)
  12128. + goto unreg_mmal;
  12129. +
  12130. + if (dev->component[MMAL_COMPONENT_CAMERA]->outputs <
  12131. + MMAL_CAMERA_PORT_COUNT) {
  12132. + ret = -EINVAL;
  12133. + goto unreg_camera;
  12134. + }
  12135. +
  12136. + ret = set_camera_parameters(dev->instance,
  12137. + dev->component[MMAL_COMPONENT_CAMERA]);
  12138. + if (ret < 0)
  12139. + goto unreg_camera;
  12140. +
  12141. + format =
  12142. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12143. + output[MMAL_CAMERA_PORT_PREVIEW].format;
  12144. +
  12145. + format->encoding = MMAL_ENCODING_OPAQUE;
  12146. + format->encoding_variant = MMAL_ENCODING_I420;
  12147. +
  12148. + format->es->video.width = 1024;
  12149. + format->es->video.height = 768;
  12150. + format->es->video.crop.x = 0;
  12151. + format->es->video.crop.y = 0;
  12152. + format->es->video.crop.width = 1024;
  12153. + format->es->video.crop.height = 768;
  12154. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12155. + format->es->video.frame_rate.den = 1;
  12156. +
  12157. + format =
  12158. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12159. + output[MMAL_CAMERA_PORT_VIDEO].format;
  12160. +
  12161. + format->encoding = MMAL_ENCODING_OPAQUE;
  12162. + format->encoding_variant = MMAL_ENCODING_I420;
  12163. +
  12164. + format->es->video.width = 1024;
  12165. + format->es->video.height = 768;
  12166. + format->es->video.crop.x = 0;
  12167. + format->es->video.crop.y = 0;
  12168. + format->es->video.crop.width = 1024;
  12169. + format->es->video.crop.height = 768;
  12170. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12171. + format->es->video.frame_rate.den = 1;
  12172. +
  12173. + vchiq_mmal_port_parameter_set(dev->instance,
  12174. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12175. + output[MMAL_CAMERA_PORT_VIDEO],
  12176. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  12177. + &bool_true, sizeof(bool_true));
  12178. +
  12179. + format =
  12180. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12181. + output[MMAL_CAMERA_PORT_CAPTURE].format;
  12182. +
  12183. + format->encoding = MMAL_ENCODING_OPAQUE;
  12184. +
  12185. + format->es->video.width = 2592;
  12186. + format->es->video.height = 1944;
  12187. + format->es->video.crop.x = 0;
  12188. + format->es->video.crop.y = 0;
  12189. + format->es->video.crop.width = 2592;
  12190. + format->es->video.crop.height = 1944;
  12191. + format->es->video.frame_rate.num = 0; /* Rely on fps_range */
  12192. + format->es->video.frame_rate.den = 1;
  12193. +
  12194. + dev->capture.width = format->es->video.width;
  12195. + dev->capture.height = format->es->video.height;
  12196. + dev->capture.fmt = &formats[0];
  12197. + dev->capture.encode_component = NULL;
  12198. + dev->capture.timeperframe = tpf_default;
  12199. + dev->capture.enc_profile = V4L2_MPEG_VIDEO_H264_PROFILE_HIGH;
  12200. + dev->capture.enc_level = V4L2_MPEG_VIDEO_H264_LEVEL_4_0;
  12201. +
  12202. + vchiq_mmal_port_parameter_set(dev->instance,
  12203. + &dev->component[MMAL_COMPONENT_CAMERA]->
  12204. + output[MMAL_CAMERA_PORT_CAPTURE],
  12205. + MMAL_PARAMETER_NO_IMAGE_PADDING,
  12206. + &bool_true, sizeof(bool_true));
  12207. +
  12208. + /* get the preview component ready */
  12209. + ret = vchiq_mmal_component_init(
  12210. + dev->instance, "ril.video_render",
  12211. + &dev->component[MMAL_COMPONENT_PREVIEW]);
  12212. + if (ret < 0)
  12213. + goto unreg_camera;
  12214. +
  12215. + if (dev->component[MMAL_COMPONENT_PREVIEW]->inputs < 1) {
  12216. + ret = -EINVAL;
  12217. + pr_debug("too few input ports %d needed %d\n",
  12218. + dev->component[MMAL_COMPONENT_PREVIEW]->inputs, 1);
  12219. + goto unreg_preview;
  12220. + }
  12221. +
  12222. + /* get the image encoder component ready */
  12223. + ret = vchiq_mmal_component_init(
  12224. + dev->instance, "ril.image_encode",
  12225. + &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12226. + if (ret < 0)
  12227. + goto unreg_preview;
  12228. +
  12229. + if (dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs < 1) {
  12230. + ret = -EINVAL;
  12231. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12232. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->inputs,
  12233. + 1);
  12234. + goto unreg_image_encoder;
  12235. + }
  12236. +
  12237. + /* get the video encoder component ready */
  12238. + ret = vchiq_mmal_component_init(dev->instance, "ril.video_encode",
  12239. + &dev->
  12240. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12241. + if (ret < 0)
  12242. + goto unreg_image_encoder;
  12243. +
  12244. + if (dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs < 1) {
  12245. + ret = -EINVAL;
  12246. + v4l2_err(&dev->v4l2_dev, "too few input ports %d needed %d\n",
  12247. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->inputs,
  12248. + 1);
  12249. + goto unreg_vid_encoder;
  12250. + }
  12251. +
  12252. + {
  12253. + struct vchiq_mmal_port *encoder_port =
  12254. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  12255. + encoder_port->format.encoding = MMAL_ENCODING_H264;
  12256. + ret = vchiq_mmal_port_set_format(dev->instance,
  12257. + encoder_port);
  12258. + }
  12259. +
  12260. + {
  12261. + unsigned int enable = 1;
  12262. + vchiq_mmal_port_parameter_set(
  12263. + dev->instance,
  12264. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12265. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  12266. + &enable, sizeof(enable));
  12267. +
  12268. + vchiq_mmal_port_parameter_set(dev->instance,
  12269. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->control,
  12270. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  12271. + &enable,
  12272. + sizeof(enable));
  12273. + }
  12274. + ret = bm2835_mmal_set_all_camera_controls(dev);
  12275. + if (ret < 0)
  12276. + goto unreg_vid_encoder;
  12277. +
  12278. + return 0;
  12279. +
  12280. +unreg_vid_encoder:
  12281. + pr_err("Cleanup: Destroy video encoder\n");
  12282. + vchiq_mmal_component_finalise(
  12283. + dev->instance,
  12284. + dev->component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12285. +
  12286. +unreg_image_encoder:
  12287. + pr_err("Cleanup: Destroy image encoder\n");
  12288. + vchiq_mmal_component_finalise(
  12289. + dev->instance,
  12290. + dev->component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12291. +
  12292. +unreg_preview:
  12293. + pr_err("Cleanup: Destroy video render\n");
  12294. + vchiq_mmal_component_finalise(dev->instance,
  12295. + dev->component[MMAL_COMPONENT_PREVIEW]);
  12296. +
  12297. +unreg_camera:
  12298. + pr_err("Cleanup: Destroy camera\n");
  12299. + vchiq_mmal_component_finalise(dev->instance,
  12300. + dev->component[MMAL_COMPONENT_CAMERA]);
  12301. +
  12302. +unreg_mmal:
  12303. + vchiq_mmal_finalise(dev->instance);
  12304. + return ret;
  12305. +}
  12306. +
  12307. +static int __init bm2835_mmal_init_device(struct bm2835_mmal_dev *dev,
  12308. + struct video_device *vfd)
  12309. +{
  12310. + int ret;
  12311. +
  12312. + *vfd = vdev_template;
  12313. + if (gst_v4l2src_is_broken) {
  12314. + v4l2_info(&dev->v4l2_dev,
  12315. + "Work-around for gstreamer issue is active.\n");
  12316. + vfd->ioctl_ops = &camera0_ioctl_ops_gstreamer;
  12317. + }
  12318. +
  12319. + vfd->v4l2_dev = &dev->v4l2_dev;
  12320. +
  12321. + vfd->lock = &dev->mutex;
  12322. +
  12323. + vfd->queue = &dev->capture.vb_vidq;
  12324. +
  12325. + set_bit(V4L2_FL_USE_FH_PRIO, &vfd->flags);
  12326. +
  12327. + /* video device needs to be able to access instance data */
  12328. + video_set_drvdata(vfd, dev);
  12329. +
  12330. + ret = video_register_device(vfd, VFL_TYPE_GRABBER, -1);
  12331. + if (ret < 0)
  12332. + return ret;
  12333. +
  12334. + v4l2_info(vfd->v4l2_dev,
  12335. + "V4L2 device registered as %s - stills mode > %dx%d\n",
  12336. + video_device_node_name(vfd), max_video_width, max_video_height);
  12337. +
  12338. + return 0;
  12339. +}
  12340. +
  12341. +static struct v4l2_format default_v4l2_format = {
  12342. + .fmt.pix.pixelformat = V4L2_PIX_FMT_JPEG,
  12343. + .fmt.pix.width = 1024,
  12344. + .fmt.pix.bytesperline = 1024,
  12345. + .fmt.pix.height = 768,
  12346. + .fmt.pix.sizeimage = 1024*768,
  12347. +};
  12348. +
  12349. +static int __init bm2835_mmal_init(void)
  12350. +{
  12351. + int ret;
  12352. + struct bm2835_mmal_dev *dev;
  12353. + struct vb2_queue *q;
  12354. +
  12355. + dev = kzalloc(sizeof(*gdev), GFP_KERNEL);
  12356. + if (!dev)
  12357. + return -ENOMEM;
  12358. +
  12359. + /* setup device defaults */
  12360. + dev->overlay.w.left = 150;
  12361. + dev->overlay.w.top = 50;
  12362. + dev->overlay.w.width = 1024;
  12363. + dev->overlay.w.height = 768;
  12364. + dev->overlay.clipcount = 0;
  12365. + dev->overlay.field = V4L2_FIELD_NONE;
  12366. +
  12367. + dev->capture.fmt = &formats[3]; /* JPEG */
  12368. +
  12369. + /* v4l device registration */
  12370. + snprintf(dev->v4l2_dev.name, sizeof(dev->v4l2_dev.name),
  12371. + "%s", BM2835_MMAL_MODULE_NAME);
  12372. + ret = v4l2_device_register(NULL, &dev->v4l2_dev);
  12373. + if (ret)
  12374. + goto free_dev;
  12375. +
  12376. + /* setup v4l controls */
  12377. + ret = bm2835_mmal_init_controls(dev, &dev->ctrl_handler);
  12378. + if (ret < 0)
  12379. + goto unreg_dev;
  12380. + dev->v4l2_dev.ctrl_handler = &dev->ctrl_handler;
  12381. +
  12382. + /* mmal init */
  12383. + ret = mmal_init(dev);
  12384. + if (ret < 0)
  12385. + goto unreg_dev;
  12386. +
  12387. + /* initialize queue */
  12388. + q = &dev->capture.vb_vidq;
  12389. + memset(q, 0, sizeof(*q));
  12390. + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
  12391. + q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
  12392. + q->drv_priv = dev;
  12393. + q->buf_struct_size = sizeof(struct mmal_buffer);
  12394. + q->ops = &bm2835_mmal_video_qops;
  12395. + q->mem_ops = &vb2_vmalloc_memops;
  12396. + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
  12397. + ret = vb2_queue_init(q);
  12398. + if (ret < 0)
  12399. + goto unreg_dev;
  12400. +
  12401. + /* v4l2 core mutex used to protect all fops and v4l2 ioctls. */
  12402. + mutex_init(&dev->mutex);
  12403. +
  12404. + /* initialise video devices */
  12405. + ret = bm2835_mmal_init_device(dev, &dev->vdev);
  12406. + if (ret < 0)
  12407. + goto unreg_dev;
  12408. +
  12409. + /* Really want to call vidioc_s_fmt_vid_cap with the default
  12410. + * format, but currently the APIs don't join up.
  12411. + */
  12412. + ret = mmal_setup_components(dev, &default_v4l2_format);
  12413. + if (ret < 0) {
  12414. + v4l2_err(&dev->v4l2_dev,
  12415. + "%s: could not setup components\n", __func__);
  12416. + goto unreg_dev;
  12417. + }
  12418. +
  12419. + v4l2_info(&dev->v4l2_dev,
  12420. + "Broadcom 2835 MMAL video capture ver %s loaded.\n",
  12421. + BM2835_MMAL_VERSION);
  12422. +
  12423. + gdev = dev;
  12424. + return 0;
  12425. +
  12426. +unreg_dev:
  12427. + v4l2_ctrl_handler_free(&dev->ctrl_handler);
  12428. + v4l2_device_unregister(&dev->v4l2_dev);
  12429. +
  12430. +free_dev:
  12431. + kfree(dev);
  12432. +
  12433. + v4l2_err(&dev->v4l2_dev,
  12434. + "%s: error %d while loading driver\n",
  12435. + BM2835_MMAL_MODULE_NAME, ret);
  12436. +
  12437. + return ret;
  12438. +}
  12439. +
  12440. +static void __exit bm2835_mmal_exit(void)
  12441. +{
  12442. + if (!gdev)
  12443. + return;
  12444. +
  12445. + v4l2_info(&gdev->v4l2_dev, "unregistering %s\n",
  12446. + video_device_node_name(&gdev->vdev));
  12447. +
  12448. + video_unregister_device(&gdev->vdev);
  12449. +
  12450. + if (gdev->capture.encode_component) {
  12451. + v4l2_dbg(1, bcm2835_v4l2_debug, &gdev->v4l2_dev,
  12452. + "mmal_exit - disconnect tunnel\n");
  12453. + vchiq_mmal_port_connect_tunnel(gdev->instance,
  12454. + gdev->capture.camera_port, NULL);
  12455. + vchiq_mmal_component_disable(gdev->instance,
  12456. + gdev->capture.encode_component);
  12457. + }
  12458. + vchiq_mmal_component_disable(gdev->instance,
  12459. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12460. +
  12461. + vchiq_mmal_component_finalise(gdev->instance,
  12462. + gdev->
  12463. + component[MMAL_COMPONENT_VIDEO_ENCODE]);
  12464. +
  12465. + vchiq_mmal_component_finalise(gdev->instance,
  12466. + gdev->
  12467. + component[MMAL_COMPONENT_IMAGE_ENCODE]);
  12468. +
  12469. + vchiq_mmal_component_finalise(gdev->instance,
  12470. + gdev->component[MMAL_COMPONENT_PREVIEW]);
  12471. +
  12472. + vchiq_mmal_component_finalise(gdev->instance,
  12473. + gdev->component[MMAL_COMPONENT_CAMERA]);
  12474. +
  12475. + vchiq_mmal_finalise(gdev->instance);
  12476. +
  12477. + v4l2_ctrl_handler_free(&gdev->ctrl_handler);
  12478. +
  12479. + v4l2_device_unregister(&gdev->v4l2_dev);
  12480. +
  12481. + kfree(gdev);
  12482. +}
  12483. +
  12484. +module_init(bm2835_mmal_init);
  12485. +module_exit(bm2835_mmal_exit);
  12486. diff -Nur linux-3.15/drivers/media/platform/bcm2835/bcm2835-camera.h linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h
  12487. --- linux-3.15/drivers/media/platform/bcm2835/bcm2835-camera.h 1970-01-01 01:00:00.000000000 +0100
  12488. +++ linux-rpi/drivers/media/platform/bcm2835/bcm2835-camera.h 2014-06-11 21:03:33.000000000 +0200
  12489. @@ -0,0 +1,126 @@
  12490. +/*
  12491. + * Broadcom BM2835 V4L2 driver
  12492. + *
  12493. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12494. + *
  12495. + * This file is subject to the terms and conditions of the GNU General Public
  12496. + * License. See the file COPYING in the main directory of this archive
  12497. + * for more details.
  12498. + *
  12499. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12500. + * Dave Stevenson <dsteve@broadcom.com>
  12501. + * Simon Mellor <simellor@broadcom.com>
  12502. + * Luke Diamand <luked@broadcom.com>
  12503. + *
  12504. + * core driver device
  12505. + */
  12506. +
  12507. +#define V4L2_CTRL_COUNT 28 /* number of v4l controls */
  12508. +
  12509. +enum {
  12510. + MMAL_COMPONENT_CAMERA = 0,
  12511. + MMAL_COMPONENT_PREVIEW,
  12512. + MMAL_COMPONENT_IMAGE_ENCODE,
  12513. + MMAL_COMPONENT_VIDEO_ENCODE,
  12514. + MMAL_COMPONENT_COUNT
  12515. +};
  12516. +
  12517. +enum {
  12518. + MMAL_CAMERA_PORT_PREVIEW = 0,
  12519. + MMAL_CAMERA_PORT_VIDEO,
  12520. + MMAL_CAMERA_PORT_CAPTURE,
  12521. + MMAL_CAMERA_PORT_COUNT
  12522. +};
  12523. +
  12524. +#define PREVIEW_LAYER 2
  12525. +
  12526. +extern int bcm2835_v4l2_debug;
  12527. +
  12528. +struct bm2835_mmal_dev {
  12529. + /* v4l2 devices */
  12530. + struct v4l2_device v4l2_dev;
  12531. + struct video_device vdev;
  12532. + struct mutex mutex;
  12533. +
  12534. + /* controls */
  12535. + struct v4l2_ctrl_handler ctrl_handler;
  12536. + struct v4l2_ctrl *ctrls[V4L2_CTRL_COUNT];
  12537. + enum v4l2_scene_mode scene_mode;
  12538. + struct mmal_colourfx colourfx;
  12539. + int hflip;
  12540. + int vflip;
  12541. + int red_gain;
  12542. + int blue_gain;
  12543. + enum mmal_parameter_exposuremode exposure_mode_user;
  12544. + enum v4l2_exposure_auto_type exposure_mode_v4l2_user;
  12545. + /* active exposure mode may differ if selected via a scene mode */
  12546. + enum mmal_parameter_exposuremode exposure_mode_active;
  12547. + enum mmal_parameter_exposuremeteringmode metering_mode;
  12548. + unsigned int manual_shutter_speed;
  12549. + bool exp_auto_priority;
  12550. +
  12551. + /* allocated mmal instance and components */
  12552. + struct vchiq_mmal_instance *instance;
  12553. + struct vchiq_mmal_component *component[MMAL_COMPONENT_COUNT];
  12554. + int camera_use_count;
  12555. +
  12556. + struct v4l2_window overlay;
  12557. +
  12558. + struct {
  12559. + unsigned int width; /* width */
  12560. + unsigned int height; /* height */
  12561. + unsigned int stride; /* stride */
  12562. + unsigned int buffersize; /* buffer size with padding */
  12563. + struct mmal_fmt *fmt;
  12564. + struct v4l2_fract timeperframe;
  12565. +
  12566. + /* H264 encode bitrate */
  12567. + int encode_bitrate;
  12568. + /* H264 bitrate mode. CBR/VBR */
  12569. + int encode_bitrate_mode;
  12570. + /* H264 profile */
  12571. + enum v4l2_mpeg_video_h264_profile enc_profile;
  12572. + /* H264 level */
  12573. + enum v4l2_mpeg_video_h264_level enc_level;
  12574. + /* JPEG Q-factor */
  12575. + int q_factor;
  12576. +
  12577. + struct vb2_queue vb_vidq;
  12578. +
  12579. + /* VC start timestamp for streaming */
  12580. + s64 vc_start_timestamp;
  12581. + /* Kernel start timestamp for streaming */
  12582. + struct timeval kernel_start_ts;
  12583. +
  12584. + struct vchiq_mmal_port *port; /* port being used for capture */
  12585. + /* camera port being used for capture */
  12586. + struct vchiq_mmal_port *camera_port;
  12587. + /* component being used for encode */
  12588. + struct vchiq_mmal_component *encode_component;
  12589. + /* number of frames remaining which driver should capture */
  12590. + unsigned int frame_count;
  12591. + /* last frame completion */
  12592. + struct completion frame_cmplt;
  12593. +
  12594. + } capture;
  12595. +
  12596. +};
  12597. +
  12598. +int bm2835_mmal_init_controls(
  12599. + struct bm2835_mmal_dev *dev,
  12600. + struct v4l2_ctrl_handler *hdl);
  12601. +
  12602. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev);
  12603. +int set_framerate_params(struct bm2835_mmal_dev *dev);
  12604. +
  12605. +/* Debug helpers */
  12606. +
  12607. +#define v4l2_dump_pix_format(level, debug, dev, pix_fmt, desc) \
  12608. +{ \
  12609. + v4l2_dbg(level, debug, dev, \
  12610. +"%s: w %u h %u field %u pfmt 0x%x bpl %u sz_img %u colorspace 0x%x priv %u\n", \
  12611. + desc == NULL ? "" : desc, \
  12612. + (pix_fmt)->width, (pix_fmt)->height, (pix_fmt)->field, \
  12613. + (pix_fmt)->pixelformat, (pix_fmt)->bytesperline, \
  12614. + (pix_fmt)->sizeimage, (pix_fmt)->colorspace, (pix_fmt)->priv); \
  12615. +}
  12616. diff -Nur linux-3.15/drivers/media/platform/bcm2835/controls.c linux-rpi/drivers/media/platform/bcm2835/controls.c
  12617. --- linux-3.15/drivers/media/platform/bcm2835/controls.c 1970-01-01 01:00:00.000000000 +0100
  12618. +++ linux-rpi/drivers/media/platform/bcm2835/controls.c 2014-06-11 21:03:33.000000000 +0200
  12619. @@ -0,0 +1,1322 @@
  12620. +/*
  12621. + * Broadcom BM2835 V4L2 driver
  12622. + *
  12623. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  12624. + *
  12625. + * This file is subject to the terms and conditions of the GNU General Public
  12626. + * License. See the file COPYING in the main directory of this archive
  12627. + * for more details.
  12628. + *
  12629. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  12630. + * Dave Stevenson <dsteve@broadcom.com>
  12631. + * Simon Mellor <simellor@broadcom.com>
  12632. + * Luke Diamand <luked@broadcom.com>
  12633. + */
  12634. +
  12635. +#include <linux/errno.h>
  12636. +#include <linux/kernel.h>
  12637. +#include <linux/module.h>
  12638. +#include <linux/slab.h>
  12639. +#include <media/videobuf2-vmalloc.h>
  12640. +#include <media/v4l2-device.h>
  12641. +#include <media/v4l2-ioctl.h>
  12642. +#include <media/v4l2-ctrls.h>
  12643. +#include <media/v4l2-fh.h>
  12644. +#include <media/v4l2-event.h>
  12645. +#include <media/v4l2-common.h>
  12646. +
  12647. +#include "mmal-common.h"
  12648. +#include "mmal-vchiq.h"
  12649. +#include "mmal-parameters.h"
  12650. +#include "bcm2835-camera.h"
  12651. +
  12652. +/* The supported V4L2_CID_AUTO_EXPOSURE_BIAS values are from -4.0 to +4.0.
  12653. + * MMAL values are in 1/6th increments so the MMAL range is -24 to +24.
  12654. + * V4L2 docs say value "is expressed in terms of EV, drivers should interpret
  12655. + * the values as 0.001 EV units, where the value 1000 stands for +1 EV."
  12656. + * V4L2 is limited to a max of 32 values in a menu, so count in 1/3rds from
  12657. + * -4 to +4
  12658. + */
  12659. +static const s64 ev_bias_qmenu[] = {
  12660. + -4000, -3667, -3333,
  12661. + -3000, -2667, -2333,
  12662. + -2000, -1667, -1333,
  12663. + -1000, -667, -333,
  12664. + 0, 333, 667,
  12665. + 1000, 1333, 1667,
  12666. + 2000, 2333, 2667,
  12667. + 3000, 3333, 3667,
  12668. + 4000
  12669. +};
  12670. +
  12671. +/* Supported ISO values
  12672. + * ISOO = auto ISO
  12673. + */
  12674. +static const s64 iso_qmenu[] = {
  12675. + 0, 100, 200, 400, 800,
  12676. +};
  12677. +
  12678. +static const s64 mains_freq_qmenu[] = {
  12679. + V4L2_CID_POWER_LINE_FREQUENCY_DISABLED,
  12680. + V4L2_CID_POWER_LINE_FREQUENCY_50HZ,
  12681. + V4L2_CID_POWER_LINE_FREQUENCY_60HZ,
  12682. + V4L2_CID_POWER_LINE_FREQUENCY_AUTO
  12683. +};
  12684. +
  12685. +/* Supported video encode modes */
  12686. +static const s64 bitrate_mode_qmenu[] = {
  12687. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
  12688. + (s64)V4L2_MPEG_VIDEO_BITRATE_MODE_CBR,
  12689. +};
  12690. +
  12691. +enum bm2835_mmal_ctrl_type {
  12692. + MMAL_CONTROL_TYPE_STD,
  12693. + MMAL_CONTROL_TYPE_STD_MENU,
  12694. + MMAL_CONTROL_TYPE_INT_MENU,
  12695. + MMAL_CONTROL_TYPE_CLUSTER, /* special cluster entry */
  12696. +};
  12697. +
  12698. +struct bm2835_mmal_v4l2_ctrl;
  12699. +
  12700. +typedef int(bm2835_mmal_v4l2_ctrl_cb)(
  12701. + struct bm2835_mmal_dev *dev,
  12702. + struct v4l2_ctrl *ctrl,
  12703. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl);
  12704. +
  12705. +struct bm2835_mmal_v4l2_ctrl {
  12706. + u32 id; /* v4l2 control identifier */
  12707. + enum bm2835_mmal_ctrl_type type;
  12708. + /* control minimum value or
  12709. + * mask for MMAL_CONTROL_TYPE_STD_MENU */
  12710. + s32 min;
  12711. + s32 max; /* maximum value of control */
  12712. + s32 def; /* default value of control */
  12713. + s32 step; /* step size of the control */
  12714. + const s64 *imenu; /* integer menu array */
  12715. + u32 mmal_id; /* mmal parameter id */
  12716. + bm2835_mmal_v4l2_ctrl_cb *setter;
  12717. + bool ignore_errors;
  12718. +};
  12719. +
  12720. +struct v4l2_to_mmal_effects_setting {
  12721. + u32 v4l2_effect;
  12722. + u32 mmal_effect;
  12723. + s32 col_fx_enable;
  12724. + s32 col_fx_fixed_cbcr;
  12725. + u32 u;
  12726. + u32 v;
  12727. + u32 num_effect_params;
  12728. + u32 effect_params[MMAL_MAX_IMAGEFX_PARAMETERS];
  12729. +};
  12730. +
  12731. +static const struct v4l2_to_mmal_effects_setting
  12732. + v4l2_to_mmal_effects_values[] = {
  12733. + { V4L2_COLORFX_NONE, MMAL_PARAM_IMAGEFX_NONE,
  12734. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12735. + { V4L2_COLORFX_BW, MMAL_PARAM_IMAGEFX_NONE,
  12736. + 1, 0, 128, 128, 0, {0, 0, 0, 0, 0} },
  12737. + { V4L2_COLORFX_SEPIA, MMAL_PARAM_IMAGEFX_NONE,
  12738. + 1, 0, 87, 151, 0, {0, 0, 0, 0, 0} },
  12739. + { V4L2_COLORFX_NEGATIVE, MMAL_PARAM_IMAGEFX_NEGATIVE,
  12740. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12741. + { V4L2_COLORFX_EMBOSS, MMAL_PARAM_IMAGEFX_EMBOSS,
  12742. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12743. + { V4L2_COLORFX_SKETCH, MMAL_PARAM_IMAGEFX_SKETCH,
  12744. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12745. + { V4L2_COLORFX_SKY_BLUE, MMAL_PARAM_IMAGEFX_PASTEL,
  12746. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12747. + { V4L2_COLORFX_GRASS_GREEN, MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  12748. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12749. + { V4L2_COLORFX_SKIN_WHITEN, MMAL_PARAM_IMAGEFX_WASHEDOUT,
  12750. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12751. + { V4L2_COLORFX_VIVID, MMAL_PARAM_IMAGEFX_SATURATION,
  12752. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12753. + { V4L2_COLORFX_AQUA, MMAL_PARAM_IMAGEFX_NONE,
  12754. + 1, 0, 171, 121, 0, {0, 0, 0, 0, 0} },
  12755. + { V4L2_COLORFX_ART_FREEZE, MMAL_PARAM_IMAGEFX_HATCH,
  12756. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12757. + { V4L2_COLORFX_SILHOUETTE, MMAL_PARAM_IMAGEFX_FILM,
  12758. + 0, 0, 0, 0, 0, {0, 0, 0, 0, 0} },
  12759. + { V4L2_COLORFX_SOLARIZATION, MMAL_PARAM_IMAGEFX_SOLARIZE,
  12760. + 0, 0, 0, 0, 5, {1, 128, 160, 160, 48} },
  12761. + { V4L2_COLORFX_ANTIQUE, MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  12762. + 0, 0, 0, 0, 3, {108, 274, 238, 0, 0} },
  12763. + { V4L2_COLORFX_SET_CBCR, MMAL_PARAM_IMAGEFX_NONE,
  12764. + 1, 1, 0, 0, 0, {0, 0, 0, 0, 0} }
  12765. +};
  12766. +
  12767. +struct v4l2_mmal_scene_config {
  12768. + enum v4l2_scene_mode v4l2_scene;
  12769. + enum mmal_parameter_exposuremode exposure_mode;
  12770. + enum mmal_parameter_exposuremeteringmode metering_mode;
  12771. +};
  12772. +
  12773. +static const struct v4l2_mmal_scene_config scene_configs[] = {
  12774. + /* V4L2_SCENE_MODE_NONE automatically added */
  12775. + {
  12776. + V4L2_SCENE_MODE_NIGHT,
  12777. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  12778. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  12779. + },
  12780. + {
  12781. + V4L2_SCENE_MODE_SPORTS,
  12782. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  12783. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE
  12784. + },
  12785. +};
  12786. +
  12787. +/* control handlers*/
  12788. +
  12789. +static int ctrl_set_rational(struct bm2835_mmal_dev *dev,
  12790. + struct v4l2_ctrl *ctrl,
  12791. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12792. +{
  12793. + struct mmal_parameter_rational rational_value;
  12794. + struct vchiq_mmal_port *control;
  12795. +
  12796. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12797. +
  12798. + rational_value.num = ctrl->val;
  12799. + rational_value.den = 100;
  12800. +
  12801. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12802. + mmal_ctrl->mmal_id,
  12803. + &rational_value,
  12804. + sizeof(rational_value));
  12805. +}
  12806. +
  12807. +static int ctrl_set_value(struct bm2835_mmal_dev *dev,
  12808. + struct v4l2_ctrl *ctrl,
  12809. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12810. +{
  12811. + u32 u32_value;
  12812. + struct vchiq_mmal_port *control;
  12813. +
  12814. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12815. +
  12816. + u32_value = ctrl->val;
  12817. +
  12818. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12819. + mmal_ctrl->mmal_id,
  12820. + &u32_value, sizeof(u32_value));
  12821. +}
  12822. +
  12823. +static int ctrl_set_value_menu(struct bm2835_mmal_dev *dev,
  12824. + struct v4l2_ctrl *ctrl,
  12825. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12826. +{
  12827. + u32 u32_value;
  12828. + struct vchiq_mmal_port *control;
  12829. +
  12830. + if (ctrl->val > mmal_ctrl->max || ctrl->val < mmal_ctrl->min)
  12831. + return 1;
  12832. +
  12833. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12834. +
  12835. + u32_value = mmal_ctrl->imenu[ctrl->val];
  12836. +
  12837. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12838. + mmal_ctrl->mmal_id,
  12839. + &u32_value, sizeof(u32_value));
  12840. +}
  12841. +
  12842. +static int ctrl_set_value_ev(struct bm2835_mmal_dev *dev,
  12843. + struct v4l2_ctrl *ctrl,
  12844. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12845. +{
  12846. + s32 s32_value;
  12847. + struct vchiq_mmal_port *control;
  12848. +
  12849. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12850. +
  12851. + s32_value = (ctrl->val-12)*2; /* Convert from index to 1/6ths */
  12852. +
  12853. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  12854. + mmal_ctrl->mmal_id,
  12855. + &s32_value, sizeof(s32_value));
  12856. +}
  12857. +
  12858. +static int ctrl_set_rotate(struct bm2835_mmal_dev *dev,
  12859. + struct v4l2_ctrl *ctrl,
  12860. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12861. +{
  12862. + int ret;
  12863. + u32 u32_value;
  12864. + struct vchiq_mmal_component *camera;
  12865. +
  12866. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12867. +
  12868. + u32_value = ((ctrl->val % 360) / 90) * 90;
  12869. +
  12870. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12871. + mmal_ctrl->mmal_id,
  12872. + &u32_value, sizeof(u32_value));
  12873. + if (ret < 0)
  12874. + return ret;
  12875. +
  12876. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12877. + mmal_ctrl->mmal_id,
  12878. + &u32_value, sizeof(u32_value));
  12879. + if (ret < 0)
  12880. + return ret;
  12881. +
  12882. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12883. + mmal_ctrl->mmal_id,
  12884. + &u32_value, sizeof(u32_value));
  12885. +
  12886. + return ret;
  12887. +}
  12888. +
  12889. +static int ctrl_set_flip(struct bm2835_mmal_dev *dev,
  12890. + struct v4l2_ctrl *ctrl,
  12891. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12892. +{
  12893. + int ret;
  12894. + u32 u32_value;
  12895. + struct vchiq_mmal_component *camera;
  12896. +
  12897. + if (ctrl->id == V4L2_CID_HFLIP)
  12898. + dev->hflip = ctrl->val;
  12899. + else
  12900. + dev->vflip = ctrl->val;
  12901. +
  12902. + camera = dev->component[MMAL_COMPONENT_CAMERA];
  12903. +
  12904. + if (dev->hflip && dev->vflip)
  12905. + u32_value = MMAL_PARAM_MIRROR_BOTH;
  12906. + else if (dev->hflip)
  12907. + u32_value = MMAL_PARAM_MIRROR_HORIZONTAL;
  12908. + else if (dev->vflip)
  12909. + u32_value = MMAL_PARAM_MIRROR_VERTICAL;
  12910. + else
  12911. + u32_value = MMAL_PARAM_MIRROR_NONE;
  12912. +
  12913. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[0],
  12914. + mmal_ctrl->mmal_id,
  12915. + &u32_value, sizeof(u32_value));
  12916. + if (ret < 0)
  12917. + return ret;
  12918. +
  12919. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[1],
  12920. + mmal_ctrl->mmal_id,
  12921. + &u32_value, sizeof(u32_value));
  12922. + if (ret < 0)
  12923. + return ret;
  12924. +
  12925. + ret = vchiq_mmal_port_parameter_set(dev->instance, &camera->output[2],
  12926. + mmal_ctrl->mmal_id,
  12927. + &u32_value, sizeof(u32_value));
  12928. +
  12929. + return ret;
  12930. +
  12931. +}
  12932. +
  12933. +static int ctrl_set_exposure(struct bm2835_mmal_dev *dev,
  12934. + struct v4l2_ctrl *ctrl,
  12935. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12936. +{
  12937. + enum mmal_parameter_exposuremode exp_mode = dev->exposure_mode_user;
  12938. + u32 shutter_speed = 0;
  12939. + struct vchiq_mmal_port *control;
  12940. + int ret = 0;
  12941. +
  12942. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  12943. +
  12944. + if (mmal_ctrl->mmal_id == MMAL_PARAMETER_SHUTTER_SPEED) {
  12945. + /* V4L2 is in 100usec increments.
  12946. + * MMAL is 1usec.
  12947. + */
  12948. + dev->manual_shutter_speed = ctrl->val * 100;
  12949. + } else if (mmal_ctrl->mmal_id == MMAL_PARAMETER_EXPOSURE_MODE) {
  12950. + switch (ctrl->val) {
  12951. + case V4L2_EXPOSURE_AUTO:
  12952. + exp_mode = MMAL_PARAM_EXPOSUREMODE_AUTO;
  12953. + break;
  12954. +
  12955. + case V4L2_EXPOSURE_MANUAL:
  12956. + exp_mode = MMAL_PARAM_EXPOSUREMODE_OFF;
  12957. + break;
  12958. + }
  12959. + dev->exposure_mode_user = exp_mode;
  12960. + dev->exposure_mode_v4l2_user = ctrl->val;
  12961. + } else if (mmal_ctrl->id == V4L2_CID_EXPOSURE_AUTO_PRIORITY) {
  12962. + dev->exp_auto_priority = ctrl->val;
  12963. + }
  12964. +
  12965. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  12966. + if (exp_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  12967. + shutter_speed = dev->manual_shutter_speed;
  12968. +
  12969. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  12970. + control,
  12971. + MMAL_PARAMETER_SHUTTER_SPEED,
  12972. + &shutter_speed,
  12973. + sizeof(shutter_speed));
  12974. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  12975. + control,
  12976. + MMAL_PARAMETER_EXPOSURE_MODE,
  12977. + &exp_mode,
  12978. + sizeof(u32));
  12979. + dev->exposure_mode_active = exp_mode;
  12980. + }
  12981. + /* exposure_dynamic_framerate (V4L2_CID_EXPOSURE_AUTO_PRIORITY) should
  12982. + * always apply irrespective of scene mode.
  12983. + */
  12984. + ret += set_framerate_params(dev);
  12985. +
  12986. + return ret;
  12987. +}
  12988. +
  12989. +static int ctrl_set_metering_mode(struct bm2835_mmal_dev *dev,
  12990. + struct v4l2_ctrl *ctrl,
  12991. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  12992. +{
  12993. + switch (ctrl->val) {
  12994. + case V4L2_EXPOSURE_METERING_AVERAGE:
  12995. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE;
  12996. + break;
  12997. +
  12998. + case V4L2_EXPOSURE_METERING_CENTER_WEIGHTED:
  12999. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT;
  13000. + break;
  13001. +
  13002. + case V4L2_EXPOSURE_METERING_SPOT:
  13003. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT;
  13004. + break;
  13005. +
  13006. + /* todo matrix weighting not added to Linux API till 3.9
  13007. + case V4L2_EXPOSURE_METERING_MATRIX:
  13008. + dev->metering_mode = MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX;
  13009. + break;
  13010. + */
  13011. +
  13012. + }
  13013. +
  13014. + if (dev->scene_mode == V4L2_SCENE_MODE_NONE) {
  13015. + struct vchiq_mmal_port *control;
  13016. + u32 u32_value = dev->metering_mode;
  13017. +
  13018. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13019. +
  13020. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13021. + mmal_ctrl->mmal_id,
  13022. + &u32_value, sizeof(u32_value));
  13023. + } else
  13024. + return 0;
  13025. +}
  13026. +
  13027. +static int ctrl_set_flicker_avoidance(struct bm2835_mmal_dev *dev,
  13028. + struct v4l2_ctrl *ctrl,
  13029. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13030. +{
  13031. + u32 u32_value;
  13032. + struct vchiq_mmal_port *control;
  13033. +
  13034. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13035. +
  13036. + switch (ctrl->val) {
  13037. + case V4L2_CID_POWER_LINE_FREQUENCY_DISABLED:
  13038. + u32_value = MMAL_PARAM_FLICKERAVOID_OFF;
  13039. + break;
  13040. + case V4L2_CID_POWER_LINE_FREQUENCY_50HZ:
  13041. + u32_value = MMAL_PARAM_FLICKERAVOID_50HZ;
  13042. + break;
  13043. + case V4L2_CID_POWER_LINE_FREQUENCY_60HZ:
  13044. + u32_value = MMAL_PARAM_FLICKERAVOID_60HZ;
  13045. + break;
  13046. + case V4L2_CID_POWER_LINE_FREQUENCY_AUTO:
  13047. + u32_value = MMAL_PARAM_FLICKERAVOID_AUTO;
  13048. + break;
  13049. + }
  13050. +
  13051. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13052. + mmal_ctrl->mmal_id,
  13053. + &u32_value, sizeof(u32_value));
  13054. +}
  13055. +
  13056. +static int ctrl_set_awb_mode(struct bm2835_mmal_dev *dev,
  13057. + struct v4l2_ctrl *ctrl,
  13058. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13059. +{
  13060. + u32 u32_value;
  13061. + struct vchiq_mmal_port *control;
  13062. +
  13063. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13064. +
  13065. + switch (ctrl->val) {
  13066. + case V4L2_WHITE_BALANCE_MANUAL:
  13067. + u32_value = MMAL_PARAM_AWBMODE_OFF;
  13068. + break;
  13069. +
  13070. + case V4L2_WHITE_BALANCE_AUTO:
  13071. + u32_value = MMAL_PARAM_AWBMODE_AUTO;
  13072. + break;
  13073. +
  13074. + case V4L2_WHITE_BALANCE_INCANDESCENT:
  13075. + u32_value = MMAL_PARAM_AWBMODE_INCANDESCENT;
  13076. + break;
  13077. +
  13078. + case V4L2_WHITE_BALANCE_FLUORESCENT:
  13079. + u32_value = MMAL_PARAM_AWBMODE_FLUORESCENT;
  13080. + break;
  13081. +
  13082. + case V4L2_WHITE_BALANCE_FLUORESCENT_H:
  13083. + u32_value = MMAL_PARAM_AWBMODE_TUNGSTEN;
  13084. + break;
  13085. +
  13086. + case V4L2_WHITE_BALANCE_HORIZON:
  13087. + u32_value = MMAL_PARAM_AWBMODE_HORIZON;
  13088. + break;
  13089. +
  13090. + case V4L2_WHITE_BALANCE_DAYLIGHT:
  13091. + u32_value = MMAL_PARAM_AWBMODE_SUNLIGHT;
  13092. + break;
  13093. +
  13094. + case V4L2_WHITE_BALANCE_FLASH:
  13095. + u32_value = MMAL_PARAM_AWBMODE_FLASH;
  13096. + break;
  13097. +
  13098. + case V4L2_WHITE_BALANCE_CLOUDY:
  13099. + u32_value = MMAL_PARAM_AWBMODE_CLOUDY;
  13100. + break;
  13101. +
  13102. + case V4L2_WHITE_BALANCE_SHADE:
  13103. + u32_value = MMAL_PARAM_AWBMODE_SHADE;
  13104. + break;
  13105. +
  13106. + }
  13107. +
  13108. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13109. + mmal_ctrl->mmal_id,
  13110. + &u32_value, sizeof(u32_value));
  13111. +}
  13112. +
  13113. +static int ctrl_set_awb_gains(struct bm2835_mmal_dev *dev,
  13114. + struct v4l2_ctrl *ctrl,
  13115. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13116. +{
  13117. + struct vchiq_mmal_port *control;
  13118. + struct mmal_parameter_awbgains gains;
  13119. +
  13120. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13121. +
  13122. + if (ctrl->id == V4L2_CID_RED_BALANCE)
  13123. + dev->red_gain = ctrl->val;
  13124. + else if (ctrl->id == V4L2_CID_BLUE_BALANCE)
  13125. + dev->blue_gain = ctrl->val;
  13126. +
  13127. + gains.r_gain.num = dev->red_gain;
  13128. + gains.b_gain.num = dev->blue_gain;
  13129. + gains.r_gain.den = gains.b_gain.den = 1000;
  13130. +
  13131. + return vchiq_mmal_port_parameter_set(dev->instance, control,
  13132. + mmal_ctrl->mmal_id,
  13133. + &gains, sizeof(gains));
  13134. +}
  13135. +
  13136. +static int ctrl_set_image_effect(struct bm2835_mmal_dev *dev,
  13137. + struct v4l2_ctrl *ctrl,
  13138. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13139. +{
  13140. + int ret = -EINVAL;
  13141. + int i, j;
  13142. + struct vchiq_mmal_port *control;
  13143. + struct mmal_parameter_imagefx_parameters imagefx;
  13144. +
  13145. + for (i = 0; i < ARRAY_SIZE(v4l2_to_mmal_effects_values); i++) {
  13146. + if (ctrl->val == v4l2_to_mmal_effects_values[i].v4l2_effect) {
  13147. +
  13148. + imagefx.effect =
  13149. + v4l2_to_mmal_effects_values[i].mmal_effect;
  13150. + imagefx.num_effect_params =
  13151. + v4l2_to_mmal_effects_values[i].num_effect_params;
  13152. +
  13153. + if (imagefx.num_effect_params > MMAL_MAX_IMAGEFX_PARAMETERS)
  13154. + imagefx.num_effect_params = MMAL_MAX_IMAGEFX_PARAMETERS;
  13155. +
  13156. + for (j = 0; j < imagefx.num_effect_params; j++)
  13157. + imagefx.effect_parameter[j] =
  13158. + v4l2_to_mmal_effects_values[i].effect_params[j];
  13159. +
  13160. + dev->colourfx.enable =
  13161. + v4l2_to_mmal_effects_values[i].col_fx_enable;
  13162. + if (!v4l2_to_mmal_effects_values[i].col_fx_fixed_cbcr) {
  13163. + dev->colourfx.u =
  13164. + v4l2_to_mmal_effects_values[i].u;
  13165. + dev->colourfx.v =
  13166. + v4l2_to_mmal_effects_values[i].v;
  13167. + }
  13168. +
  13169. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13170. +
  13171. + ret = vchiq_mmal_port_parameter_set(
  13172. + dev->instance, control,
  13173. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  13174. + &imagefx, sizeof(imagefx));
  13175. + if (ret)
  13176. + goto exit;
  13177. +
  13178. + ret = vchiq_mmal_port_parameter_set(
  13179. + dev->instance, control,
  13180. + MMAL_PARAMETER_COLOUR_EFFECT,
  13181. + &dev->colourfx, sizeof(dev->colourfx));
  13182. + }
  13183. + }
  13184. +
  13185. +exit:
  13186. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13187. + "mmal_ctrl:%p ctrl id:0x%x ctrl val:%d imagefx:0x%x color_effect:%s u:%d v:%d ret %d(%d)\n",
  13188. + mmal_ctrl, ctrl->id, ctrl->val, imagefx.effect,
  13189. + dev->colourfx.enable ? "true" : "false",
  13190. + dev->colourfx.u, dev->colourfx.v,
  13191. + ret, (ret == 0 ? 0 : -EINVAL));
  13192. + return (ret == 0 ? 0 : EINVAL);
  13193. +}
  13194. +
  13195. +static int ctrl_set_colfx(struct bm2835_mmal_dev *dev,
  13196. + struct v4l2_ctrl *ctrl,
  13197. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13198. +{
  13199. + int ret = -EINVAL;
  13200. + struct vchiq_mmal_port *control;
  13201. +
  13202. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13203. +
  13204. + dev->colourfx.enable = (ctrl->val & 0xff00) >> 8;
  13205. + dev->colourfx.enable = ctrl->val & 0xff;
  13206. +
  13207. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13208. + MMAL_PARAMETER_COLOUR_EFFECT,
  13209. + &dev->colourfx, sizeof(dev->colourfx));
  13210. +
  13211. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13212. + "%s: After: mmal_ctrl:%p ctrl id:0x%x ctrl val:%d ret %d(%d)\n",
  13213. + __func__, mmal_ctrl, ctrl->id, ctrl->val, ret,
  13214. + (ret == 0 ? 0 : -EINVAL));
  13215. + return (ret == 0 ? 0 : EINVAL);
  13216. +}
  13217. +
  13218. +static int ctrl_set_bitrate(struct bm2835_mmal_dev *dev,
  13219. + struct v4l2_ctrl *ctrl,
  13220. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13221. +{
  13222. + int ret;
  13223. + struct vchiq_mmal_port *encoder_out;
  13224. +
  13225. + dev->capture.encode_bitrate = ctrl->val;
  13226. +
  13227. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13228. +
  13229. + ret = vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13230. + mmal_ctrl->mmal_id,
  13231. + &ctrl->val, sizeof(ctrl->val));
  13232. + ret = 0;
  13233. + return ret;
  13234. +}
  13235. +
  13236. +static int ctrl_set_bitrate_mode(struct bm2835_mmal_dev *dev,
  13237. + struct v4l2_ctrl *ctrl,
  13238. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13239. +{
  13240. + u32 bitrate_mode;
  13241. + struct vchiq_mmal_port *encoder_out;
  13242. +
  13243. + encoder_out = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13244. +
  13245. + dev->capture.encode_bitrate_mode = ctrl->val;
  13246. + switch (ctrl->val) {
  13247. + default:
  13248. + case V4L2_MPEG_VIDEO_BITRATE_MODE_VBR:
  13249. + bitrate_mode = MMAL_VIDEO_RATECONTROL_VARIABLE;
  13250. + break;
  13251. + case V4L2_MPEG_VIDEO_BITRATE_MODE_CBR:
  13252. + bitrate_mode = MMAL_VIDEO_RATECONTROL_CONSTANT;
  13253. + break;
  13254. + }
  13255. +
  13256. + vchiq_mmal_port_parameter_set(dev->instance, encoder_out,
  13257. + mmal_ctrl->mmal_id,
  13258. + &bitrate_mode,
  13259. + sizeof(bitrate_mode));
  13260. + return 0;
  13261. +}
  13262. +
  13263. +static int ctrl_set_image_encode_output(struct bm2835_mmal_dev *dev,
  13264. + struct v4l2_ctrl *ctrl,
  13265. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13266. +{
  13267. + u32 u32_value;
  13268. + struct vchiq_mmal_port *jpeg_out;
  13269. +
  13270. + jpeg_out = &dev->component[MMAL_COMPONENT_IMAGE_ENCODE]->output[0];
  13271. +
  13272. + u32_value = ctrl->val;
  13273. +
  13274. + return vchiq_mmal_port_parameter_set(dev->instance, jpeg_out,
  13275. + mmal_ctrl->mmal_id,
  13276. + &u32_value, sizeof(u32_value));
  13277. +}
  13278. +
  13279. +static int ctrl_set_video_encode_param_output(struct bm2835_mmal_dev *dev,
  13280. + struct v4l2_ctrl *ctrl,
  13281. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13282. +{
  13283. + u32 u32_value;
  13284. + struct vchiq_mmal_port *vid_enc_ctl;
  13285. +
  13286. + vid_enc_ctl = &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0];
  13287. +
  13288. + u32_value = ctrl->val;
  13289. +
  13290. + return vchiq_mmal_port_parameter_set(dev->instance, vid_enc_ctl,
  13291. + mmal_ctrl->mmal_id,
  13292. + &u32_value, sizeof(u32_value));
  13293. +}
  13294. +
  13295. +static int ctrl_set_video_encode_profile_level(struct bm2835_mmal_dev *dev,
  13296. + struct v4l2_ctrl *ctrl,
  13297. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13298. +{
  13299. + struct mmal_parameter_video_profile param;
  13300. + int ret = 0;
  13301. +
  13302. + if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_PROFILE) {
  13303. + switch (ctrl->val) {
  13304. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13305. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13306. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13307. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13308. + dev->capture.enc_profile = ctrl->val;
  13309. + break;
  13310. + default:
  13311. + ret = -EINVAL;
  13312. + break;
  13313. + }
  13314. + } else if (ctrl->id == V4L2_CID_MPEG_VIDEO_H264_LEVEL) {
  13315. + switch (ctrl->val) {
  13316. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13317. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13318. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13319. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13320. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13321. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13322. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13323. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13324. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13325. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13326. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13327. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13328. + dev->capture.enc_level = ctrl->val;
  13329. + break;
  13330. + default:
  13331. + ret = -EINVAL;
  13332. + break;
  13333. + }
  13334. + }
  13335. +
  13336. + if (!ret) {
  13337. + switch (dev->capture.enc_profile) {
  13338. + case V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE:
  13339. + param.profile = MMAL_VIDEO_PROFILE_H264_BASELINE;
  13340. + break;
  13341. + case V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE:
  13342. + param.profile =
  13343. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE;
  13344. + break;
  13345. + case V4L2_MPEG_VIDEO_H264_PROFILE_MAIN:
  13346. + param.profile = MMAL_VIDEO_PROFILE_H264_MAIN;
  13347. + break;
  13348. + case V4L2_MPEG_VIDEO_H264_PROFILE_HIGH:
  13349. + param.profile = MMAL_VIDEO_PROFILE_H264_HIGH;
  13350. + break;
  13351. + default:
  13352. + /* Should never get here */
  13353. + break;
  13354. + }
  13355. +
  13356. + switch (dev->capture.enc_level) {
  13357. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_0:
  13358. + param.level = MMAL_VIDEO_LEVEL_H264_1;
  13359. + break;
  13360. + case V4L2_MPEG_VIDEO_H264_LEVEL_1B:
  13361. + param.level = MMAL_VIDEO_LEVEL_H264_1b;
  13362. + break;
  13363. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_1:
  13364. + param.level = MMAL_VIDEO_LEVEL_H264_11;
  13365. + break;
  13366. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_2:
  13367. + param.level = MMAL_VIDEO_LEVEL_H264_12;
  13368. + break;
  13369. + case V4L2_MPEG_VIDEO_H264_LEVEL_1_3:
  13370. + param.level = MMAL_VIDEO_LEVEL_H264_13;
  13371. + break;
  13372. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_0:
  13373. + param.level = MMAL_VIDEO_LEVEL_H264_2;
  13374. + break;
  13375. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_1:
  13376. + param.level = MMAL_VIDEO_LEVEL_H264_21;
  13377. + break;
  13378. + case V4L2_MPEG_VIDEO_H264_LEVEL_2_2:
  13379. + param.level = MMAL_VIDEO_LEVEL_H264_22;
  13380. + break;
  13381. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_0:
  13382. + param.level = MMAL_VIDEO_LEVEL_H264_3;
  13383. + break;
  13384. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_1:
  13385. + param.level = MMAL_VIDEO_LEVEL_H264_31;
  13386. + break;
  13387. + case V4L2_MPEG_VIDEO_H264_LEVEL_3_2:
  13388. + param.level = MMAL_VIDEO_LEVEL_H264_32;
  13389. + break;
  13390. + case V4L2_MPEG_VIDEO_H264_LEVEL_4_0:
  13391. + param.level = MMAL_VIDEO_LEVEL_H264_4;
  13392. + break;
  13393. + default:
  13394. + /* Should never get here */
  13395. + break;
  13396. + }
  13397. +
  13398. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13399. + &dev->component[MMAL_COMPONENT_VIDEO_ENCODE]->output[0],
  13400. + mmal_ctrl->mmal_id,
  13401. + &param, sizeof(param));
  13402. + }
  13403. + return ret;
  13404. +}
  13405. +
  13406. +static int ctrl_set_scene_mode(struct bm2835_mmal_dev *dev,
  13407. + struct v4l2_ctrl *ctrl,
  13408. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl)
  13409. +{
  13410. + int ret = 0;
  13411. + int shutter_speed;
  13412. + struct vchiq_mmal_port *control;
  13413. +
  13414. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13415. + "scene mode selected %d, was %d\n", ctrl->val,
  13416. + dev->scene_mode);
  13417. + control = &dev->component[MMAL_COMPONENT_CAMERA]->control;
  13418. +
  13419. + if (ctrl->val == dev->scene_mode)
  13420. + return 0;
  13421. +
  13422. + if (ctrl->val == V4L2_SCENE_MODE_NONE) {
  13423. + /* Restore all user selections */
  13424. + dev->scene_mode = V4L2_SCENE_MODE_NONE;
  13425. +
  13426. + if (dev->exposure_mode_user == MMAL_PARAM_EXPOSUREMODE_OFF)
  13427. + shutter_speed = dev->manual_shutter_speed;
  13428. + else
  13429. + shutter_speed = 0;
  13430. +
  13431. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13432. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  13433. + __func__, shutter_speed, dev->exposure_mode_user,
  13434. + dev->metering_mode);
  13435. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13436. + control,
  13437. + MMAL_PARAMETER_SHUTTER_SPEED,
  13438. + &shutter_speed,
  13439. + sizeof(shutter_speed));
  13440. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13441. + control,
  13442. + MMAL_PARAMETER_EXPOSURE_MODE,
  13443. + &dev->exposure_mode_user,
  13444. + sizeof(u32));
  13445. + dev->exposure_mode_active = dev->exposure_mode_user;
  13446. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13447. + control,
  13448. + MMAL_PARAMETER_EXP_METERING_MODE,
  13449. + &dev->metering_mode,
  13450. + sizeof(u32));
  13451. + ret += set_framerate_params(dev);
  13452. + } else {
  13453. + /* Set up scene mode */
  13454. + int i;
  13455. + const struct v4l2_mmal_scene_config *scene = NULL;
  13456. + int shutter_speed;
  13457. + enum mmal_parameter_exposuremode exposure_mode;
  13458. + enum mmal_parameter_exposuremeteringmode metering_mode;
  13459. +
  13460. + for (i = 0; i < ARRAY_SIZE(scene_configs); i++) {
  13461. + if (scene_configs[i].v4l2_scene ==
  13462. + ctrl->val) {
  13463. + scene = &scene_configs[i];
  13464. + break;
  13465. + }
  13466. + }
  13467. + if (i >= ARRAY_SIZE(scene_configs))
  13468. + return -EINVAL;
  13469. +
  13470. + /* Set all the values */
  13471. + dev->scene_mode = ctrl->val;
  13472. +
  13473. + if (scene->exposure_mode == MMAL_PARAM_EXPOSUREMODE_OFF)
  13474. + shutter_speed = dev->manual_shutter_speed;
  13475. + else
  13476. + shutter_speed = 0;
  13477. + exposure_mode = scene->exposure_mode;
  13478. + metering_mode = scene->metering_mode;
  13479. +
  13480. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13481. + "%s: scene mode none: shut_speed %d, exp_mode %d, metering %d\n",
  13482. + __func__, shutter_speed, exposure_mode, metering_mode);
  13483. +
  13484. + ret = vchiq_mmal_port_parameter_set(dev->instance, control,
  13485. + MMAL_PARAMETER_SHUTTER_SPEED,
  13486. + &shutter_speed,
  13487. + sizeof(shutter_speed));
  13488. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13489. + control,
  13490. + MMAL_PARAMETER_EXPOSURE_MODE,
  13491. + &exposure_mode,
  13492. + sizeof(u32));
  13493. + dev->exposure_mode_active = exposure_mode;
  13494. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  13495. + MMAL_PARAMETER_EXPOSURE_MODE,
  13496. + &exposure_mode,
  13497. + sizeof(u32));
  13498. + ret += vchiq_mmal_port_parameter_set(dev->instance, control,
  13499. + MMAL_PARAMETER_EXP_METERING_MODE,
  13500. + &metering_mode,
  13501. + sizeof(u32));
  13502. + ret += set_framerate_params(dev);
  13503. + }
  13504. + if (ret) {
  13505. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13506. + "%s: Setting scene to %d, ret=%d\n",
  13507. + __func__, ctrl->val, ret);
  13508. + ret = -EINVAL;
  13509. + }
  13510. + return 0;
  13511. +}
  13512. +
  13513. +static int bm2835_mmal_s_ctrl(struct v4l2_ctrl *ctrl)
  13514. +{
  13515. + struct bm2835_mmal_dev *dev =
  13516. + container_of(ctrl->handler, struct bm2835_mmal_dev,
  13517. + ctrl_handler);
  13518. + const struct bm2835_mmal_v4l2_ctrl *mmal_ctrl = ctrl->priv;
  13519. + int ret;
  13520. +
  13521. + if ((mmal_ctrl == NULL) ||
  13522. + (mmal_ctrl->id != ctrl->id) ||
  13523. + (mmal_ctrl->setter == NULL)) {
  13524. + pr_warn("mmal_ctrl:%p ctrl id:%d\n", mmal_ctrl, ctrl->id);
  13525. + return -EINVAL;
  13526. + }
  13527. +
  13528. + ret = mmal_ctrl->setter(dev, ctrl, mmal_ctrl);
  13529. + if (ret)
  13530. + pr_warn("ctrl id:%d/MMAL param %08X- returned ret %d\n",
  13531. + ctrl->id, mmal_ctrl->mmal_id, ret);
  13532. + if (mmal_ctrl->ignore_errors)
  13533. + ret = 0;
  13534. + return ret;
  13535. +}
  13536. +
  13537. +static const struct v4l2_ctrl_ops bm2835_mmal_ctrl_ops = {
  13538. + .s_ctrl = bm2835_mmal_s_ctrl,
  13539. +};
  13540. +
  13541. +
  13542. +
  13543. +static const struct bm2835_mmal_v4l2_ctrl v4l2_ctrls[V4L2_CTRL_COUNT] = {
  13544. + {
  13545. + V4L2_CID_SATURATION, MMAL_CONTROL_TYPE_STD,
  13546. + -100, 100, 0, 1, NULL,
  13547. + MMAL_PARAMETER_SATURATION,
  13548. + &ctrl_set_rational,
  13549. + false
  13550. + },
  13551. + {
  13552. + V4L2_CID_SHARPNESS, MMAL_CONTROL_TYPE_STD,
  13553. + -100, 100, 0, 1, NULL,
  13554. + MMAL_PARAMETER_SHARPNESS,
  13555. + &ctrl_set_rational,
  13556. + false
  13557. + },
  13558. + {
  13559. + V4L2_CID_CONTRAST, MMAL_CONTROL_TYPE_STD,
  13560. + -100, 100, 0, 1, NULL,
  13561. + MMAL_PARAMETER_CONTRAST,
  13562. + &ctrl_set_rational,
  13563. + false
  13564. + },
  13565. + {
  13566. + V4L2_CID_BRIGHTNESS, MMAL_CONTROL_TYPE_STD,
  13567. + 0, 100, 50, 1, NULL,
  13568. + MMAL_PARAMETER_BRIGHTNESS,
  13569. + &ctrl_set_rational,
  13570. + false
  13571. + },
  13572. + {
  13573. + V4L2_CID_ISO_SENSITIVITY, MMAL_CONTROL_TYPE_INT_MENU,
  13574. + 0, ARRAY_SIZE(iso_qmenu) - 1, 0, 1, iso_qmenu,
  13575. + MMAL_PARAMETER_ISO,
  13576. + &ctrl_set_value_menu,
  13577. + false
  13578. + },
  13579. + {
  13580. + V4L2_CID_IMAGE_STABILIZATION, MMAL_CONTROL_TYPE_STD,
  13581. + 0, 1, 0, 1, NULL,
  13582. + MMAL_PARAMETER_VIDEO_STABILISATION,
  13583. + &ctrl_set_value,
  13584. + false
  13585. + },
  13586. +/* {
  13587. + 0, MMAL_CONTROL_TYPE_CLUSTER, 3, 1, 0, NULL, 0, NULL
  13588. + }, */
  13589. + {
  13590. + V4L2_CID_EXPOSURE_AUTO, MMAL_CONTROL_TYPE_STD_MENU,
  13591. + ~0x03, 3, V4L2_EXPOSURE_AUTO, 0, NULL,
  13592. + MMAL_PARAMETER_EXPOSURE_MODE,
  13593. + &ctrl_set_exposure,
  13594. + false
  13595. + },
  13596. +/* todo this needs mixing in with set exposure
  13597. + {
  13598. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13599. + },
  13600. + */
  13601. + {
  13602. + V4L2_CID_EXPOSURE_ABSOLUTE, MMAL_CONTROL_TYPE_STD,
  13603. + /* Units of 100usecs */
  13604. + 1, 1*1000*10, 100*10, 1, NULL,
  13605. + MMAL_PARAMETER_SHUTTER_SPEED,
  13606. + &ctrl_set_exposure,
  13607. + false
  13608. + },
  13609. + {
  13610. + V4L2_CID_AUTO_EXPOSURE_BIAS, MMAL_CONTROL_TYPE_INT_MENU,
  13611. + 0, ARRAY_SIZE(ev_bias_qmenu) - 1,
  13612. + (ARRAY_SIZE(ev_bias_qmenu)+1)/2 - 1, 0, ev_bias_qmenu,
  13613. + MMAL_PARAMETER_EXPOSURE_COMP,
  13614. + &ctrl_set_value_ev,
  13615. + false
  13616. + },
  13617. + {
  13618. + V4L2_CID_EXPOSURE_AUTO_PRIORITY, MMAL_CONTROL_TYPE_STD,
  13619. + 0, 1,
  13620. + 0, 1, NULL,
  13621. + 0, /* Dummy MMAL ID as it gets mapped into FPS range*/
  13622. + &ctrl_set_exposure,
  13623. + false
  13624. + },
  13625. + {
  13626. + V4L2_CID_EXPOSURE_METERING,
  13627. + MMAL_CONTROL_TYPE_STD_MENU,
  13628. + ~0x7, 2, V4L2_EXPOSURE_METERING_AVERAGE, 0, NULL,
  13629. + MMAL_PARAMETER_EXP_METERING_MODE,
  13630. + &ctrl_set_metering_mode,
  13631. + false
  13632. + },
  13633. + {
  13634. + V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE,
  13635. + MMAL_CONTROL_TYPE_STD_MENU,
  13636. + ~0x3ff, 9, V4L2_WHITE_BALANCE_AUTO, 0, NULL,
  13637. + MMAL_PARAMETER_AWB_MODE,
  13638. + &ctrl_set_awb_mode,
  13639. + false
  13640. + },
  13641. + {
  13642. + V4L2_CID_RED_BALANCE, MMAL_CONTROL_TYPE_STD,
  13643. + 1, 7999, 1000, 1, NULL,
  13644. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  13645. + &ctrl_set_awb_gains,
  13646. + false
  13647. + },
  13648. + {
  13649. + V4L2_CID_BLUE_BALANCE, MMAL_CONTROL_TYPE_STD,
  13650. + 1, 7999, 1000, 1, NULL,
  13651. + MMAL_PARAMETER_CUSTOM_AWB_GAINS,
  13652. + &ctrl_set_awb_gains,
  13653. + false
  13654. + },
  13655. + {
  13656. + V4L2_CID_COLORFX, MMAL_CONTROL_TYPE_STD_MENU,
  13657. + 0, 15, V4L2_COLORFX_NONE, 0, NULL,
  13658. + MMAL_PARAMETER_IMAGE_EFFECT,
  13659. + &ctrl_set_image_effect,
  13660. + false
  13661. + },
  13662. + {
  13663. + V4L2_CID_COLORFX_CBCR, MMAL_CONTROL_TYPE_STD,
  13664. + 0, 0xffff, 0x8080, 1, NULL,
  13665. + MMAL_PARAMETER_COLOUR_EFFECT,
  13666. + &ctrl_set_colfx,
  13667. + false
  13668. + },
  13669. + {
  13670. + V4L2_CID_ROTATE, MMAL_CONTROL_TYPE_STD,
  13671. + 0, 360, 0, 90, NULL,
  13672. + MMAL_PARAMETER_ROTATION,
  13673. + &ctrl_set_rotate,
  13674. + false
  13675. + },
  13676. + {
  13677. + V4L2_CID_HFLIP, MMAL_CONTROL_TYPE_STD,
  13678. + 0, 1, 0, 1, NULL,
  13679. + MMAL_PARAMETER_MIRROR,
  13680. + &ctrl_set_flip,
  13681. + false
  13682. + },
  13683. + {
  13684. + V4L2_CID_VFLIP, MMAL_CONTROL_TYPE_STD,
  13685. + 0, 1, 0, 1, NULL,
  13686. + MMAL_PARAMETER_MIRROR,
  13687. + &ctrl_set_flip,
  13688. + false
  13689. + },
  13690. + {
  13691. + V4L2_CID_MPEG_VIDEO_BITRATE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13692. + 0, ARRAY_SIZE(bitrate_mode_qmenu) - 1,
  13693. + 0, 0, bitrate_mode_qmenu,
  13694. + MMAL_PARAMETER_RATECONTROL,
  13695. + &ctrl_set_bitrate_mode,
  13696. + false
  13697. + },
  13698. + {
  13699. + V4L2_CID_MPEG_VIDEO_BITRATE, MMAL_CONTROL_TYPE_STD,
  13700. + 25*1000, 25*1000*1000, 10*1000*1000, 25*1000, NULL,
  13701. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  13702. + &ctrl_set_bitrate,
  13703. + false
  13704. + },
  13705. + {
  13706. + V4L2_CID_JPEG_COMPRESSION_QUALITY, MMAL_CONTROL_TYPE_STD,
  13707. + 1, 100,
  13708. + 30, 1, NULL,
  13709. + MMAL_PARAMETER_JPEG_Q_FACTOR,
  13710. + &ctrl_set_image_encode_output,
  13711. + false
  13712. + },
  13713. + {
  13714. + V4L2_CID_POWER_LINE_FREQUENCY, MMAL_CONTROL_TYPE_STD_MENU,
  13715. + 0, ARRAY_SIZE(mains_freq_qmenu) - 1,
  13716. + 1, 1, NULL,
  13717. + MMAL_PARAMETER_FLICKER_AVOID,
  13718. + &ctrl_set_flicker_avoidance,
  13719. + false
  13720. + },
  13721. + {
  13722. + V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER, MMAL_CONTROL_TYPE_STD,
  13723. + 0, 1,
  13724. + 0, 1, NULL,
  13725. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER,
  13726. + &ctrl_set_video_encode_param_output,
  13727. + true /* Errors ignored as requires latest firmware to work */
  13728. + },
  13729. + {
  13730. + V4L2_CID_MPEG_VIDEO_H264_PROFILE,
  13731. + MMAL_CONTROL_TYPE_STD_MENU,
  13732. + ~((1<<V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE) |
  13733. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE) |
  13734. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_MAIN) |
  13735. + (1<<V4L2_MPEG_VIDEO_H264_PROFILE_HIGH)),
  13736. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH,
  13737. + V4L2_MPEG_VIDEO_H264_PROFILE_HIGH, 1, NULL,
  13738. + MMAL_PARAMETER_PROFILE,
  13739. + &ctrl_set_video_encode_profile_level,
  13740. + false
  13741. + },
  13742. + {
  13743. + V4L2_CID_MPEG_VIDEO_H264_LEVEL, MMAL_CONTROL_TYPE_STD_MENU,
  13744. + ~((1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_0) |
  13745. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1B) |
  13746. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_1) |
  13747. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_2) |
  13748. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_1_3) |
  13749. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_0) |
  13750. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_1) |
  13751. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_2_2) |
  13752. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_0) |
  13753. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_1) |
  13754. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_3_2) |
  13755. + (1<<V4L2_MPEG_VIDEO_H264_LEVEL_4_0)),
  13756. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0,
  13757. + V4L2_MPEG_VIDEO_H264_LEVEL_4_0, 1, NULL,
  13758. + MMAL_PARAMETER_PROFILE,
  13759. + &ctrl_set_video_encode_profile_level,
  13760. + false
  13761. + },
  13762. + {
  13763. + V4L2_CID_SCENE_MODE, MMAL_CONTROL_TYPE_STD_MENU,
  13764. + -1, /* Min is computed at runtime */
  13765. + V4L2_SCENE_MODE_TEXT,
  13766. + V4L2_SCENE_MODE_NONE, 1, NULL,
  13767. + MMAL_PARAMETER_PROFILE,
  13768. + &ctrl_set_scene_mode,
  13769. + false
  13770. + },
  13771. + {
  13772. + V4L2_CID_MPEG_VIDEO_H264_I_PERIOD, MMAL_CONTROL_TYPE_STD,
  13773. + 0, 0x7FFFFFFF, 60, 1, NULL,
  13774. + MMAL_PARAMETER_INTRAPERIOD,
  13775. + &ctrl_set_video_encode_param_output,
  13776. + false
  13777. + },
  13778. +};
  13779. +
  13780. +int bm2835_mmal_set_all_camera_controls(struct bm2835_mmal_dev *dev)
  13781. +{
  13782. + int c;
  13783. + int ret = 0;
  13784. +
  13785. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13786. + if ((dev->ctrls[c]) && (v4l2_ctrls[c].setter)) {
  13787. + ret = v4l2_ctrls[c].setter(dev, dev->ctrls[c],
  13788. + &v4l2_ctrls[c]);
  13789. + if (!v4l2_ctrls[c].ignore_errors && ret) {
  13790. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13791. + "Failed when setting default values for ctrl %d\n",
  13792. + c);
  13793. + break;
  13794. + }
  13795. + }
  13796. + }
  13797. + return ret;
  13798. +}
  13799. +
  13800. +int set_framerate_params(struct bm2835_mmal_dev *dev)
  13801. +{
  13802. + struct mmal_parameter_fps_range fps_range;
  13803. + int ret;
  13804. +
  13805. + if ((dev->exposure_mode_active != MMAL_PARAM_EXPOSUREMODE_OFF) &&
  13806. + (dev->exp_auto_priority)) {
  13807. + /* Variable FPS. Define min FPS as 1fps.
  13808. + * Max as max defined FPS.
  13809. + */
  13810. + fps_range.fps_low.num = 1;
  13811. + fps_range.fps_low.den = 1;
  13812. + fps_range.fps_high.num = dev->capture.timeperframe.denominator;
  13813. + fps_range.fps_high.den = dev->capture.timeperframe.numerator;
  13814. + } else {
  13815. + /* Fixed FPS - set min and max to be the same */
  13816. + fps_range.fps_low.num = fps_range.fps_high.num =
  13817. + dev->capture.timeperframe.denominator;
  13818. + fps_range.fps_low.den = fps_range.fps_high.den =
  13819. + dev->capture.timeperframe.numerator;
  13820. + }
  13821. +
  13822. + v4l2_dbg(1, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13823. + "Set fps range to %d/%d to %d/%d\n",
  13824. + fps_range.fps_low.num,
  13825. + fps_range.fps_low.den,
  13826. + fps_range.fps_high.num,
  13827. + fps_range.fps_high.den
  13828. + );
  13829. +
  13830. + ret = vchiq_mmal_port_parameter_set(dev->instance,
  13831. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13832. + output[MMAL_CAMERA_PORT_PREVIEW],
  13833. + MMAL_PARAMETER_FPS_RANGE,
  13834. + &fps_range, sizeof(fps_range));
  13835. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13836. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13837. + output[MMAL_CAMERA_PORT_VIDEO],
  13838. + MMAL_PARAMETER_FPS_RANGE,
  13839. + &fps_range, sizeof(fps_range));
  13840. + ret += vchiq_mmal_port_parameter_set(dev->instance,
  13841. + &dev->component[MMAL_COMPONENT_CAMERA]->
  13842. + output[MMAL_CAMERA_PORT_CAPTURE],
  13843. + MMAL_PARAMETER_FPS_RANGE,
  13844. + &fps_range, sizeof(fps_range));
  13845. + if (ret)
  13846. + v4l2_dbg(0, bcm2835_v4l2_debug, &dev->v4l2_dev,
  13847. + "Failed to set fps ret %d\n",
  13848. + ret);
  13849. +
  13850. + return ret;
  13851. +
  13852. +}
  13853. +
  13854. +int bm2835_mmal_init_controls(struct bm2835_mmal_dev *dev,
  13855. + struct v4l2_ctrl_handler *hdl)
  13856. +{
  13857. + int c;
  13858. + const struct bm2835_mmal_v4l2_ctrl *ctrl;
  13859. +
  13860. + v4l2_ctrl_handler_init(hdl, V4L2_CTRL_COUNT);
  13861. +
  13862. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13863. + ctrl = &v4l2_ctrls[c];
  13864. +
  13865. + switch (ctrl->type) {
  13866. + case MMAL_CONTROL_TYPE_STD:
  13867. + dev->ctrls[c] = v4l2_ctrl_new_std(hdl,
  13868. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13869. + ctrl->min, ctrl->max, ctrl->step, ctrl->def);
  13870. + break;
  13871. +
  13872. + case MMAL_CONTROL_TYPE_STD_MENU:
  13873. + {
  13874. + int mask = ctrl->min;
  13875. +
  13876. + if (ctrl->id == V4L2_CID_SCENE_MODE) {
  13877. + /* Special handling to work out the mask
  13878. + * value based on the scene_configs array
  13879. + * at runtime. Reduces the chance of
  13880. + * mismatches.
  13881. + */
  13882. + int i;
  13883. + mask = 1<<V4L2_SCENE_MODE_NONE;
  13884. + for (i = 0;
  13885. + i < ARRAY_SIZE(scene_configs);
  13886. + i++) {
  13887. + mask |= 1<<scene_configs[i].v4l2_scene;
  13888. + }
  13889. + mask = ~mask;
  13890. + }
  13891. +
  13892. + dev->ctrls[c] = v4l2_ctrl_new_std_menu(hdl,
  13893. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13894. + ctrl->max, mask, ctrl->def);
  13895. + break;
  13896. + }
  13897. +
  13898. + case MMAL_CONTROL_TYPE_INT_MENU:
  13899. + dev->ctrls[c] = v4l2_ctrl_new_int_menu(hdl,
  13900. + &bm2835_mmal_ctrl_ops, ctrl->id,
  13901. + ctrl->max, ctrl->def, ctrl->imenu);
  13902. + break;
  13903. +
  13904. + case MMAL_CONTROL_TYPE_CLUSTER:
  13905. + /* skip this entry when constructing controls */
  13906. + continue;
  13907. + }
  13908. +
  13909. + if (hdl->error)
  13910. + break;
  13911. +
  13912. + dev->ctrls[c]->priv = (void *)ctrl;
  13913. + }
  13914. +
  13915. + if (hdl->error) {
  13916. + pr_err("error adding control %d/%d id 0x%x\n", c,
  13917. + V4L2_CTRL_COUNT, ctrl->id);
  13918. + return hdl->error;
  13919. + }
  13920. +
  13921. + for (c = 0; c < V4L2_CTRL_COUNT; c++) {
  13922. + ctrl = &v4l2_ctrls[c];
  13923. +
  13924. + switch (ctrl->type) {
  13925. + case MMAL_CONTROL_TYPE_CLUSTER:
  13926. + v4l2_ctrl_auto_cluster(ctrl->min,
  13927. + &dev->ctrls[c+1],
  13928. + ctrl->max,
  13929. + ctrl->def);
  13930. + break;
  13931. +
  13932. + case MMAL_CONTROL_TYPE_STD:
  13933. + case MMAL_CONTROL_TYPE_STD_MENU:
  13934. + case MMAL_CONTROL_TYPE_INT_MENU:
  13935. + break;
  13936. + }
  13937. +
  13938. + }
  13939. +
  13940. + return 0;
  13941. +}
  13942. diff -Nur linux-3.15/drivers/media/platform/bcm2835/Kconfig linux-rpi/drivers/media/platform/bcm2835/Kconfig
  13943. --- linux-3.15/drivers/media/platform/bcm2835/Kconfig 1970-01-01 01:00:00.000000000 +0100
  13944. +++ linux-rpi/drivers/media/platform/bcm2835/Kconfig 2014-06-11 21:03:33.000000000 +0200
  13945. @@ -0,0 +1,25 @@
  13946. +# Broadcom VideoCore IV v4l2 camera support
  13947. +
  13948. +config VIDEO_BCM2835
  13949. + bool "Broadcom BCM2835 camera interface driver"
  13950. + depends on VIDEO_V4L2 && ARCH_BCM2708
  13951. + ---help---
  13952. + Say Y here to enable camera host interface devices for
  13953. + Broadcom BCM2835 SoC. This operates over the VCHIQ interface
  13954. + to a service running on VideoCore.
  13955. +
  13956. +
  13957. +if VIDEO_BCM2835
  13958. +
  13959. +config VIDEO_BCM2835_MMAL
  13960. + tristate "Broadcom BM2835 MMAL camera interface driver"
  13961. + depends on BCM2708_VCHIQ
  13962. + select VIDEOBUF2_VMALLOC
  13963. + ---help---
  13964. + This is a V4L2 driver for the Broadcom BCM2835 MMAL camera host interface
  13965. +
  13966. + To compile this driver as a module, choose M here: the
  13967. + module will be called bcm2835-v4l2.o
  13968. +
  13969. +
  13970. +endif # VIDEO_BM2835
  13971. diff -Nur linux-3.15/drivers/media/platform/bcm2835/Makefile linux-rpi/drivers/media/platform/bcm2835/Makefile
  13972. --- linux-3.15/drivers/media/platform/bcm2835/Makefile 1970-01-01 01:00:00.000000000 +0100
  13973. +++ linux-rpi/drivers/media/platform/bcm2835/Makefile 2014-06-11 21:03:33.000000000 +0200
  13974. @@ -0,0 +1,5 @@
  13975. +bcm2835-v4l2-objs := bcm2835-camera.o controls.o mmal-vchiq.o
  13976. +
  13977. +obj-$(CONFIG_VIDEO_BCM2835_MMAL) += bcm2835-v4l2.o
  13978. +
  13979. +ccflags-$(CONFIG_VIDEO_BCM2835) += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  13980. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-common.h
  13981. --- linux-3.15/drivers/media/platform/bcm2835/mmal-common.h 1970-01-01 01:00:00.000000000 +0100
  13982. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-common.h 2014-06-11 21:03:33.000000000 +0200
  13983. @@ -0,0 +1,53 @@
  13984. +/*
  13985. + * Broadcom BM2835 V4L2 driver
  13986. + *
  13987. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  13988. + *
  13989. + * This file is subject to the terms and conditions of the GNU General Public
  13990. + * License. See the file COPYING in the main directory of this archive
  13991. + * for more details.
  13992. + *
  13993. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  13994. + * Dave Stevenson <dsteve@broadcom.com>
  13995. + * Simon Mellor <simellor@broadcom.com>
  13996. + * Luke Diamand <luked@broadcom.com>
  13997. + *
  13998. + * MMAL structures
  13999. + *
  14000. + */
  14001. +
  14002. +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24))
  14003. +#define MMAL_MAGIC MMAL_FOURCC('m', 'm', 'a', 'l')
  14004. +
  14005. +/** Special value signalling that time is not known */
  14006. +#define MMAL_TIME_UNKNOWN (1LL<<63)
  14007. +
  14008. +/* mapping between v4l and mmal video modes */
  14009. +struct mmal_fmt {
  14010. + char *name;
  14011. + u32 fourcc; /* v4l2 format id */
  14012. + int flags; /* v4l2 flags field */
  14013. + u32 mmal;
  14014. + int depth;
  14015. + u32 mmal_component; /* MMAL component index to be used to encode */
  14016. +};
  14017. +
  14018. +/* buffer for one video frame */
  14019. +struct mmal_buffer {
  14020. + /* v4l buffer data -- must be first */
  14021. + struct vb2_buffer vb;
  14022. +
  14023. + /* list of buffers available */
  14024. + struct list_head list;
  14025. +
  14026. + void *buffer; /* buffer pointer */
  14027. + unsigned long buffer_size; /* size of allocated buffer */
  14028. +};
  14029. +
  14030. +/* */
  14031. +struct mmal_colourfx {
  14032. + s32 enable;
  14033. + u32 u;
  14034. + u32 v;
  14035. +};
  14036. +
  14037. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-encodings.h linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h
  14038. --- linux-3.15/drivers/media/platform/bcm2835/mmal-encodings.h 1970-01-01 01:00:00.000000000 +0100
  14039. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-encodings.h 2014-06-11 21:03:33.000000000 +0200
  14040. @@ -0,0 +1,127 @@
  14041. +/*
  14042. + * Broadcom BM2835 V4L2 driver
  14043. + *
  14044. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14045. + *
  14046. + * This file is subject to the terms and conditions of the GNU General Public
  14047. + * License. See the file COPYING in the main directory of this archive
  14048. + * for more details.
  14049. + *
  14050. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14051. + * Dave Stevenson <dsteve@broadcom.com>
  14052. + * Simon Mellor <simellor@broadcom.com>
  14053. + * Luke Diamand <luked@broadcom.com>
  14054. + */
  14055. +#ifndef MMAL_ENCODINGS_H
  14056. +#define MMAL_ENCODINGS_H
  14057. +
  14058. +#define MMAL_ENCODING_H264 MMAL_FOURCC('H', '2', '6', '4')
  14059. +#define MMAL_ENCODING_H263 MMAL_FOURCC('H', '2', '6', '3')
  14060. +#define MMAL_ENCODING_MP4V MMAL_FOURCC('M', 'P', '4', 'V')
  14061. +#define MMAL_ENCODING_MP2V MMAL_FOURCC('M', 'P', '2', 'V')
  14062. +#define MMAL_ENCODING_MP1V MMAL_FOURCC('M', 'P', '1', 'V')
  14063. +#define MMAL_ENCODING_WMV3 MMAL_FOURCC('W', 'M', 'V', '3')
  14064. +#define MMAL_ENCODING_WMV2 MMAL_FOURCC('W', 'M', 'V', '2')
  14065. +#define MMAL_ENCODING_WMV1 MMAL_FOURCC('W', 'M', 'V', '1')
  14066. +#define MMAL_ENCODING_WVC1 MMAL_FOURCC('W', 'V', 'C', '1')
  14067. +#define MMAL_ENCODING_VP8 MMAL_FOURCC('V', 'P', '8', ' ')
  14068. +#define MMAL_ENCODING_VP7 MMAL_FOURCC('V', 'P', '7', ' ')
  14069. +#define MMAL_ENCODING_VP6 MMAL_FOURCC('V', 'P', '6', ' ')
  14070. +#define MMAL_ENCODING_THEORA MMAL_FOURCC('T', 'H', 'E', 'O')
  14071. +#define MMAL_ENCODING_SPARK MMAL_FOURCC('S', 'P', 'R', 'K')
  14072. +#define MMAL_ENCODING_MJPEG MMAL_FOURCC('M', 'J', 'P', 'G')
  14073. +
  14074. +#define MMAL_ENCODING_JPEG MMAL_FOURCC('J', 'P', 'E', 'G')
  14075. +#define MMAL_ENCODING_GIF MMAL_FOURCC('G', 'I', 'F', ' ')
  14076. +#define MMAL_ENCODING_PNG MMAL_FOURCC('P', 'N', 'G', ' ')
  14077. +#define MMAL_ENCODING_PPM MMAL_FOURCC('P', 'P', 'M', ' ')
  14078. +#define MMAL_ENCODING_TGA MMAL_FOURCC('T', 'G', 'A', ' ')
  14079. +#define MMAL_ENCODING_BMP MMAL_FOURCC('B', 'M', 'P', ' ')
  14080. +
  14081. +#define MMAL_ENCODING_I420 MMAL_FOURCC('I', '4', '2', '0')
  14082. +#define MMAL_ENCODING_I420_SLICE MMAL_FOURCC('S', '4', '2', '0')
  14083. +#define MMAL_ENCODING_YV12 MMAL_FOURCC('Y', 'V', '1', '2')
  14084. +#define MMAL_ENCODING_I422 MMAL_FOURCC('I', '4', '2', '2')
  14085. +#define MMAL_ENCODING_I422_SLICE MMAL_FOURCC('S', '4', '2', '2')
  14086. +#define MMAL_ENCODING_YUYV MMAL_FOURCC('Y', 'U', 'Y', 'V')
  14087. +#define MMAL_ENCODING_YVYU MMAL_FOURCC('Y', 'V', 'Y', 'U')
  14088. +#define MMAL_ENCODING_UYVY MMAL_FOURCC('U', 'Y', 'V', 'Y')
  14089. +#define MMAL_ENCODING_VYUY MMAL_FOURCC('V', 'Y', 'U', 'Y')
  14090. +#define MMAL_ENCODING_NV12 MMAL_FOURCC('N', 'V', '1', '2')
  14091. +#define MMAL_ENCODING_NV21 MMAL_FOURCC('N', 'V', '2', '1')
  14092. +#define MMAL_ENCODING_ARGB MMAL_FOURCC('A', 'R', 'G', 'B')
  14093. +#define MMAL_ENCODING_RGBA MMAL_FOURCC('R', 'G', 'B', 'A')
  14094. +#define MMAL_ENCODING_ABGR MMAL_FOURCC('A', 'B', 'G', 'R')
  14095. +#define MMAL_ENCODING_BGRA MMAL_FOURCC('B', 'G', 'R', 'A')
  14096. +#define MMAL_ENCODING_RGB16 MMAL_FOURCC('R', 'G', 'B', '2')
  14097. +#define MMAL_ENCODING_RGB24 MMAL_FOURCC('R', 'G', 'B', '3')
  14098. +#define MMAL_ENCODING_RGB32 MMAL_FOURCC('R', 'G', 'B', '4')
  14099. +#define MMAL_ENCODING_BGR16 MMAL_FOURCC('B', 'G', 'R', '2')
  14100. +#define MMAL_ENCODING_BGR24 MMAL_FOURCC('B', 'G', 'R', '3')
  14101. +#define MMAL_ENCODING_BGR32 MMAL_FOURCC('B', 'G', 'R', '4')
  14102. +
  14103. +/** SAND Video (YUVUV128) format, native format understood by VideoCore.
  14104. + * This format is *not* opaque - if requested you will receive full frames
  14105. + * of YUV_UV video.
  14106. + */
  14107. +#define MMAL_ENCODING_YUVUV128 MMAL_FOURCC('S', 'A', 'N', 'D')
  14108. +
  14109. +/** VideoCore opaque image format, image handles are returned to
  14110. + * the host but not the actual image data.
  14111. + */
  14112. +#define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V')
  14113. +
  14114. +/** An EGL image handle
  14115. + */
  14116. +#define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I')
  14117. +
  14118. +/* }@ */
  14119. +
  14120. +/** \name Pre-defined audio encodings */
  14121. +/* @{ */
  14122. +#define MMAL_ENCODING_PCM_UNSIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'U')
  14123. +#define MMAL_ENCODING_PCM_UNSIGNED_LE MMAL_FOURCC('p', 'c', 'm', 'u')
  14124. +#define MMAL_ENCODING_PCM_SIGNED_BE MMAL_FOURCC('P', 'C', 'M', 'S')
  14125. +#define MMAL_ENCODING_PCM_SIGNED_LE MMAL_FOURCC('p', 'c', 'm', 's')
  14126. +#define MMAL_ENCODING_PCM_FLOAT_BE MMAL_FOURCC('P', 'C', 'M', 'F')
  14127. +#define MMAL_ENCODING_PCM_FLOAT_LE MMAL_FOURCC('p', 'c', 'm', 'f')
  14128. +
  14129. +/* Pre-defined H264 encoding variants */
  14130. +
  14131. +/** ISO 14496-10 Annex B byte stream format */
  14132. +#define MMAL_ENCODING_VARIANT_H264_DEFAULT 0
  14133. +/** ISO 14496-15 AVC stream format */
  14134. +#define MMAL_ENCODING_VARIANT_H264_AVC1 MMAL_FOURCC('A', 'V', 'C', '1')
  14135. +/** Implicitly delineated NAL units without emulation prevention */
  14136. +#define MMAL_ENCODING_VARIANT_H264_RAW MMAL_FOURCC('R', 'A', 'W', ' ')
  14137. +
  14138. +
  14139. +/** \defgroup MmalColorSpace List of pre-defined video color spaces
  14140. + * This defines a list of common color spaces. This list isn't exhaustive and
  14141. + * is only provided as a convenience to avoid clients having to use FourCC
  14142. + * codes directly. However components are allowed to define and use their own
  14143. + * FourCC codes.
  14144. + */
  14145. +/* @{ */
  14146. +
  14147. +/** Unknown color space */
  14148. +#define MMAL_COLOR_SPACE_UNKNOWN 0
  14149. +/** ITU-R BT.601-5 [SDTV] */
  14150. +#define MMAL_COLOR_SPACE_ITUR_BT601 MMAL_FOURCC('Y', '6', '0', '1')
  14151. +/** ITU-R BT.709-3 [HDTV] */
  14152. +#define MMAL_COLOR_SPACE_ITUR_BT709 MMAL_FOURCC('Y', '7', '0', '9')
  14153. +/** JPEG JFIF */
  14154. +#define MMAL_COLOR_SPACE_JPEG_JFIF MMAL_FOURCC('Y', 'J', 'F', 'I')
  14155. +/** Title 47 Code of Federal Regulations (2003) 73.682 (a) (20) */
  14156. +#define MMAL_COLOR_SPACE_FCC MMAL_FOURCC('Y', 'F', 'C', 'C')
  14157. +/** Society of Motion Picture and Television Engineers 240M (1999) */
  14158. +#define MMAL_COLOR_SPACE_SMPTE240M MMAL_FOURCC('Y', '2', '4', '0')
  14159. +/** ITU-R BT.470-2 System M */
  14160. +#define MMAL_COLOR_SPACE_BT470_2_M MMAL_FOURCC('Y', '_', '_', 'M')
  14161. +/** ITU-R BT.470-2 System BG */
  14162. +#define MMAL_COLOR_SPACE_BT470_2_BG MMAL_FOURCC('Y', '_', 'B', 'G')
  14163. +/** JPEG JFIF, but with 16..255 luma */
  14164. +#define MMAL_COLOR_SPACE_JFIF_Y16_255 MMAL_FOURCC('Y', 'Y', '1', '6')
  14165. +/* @} MmalColorSpace List */
  14166. +
  14167. +#endif /* MMAL_ENCODINGS_H */
  14168. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-msg-common.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h
  14169. --- linux-3.15/drivers/media/platform/bcm2835/mmal-msg-common.h 1970-01-01 01:00:00.000000000 +0100
  14170. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-common.h 2014-06-11 21:03:33.000000000 +0200
  14171. @@ -0,0 +1,50 @@
  14172. +/*
  14173. + * Broadcom BM2835 V4L2 driver
  14174. + *
  14175. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14176. + *
  14177. + * This file is subject to the terms and conditions of the GNU General Public
  14178. + * License. See the file COPYING in the main directory of this archive
  14179. + * for more details.
  14180. + *
  14181. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14182. + * Dave Stevenson <dsteve@broadcom.com>
  14183. + * Simon Mellor <simellor@broadcom.com>
  14184. + * Luke Diamand <luked@broadcom.com>
  14185. + */
  14186. +
  14187. +#ifndef MMAL_MSG_COMMON_H
  14188. +#define MMAL_MSG_COMMON_H
  14189. +
  14190. +enum mmal_msg_status {
  14191. + MMAL_MSG_STATUS_SUCCESS = 0, /**< Success */
  14192. + MMAL_MSG_STATUS_ENOMEM, /**< Out of memory */
  14193. + MMAL_MSG_STATUS_ENOSPC, /**< Out of resources other than memory */
  14194. + MMAL_MSG_STATUS_EINVAL, /**< Argument is invalid */
  14195. + MMAL_MSG_STATUS_ENOSYS, /**< Function not implemented */
  14196. + MMAL_MSG_STATUS_ENOENT, /**< No such file or directory */
  14197. + MMAL_MSG_STATUS_ENXIO, /**< No such device or address */
  14198. + MMAL_MSG_STATUS_EIO, /**< I/O error */
  14199. + MMAL_MSG_STATUS_ESPIPE, /**< Illegal seek */
  14200. + MMAL_MSG_STATUS_ECORRUPT, /**< Data is corrupt \attention */
  14201. + MMAL_MSG_STATUS_ENOTREADY, /**< Component is not ready */
  14202. + MMAL_MSG_STATUS_ECONFIG, /**< Component is not configured */
  14203. + MMAL_MSG_STATUS_EISCONN, /**< Port is already connected */
  14204. + MMAL_MSG_STATUS_ENOTCONN, /**< Port is disconnected */
  14205. + MMAL_MSG_STATUS_EAGAIN, /**< Resource temporarily unavailable. */
  14206. + MMAL_MSG_STATUS_EFAULT, /**< Bad address */
  14207. +};
  14208. +
  14209. +struct mmal_rect {
  14210. + s32 x; /**< x coordinate (from left) */
  14211. + s32 y; /**< y coordinate (from top) */
  14212. + s32 width; /**< width */
  14213. + s32 height; /**< height */
  14214. +};
  14215. +
  14216. +struct mmal_rational {
  14217. + s32 num; /**< Numerator */
  14218. + s32 den; /**< Denominator */
  14219. +};
  14220. +
  14221. +#endif /* MMAL_MSG_COMMON_H */
  14222. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-msg-format.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h
  14223. --- linux-3.15/drivers/media/platform/bcm2835/mmal-msg-format.h 1970-01-01 01:00:00.000000000 +0100
  14224. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-format.h 2014-06-11 21:03:33.000000000 +0200
  14225. @@ -0,0 +1,81 @@
  14226. +/*
  14227. + * Broadcom BM2835 V4L2 driver
  14228. + *
  14229. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14230. + *
  14231. + * This file is subject to the terms and conditions of the GNU General Public
  14232. + * License. See the file COPYING in the main directory of this archive
  14233. + * for more details.
  14234. + *
  14235. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14236. + * Dave Stevenson <dsteve@broadcom.com>
  14237. + * Simon Mellor <simellor@broadcom.com>
  14238. + * Luke Diamand <luked@broadcom.com>
  14239. + */
  14240. +
  14241. +#ifndef MMAL_MSG_FORMAT_H
  14242. +#define MMAL_MSG_FORMAT_H
  14243. +
  14244. +#include "mmal-msg-common.h"
  14245. +
  14246. +/* MMAL_ES_FORMAT_T */
  14247. +
  14248. +
  14249. +struct mmal_audio_format {
  14250. + u32 channels; /**< Number of audio channels */
  14251. + u32 sample_rate; /**< Sample rate */
  14252. +
  14253. + u32 bits_per_sample; /**< Bits per sample */
  14254. + u32 block_align; /**< Size of a block of data */
  14255. +};
  14256. +
  14257. +struct mmal_video_format {
  14258. + u32 width; /**< Width of frame in pixels */
  14259. + u32 height; /**< Height of frame in rows of pixels */
  14260. + struct mmal_rect crop; /**< Visible region of the frame */
  14261. + struct mmal_rational frame_rate; /**< Frame rate */
  14262. + struct mmal_rational par; /**< Pixel aspect ratio */
  14263. +
  14264. + /* FourCC specifying the color space of the video stream. See the
  14265. + * \ref MmalColorSpace "pre-defined color spaces" for some examples.
  14266. + */
  14267. + u32 color_space;
  14268. +};
  14269. +
  14270. +struct mmal_subpicture_format {
  14271. + u32 x_offset;
  14272. + u32 y_offset;
  14273. +};
  14274. +
  14275. +union mmal_es_specific_format {
  14276. + struct mmal_audio_format audio;
  14277. + struct mmal_video_format video;
  14278. + struct mmal_subpicture_format subpicture;
  14279. +};
  14280. +
  14281. +/** Definition of an elementary stream format (MMAL_ES_FORMAT_T) */
  14282. +struct mmal_es_format {
  14283. + u32 type; /* enum mmal_es_type */
  14284. +
  14285. + u32 encoding; /* FourCC specifying encoding of the elementary stream.*/
  14286. + u32 encoding_variant; /* FourCC specifying the specific
  14287. + * encoding variant of the elementary
  14288. + * stream.
  14289. + */
  14290. +
  14291. + union mmal_es_specific_format *es; /* TODO: pointers in
  14292. + * message serialisation?!?
  14293. + */
  14294. + /* Type specific
  14295. + * information for the
  14296. + * elementary stream
  14297. + */
  14298. +
  14299. + u32 bitrate; /**< Bitrate in bits per second */
  14300. + u32 flags; /**< Flags describing properties of the elementary stream. */
  14301. +
  14302. + u32 extradata_size; /**< Size of the codec specific data */
  14303. + u8 *extradata; /**< Codec specific data */
  14304. +};
  14305. +
  14306. +#endif /* MMAL_MSG_FORMAT_H */
  14307. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-msg.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h
  14308. --- linux-3.15/drivers/media/platform/bcm2835/mmal-msg.h 1970-01-01 01:00:00.000000000 +0100
  14309. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg.h 2014-06-11 21:03:33.000000000 +0200
  14310. @@ -0,0 +1,404 @@
  14311. +/*
  14312. + * Broadcom BM2835 V4L2 driver
  14313. + *
  14314. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14315. + *
  14316. + * This file is subject to the terms and conditions of the GNU General Public
  14317. + * License. See the file COPYING in the main directory of this archive
  14318. + * for more details.
  14319. + *
  14320. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14321. + * Dave Stevenson <dsteve@broadcom.com>
  14322. + * Simon Mellor <simellor@broadcom.com>
  14323. + * Luke Diamand <luked@broadcom.com>
  14324. + */
  14325. +
  14326. +/* all the data structures which serialise the MMAL protocol. note
  14327. + * these are directly mapped onto the recived message data.
  14328. + *
  14329. + * BEWARE: They seem to *assume* pointers are u32 and that there is no
  14330. + * structure padding!
  14331. + *
  14332. + * NOTE: this implementation uses kernel types to ensure sizes. Rather
  14333. + * than assigning values to enums to force their size the
  14334. + * implementation uses fixed size types and not the enums (though the
  14335. + * comments have the actual enum type
  14336. + */
  14337. +
  14338. +#define VC_MMAL_VER 15
  14339. +#define VC_MMAL_MIN_VER 10
  14340. +#define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal")
  14341. +
  14342. +/* max total message size is 512 bytes */
  14343. +#define MMAL_MSG_MAX_SIZE 512
  14344. +/* with six 32bit header elements max payload is therefore 488 bytes */
  14345. +#define MMAL_MSG_MAX_PAYLOAD 488
  14346. +
  14347. +#include "mmal-msg-common.h"
  14348. +#include "mmal-msg-format.h"
  14349. +#include "mmal-msg-port.h"
  14350. +
  14351. +enum mmal_msg_type {
  14352. + MMAL_MSG_TYPE_QUIT = 1,
  14353. + MMAL_MSG_TYPE_SERVICE_CLOSED,
  14354. + MMAL_MSG_TYPE_GET_VERSION,
  14355. + MMAL_MSG_TYPE_COMPONENT_CREATE,
  14356. + MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */
  14357. + MMAL_MSG_TYPE_COMPONENT_ENABLE,
  14358. + MMAL_MSG_TYPE_COMPONENT_DISABLE,
  14359. + MMAL_MSG_TYPE_PORT_INFO_GET,
  14360. + MMAL_MSG_TYPE_PORT_INFO_SET,
  14361. + MMAL_MSG_TYPE_PORT_ACTION, /* 10 */
  14362. + MMAL_MSG_TYPE_BUFFER_FROM_HOST,
  14363. + MMAL_MSG_TYPE_BUFFER_TO_HOST,
  14364. + MMAL_MSG_TYPE_GET_STATS,
  14365. + MMAL_MSG_TYPE_PORT_PARAMETER_SET,
  14366. + MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */
  14367. + MMAL_MSG_TYPE_EVENT_TO_HOST,
  14368. + MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT,
  14369. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR,
  14370. + MMAL_MSG_TYPE_CONSUME_MEM,
  14371. + MMAL_MSG_TYPE_LMK, /* 20 */
  14372. + MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC,
  14373. + MMAL_MSG_TYPE_DRM_GET_LHS32,
  14374. + MMAL_MSG_TYPE_DRM_GET_TIME,
  14375. + MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN,
  14376. + MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */
  14377. + MMAL_MSG_TYPE_HOST_LOG,
  14378. + MMAL_MSG_TYPE_MSG_LAST
  14379. +};
  14380. +
  14381. +/* port action request messages differ depending on the action type */
  14382. +enum mmal_msg_port_action_type {
  14383. + MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */
  14384. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */
  14385. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */
  14386. + MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */
  14387. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */
  14388. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */
  14389. + MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/
  14390. +};
  14391. +
  14392. +struct mmal_msg_header {
  14393. + u32 magic;
  14394. + u32 type; /** enum mmal_msg_type */
  14395. +
  14396. + /* Opaque handle to the control service */
  14397. + struct mmal_control_service *control_service;
  14398. +
  14399. + struct mmal_msg_context *context; /** a u32 per message context */
  14400. + u32 status; /** The status of the vchiq operation */
  14401. + u32 padding;
  14402. +};
  14403. +
  14404. +/* Send from VC to host to report version */
  14405. +struct mmal_msg_version {
  14406. + u32 flags;
  14407. + u32 major;
  14408. + u32 minor;
  14409. + u32 minimum;
  14410. +};
  14411. +
  14412. +/* request to VC to create component */
  14413. +struct mmal_msg_component_create {
  14414. + void *client_component; /* component context */
  14415. + char name[128];
  14416. + u32 pid; /* For debug */
  14417. +};
  14418. +
  14419. +/* reply from VC to component creation request */
  14420. +struct mmal_msg_component_create_reply {
  14421. + u32 status; /** enum mmal_msg_status - how does this differ to
  14422. + * the one in the header?
  14423. + */
  14424. + u32 component_handle; /* VideoCore handle for component */
  14425. + u32 input_num; /* Number of input ports */
  14426. + u32 output_num; /* Number of output ports */
  14427. + u32 clock_num; /* Number of clock ports */
  14428. +};
  14429. +
  14430. +/* request to VC to destroy a component */
  14431. +struct mmal_msg_component_destroy {
  14432. + u32 component_handle;
  14433. +};
  14434. +
  14435. +struct mmal_msg_component_destroy_reply {
  14436. + u32 status; /** The component destruction status */
  14437. +};
  14438. +
  14439. +
  14440. +/* request and reply to VC to enable a component */
  14441. +struct mmal_msg_component_enable {
  14442. + u32 component_handle;
  14443. +};
  14444. +
  14445. +struct mmal_msg_component_enable_reply {
  14446. + u32 status; /** The component enable status */
  14447. +};
  14448. +
  14449. +
  14450. +/* request and reply to VC to disable a component */
  14451. +struct mmal_msg_component_disable {
  14452. + u32 component_handle;
  14453. +};
  14454. +
  14455. +struct mmal_msg_component_disable_reply {
  14456. + u32 status; /** The component disable status */
  14457. +};
  14458. +
  14459. +/* request to VC to get port information */
  14460. +struct mmal_msg_port_info_get {
  14461. + u32 component_handle; /* component handle port is associated with */
  14462. + u32 port_type; /* enum mmal_msg_port_type */
  14463. + u32 index; /* port index to query */
  14464. +};
  14465. +
  14466. +/* reply from VC to get port info request */
  14467. +struct mmal_msg_port_info_get_reply {
  14468. + u32 status; /** enum mmal_msg_status */
  14469. + u32 component_handle; /* component handle port is associated with */
  14470. + u32 port_type; /* enum mmal_msg_port_type */
  14471. + u32 port_index; /* port indexed in query */
  14472. + s32 found; /* unused */
  14473. + u32 port_handle; /**< Handle to use for this port */
  14474. + struct mmal_port port;
  14475. + struct mmal_es_format format; /* elementry stream format */
  14476. + union mmal_es_specific_format es; /* es type specific data */
  14477. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */
  14478. +};
  14479. +
  14480. +/* request to VC to set port information */
  14481. +struct mmal_msg_port_info_set {
  14482. + u32 component_handle;
  14483. + u32 port_type; /* enum mmal_msg_port_type */
  14484. + u32 port_index; /* port indexed in query */
  14485. + struct mmal_port port;
  14486. + struct mmal_es_format format;
  14487. + union mmal_es_specific_format es;
  14488. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14489. +};
  14490. +
  14491. +/* reply from VC to port info set request */
  14492. +struct mmal_msg_port_info_set_reply {
  14493. + u32 status;
  14494. + u32 component_handle; /* component handle port is associated with */
  14495. + u32 port_type; /* enum mmal_msg_port_type */
  14496. + u32 index; /* port indexed in query */
  14497. + s32 found; /* unused */
  14498. + u32 port_handle; /**< Handle to use for this port */
  14499. + struct mmal_port port;
  14500. + struct mmal_es_format format;
  14501. + union mmal_es_specific_format es;
  14502. + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE];
  14503. +};
  14504. +
  14505. +
  14506. +/* port action requests that take a mmal_port as a parameter */
  14507. +struct mmal_msg_port_action_port {
  14508. + u32 component_handle;
  14509. + u32 port_handle;
  14510. + u32 action; /* enum mmal_msg_port_action_type */
  14511. + struct mmal_port port;
  14512. +};
  14513. +
  14514. +/* port action requests that take handles as a parameter */
  14515. +struct mmal_msg_port_action_handle {
  14516. + u32 component_handle;
  14517. + u32 port_handle;
  14518. + u32 action; /* enum mmal_msg_port_action_type */
  14519. + u32 connect_component_handle;
  14520. + u32 connect_port_handle;
  14521. +};
  14522. +
  14523. +struct mmal_msg_port_action_reply {
  14524. + u32 status; /** The port action operation status */
  14525. +};
  14526. +
  14527. +
  14528. +
  14529. +
  14530. +/* MMAL buffer transfer */
  14531. +
  14532. +/** Size of space reserved in a buffer message for short messages. */
  14533. +#define MMAL_VC_SHORT_DATA 128
  14534. +
  14535. +/** Signals that the current payload is the end of the stream of data */
  14536. +#define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0)
  14537. +/** Signals that the start of the current payload starts a frame */
  14538. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1)
  14539. +/** Signals that the end of the current payload ends a frame */
  14540. +#define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2)
  14541. +/** Signals that the current payload contains only complete frames (>1) */
  14542. +#define MMAL_BUFFER_HEADER_FLAG_FRAME \
  14543. + (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END)
  14544. +/** Signals that the current payload is a keyframe (i.e. self decodable) */
  14545. +#define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3)
  14546. +/** Signals a discontinuity in the stream of data (e.g. after a seek).
  14547. + * Can be used for instance by a decoder to reset its state */
  14548. +#define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4)
  14549. +/** Signals a buffer containing some kind of config data for the component
  14550. + * (e.g. codec config data) */
  14551. +#define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5)
  14552. +/** Signals an encrypted payload */
  14553. +#define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6)
  14554. +/** Signals a buffer containing side information */
  14555. +#define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7)
  14556. +/** Signals a buffer which is the snapshot/postview image from a stills
  14557. + * capture
  14558. + */
  14559. +#define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8)
  14560. +/** Signals a buffer which contains data known to be corrupted */
  14561. +#define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9)
  14562. +/** Signals that a buffer failed to be transmitted */
  14563. +#define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10)
  14564. +
  14565. +struct mmal_driver_buffer {
  14566. + u32 magic;
  14567. + u32 component_handle;
  14568. + u32 port_handle;
  14569. + void *client_context;
  14570. +};
  14571. +
  14572. +/* buffer header */
  14573. +struct mmal_buffer_header {
  14574. + struct mmal_buffer_header *next; /* next header */
  14575. + void *priv; /* framework private data */
  14576. + u32 cmd;
  14577. + void *data;
  14578. + u32 alloc_size;
  14579. + u32 length;
  14580. + u32 offset;
  14581. + u32 flags;
  14582. + s64 pts;
  14583. + s64 dts;
  14584. + void *type;
  14585. + void *user_data;
  14586. +};
  14587. +
  14588. +struct mmal_buffer_header_type_specific {
  14589. + union {
  14590. + struct {
  14591. + u32 planes;
  14592. + u32 offset[4];
  14593. + u32 pitch[4];
  14594. + u32 flags;
  14595. + } video;
  14596. + } u;
  14597. +};
  14598. +
  14599. +struct mmal_msg_buffer_from_host {
  14600. + /* The front 32 bytes of the buffer header are copied
  14601. + * back to us in the reply to allow for context. This
  14602. + * area is used to store two mmal_driver_buffer structures to
  14603. + * allow for multiple concurrent service users.
  14604. + */
  14605. + /* control data */
  14606. + struct mmal_driver_buffer drvbuf;
  14607. +
  14608. + /* referenced control data for passthrough buffer management */
  14609. + struct mmal_driver_buffer drvbuf_ref;
  14610. + struct mmal_buffer_header buffer_header; /* buffer header itself */
  14611. + struct mmal_buffer_header_type_specific buffer_header_type_specific;
  14612. + s32 is_zero_copy;
  14613. + s32 has_reference;
  14614. +
  14615. + /** allows short data to be xfered in control message */
  14616. + u32 payload_in_message;
  14617. + u8 short_data[MMAL_VC_SHORT_DATA];
  14618. +};
  14619. +
  14620. +
  14621. +/* port parameter setting */
  14622. +
  14623. +#define MMAL_WORKER_PORT_PARAMETER_SPACE 96
  14624. +
  14625. +struct mmal_msg_port_parameter_set {
  14626. + u32 component_handle; /* component */
  14627. + u32 port_handle; /* port */
  14628. + u32 id; /* Parameter ID */
  14629. + u32 size; /* Parameter size */
  14630. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14631. +};
  14632. +
  14633. +struct mmal_msg_port_parameter_set_reply {
  14634. + u32 status; /** enum mmal_msg_status todo: how does this
  14635. + * differ to the one in the header?
  14636. + */
  14637. +};
  14638. +
  14639. +/* port parameter getting */
  14640. +
  14641. +struct mmal_msg_port_parameter_get {
  14642. + u32 component_handle; /* component */
  14643. + u32 port_handle; /* port */
  14644. + u32 id; /* Parameter ID */
  14645. + u32 size; /* Parameter size */
  14646. +};
  14647. +
  14648. +struct mmal_msg_port_parameter_get_reply {
  14649. + u32 status; /* Status of mmal_port_parameter_get call */
  14650. + u32 id; /* Parameter ID */
  14651. + u32 size; /* Parameter size */
  14652. + uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE];
  14653. +};
  14654. +
  14655. +/* event messages */
  14656. +#define MMAL_WORKER_EVENT_SPACE 256
  14657. +
  14658. +struct mmal_msg_event_to_host {
  14659. + void *client_component; /* component context */
  14660. +
  14661. + u32 port_type;
  14662. + u32 port_num;
  14663. +
  14664. + u32 cmd;
  14665. + u32 length;
  14666. + u8 data[MMAL_WORKER_EVENT_SPACE];
  14667. + struct mmal_buffer_header *delayed_buffer;
  14668. +};
  14669. +
  14670. +/* all mmal messages are serialised through this structure */
  14671. +struct mmal_msg {
  14672. + /* header */
  14673. + struct mmal_msg_header h;
  14674. + /* payload */
  14675. + union {
  14676. + struct mmal_msg_version version;
  14677. +
  14678. + struct mmal_msg_component_create component_create;
  14679. + struct mmal_msg_component_create_reply component_create_reply;
  14680. +
  14681. + struct mmal_msg_component_destroy component_destroy;
  14682. + struct mmal_msg_component_destroy_reply component_destroy_reply;
  14683. +
  14684. + struct mmal_msg_component_enable component_enable;
  14685. + struct mmal_msg_component_enable_reply component_enable_reply;
  14686. +
  14687. + struct mmal_msg_component_disable component_disable;
  14688. + struct mmal_msg_component_disable_reply component_disable_reply;
  14689. +
  14690. + struct mmal_msg_port_info_get port_info_get;
  14691. + struct mmal_msg_port_info_get_reply port_info_get_reply;
  14692. +
  14693. + struct mmal_msg_port_info_set port_info_set;
  14694. + struct mmal_msg_port_info_set_reply port_info_set_reply;
  14695. +
  14696. + struct mmal_msg_port_action_port port_action_port;
  14697. + struct mmal_msg_port_action_handle port_action_handle;
  14698. + struct mmal_msg_port_action_reply port_action_reply;
  14699. +
  14700. + struct mmal_msg_buffer_from_host buffer_from_host;
  14701. +
  14702. + struct mmal_msg_port_parameter_set port_parameter_set;
  14703. + struct mmal_msg_port_parameter_set_reply
  14704. + port_parameter_set_reply;
  14705. + struct mmal_msg_port_parameter_get
  14706. + port_parameter_get;
  14707. + struct mmal_msg_port_parameter_get_reply
  14708. + port_parameter_get_reply;
  14709. +
  14710. + struct mmal_msg_event_to_host event_to_host;
  14711. +
  14712. + u8 payload[MMAL_MSG_MAX_PAYLOAD];
  14713. + } u;
  14714. +};
  14715. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-msg-port.h linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h
  14716. --- linux-3.15/drivers/media/platform/bcm2835/mmal-msg-port.h 1970-01-01 01:00:00.000000000 +0100
  14717. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-msg-port.h 2014-06-11 21:03:33.000000000 +0200
  14718. @@ -0,0 +1,107 @@
  14719. +/*
  14720. + * Broadcom BM2835 V4L2 driver
  14721. + *
  14722. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14723. + *
  14724. + * This file is subject to the terms and conditions of the GNU General Public
  14725. + * License. See the file COPYING in the main directory of this archive
  14726. + * for more details.
  14727. + *
  14728. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14729. + * Dave Stevenson <dsteve@broadcom.com>
  14730. + * Simon Mellor <simellor@broadcom.com>
  14731. + * Luke Diamand <luked@broadcom.com>
  14732. + */
  14733. +
  14734. +/* MMAL_PORT_TYPE_T */
  14735. +enum mmal_port_type {
  14736. + MMAL_PORT_TYPE_UNKNOWN = 0, /**< Unknown port type */
  14737. + MMAL_PORT_TYPE_CONTROL, /**< Control port */
  14738. + MMAL_PORT_TYPE_INPUT, /**< Input port */
  14739. + MMAL_PORT_TYPE_OUTPUT, /**< Output port */
  14740. + MMAL_PORT_TYPE_CLOCK, /**< Clock port */
  14741. +};
  14742. +
  14743. +/** The port is pass-through and doesn't need buffer headers allocated */
  14744. +#define MMAL_PORT_CAPABILITY_PASSTHROUGH 0x01
  14745. +/** The port wants to allocate the buffer payloads.
  14746. + * This signals a preference that payload allocation should be done
  14747. + * on this port for efficiency reasons. */
  14748. +#define MMAL_PORT_CAPABILITY_ALLOCATION 0x02
  14749. +/** The port supports format change events.
  14750. + * This applies to input ports and is used to let the client know
  14751. + * whether the port supports being reconfigured via a format
  14752. + * change event (i.e. without having to disable the port). */
  14753. +#define MMAL_PORT_CAPABILITY_SUPPORTS_EVENT_FORMAT_CHANGE 0x04
  14754. +
  14755. +/* mmal port structure (MMAL_PORT_T)
  14756. + *
  14757. + * most elements are informational only, the pointer values for
  14758. + * interogation messages are generally provided as additional
  14759. + * strucures within the message. When used to set values only teh
  14760. + * buffer_num, buffer_size and userdata parameters are writable.
  14761. + */
  14762. +struct mmal_port {
  14763. + void *priv; /* Private member used by the framework */
  14764. + const char *name; /* Port name. Used for debugging purposes (RO) */
  14765. +
  14766. + u32 type; /* Type of the port (RO) enum mmal_port_type */
  14767. + u16 index; /* Index of the port in its type list (RO) */
  14768. + u16 index_all; /* Index of the port in the list of all ports (RO) */
  14769. +
  14770. + u32 is_enabled; /* Indicates whether the port is enabled or not (RO) */
  14771. + struct mmal_es_format *format; /* Format of the elementary stream */
  14772. +
  14773. + u32 buffer_num_min; /* Minimum number of buffers the port
  14774. + * requires (RO). This is set by the
  14775. + * component.
  14776. + */
  14777. +
  14778. + u32 buffer_size_min; /* Minimum size of buffers the port
  14779. + * requires (RO). This is set by the
  14780. + * component.
  14781. + */
  14782. +
  14783. + u32 buffer_alignment_min; /* Minimum alignment requirement for
  14784. + * the buffers (RO). A value of
  14785. + * zero means no special alignment
  14786. + * requirements. This is set by the
  14787. + * component.
  14788. + */
  14789. +
  14790. + u32 buffer_num_recommended; /* Number of buffers the port
  14791. + * recommends for optimal
  14792. + * performance (RO). A value of
  14793. + * zero means no special
  14794. + * recommendation. This is set
  14795. + * by the component.
  14796. + */
  14797. +
  14798. + u32 buffer_size_recommended; /* Size of buffers the port
  14799. + * recommends for optimal
  14800. + * performance (RO). A value of
  14801. + * zero means no special
  14802. + * recommendation. This is set
  14803. + * by the component.
  14804. + */
  14805. +
  14806. + u32 buffer_num; /* Actual number of buffers the port will use.
  14807. + * This is set by the client.
  14808. + */
  14809. +
  14810. + u32 buffer_size; /* Actual maximum size of the buffers that
  14811. + * will be sent to the port. This is set by
  14812. + * the client.
  14813. + */
  14814. +
  14815. + void *component; /* Component this port belongs to (Read Only) */
  14816. +
  14817. + void *userdata; /* Field reserved for use by the client */
  14818. +
  14819. + u32 capabilities; /* Flags describing the capabilities of a
  14820. + * port (RO). Bitwise combination of \ref
  14821. + * portcapabilities "Port capabilities"
  14822. + * values.
  14823. + */
  14824. +
  14825. +};
  14826. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-parameters.h linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h
  14827. --- linux-3.15/drivers/media/platform/bcm2835/mmal-parameters.h 1970-01-01 01:00:00.000000000 +0100
  14828. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-parameters.h 2014-06-11 21:03:33.000000000 +0200
  14829. @@ -0,0 +1,656 @@
  14830. +/*
  14831. + * Broadcom BM2835 V4L2 driver
  14832. + *
  14833. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  14834. + *
  14835. + * This file is subject to the terms and conditions of the GNU General Public
  14836. + * License. See the file COPYING in the main directory of this archive
  14837. + * for more details.
  14838. + *
  14839. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  14840. + * Dave Stevenson <dsteve@broadcom.com>
  14841. + * Simon Mellor <simellor@broadcom.com>
  14842. + * Luke Diamand <luked@broadcom.com>
  14843. + */
  14844. +
  14845. +/* common parameters */
  14846. +
  14847. +/** @name Parameter groups
  14848. + * Parameters are divided into groups, and then allocated sequentially within
  14849. + * a group using an enum.
  14850. + * @{
  14851. + */
  14852. +
  14853. +/** Common parameter ID group, used with many types of component. */
  14854. +#define MMAL_PARAMETER_GROUP_COMMON (0<<16)
  14855. +/** Camera-specific parameter ID group. */
  14856. +#define MMAL_PARAMETER_GROUP_CAMERA (1<<16)
  14857. +/** Video-specific parameter ID group. */
  14858. +#define MMAL_PARAMETER_GROUP_VIDEO (2<<16)
  14859. +/** Audio-specific parameter ID group. */
  14860. +#define MMAL_PARAMETER_GROUP_AUDIO (3<<16)
  14861. +/** Clock-specific parameter ID group. */
  14862. +#define MMAL_PARAMETER_GROUP_CLOCK (4<<16)
  14863. +/** Miracast-specific parameter ID group. */
  14864. +#define MMAL_PARAMETER_GROUP_MIRACAST (5<<16)
  14865. +
  14866. +/* Common parameters */
  14867. +enum mmal_parameter_common_type {
  14868. + MMAL_PARAMETER_UNUSED /**< Never a valid parameter ID */
  14869. + = MMAL_PARAMETER_GROUP_COMMON,
  14870. + MMAL_PARAMETER_SUPPORTED_ENCODINGS, /**< MMAL_PARAMETER_ENCODING_T */
  14871. + MMAL_PARAMETER_URI, /**< MMAL_PARAMETER_URI_T */
  14872. +
  14873. + /** MMAL_PARAMETER_CHANGE_EVENT_REQUEST_T */
  14874. + MMAL_PARAMETER_CHANGE_EVENT_REQUEST,
  14875. +
  14876. + /** MMAL_PARAMETER_BOOLEAN_T */
  14877. + MMAL_PARAMETER_ZERO_COPY,
  14878. +
  14879. + /**< MMAL_PARAMETER_BUFFER_REQUIREMENTS_T */
  14880. + MMAL_PARAMETER_BUFFER_REQUIREMENTS,
  14881. +
  14882. + MMAL_PARAMETER_STATISTICS, /**< MMAL_PARAMETER_STATISTICS_T */
  14883. + MMAL_PARAMETER_CORE_STATISTICS, /**< MMAL_PARAMETER_CORE_STATISTICS_T */
  14884. + MMAL_PARAMETER_MEM_USAGE, /**< MMAL_PARAMETER_MEM_USAGE_T */
  14885. + MMAL_PARAMETER_BUFFER_FLAG_FILTER, /**< MMAL_PARAMETER_UINT32_T */
  14886. + MMAL_PARAMETER_SEEK, /**< MMAL_PARAMETER_SEEK_T */
  14887. + MMAL_PARAMETER_POWERMON_ENABLE, /**< MMAL_PARAMETER_BOOLEAN_T */
  14888. + MMAL_PARAMETER_LOGGING, /**< MMAL_PARAMETER_LOGGING_T */
  14889. + MMAL_PARAMETER_SYSTEM_TIME, /**< MMAL_PARAMETER_UINT64_T */
  14890. + MMAL_PARAMETER_NO_IMAGE_PADDING /**< MMAL_PARAMETER_BOOLEAN_T */
  14891. +};
  14892. +
  14893. +/* camera parameters */
  14894. +
  14895. +enum mmal_parameter_camera_type {
  14896. + /* 0 */
  14897. + /** @ref MMAL_PARAMETER_THUMBNAIL_CONFIG_T */
  14898. + MMAL_PARAMETER_THUMBNAIL_CONFIGURATION
  14899. + = MMAL_PARAMETER_GROUP_CAMERA,
  14900. + MMAL_PARAMETER_CAPTURE_QUALITY, /**< Unused? */
  14901. + MMAL_PARAMETER_ROTATION, /**< @ref MMAL_PARAMETER_INT32_T */
  14902. + MMAL_PARAMETER_EXIF_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14903. + MMAL_PARAMETER_EXIF, /**< @ref MMAL_PARAMETER_EXIF_T */
  14904. + MMAL_PARAMETER_AWB_MODE, /**< @ref MMAL_PARAM_AWBMODE_T */
  14905. + MMAL_PARAMETER_IMAGE_EFFECT, /**< @ref MMAL_PARAMETER_IMAGEFX_T */
  14906. + MMAL_PARAMETER_COLOUR_EFFECT, /**< @ref MMAL_PARAMETER_COLOURFX_T */
  14907. + MMAL_PARAMETER_FLICKER_AVOID, /**< @ref MMAL_PARAMETER_FLICKERAVOID_T */
  14908. + MMAL_PARAMETER_FLASH, /**< @ref MMAL_PARAMETER_FLASH_T */
  14909. + MMAL_PARAMETER_REDEYE, /**< @ref MMAL_PARAMETER_REDEYE_T */
  14910. + MMAL_PARAMETER_FOCUS, /**< @ref MMAL_PARAMETER_FOCUS_T */
  14911. + MMAL_PARAMETER_FOCAL_LENGTHS, /**< Unused? */
  14912. + MMAL_PARAMETER_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14913. + MMAL_PARAMETER_ZOOM, /**< @ref MMAL_PARAMETER_SCALEFACTOR_T */
  14914. + MMAL_PARAMETER_MIRROR, /**< @ref MMAL_PARAMETER_MIRROR_T */
  14915. +
  14916. + /* 0x10 */
  14917. + MMAL_PARAMETER_CAMERA_NUM, /**< @ref MMAL_PARAMETER_UINT32_T */
  14918. + MMAL_PARAMETER_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14919. + MMAL_PARAMETER_EXPOSURE_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMODE_T */
  14920. + MMAL_PARAMETER_EXP_METERING_MODE, /**< @ref MMAL_PARAMETER_EXPOSUREMETERINGMODE_T */
  14921. + MMAL_PARAMETER_FOCUS_STATUS, /**< @ref MMAL_PARAMETER_FOCUS_STATUS_T */
  14922. + MMAL_PARAMETER_CAMERA_CONFIG, /**< @ref MMAL_PARAMETER_CAMERA_CONFIG_T */
  14923. + MMAL_PARAMETER_CAPTURE_STATUS, /**< @ref MMAL_PARAMETER_CAPTURE_STATUS_T */
  14924. + MMAL_PARAMETER_FACE_TRACK, /**< @ref MMAL_PARAMETER_FACE_TRACK_T */
  14925. + MMAL_PARAMETER_DRAW_BOX_FACES_AND_FOCUS, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14926. + MMAL_PARAMETER_JPEG_Q_FACTOR, /**< @ref MMAL_PARAMETER_UINT32_T */
  14927. + MMAL_PARAMETER_FRAME_RATE, /**< @ref MMAL_PARAMETER_FRAME_RATE_T */
  14928. + MMAL_PARAMETER_USE_STC, /**< @ref MMAL_PARAMETER_CAMERA_STC_MODE_T */
  14929. + MMAL_PARAMETER_CAMERA_INFO, /**< @ref MMAL_PARAMETER_CAMERA_INFO_T */
  14930. + MMAL_PARAMETER_VIDEO_STABILISATION, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14931. + MMAL_PARAMETER_FACE_TRACK_RESULTS, /**< @ref MMAL_PARAMETER_FACE_TRACK_RESULTS_T */
  14932. + MMAL_PARAMETER_ENABLE_RAW_CAPTURE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14933. +
  14934. + /* 0x20 */
  14935. + MMAL_PARAMETER_DPF_FILE, /**< @ref MMAL_PARAMETER_URI_T */
  14936. + MMAL_PARAMETER_ENABLE_DPF_FILE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14937. + MMAL_PARAMETER_DPF_FAIL_IS_FATAL, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14938. + MMAL_PARAMETER_CAPTURE_MODE, /**< @ref MMAL_PARAMETER_CAPTUREMODE_T */
  14939. + MMAL_PARAMETER_FOCUS_REGIONS, /**< @ref MMAL_PARAMETER_FOCUS_REGIONS_T */
  14940. + MMAL_PARAMETER_INPUT_CROP, /**< @ref MMAL_PARAMETER_INPUT_CROP_T */
  14941. + MMAL_PARAMETER_SENSOR_INFORMATION, /**< @ref MMAL_PARAMETER_SENSOR_INFORMATION_T */
  14942. + MMAL_PARAMETER_FLASH_SELECT, /**< @ref MMAL_PARAMETER_FLASH_SELECT_T */
  14943. + MMAL_PARAMETER_FIELD_OF_VIEW, /**< @ref MMAL_PARAMETER_FIELD_OF_VIEW_T */
  14944. + MMAL_PARAMETER_HIGH_DYNAMIC_RANGE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14945. + MMAL_PARAMETER_DYNAMIC_RANGE_COMPRESSION, /**< @ref MMAL_PARAMETER_DRC_T */
  14946. + MMAL_PARAMETER_ALGORITHM_CONTROL, /**< @ref MMAL_PARAMETER_ALGORITHM_CONTROL_T */
  14947. + MMAL_PARAMETER_SHARPNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14948. + MMAL_PARAMETER_CONTRAST, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14949. + MMAL_PARAMETER_BRIGHTNESS, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14950. + MMAL_PARAMETER_SATURATION, /**< @ref MMAL_PARAMETER_RATIONAL_T */
  14951. +
  14952. + /* 0x30 */
  14953. + MMAL_PARAMETER_ISO, /**< @ref MMAL_PARAMETER_UINT32_T */
  14954. + MMAL_PARAMETER_ANTISHAKE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14955. +
  14956. + /** @ref MMAL_PARAMETER_IMAGEFX_PARAMETERS_T */
  14957. + MMAL_PARAMETER_IMAGE_EFFECT_PARAMETERS,
  14958. +
  14959. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14960. + MMAL_PARAMETER_CAMERA_BURST_CAPTURE,
  14961. +
  14962. + /** @ref MMAL_PARAMETER_UINT32_T */
  14963. + MMAL_PARAMETER_CAMERA_MIN_ISO,
  14964. +
  14965. + /** @ref MMAL_PARAMETER_CAMERA_USE_CASE_T */
  14966. + MMAL_PARAMETER_CAMERA_USE_CASE,
  14967. +
  14968. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14969. + MMAL_PARAMETER_CAPTURE_STATS_PASS,
  14970. +
  14971. + /** @ref MMAL_PARAMETER_UINT32_T */
  14972. + MMAL_PARAMETER_CAMERA_CUSTOM_SENSOR_CONFIG,
  14973. +
  14974. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14975. + MMAL_PARAMETER_ENABLE_REGISTER_FILE,
  14976. +
  14977. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  14978. + MMAL_PARAMETER_REGISTER_FAIL_IS_FATAL,
  14979. +
  14980. + /** @ref MMAL_PARAMETER_CONFIGFILE_T */
  14981. + MMAL_PARAMETER_CONFIGFILE_REGISTERS,
  14982. +
  14983. + /** @ref MMAL_PARAMETER_CONFIGFILE_CHUNK_T */
  14984. + MMAL_PARAMETER_CONFIGFILE_CHUNK_REGISTERS,
  14985. + MMAL_PARAMETER_JPEG_ATTACH_LOG, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14986. + MMAL_PARAMETER_ZERO_SHUTTER_LAG, /**< @ref MMAL_PARAMETER_ZEROSHUTTERLAG_T */
  14987. + MMAL_PARAMETER_FPS_RANGE, /**< @ref MMAL_PARAMETER_FPS_RANGE_T */
  14988. + MMAL_PARAMETER_CAPTURE_EXPOSURE_COMP, /**< @ref MMAL_PARAMETER_INT32_T */
  14989. +
  14990. + /* 0x40 */
  14991. + MMAL_PARAMETER_SW_SHARPEN_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14992. + MMAL_PARAMETER_FLASH_REQUIRED, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14993. + MMAL_PARAMETER_SW_SATURATION_DISABLE, /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  14994. + MMAL_PARAMETER_SHUTTER_SPEED, /**< Takes a @ref MMAL_PARAMETER_UINT32_T */
  14995. + MMAL_PARAMETER_CUSTOM_AWB_GAINS, /**< Takes a @ref MMAL_PARAMETER_AWB_GAINS_T */
  14996. +};
  14997. +
  14998. +struct mmal_parameter_rational {
  14999. + s32 num; /**< Numerator */
  15000. + s32 den; /**< Denominator */
  15001. +};
  15002. +
  15003. +enum mmal_parameter_camera_config_timestamp_mode {
  15004. + MMAL_PARAM_TIMESTAMP_MODE_ZERO = 0, /* Always timestamp frames as 0 */
  15005. + MMAL_PARAM_TIMESTAMP_MODE_RAW_STC, /* Use the raw STC value
  15006. + * for the frame timestamp
  15007. + */
  15008. + MMAL_PARAM_TIMESTAMP_MODE_RESET_STC, /* Use the STC timestamp
  15009. + * but subtract the
  15010. + * timestamp of the first
  15011. + * frame sent to give a
  15012. + * zero based timestamp.
  15013. + */
  15014. +};
  15015. +
  15016. +struct mmal_parameter_fps_range {
  15017. + /**< Low end of the permitted framerate range */
  15018. + struct mmal_parameter_rational fps_low;
  15019. + /**< High end of the permitted framerate range */
  15020. + struct mmal_parameter_rational fps_high;
  15021. +};
  15022. +
  15023. +
  15024. +/* camera configuration parameter */
  15025. +struct mmal_parameter_camera_config {
  15026. + /* Parameters for setting up the image pools */
  15027. + u32 max_stills_w; /* Max size of stills capture */
  15028. + u32 max_stills_h;
  15029. + u32 stills_yuv422; /* Allow YUV422 stills capture */
  15030. + u32 one_shot_stills; /* Continuous or one shot stills captures. */
  15031. +
  15032. + u32 max_preview_video_w; /* Max size of the preview or video
  15033. + * capture frames
  15034. + */
  15035. + u32 max_preview_video_h;
  15036. + u32 num_preview_video_frames;
  15037. +
  15038. + /** Sets the height of the circular buffer for stills capture. */
  15039. + u32 stills_capture_circular_buffer_height;
  15040. +
  15041. + /** Allows preview/encode to resume as fast as possible after the stills
  15042. + * input frame has been received, and then processes the still frame in
  15043. + * the background whilst preview/encode has resumed.
  15044. + * Actual mode is controlled by MMAL_PARAMETER_CAPTURE_MODE.
  15045. + */
  15046. + u32 fast_preview_resume;
  15047. +
  15048. + /** Selects algorithm for timestamping frames if
  15049. + * there is no clock component connected.
  15050. + * enum mmal_parameter_camera_config_timestamp_mode
  15051. + */
  15052. + s32 use_stc_timestamp;
  15053. +};
  15054. +
  15055. +
  15056. +enum mmal_parameter_exposuremode {
  15057. + MMAL_PARAM_EXPOSUREMODE_OFF,
  15058. + MMAL_PARAM_EXPOSUREMODE_AUTO,
  15059. + MMAL_PARAM_EXPOSUREMODE_NIGHT,
  15060. + MMAL_PARAM_EXPOSUREMODE_NIGHTPREVIEW,
  15061. + MMAL_PARAM_EXPOSUREMODE_BACKLIGHT,
  15062. + MMAL_PARAM_EXPOSUREMODE_SPOTLIGHT,
  15063. + MMAL_PARAM_EXPOSUREMODE_SPORTS,
  15064. + MMAL_PARAM_EXPOSUREMODE_SNOW,
  15065. + MMAL_PARAM_EXPOSUREMODE_BEACH,
  15066. + MMAL_PARAM_EXPOSUREMODE_VERYLONG,
  15067. + MMAL_PARAM_EXPOSUREMODE_FIXEDFPS,
  15068. + MMAL_PARAM_EXPOSUREMODE_ANTISHAKE,
  15069. + MMAL_PARAM_EXPOSUREMODE_FIREWORKS,
  15070. +};
  15071. +
  15072. +enum mmal_parameter_exposuremeteringmode {
  15073. + MMAL_PARAM_EXPOSUREMETERINGMODE_AVERAGE,
  15074. + MMAL_PARAM_EXPOSUREMETERINGMODE_SPOT,
  15075. + MMAL_PARAM_EXPOSUREMETERINGMODE_BACKLIT,
  15076. + MMAL_PARAM_EXPOSUREMETERINGMODE_MATRIX,
  15077. +};
  15078. +
  15079. +enum mmal_parameter_awbmode {
  15080. + MMAL_PARAM_AWBMODE_OFF,
  15081. + MMAL_PARAM_AWBMODE_AUTO,
  15082. + MMAL_PARAM_AWBMODE_SUNLIGHT,
  15083. + MMAL_PARAM_AWBMODE_CLOUDY,
  15084. + MMAL_PARAM_AWBMODE_SHADE,
  15085. + MMAL_PARAM_AWBMODE_TUNGSTEN,
  15086. + MMAL_PARAM_AWBMODE_FLUORESCENT,
  15087. + MMAL_PARAM_AWBMODE_INCANDESCENT,
  15088. + MMAL_PARAM_AWBMODE_FLASH,
  15089. + MMAL_PARAM_AWBMODE_HORIZON,
  15090. +};
  15091. +
  15092. +enum mmal_parameter_imagefx {
  15093. + MMAL_PARAM_IMAGEFX_NONE,
  15094. + MMAL_PARAM_IMAGEFX_NEGATIVE,
  15095. + MMAL_PARAM_IMAGEFX_SOLARIZE,
  15096. + MMAL_PARAM_IMAGEFX_POSTERIZE,
  15097. + MMAL_PARAM_IMAGEFX_WHITEBOARD,
  15098. + MMAL_PARAM_IMAGEFX_BLACKBOARD,
  15099. + MMAL_PARAM_IMAGEFX_SKETCH,
  15100. + MMAL_PARAM_IMAGEFX_DENOISE,
  15101. + MMAL_PARAM_IMAGEFX_EMBOSS,
  15102. + MMAL_PARAM_IMAGEFX_OILPAINT,
  15103. + MMAL_PARAM_IMAGEFX_HATCH,
  15104. + MMAL_PARAM_IMAGEFX_GPEN,
  15105. + MMAL_PARAM_IMAGEFX_PASTEL,
  15106. + MMAL_PARAM_IMAGEFX_WATERCOLOUR,
  15107. + MMAL_PARAM_IMAGEFX_FILM,
  15108. + MMAL_PARAM_IMAGEFX_BLUR,
  15109. + MMAL_PARAM_IMAGEFX_SATURATION,
  15110. + MMAL_PARAM_IMAGEFX_COLOURSWAP,
  15111. + MMAL_PARAM_IMAGEFX_WASHEDOUT,
  15112. + MMAL_PARAM_IMAGEFX_POSTERISE,
  15113. + MMAL_PARAM_IMAGEFX_COLOURPOINT,
  15114. + MMAL_PARAM_IMAGEFX_COLOURBALANCE,
  15115. + MMAL_PARAM_IMAGEFX_CARTOON,
  15116. +};
  15117. +
  15118. +enum MMAL_PARAM_FLICKERAVOID_T {
  15119. + MMAL_PARAM_FLICKERAVOID_OFF,
  15120. + MMAL_PARAM_FLICKERAVOID_AUTO,
  15121. + MMAL_PARAM_FLICKERAVOID_50HZ,
  15122. + MMAL_PARAM_FLICKERAVOID_60HZ,
  15123. + MMAL_PARAM_FLICKERAVOID_MAX = 0x7FFFFFFF
  15124. +};
  15125. +
  15126. +struct mmal_parameter_awbgains {
  15127. + struct mmal_parameter_rational r_gain; /**< Red gain */
  15128. + struct mmal_parameter_rational b_gain; /**< Blue gain */
  15129. +};
  15130. +
  15131. +/** Manner of video rate control */
  15132. +enum mmal_parameter_rate_control_mode {
  15133. + MMAL_VIDEO_RATECONTROL_DEFAULT,
  15134. + MMAL_VIDEO_RATECONTROL_VARIABLE,
  15135. + MMAL_VIDEO_RATECONTROL_CONSTANT,
  15136. + MMAL_VIDEO_RATECONTROL_VARIABLE_SKIP_FRAMES,
  15137. + MMAL_VIDEO_RATECONTROL_CONSTANT_SKIP_FRAMES
  15138. +};
  15139. +
  15140. +enum mmal_video_profile {
  15141. + MMAL_VIDEO_PROFILE_H263_BASELINE,
  15142. + MMAL_VIDEO_PROFILE_H263_H320CODING,
  15143. + MMAL_VIDEO_PROFILE_H263_BACKWARDCOMPATIBLE,
  15144. + MMAL_VIDEO_PROFILE_H263_ISWV2,
  15145. + MMAL_VIDEO_PROFILE_H263_ISWV3,
  15146. + MMAL_VIDEO_PROFILE_H263_HIGHCOMPRESSION,
  15147. + MMAL_VIDEO_PROFILE_H263_INTERNET,
  15148. + MMAL_VIDEO_PROFILE_H263_INTERLACE,
  15149. + MMAL_VIDEO_PROFILE_H263_HIGHLATENCY,
  15150. + MMAL_VIDEO_PROFILE_MP4V_SIMPLE,
  15151. + MMAL_VIDEO_PROFILE_MP4V_SIMPLESCALABLE,
  15152. + MMAL_VIDEO_PROFILE_MP4V_CORE,
  15153. + MMAL_VIDEO_PROFILE_MP4V_MAIN,
  15154. + MMAL_VIDEO_PROFILE_MP4V_NBIT,
  15155. + MMAL_VIDEO_PROFILE_MP4V_SCALABLETEXTURE,
  15156. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFACE,
  15157. + MMAL_VIDEO_PROFILE_MP4V_SIMPLEFBA,
  15158. + MMAL_VIDEO_PROFILE_MP4V_BASICANIMATED,
  15159. + MMAL_VIDEO_PROFILE_MP4V_HYBRID,
  15160. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDREALTIME,
  15161. + MMAL_VIDEO_PROFILE_MP4V_CORESCALABLE,
  15162. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCODING,
  15163. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDCORE,
  15164. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSCALABLE,
  15165. + MMAL_VIDEO_PROFILE_MP4V_ADVANCEDSIMPLE,
  15166. + MMAL_VIDEO_PROFILE_H264_BASELINE,
  15167. + MMAL_VIDEO_PROFILE_H264_MAIN,
  15168. + MMAL_VIDEO_PROFILE_H264_EXTENDED,
  15169. + MMAL_VIDEO_PROFILE_H264_HIGH,
  15170. + MMAL_VIDEO_PROFILE_H264_HIGH10,
  15171. + MMAL_VIDEO_PROFILE_H264_HIGH422,
  15172. + MMAL_VIDEO_PROFILE_H264_HIGH444,
  15173. + MMAL_VIDEO_PROFILE_H264_CONSTRAINED_BASELINE,
  15174. + MMAL_VIDEO_PROFILE_DUMMY = 0x7FFFFFFF
  15175. +};
  15176. +
  15177. +enum mmal_video_level {
  15178. + MMAL_VIDEO_LEVEL_H263_10,
  15179. + MMAL_VIDEO_LEVEL_H263_20,
  15180. + MMAL_VIDEO_LEVEL_H263_30,
  15181. + MMAL_VIDEO_LEVEL_H263_40,
  15182. + MMAL_VIDEO_LEVEL_H263_45,
  15183. + MMAL_VIDEO_LEVEL_H263_50,
  15184. + MMAL_VIDEO_LEVEL_H263_60,
  15185. + MMAL_VIDEO_LEVEL_H263_70,
  15186. + MMAL_VIDEO_LEVEL_MP4V_0,
  15187. + MMAL_VIDEO_LEVEL_MP4V_0b,
  15188. + MMAL_VIDEO_LEVEL_MP4V_1,
  15189. + MMAL_VIDEO_LEVEL_MP4V_2,
  15190. + MMAL_VIDEO_LEVEL_MP4V_3,
  15191. + MMAL_VIDEO_LEVEL_MP4V_4,
  15192. + MMAL_VIDEO_LEVEL_MP4V_4a,
  15193. + MMAL_VIDEO_LEVEL_MP4V_5,
  15194. + MMAL_VIDEO_LEVEL_MP4V_6,
  15195. + MMAL_VIDEO_LEVEL_H264_1,
  15196. + MMAL_VIDEO_LEVEL_H264_1b,
  15197. + MMAL_VIDEO_LEVEL_H264_11,
  15198. + MMAL_VIDEO_LEVEL_H264_12,
  15199. + MMAL_VIDEO_LEVEL_H264_13,
  15200. + MMAL_VIDEO_LEVEL_H264_2,
  15201. + MMAL_VIDEO_LEVEL_H264_21,
  15202. + MMAL_VIDEO_LEVEL_H264_22,
  15203. + MMAL_VIDEO_LEVEL_H264_3,
  15204. + MMAL_VIDEO_LEVEL_H264_31,
  15205. + MMAL_VIDEO_LEVEL_H264_32,
  15206. + MMAL_VIDEO_LEVEL_H264_4,
  15207. + MMAL_VIDEO_LEVEL_H264_41,
  15208. + MMAL_VIDEO_LEVEL_H264_42,
  15209. + MMAL_VIDEO_LEVEL_H264_5,
  15210. + MMAL_VIDEO_LEVEL_H264_51,
  15211. + MMAL_VIDEO_LEVEL_DUMMY = 0x7FFFFFFF
  15212. +};
  15213. +
  15214. +struct mmal_parameter_video_profile {
  15215. + enum mmal_video_profile profile;
  15216. + enum mmal_video_level level;
  15217. +};
  15218. +
  15219. +/* video parameters */
  15220. +
  15221. +enum mmal_parameter_video_type {
  15222. + /** @ref MMAL_DISPLAYREGION_T */
  15223. + MMAL_PARAMETER_DISPLAYREGION = MMAL_PARAMETER_GROUP_VIDEO,
  15224. +
  15225. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15226. + MMAL_PARAMETER_SUPPORTED_PROFILES,
  15227. +
  15228. + /** @ref MMAL_PARAMETER_VIDEO_PROFILE_T */
  15229. + MMAL_PARAMETER_PROFILE,
  15230. +
  15231. + /** @ref MMAL_PARAMETER_UINT32_T */
  15232. + MMAL_PARAMETER_INTRAPERIOD,
  15233. +
  15234. + /** @ref MMAL_PARAMETER_VIDEO_RATECONTROL_T */
  15235. + MMAL_PARAMETER_RATECONTROL,
  15236. +
  15237. + /** @ref MMAL_PARAMETER_VIDEO_NALUNITFORMAT_T */
  15238. + MMAL_PARAMETER_NALUNITFORMAT,
  15239. +
  15240. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15241. + MMAL_PARAMETER_MINIMISE_FRAGMENTATION,
  15242. +
  15243. + /** @ref MMAL_PARAMETER_UINT32_T.
  15244. + * Setting the value to zero resets to the default (one slice per frame).
  15245. + */
  15246. + MMAL_PARAMETER_MB_ROWS_PER_SLICE,
  15247. +
  15248. + /** @ref MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION_T */
  15249. + MMAL_PARAMETER_VIDEO_LEVEL_EXTENSION,
  15250. +
  15251. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_ENABLE_T */
  15252. + MMAL_PARAMETER_VIDEO_EEDE_ENABLE,
  15253. +
  15254. + /** @ref MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE_T */
  15255. + MMAL_PARAMETER_VIDEO_EEDE_LOSSRATE,
  15256. +
  15257. + /** @ref MMAL_PARAMETER_BOOLEAN_T. Request an I-frame. */
  15258. + MMAL_PARAMETER_VIDEO_REQUEST_I_FRAME,
  15259. + /** @ref MMAL_PARAMETER_VIDEO_INTRA_REFRESH_T */
  15260. + MMAL_PARAMETER_VIDEO_INTRA_REFRESH,
  15261. +
  15262. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15263. + MMAL_PARAMETER_VIDEO_IMMUTABLE_INPUT,
  15264. +
  15265. + /** @ref MMAL_PARAMETER_UINT32_T. Run-time bit rate control */
  15266. + MMAL_PARAMETER_VIDEO_BIT_RATE,
  15267. +
  15268. + /** @ref MMAL_PARAMETER_FRAME_RATE_T */
  15269. + MMAL_PARAMETER_VIDEO_FRAME_RATE,
  15270. +
  15271. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15272. + MMAL_PARAMETER_VIDEO_ENCODE_MIN_QUANT,
  15273. +
  15274. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15275. + MMAL_PARAMETER_VIDEO_ENCODE_MAX_QUANT,
  15276. +
  15277. + /** @ref MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL_T. */
  15278. + MMAL_PARAMETER_VIDEO_ENCODE_RC_MODEL,
  15279. +
  15280. + MMAL_PARAMETER_EXTRA_BUFFERS, /**< @ref MMAL_PARAMETER_UINT32_T. */
  15281. + /** @ref MMAL_PARAMETER_UINT32_T.
  15282. + * Changing this parameter from the default can reduce frame rate
  15283. + * because image buffers need to be re-pitched.
  15284. + */
  15285. + MMAL_PARAMETER_VIDEO_ALIGN_HORIZ,
  15286. +
  15287. + /** @ref MMAL_PARAMETER_UINT32_T.
  15288. + * Changing this parameter from the default can reduce frame rate
  15289. + * because image buffers need to be re-pitched.
  15290. + */
  15291. + MMAL_PARAMETER_VIDEO_ALIGN_VERT,
  15292. +
  15293. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15294. + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAMES,
  15295. +
  15296. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15297. + MMAL_PARAMETER_VIDEO_ENCODE_INITIAL_QUANT,
  15298. +
  15299. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15300. + MMAL_PARAMETER_VIDEO_ENCODE_QP_P,
  15301. +
  15302. + /**< @ref MMAL_PARAMETER_UINT32_T. */
  15303. + MMAL_PARAMETER_VIDEO_ENCODE_RC_SLICE_DQUANT,
  15304. +
  15305. + /** @ref MMAL_PARAMETER_UINT32_T */
  15306. + MMAL_PARAMETER_VIDEO_ENCODE_FRAME_LIMIT_BITS,
  15307. +
  15308. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15309. + MMAL_PARAMETER_VIDEO_ENCODE_PEAK_RATE,
  15310. +
  15311. + /* H264 specific parameters */
  15312. +
  15313. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15314. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DISABLE_CABAC,
  15315. +
  15316. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15317. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_LATENCY,
  15318. +
  15319. + /** @ref MMAL_PARAMETER_BOOLEAN_T. */
  15320. + MMAL_PARAMETER_VIDEO_ENCODE_H264_AU_DELIMITERS,
  15321. +
  15322. + /** @ref MMAL_PARAMETER_UINT32_T. */
  15323. + MMAL_PARAMETER_VIDEO_ENCODE_H264_DEBLOCK_IDC,
  15324. +
  15325. + /** @ref MMAL_PARAMETER_VIDEO_ENCODER_H264_MB_INTRA_MODES_T. */
  15326. + MMAL_PARAMETER_VIDEO_ENCODE_H264_MB_INTRA_MODE,
  15327. +
  15328. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15329. + MMAL_PARAMETER_VIDEO_ENCODE_HEADER_ON_OPEN,
  15330. +
  15331. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15332. + MMAL_PARAMETER_VIDEO_ENCODE_PRECODE_FOR_QP,
  15333. +
  15334. + /** @ref MMAL_PARAMETER_VIDEO_DRM_INIT_INFO_T. */
  15335. + MMAL_PARAMETER_VIDEO_DRM_INIT_INFO,
  15336. +
  15337. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15338. + MMAL_PARAMETER_VIDEO_TIMESTAMP_FIFO,
  15339. +
  15340. + /** @ref MMAL_PARAMETER_BOOLEAN_T */
  15341. + MMAL_PARAMETER_VIDEO_DECODE_ERROR_CONCEALMENT,
  15342. +
  15343. + /** @ref MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER_T. */
  15344. + MMAL_PARAMETER_VIDEO_DRM_PROTECT_BUFFER,
  15345. +
  15346. + /** @ref MMAL_PARAMETER_BYTES_T */
  15347. + MMAL_PARAMETER_VIDEO_DECODE_CONFIG_VD3,
  15348. +
  15349. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15350. + MMAL_PARAMETER_VIDEO_ENCODE_H264_VCL_HRD_PARAMETERS,
  15351. +
  15352. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15353. + MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG,
  15354. +
  15355. + /**< @ref MMAL_PARAMETER_BOOLEAN_T */
  15356. + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER
  15357. +};
  15358. +
  15359. +/** Valid mirror modes */
  15360. +enum mmal_parameter_mirror {
  15361. + MMAL_PARAM_MIRROR_NONE,
  15362. + MMAL_PARAM_MIRROR_VERTICAL,
  15363. + MMAL_PARAM_MIRROR_HORIZONTAL,
  15364. + MMAL_PARAM_MIRROR_BOTH,
  15365. +};
  15366. +
  15367. +enum mmal_parameter_displaytransform {
  15368. + MMAL_DISPLAY_ROT0 = 0,
  15369. + MMAL_DISPLAY_MIRROR_ROT0 = 1,
  15370. + MMAL_DISPLAY_MIRROR_ROT180 = 2,
  15371. + MMAL_DISPLAY_ROT180 = 3,
  15372. + MMAL_DISPLAY_MIRROR_ROT90 = 4,
  15373. + MMAL_DISPLAY_ROT270 = 5,
  15374. + MMAL_DISPLAY_ROT90 = 6,
  15375. + MMAL_DISPLAY_MIRROR_ROT270 = 7,
  15376. +};
  15377. +
  15378. +enum mmal_parameter_displaymode {
  15379. + MMAL_DISPLAY_MODE_FILL = 0,
  15380. + MMAL_DISPLAY_MODE_LETTERBOX = 1,
  15381. +};
  15382. +
  15383. +enum mmal_parameter_displayset {
  15384. + MMAL_DISPLAY_SET_NONE = 0,
  15385. + MMAL_DISPLAY_SET_NUM = 1,
  15386. + MMAL_DISPLAY_SET_FULLSCREEN = 2,
  15387. + MMAL_DISPLAY_SET_TRANSFORM = 4,
  15388. + MMAL_DISPLAY_SET_DEST_RECT = 8,
  15389. + MMAL_DISPLAY_SET_SRC_RECT = 0x10,
  15390. + MMAL_DISPLAY_SET_MODE = 0x20,
  15391. + MMAL_DISPLAY_SET_PIXEL = 0x40,
  15392. + MMAL_DISPLAY_SET_NOASPECT = 0x80,
  15393. + MMAL_DISPLAY_SET_LAYER = 0x100,
  15394. + MMAL_DISPLAY_SET_COPYPROTECT = 0x200,
  15395. + MMAL_DISPLAY_SET_ALPHA = 0x400,
  15396. +};
  15397. +
  15398. +struct mmal_parameter_displayregion {
  15399. + /** Bitfield that indicates which fields are set and should be
  15400. + * used. All other fields will maintain their current value.
  15401. + * \ref MMAL_DISPLAYSET_T defines the bits that can be
  15402. + * combined.
  15403. + */
  15404. + u32 set;
  15405. +
  15406. + /** Describes the display output device, with 0 typically
  15407. + * being a directly connected LCD display. The actual values
  15408. + * will depend on the hardware. Code using hard-wired numbers
  15409. + * (e.g. 2) is certain to fail.
  15410. + */
  15411. +
  15412. + u32 display_num;
  15413. + /** Indicates that we are using the full device screen area,
  15414. + * rather than a window of the display. If zero, then
  15415. + * dest_rect is used to specify a region of the display to
  15416. + * use.
  15417. + */
  15418. +
  15419. + s32 fullscreen;
  15420. + /** Indicates any rotation or flipping used to map frames onto
  15421. + * the natural display orientation.
  15422. + */
  15423. + u32 transform; /* enum mmal_parameter_displaytransform */
  15424. +
  15425. + /** Where to display the frame within the screen, if
  15426. + * fullscreen is zero.
  15427. + */
  15428. + struct vchiq_mmal_rect dest_rect;
  15429. +
  15430. + /** Indicates which area of the frame to display. If all
  15431. + * values are zero, the whole frame will be used.
  15432. + */
  15433. + struct vchiq_mmal_rect src_rect;
  15434. +
  15435. + /** If set to non-zero, indicates that any display scaling
  15436. + * should disregard the aspect ratio of the frame region being
  15437. + * displayed.
  15438. + */
  15439. + s32 noaspect;
  15440. +
  15441. + /** Indicates how the image should be scaled to fit the
  15442. + * display. \code MMAL_DISPLAY_MODE_FILL \endcode indicates
  15443. + * that the image should fill the screen by potentially
  15444. + * cropping the frames. Setting \code mode \endcode to \code
  15445. + * MMAL_DISPLAY_MODE_LETTERBOX \endcode indicates that all the
  15446. + * source region should be displayed and black bars added if
  15447. + * necessary.
  15448. + */
  15449. + u32 mode; /* enum mmal_parameter_displaymode */
  15450. +
  15451. + /** If non-zero, defines the width of a source pixel relative
  15452. + * to \code pixel_y \endcode. If zero, then pixels default to
  15453. + * being square.
  15454. + */
  15455. + u32 pixel_x;
  15456. +
  15457. + /** If non-zero, defines the height of a source pixel relative
  15458. + * to \code pixel_x \endcode. If zero, then pixels default to
  15459. + * being square.
  15460. + */
  15461. + u32 pixel_y;
  15462. +
  15463. + /** Sets the relative depth of the images, with greater values
  15464. + * being in front of smaller values.
  15465. + */
  15466. + u32 layer;
  15467. +
  15468. + /** Set to non-zero to ensure copy protection is used on
  15469. + * output.
  15470. + */
  15471. + s32 copyprotect_required;
  15472. +
  15473. + /** Level of opacity of the layer, where zero is fully
  15474. + * transparent and 255 is fully opaque.
  15475. + */
  15476. + u32 alpha;
  15477. +};
  15478. +
  15479. +#define MMAL_MAX_IMAGEFX_PARAMETERS 5
  15480. +
  15481. +struct mmal_parameter_imagefx_parameters {
  15482. + enum mmal_parameter_imagefx effect;
  15483. + u32 num_effect_params;
  15484. + u32 effect_parameter[MMAL_MAX_IMAGEFX_PARAMETERS];
  15485. +};
  15486. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-vchiq.c linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c
  15487. --- linux-3.15/drivers/media/platform/bcm2835/mmal-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  15488. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.c 2014-06-11 21:03:33.000000000 +0200
  15489. @@ -0,0 +1,1916 @@
  15490. +/*
  15491. + * Broadcom BM2835 V4L2 driver
  15492. + *
  15493. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  15494. + *
  15495. + * This file is subject to the terms and conditions of the GNU General Public
  15496. + * License. See the file COPYING in the main directory of this archive
  15497. + * for more details.
  15498. + *
  15499. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  15500. + * Dave Stevenson <dsteve@broadcom.com>
  15501. + * Simon Mellor <simellor@broadcom.com>
  15502. + * Luke Diamand <luked@broadcom.com>
  15503. + *
  15504. + * V4L2 driver MMAL vchiq interface code
  15505. + */
  15506. +
  15507. +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  15508. +
  15509. +#include <linux/errno.h>
  15510. +#include <linux/kernel.h>
  15511. +#include <linux/mutex.h>
  15512. +#include <linux/mm.h>
  15513. +#include <linux/slab.h>
  15514. +#include <linux/completion.h>
  15515. +#include <linux/vmalloc.h>
  15516. +#include <asm/cacheflush.h>
  15517. +#include <media/videobuf2-vmalloc.h>
  15518. +
  15519. +#include "mmal-common.h"
  15520. +#include "mmal-vchiq.h"
  15521. +#include "mmal-msg.h"
  15522. +
  15523. +#define USE_VCHIQ_ARM
  15524. +#include "interface/vchi/vchi.h"
  15525. +
  15526. +/* maximum number of components supported */
  15527. +#define VCHIQ_MMAL_MAX_COMPONENTS 4
  15528. +
  15529. +/*#define FULL_MSG_DUMP 1*/
  15530. +
  15531. +#ifdef DEBUG
  15532. +static const char *const msg_type_names[] = {
  15533. + "UNKNOWN",
  15534. + "QUIT",
  15535. + "SERVICE_CLOSED",
  15536. + "GET_VERSION",
  15537. + "COMPONENT_CREATE",
  15538. + "COMPONENT_DESTROY",
  15539. + "COMPONENT_ENABLE",
  15540. + "COMPONENT_DISABLE",
  15541. + "PORT_INFO_GET",
  15542. + "PORT_INFO_SET",
  15543. + "PORT_ACTION",
  15544. + "BUFFER_FROM_HOST",
  15545. + "BUFFER_TO_HOST",
  15546. + "GET_STATS",
  15547. + "PORT_PARAMETER_SET",
  15548. + "PORT_PARAMETER_GET",
  15549. + "EVENT_TO_HOST",
  15550. + "GET_CORE_STATS_FOR_PORT",
  15551. + "OPAQUE_ALLOCATOR",
  15552. + "CONSUME_MEM",
  15553. + "LMK",
  15554. + "OPAQUE_ALLOCATOR_DESC",
  15555. + "DRM_GET_LHS32",
  15556. + "DRM_GET_TIME",
  15557. + "BUFFER_FROM_HOST_ZEROLEN",
  15558. + "PORT_FLUSH",
  15559. + "HOST_LOG",
  15560. +};
  15561. +#endif
  15562. +
  15563. +static const char *const port_action_type_names[] = {
  15564. + "UNKNOWN",
  15565. + "ENABLE",
  15566. + "DISABLE",
  15567. + "FLUSH",
  15568. + "CONNECT",
  15569. + "DISCONNECT",
  15570. + "SET_REQUIREMENTS",
  15571. +};
  15572. +
  15573. +#if defined(DEBUG)
  15574. +#if defined(FULL_MSG_DUMP)
  15575. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  15576. + do { \
  15577. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  15578. + msg_type_names[(MSG)->h.type], \
  15579. + (MSG)->h.type, (MSG_LEN)); \
  15580. + print_hex_dump(KERN_DEBUG, "<<h: ", DUMP_PREFIX_OFFSET, \
  15581. + 16, 4, (MSG), \
  15582. + sizeof(struct mmal_msg_header), 1); \
  15583. + print_hex_dump(KERN_DEBUG, "<<p: ", DUMP_PREFIX_OFFSET, \
  15584. + 16, 4, \
  15585. + ((u8 *)(MSG)) + sizeof(struct mmal_msg_header),\
  15586. + (MSG_LEN) - sizeof(struct mmal_msg_header), 1); \
  15587. + } while (0)
  15588. +#else
  15589. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE) \
  15590. + { \
  15591. + pr_debug(TITLE" type:%s(%d) length:%d\n", \
  15592. + msg_type_names[(MSG)->h.type], \
  15593. + (MSG)->h.type, (MSG_LEN)); \
  15594. + }
  15595. +#endif
  15596. +#else
  15597. +#define DBG_DUMP_MSG(MSG, MSG_LEN, TITLE)
  15598. +#endif
  15599. +
  15600. +/* normal message context */
  15601. +struct mmal_msg_context {
  15602. + union {
  15603. + struct {
  15604. + /* work struct for defered callback - must come first */
  15605. + struct work_struct work;
  15606. + /* mmal instance */
  15607. + struct vchiq_mmal_instance *instance;
  15608. + /* mmal port */
  15609. + struct vchiq_mmal_port *port;
  15610. + /* actual buffer used to store bulk reply */
  15611. + struct mmal_buffer *buffer;
  15612. + /* amount of buffer used */
  15613. + unsigned long buffer_used;
  15614. + /* MMAL buffer flags */
  15615. + u32 mmal_flags;
  15616. + /* Presentation and Decode timestamps */
  15617. + s64 pts;
  15618. + s64 dts;
  15619. +
  15620. + int status; /* context status */
  15621. +
  15622. + } bulk; /* bulk data */
  15623. +
  15624. + struct {
  15625. + /* message handle to release */
  15626. + VCHI_HELD_MSG_T msg_handle;
  15627. + /* pointer to received message */
  15628. + struct mmal_msg *msg;
  15629. + /* received message length */
  15630. + u32 msg_len;
  15631. + /* completion upon reply */
  15632. + struct completion cmplt;
  15633. + } sync; /* synchronous response */
  15634. + } u;
  15635. +
  15636. +};
  15637. +
  15638. +struct vchiq_mmal_instance {
  15639. + VCHI_SERVICE_HANDLE_T handle;
  15640. +
  15641. + /* ensure serialised access to service */
  15642. + struct mutex vchiq_mutex;
  15643. +
  15644. + /* ensure serialised access to bulk operations */
  15645. + struct mutex bulk_mutex;
  15646. +
  15647. + /* vmalloc page to receive scratch bulk xfers into */
  15648. + void *bulk_scratch;
  15649. +
  15650. + /* component to use next */
  15651. + int component_idx;
  15652. + struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
  15653. +};
  15654. +
  15655. +static struct mmal_msg_context *get_msg_context(struct vchiq_mmal_instance
  15656. + *instance)
  15657. +{
  15658. + struct mmal_msg_context *msg_context;
  15659. +
  15660. + /* todo: should this be allocated from a pool to avoid kmalloc */
  15661. + msg_context = kmalloc(sizeof(*msg_context), GFP_KERNEL);
  15662. + memset(msg_context, 0, sizeof(*msg_context));
  15663. +
  15664. + return msg_context;
  15665. +}
  15666. +
  15667. +static void release_msg_context(struct mmal_msg_context *msg_context)
  15668. +{
  15669. + kfree(msg_context);
  15670. +}
  15671. +
  15672. +/* deals with receipt of event to host message */
  15673. +static void event_to_host_cb(struct vchiq_mmal_instance *instance,
  15674. + struct mmal_msg *msg, u32 msg_len)
  15675. +{
  15676. + pr_debug("unhandled event\n");
  15677. + pr_debug("component:%p port type:%d num:%d cmd:0x%x length:%d\n",
  15678. + msg->u.event_to_host.client_component,
  15679. + msg->u.event_to_host.port_type,
  15680. + msg->u.event_to_host.port_num,
  15681. + msg->u.event_to_host.cmd, msg->u.event_to_host.length);
  15682. +}
  15683. +
  15684. +/* workqueue scheduled callback
  15685. + *
  15686. + * we do this because it is important we do not call any other vchiq
  15687. + * sync calls from witin the message delivery thread
  15688. + */
  15689. +static void buffer_work_cb(struct work_struct *work)
  15690. +{
  15691. + struct mmal_msg_context *msg_context = (struct mmal_msg_context *)work;
  15692. +
  15693. + msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance,
  15694. + msg_context->u.bulk.port,
  15695. + msg_context->u.bulk.status,
  15696. + msg_context->u.bulk.buffer,
  15697. + msg_context->u.bulk.buffer_used,
  15698. + msg_context->u.bulk.mmal_flags,
  15699. + msg_context->u.bulk.dts,
  15700. + msg_context->u.bulk.pts);
  15701. +
  15702. + /* release message context */
  15703. + release_msg_context(msg_context);
  15704. +}
  15705. +
  15706. +/* enqueue a bulk receive for a given message context */
  15707. +static int bulk_receive(struct vchiq_mmal_instance *instance,
  15708. + struct mmal_msg *msg,
  15709. + struct mmal_msg_context *msg_context)
  15710. +{
  15711. + unsigned long rd_len;
  15712. + unsigned long flags = 0;
  15713. + int ret;
  15714. +
  15715. + /* bulk mutex stops other bulk operations while we have a
  15716. + * receive in progress - released in callback
  15717. + */
  15718. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15719. + if (ret != 0)
  15720. + return ret;
  15721. +
  15722. + rd_len = msg->u.buffer_from_host.buffer_header.length;
  15723. +
  15724. + /* take buffer from queue */
  15725. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15726. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15727. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15728. + pr_err("buffer list empty trying to submit bulk receive\n");
  15729. +
  15730. + /* todo: this is a serious error, we should never have
  15731. + * commited a buffer_to_host operation to the mmal
  15732. + * port without the buffer to back it up (underflow
  15733. + * handling) and there is no obvious way to deal with
  15734. + * this - how is the mmal servie going to react when
  15735. + * we fail to do the xfer and reschedule a buffer when
  15736. + * it arrives? perhaps a starved flag to indicate a
  15737. + * waiting bulk receive?
  15738. + */
  15739. +
  15740. + mutex_unlock(&instance->bulk_mutex);
  15741. +
  15742. + return -EINVAL;
  15743. + }
  15744. +
  15745. + msg_context->u.bulk.buffer =
  15746. + list_entry(msg_context->u.bulk.port->buffers.next,
  15747. + struct mmal_buffer, list);
  15748. + list_del(&msg_context->u.bulk.buffer->list);
  15749. +
  15750. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15751. +
  15752. + /* ensure we do not overrun the available buffer */
  15753. + if (rd_len > msg_context->u.bulk.buffer->buffer_size) {
  15754. + rd_len = msg_context->u.bulk.buffer->buffer_size;
  15755. + pr_warn("short read as not enough receive buffer space\n");
  15756. + /* todo: is this the correct response, what happens to
  15757. + * the rest of the message data?
  15758. + */
  15759. + }
  15760. +
  15761. + /* store length */
  15762. + msg_context->u.bulk.buffer_used = rd_len;
  15763. + msg_context->u.bulk.mmal_flags =
  15764. + msg->u.buffer_from_host.buffer_header.flags;
  15765. + msg_context->u.bulk.dts = msg->u.buffer_from_host.buffer_header.dts;
  15766. + msg_context->u.bulk.pts = msg->u.buffer_from_host.buffer_header.pts;
  15767. +
  15768. + // only need to flush L1 cache here, as VCHIQ takes care of the L2
  15769. + // cache.
  15770. + __cpuc_flush_dcache_area(msg_context->u.bulk.buffer->buffer, rd_len);
  15771. +
  15772. + /* queue the bulk submission */
  15773. + vchi_service_use(instance->handle);
  15774. + ret = vchi_bulk_queue_receive(instance->handle,
  15775. + msg_context->u.bulk.buffer->buffer,
  15776. + /* Actual receive needs to be a multiple
  15777. + * of 4 bytes
  15778. + */
  15779. + (rd_len + 3) & ~3,
  15780. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15781. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15782. + msg_context);
  15783. +
  15784. + vchi_service_release(instance->handle);
  15785. +
  15786. + if (ret != 0) {
  15787. + /* callback will not be clearing the mutex */
  15788. + mutex_unlock(&instance->bulk_mutex);
  15789. + }
  15790. +
  15791. + return ret;
  15792. +}
  15793. +
  15794. +/* enque a dummy bulk receive for a given message context */
  15795. +static int dummy_bulk_receive(struct vchiq_mmal_instance *instance,
  15796. + struct mmal_msg_context *msg_context)
  15797. +{
  15798. + int ret;
  15799. +
  15800. + /* bulk mutex stops other bulk operations while we have a
  15801. + * receive in progress - released in callback
  15802. + */
  15803. + ret = mutex_lock_interruptible(&instance->bulk_mutex);
  15804. + if (ret != 0)
  15805. + return ret;
  15806. +
  15807. + /* zero length indicates this was a dummy transfer */
  15808. + msg_context->u.bulk.buffer_used = 0;
  15809. +
  15810. + /* queue the bulk submission */
  15811. + vchi_service_use(instance->handle);
  15812. +
  15813. + ret = vchi_bulk_queue_receive(instance->handle,
  15814. + instance->bulk_scratch,
  15815. + 8,
  15816. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE |
  15817. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED,
  15818. + msg_context);
  15819. +
  15820. + vchi_service_release(instance->handle);
  15821. +
  15822. + if (ret != 0) {
  15823. + /* callback will not be clearing the mutex */
  15824. + mutex_unlock(&instance->bulk_mutex);
  15825. + }
  15826. +
  15827. + return ret;
  15828. +}
  15829. +
  15830. +/* data in message, memcpy from packet into output buffer */
  15831. +static int inline_receive(struct vchiq_mmal_instance *instance,
  15832. + struct mmal_msg *msg,
  15833. + struct mmal_msg_context *msg_context)
  15834. +{
  15835. + unsigned long flags = 0;
  15836. +
  15837. + /* take buffer from queue */
  15838. + spin_lock_irqsave(&msg_context->u.bulk.port->slock, flags);
  15839. + if (list_empty(&msg_context->u.bulk.port->buffers)) {
  15840. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15841. + pr_err("buffer list empty trying to receive inline\n");
  15842. +
  15843. + /* todo: this is a serious error, we should never have
  15844. + * commited a buffer_to_host operation to the mmal
  15845. + * port without the buffer to back it up (with
  15846. + * underflow handling) and there is no obvious way to
  15847. + * deal with this. Less bad than the bulk case as we
  15848. + * can just drop this on the floor but...unhelpful
  15849. + */
  15850. + return -EINVAL;
  15851. + }
  15852. +
  15853. + msg_context->u.bulk.buffer =
  15854. + list_entry(msg_context->u.bulk.port->buffers.next,
  15855. + struct mmal_buffer, list);
  15856. + list_del(&msg_context->u.bulk.buffer->list);
  15857. +
  15858. + spin_unlock_irqrestore(&msg_context->u.bulk.port->slock, flags);
  15859. +
  15860. + memcpy(msg_context->u.bulk.buffer->buffer,
  15861. + msg->u.buffer_from_host.short_data,
  15862. + msg->u.buffer_from_host.payload_in_message);
  15863. +
  15864. + msg_context->u.bulk.buffer_used =
  15865. + msg->u.buffer_from_host.payload_in_message;
  15866. +
  15867. + return 0;
  15868. +}
  15869. +
  15870. +/* queue the buffer availability with MMAL_MSG_TYPE_BUFFER_FROM_HOST */
  15871. +static int
  15872. +buffer_from_host(struct vchiq_mmal_instance *instance,
  15873. + struct vchiq_mmal_port *port, struct mmal_buffer *buf)
  15874. +{
  15875. + struct mmal_msg_context *msg_context;
  15876. + struct mmal_msg m;
  15877. + int ret;
  15878. +
  15879. + pr_debug("instance:%p buffer:%p\n", instance->handle, buf);
  15880. +
  15881. + /* bulk mutex stops other bulk operations while we
  15882. + * have a receive in progress
  15883. + */
  15884. + if (mutex_lock_interruptible(&instance->bulk_mutex))
  15885. + return -EINTR;
  15886. +
  15887. + /* get context */
  15888. + msg_context = get_msg_context(instance);
  15889. + if (msg_context == NULL)
  15890. + return -ENOMEM;
  15891. +
  15892. + /* store bulk message context for when data arrives */
  15893. + msg_context->u.bulk.instance = instance;
  15894. + msg_context->u.bulk.port = port;
  15895. + msg_context->u.bulk.buffer = NULL; /* not valid until bulk xfer */
  15896. + msg_context->u.bulk.buffer_used = 0;
  15897. +
  15898. + /* initialise work structure ready to schedule callback */
  15899. + INIT_WORK(&msg_context->u.bulk.work, buffer_work_cb);
  15900. +
  15901. + /* prep the buffer from host message */
  15902. + memset(&m, 0xbc, sizeof(m)); /* just to make debug clearer */
  15903. +
  15904. + m.h.type = MMAL_MSG_TYPE_BUFFER_FROM_HOST;
  15905. + m.h.magic = MMAL_MAGIC;
  15906. + m.h.context = msg_context;
  15907. + m.h.status = 0;
  15908. +
  15909. + /* drvbuf is our private data passed back */
  15910. + m.u.buffer_from_host.drvbuf.magic = MMAL_MAGIC;
  15911. + m.u.buffer_from_host.drvbuf.component_handle = port->component->handle;
  15912. + m.u.buffer_from_host.drvbuf.port_handle = port->handle;
  15913. + m.u.buffer_from_host.drvbuf.client_context = msg_context;
  15914. +
  15915. + /* buffer header */
  15916. + m.u.buffer_from_host.buffer_header.cmd = 0;
  15917. + m.u.buffer_from_host.buffer_header.data = buf->buffer;
  15918. + m.u.buffer_from_host.buffer_header.alloc_size = buf->buffer_size;
  15919. + m.u.buffer_from_host.buffer_header.length = 0; /* nothing used yet */
  15920. + m.u.buffer_from_host.buffer_header.offset = 0; /* no offset */
  15921. + m.u.buffer_from_host.buffer_header.flags = 0; /* no flags */
  15922. + m.u.buffer_from_host.buffer_header.pts = MMAL_TIME_UNKNOWN;
  15923. + m.u.buffer_from_host.buffer_header.dts = MMAL_TIME_UNKNOWN;
  15924. +
  15925. + /* clear buffer type sepecific data */
  15926. + memset(&m.u.buffer_from_host.buffer_header_type_specific, 0,
  15927. + sizeof(m.u.buffer_from_host.buffer_header_type_specific));
  15928. +
  15929. + /* no payload in message */
  15930. + m.u.buffer_from_host.payload_in_message = 0;
  15931. +
  15932. + vchi_service_use(instance->handle);
  15933. +
  15934. + ret = vchi_msg_queue(instance->handle, &m,
  15935. + sizeof(struct mmal_msg_header) +
  15936. + sizeof(m.u.buffer_from_host),
  15937. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  15938. +
  15939. + if (ret != 0) {
  15940. + release_msg_context(msg_context);
  15941. + /* todo: is this correct error value? */
  15942. + }
  15943. +
  15944. + vchi_service_release(instance->handle);
  15945. +
  15946. + mutex_unlock(&instance->bulk_mutex);
  15947. +
  15948. + return ret;
  15949. +}
  15950. +
  15951. +/* submit a buffer to the mmal sevice
  15952. + *
  15953. + * the buffer_from_host uses size data from the ports next available
  15954. + * mmal_buffer and deals with there being no buffer available by
  15955. + * incrementing the underflow for later
  15956. + */
  15957. +static int port_buffer_from_host(struct vchiq_mmal_instance *instance,
  15958. + struct vchiq_mmal_port *port)
  15959. +{
  15960. + int ret;
  15961. + struct mmal_buffer *buf;
  15962. + unsigned long flags = 0;
  15963. +
  15964. + if (!port->enabled)
  15965. + return -EINVAL;
  15966. +
  15967. + /* peek buffer from queue */
  15968. + spin_lock_irqsave(&port->slock, flags);
  15969. + if (list_empty(&port->buffers)) {
  15970. + port->buffer_underflow++;
  15971. + spin_unlock_irqrestore(&port->slock, flags);
  15972. + return -ENOSPC;
  15973. + }
  15974. +
  15975. + buf = list_entry(port->buffers.next, struct mmal_buffer, list);
  15976. +
  15977. + spin_unlock_irqrestore(&port->slock, flags);
  15978. +
  15979. + /* issue buffer to mmal service */
  15980. + ret = buffer_from_host(instance, port, buf);
  15981. + if (ret) {
  15982. + pr_err("adding buffer header failed\n");
  15983. + /* todo: how should this be dealt with */
  15984. + }
  15985. +
  15986. + return ret;
  15987. +}
  15988. +
  15989. +/* deals with receipt of buffer to host message */
  15990. +static void buffer_to_host_cb(struct vchiq_mmal_instance *instance,
  15991. + struct mmal_msg *msg, u32 msg_len)
  15992. +{
  15993. + struct mmal_msg_context *msg_context;
  15994. +
  15995. + pr_debug("buffer_to_host_cb: instance:%p msg:%p msg_len:%d\n",
  15996. + instance, msg, msg_len);
  15997. +
  15998. + if (msg->u.buffer_from_host.drvbuf.magic == MMAL_MAGIC) {
  15999. + msg_context = msg->u.buffer_from_host.drvbuf.client_context;
  16000. + } else {
  16001. + pr_err("MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n");
  16002. + return;
  16003. + }
  16004. +
  16005. + if (msg->h.status != MMAL_MSG_STATUS_SUCCESS) {
  16006. + /* message reception had an error */
  16007. + pr_warn("error %d in reply\n", msg->h.status);
  16008. +
  16009. + msg_context->u.bulk.status = msg->h.status;
  16010. +
  16011. + } else if (msg->u.buffer_from_host.buffer_header.length == 0) {
  16012. + /* empty buffer */
  16013. + if (msg->u.buffer_from_host.buffer_header.flags &
  16014. + MMAL_BUFFER_HEADER_FLAG_EOS) {
  16015. + msg_context->u.bulk.status =
  16016. + dummy_bulk_receive(instance, msg_context);
  16017. + if (msg_context->u.bulk.status == 0)
  16018. + return; /* successful bulk submission, bulk
  16019. + * completion will trigger callback
  16020. + */
  16021. + } else {
  16022. + /* do callback with empty buffer - not EOS though */
  16023. + msg_context->u.bulk.status = 0;
  16024. + msg_context->u.bulk.buffer_used = 0;
  16025. + }
  16026. + } else if (msg->u.buffer_from_host.payload_in_message == 0) {
  16027. + /* data is not in message, queue a bulk receive */
  16028. + msg_context->u.bulk.status =
  16029. + bulk_receive(instance, msg, msg_context);
  16030. + if (msg_context->u.bulk.status == 0)
  16031. + return; /* successful bulk submission, bulk
  16032. + * completion will trigger callback
  16033. + */
  16034. +
  16035. + /* failed to submit buffer, this will end badly */
  16036. + pr_err("error %d on bulk submission\n",
  16037. + msg_context->u.bulk.status);
  16038. +
  16039. + } else if (msg->u.buffer_from_host.payload_in_message <=
  16040. + MMAL_VC_SHORT_DATA) {
  16041. + /* data payload within message */
  16042. + msg_context->u.bulk.status = inline_receive(instance, msg,
  16043. + msg_context);
  16044. + } else {
  16045. + pr_err("message with invalid short payload\n");
  16046. +
  16047. + /* signal error */
  16048. + msg_context->u.bulk.status = -EINVAL;
  16049. + msg_context->u.bulk.buffer_used =
  16050. + msg->u.buffer_from_host.payload_in_message;
  16051. + }
  16052. +
  16053. + /* replace the buffer header */
  16054. + port_buffer_from_host(instance, msg_context->u.bulk.port);
  16055. +
  16056. + /* schedule the port callback */
  16057. + schedule_work(&msg_context->u.bulk.work);
  16058. +}
  16059. +
  16060. +static void bulk_receive_cb(struct vchiq_mmal_instance *instance,
  16061. + struct mmal_msg_context *msg_context)
  16062. +{
  16063. + /* bulk receive operation complete */
  16064. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16065. +
  16066. + /* replace the buffer header */
  16067. + port_buffer_from_host(msg_context->u.bulk.instance,
  16068. + msg_context->u.bulk.port);
  16069. +
  16070. + msg_context->u.bulk.status = 0;
  16071. +
  16072. + /* schedule the port callback */
  16073. + schedule_work(&msg_context->u.bulk.work);
  16074. +}
  16075. +
  16076. +static void bulk_abort_cb(struct vchiq_mmal_instance *instance,
  16077. + struct mmal_msg_context *msg_context)
  16078. +{
  16079. + pr_err("%s: bulk ABORTED msg_context:%p\n", __func__, msg_context);
  16080. +
  16081. + /* bulk receive operation complete */
  16082. + mutex_unlock(&msg_context->u.bulk.instance->bulk_mutex);
  16083. +
  16084. + /* replace the buffer header */
  16085. + port_buffer_from_host(msg_context->u.bulk.instance,
  16086. + msg_context->u.bulk.port);
  16087. +
  16088. + msg_context->u.bulk.status = -EINTR;
  16089. +
  16090. + schedule_work(&msg_context->u.bulk.work);
  16091. +}
  16092. +
  16093. +/* incoming event service callback */
  16094. +static void service_callback(void *param,
  16095. + const VCHI_CALLBACK_REASON_T reason,
  16096. + void *bulk_ctx)
  16097. +{
  16098. + struct vchiq_mmal_instance *instance = param;
  16099. + int status;
  16100. + u32 msg_len;
  16101. + struct mmal_msg *msg;
  16102. + VCHI_HELD_MSG_T msg_handle;
  16103. +
  16104. + if (!instance) {
  16105. + pr_err("Message callback passed NULL instance\n");
  16106. + return;
  16107. + }
  16108. +
  16109. + switch (reason) {
  16110. + case VCHI_CALLBACK_MSG_AVAILABLE:
  16111. + status = vchi_msg_hold(instance->handle, (void **)&msg,
  16112. + &msg_len, VCHI_FLAGS_NONE, &msg_handle);
  16113. + if (status) {
  16114. + pr_err("Unable to dequeue a message (%d)\n", status);
  16115. + break;
  16116. + }
  16117. +
  16118. + DBG_DUMP_MSG(msg, msg_len, "<<< reply message");
  16119. +
  16120. + /* handling is different for buffer messages */
  16121. + switch (msg->h.type) {
  16122. +
  16123. + case MMAL_MSG_TYPE_BUFFER_FROM_HOST:
  16124. + vchi_held_msg_release(&msg_handle);
  16125. + break;
  16126. +
  16127. + case MMAL_MSG_TYPE_EVENT_TO_HOST:
  16128. + event_to_host_cb(instance, msg, msg_len);
  16129. + vchi_held_msg_release(&msg_handle);
  16130. +
  16131. + break;
  16132. +
  16133. + case MMAL_MSG_TYPE_BUFFER_TO_HOST:
  16134. + buffer_to_host_cb(instance, msg, msg_len);
  16135. + vchi_held_msg_release(&msg_handle);
  16136. + break;
  16137. +
  16138. + default:
  16139. + /* messages dependant on header context to complete */
  16140. +
  16141. + /* todo: the msg.context really ought to be sanity
  16142. + * checked before we just use it, afaict it comes back
  16143. + * and is used raw from the videocore. Perhaps it
  16144. + * should be verified the address lies in the kernel
  16145. + * address space.
  16146. + */
  16147. + if (msg->h.context == NULL) {
  16148. + pr_err("received message context was null!\n");
  16149. + vchi_held_msg_release(&msg_handle);
  16150. + break;
  16151. + }
  16152. +
  16153. + /* fill in context values */
  16154. + msg->h.context->u.sync.msg_handle = msg_handle;
  16155. + msg->h.context->u.sync.msg = msg;
  16156. + msg->h.context->u.sync.msg_len = msg_len;
  16157. +
  16158. + /* todo: should this check (completion_done()
  16159. + * == 1) for no one waiting? or do we need a
  16160. + * flag to tell us the completion has been
  16161. + * interrupted so we can free the message and
  16162. + * its context. This probably also solves the
  16163. + * message arriving after interruption todo
  16164. + * below
  16165. + */
  16166. +
  16167. + /* complete message so caller knows it happened */
  16168. + complete(&msg->h.context->u.sync.cmplt);
  16169. + break;
  16170. + }
  16171. +
  16172. + break;
  16173. +
  16174. + case VCHI_CALLBACK_BULK_RECEIVED:
  16175. + bulk_receive_cb(instance, bulk_ctx);
  16176. + break;
  16177. +
  16178. + case VCHI_CALLBACK_BULK_RECEIVE_ABORTED:
  16179. + bulk_abort_cb(instance, bulk_ctx);
  16180. + break;
  16181. +
  16182. + case VCHI_CALLBACK_SERVICE_CLOSED:
  16183. + /* TODO: consider if this requires action if received when
  16184. + * driver is not explicitly closing the service
  16185. + */
  16186. + break;
  16187. +
  16188. + default:
  16189. + pr_err("Received unhandled message reason %d\n", reason);
  16190. + break;
  16191. + }
  16192. +}
  16193. +
  16194. +static int send_synchronous_mmal_msg(struct vchiq_mmal_instance *instance,
  16195. + struct mmal_msg *msg,
  16196. + unsigned int payload_len,
  16197. + struct mmal_msg **msg_out,
  16198. + VCHI_HELD_MSG_T *msg_handle_out)
  16199. +{
  16200. + struct mmal_msg_context msg_context;
  16201. + int ret;
  16202. +
  16203. + /* payload size must not cause message to exceed max size */
  16204. + if (payload_len >
  16205. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header))) {
  16206. + pr_err("payload length %d exceeds max:%d\n", payload_len,
  16207. + (MMAL_MSG_MAX_SIZE - sizeof(struct mmal_msg_header)));
  16208. + return -EINVAL;
  16209. + }
  16210. +
  16211. + init_completion(&msg_context.u.sync.cmplt);
  16212. +
  16213. + msg->h.magic = MMAL_MAGIC;
  16214. + msg->h.context = &msg_context;
  16215. + msg->h.status = 0;
  16216. +
  16217. + DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len),
  16218. + ">>> sync message");
  16219. +
  16220. + vchi_service_use(instance->handle);
  16221. +
  16222. + ret = vchi_msg_queue(instance->handle,
  16223. + msg,
  16224. + sizeof(struct mmal_msg_header) + payload_len,
  16225. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  16226. +
  16227. + vchi_service_release(instance->handle);
  16228. +
  16229. + if (ret) {
  16230. + pr_err("error %d queuing message\n", ret);
  16231. + return ret;
  16232. + }
  16233. +
  16234. + ret = wait_for_completion_timeout(&msg_context.u.sync.cmplt, 3*HZ);
  16235. + if (ret <= 0) {
  16236. + pr_err("error %d waiting for sync completion\n", ret);
  16237. + if (ret == 0)
  16238. + ret = -ETIME;
  16239. + /* todo: what happens if the message arrives after aborting */
  16240. + return ret;
  16241. + }
  16242. +
  16243. + *msg_out = msg_context.u.sync.msg;
  16244. + *msg_handle_out = msg_context.u.sync.msg_handle;
  16245. +
  16246. + return 0;
  16247. +}
  16248. +
  16249. +static void dump_port_info(struct vchiq_mmal_port *port)
  16250. +{
  16251. + pr_debug("port handle:0x%x enabled:%d\n", port->handle, port->enabled);
  16252. +
  16253. + pr_debug("buffer minimum num:%d size:%d align:%d\n",
  16254. + port->minimum_buffer.num,
  16255. + port->minimum_buffer.size, port->minimum_buffer.alignment);
  16256. +
  16257. + pr_debug("buffer recommended num:%d size:%d align:%d\n",
  16258. + port->recommended_buffer.num,
  16259. + port->recommended_buffer.size,
  16260. + port->recommended_buffer.alignment);
  16261. +
  16262. + pr_debug("buffer current values num:%d size:%d align:%d\n",
  16263. + port->current_buffer.num,
  16264. + port->current_buffer.size, port->current_buffer.alignment);
  16265. +
  16266. + pr_debug("elementry stream: type:%d encoding:0x%x varient:0x%x\n",
  16267. + port->format.type,
  16268. + port->format.encoding, port->format.encoding_variant);
  16269. +
  16270. + pr_debug(" bitrate:%d flags:0x%x\n",
  16271. + port->format.bitrate, port->format.flags);
  16272. +
  16273. + if (port->format.type == MMAL_ES_TYPE_VIDEO) {
  16274. + pr_debug
  16275. + ("es video format: width:%d height:%d colourspace:0x%x\n",
  16276. + port->es.video.width, port->es.video.height,
  16277. + port->es.video.color_space);
  16278. +
  16279. + pr_debug(" : crop xywh %d,%d,%d,%d\n",
  16280. + port->es.video.crop.x,
  16281. + port->es.video.crop.y,
  16282. + port->es.video.crop.width, port->es.video.crop.height);
  16283. + pr_debug(" : framerate %d/%d aspect %d/%d\n",
  16284. + port->es.video.frame_rate.num,
  16285. + port->es.video.frame_rate.den,
  16286. + port->es.video.par.num, port->es.video.par.den);
  16287. + }
  16288. +}
  16289. +
  16290. +static void port_to_mmal_msg(struct vchiq_mmal_port *port, struct mmal_port *p)
  16291. +{
  16292. +
  16293. + /* todo do readonly fields need setting at all? */
  16294. + p->type = port->type;
  16295. + p->index = port->index;
  16296. + p->index_all = 0;
  16297. + p->is_enabled = port->enabled;
  16298. + p->buffer_num_min = port->minimum_buffer.num;
  16299. + p->buffer_size_min = port->minimum_buffer.size;
  16300. + p->buffer_alignment_min = port->minimum_buffer.alignment;
  16301. + p->buffer_num_recommended = port->recommended_buffer.num;
  16302. + p->buffer_size_recommended = port->recommended_buffer.size;
  16303. +
  16304. + /* only three writable fields in a port */
  16305. + p->buffer_num = port->current_buffer.num;
  16306. + p->buffer_size = port->current_buffer.size;
  16307. + p->userdata = port;
  16308. +}
  16309. +
  16310. +static int port_info_set(struct vchiq_mmal_instance *instance,
  16311. + struct vchiq_mmal_port *port)
  16312. +{
  16313. + int ret;
  16314. + struct mmal_msg m;
  16315. + struct mmal_msg *rmsg;
  16316. + VCHI_HELD_MSG_T rmsg_handle;
  16317. +
  16318. + pr_debug("setting port info port %p\n", port);
  16319. + if (!port)
  16320. + return -1;
  16321. + dump_port_info(port);
  16322. +
  16323. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_SET;
  16324. +
  16325. + m.u.port_info_set.component_handle = port->component->handle;
  16326. + m.u.port_info_set.port_type = port->type;
  16327. + m.u.port_info_set.port_index = port->index;
  16328. +
  16329. + port_to_mmal_msg(port, &m.u.port_info_set.port);
  16330. +
  16331. + /* elementry stream format setup */
  16332. + m.u.port_info_set.format.type = port->format.type;
  16333. + m.u.port_info_set.format.encoding = port->format.encoding;
  16334. + m.u.port_info_set.format.encoding_variant =
  16335. + port->format.encoding_variant;
  16336. + m.u.port_info_set.format.bitrate = port->format.bitrate;
  16337. + m.u.port_info_set.format.flags = port->format.flags;
  16338. +
  16339. + memcpy(&m.u.port_info_set.es, &port->es,
  16340. + sizeof(union mmal_es_specific_format));
  16341. +
  16342. + m.u.port_info_set.format.extradata_size = port->format.extradata_size;
  16343. + memcpy(rmsg->u.port_info_set.extradata, port->format.extradata,
  16344. + port->format.extradata_size);
  16345. +
  16346. + ret = send_synchronous_mmal_msg(instance, &m,
  16347. + sizeof(m.u.port_info_set),
  16348. + &rmsg, &rmsg_handle);
  16349. + if (ret)
  16350. + return ret;
  16351. +
  16352. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_SET) {
  16353. + /* got an unexpected message type in reply */
  16354. + ret = -EINVAL;
  16355. + goto release_msg;
  16356. + }
  16357. +
  16358. + /* return operation status */
  16359. + ret = -rmsg->u.port_info_get_reply.status;
  16360. +
  16361. + pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret,
  16362. + port->component->handle, port->handle);
  16363. +
  16364. +release_msg:
  16365. + vchi_held_msg_release(&rmsg_handle);
  16366. +
  16367. + return ret;
  16368. +
  16369. +}
  16370. +
  16371. +/* use port info get message to retrive port information */
  16372. +static int port_info_get(struct vchiq_mmal_instance *instance,
  16373. + struct vchiq_mmal_port *port)
  16374. +{
  16375. + int ret;
  16376. + struct mmal_msg m;
  16377. + struct mmal_msg *rmsg;
  16378. + VCHI_HELD_MSG_T rmsg_handle;
  16379. +
  16380. + /* port info time */
  16381. + m.h.type = MMAL_MSG_TYPE_PORT_INFO_GET;
  16382. + m.u.port_info_get.component_handle = port->component->handle;
  16383. + m.u.port_info_get.port_type = port->type;
  16384. + m.u.port_info_get.index = port->index;
  16385. +
  16386. + ret = send_synchronous_mmal_msg(instance, &m,
  16387. + sizeof(m.u.port_info_get),
  16388. + &rmsg, &rmsg_handle);
  16389. + if (ret)
  16390. + return ret;
  16391. +
  16392. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_INFO_GET) {
  16393. + /* got an unexpected message type in reply */
  16394. + ret = -EINVAL;
  16395. + goto release_msg;
  16396. + }
  16397. +
  16398. + /* return operation status */
  16399. + ret = -rmsg->u.port_info_get_reply.status;
  16400. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16401. + goto release_msg;
  16402. +
  16403. + if (rmsg->u.port_info_get_reply.port.is_enabled == 0)
  16404. + port->enabled = false;
  16405. + else
  16406. + port->enabled = true;
  16407. +
  16408. + /* copy the values out of the message */
  16409. + port->handle = rmsg->u.port_info_get_reply.port_handle;
  16410. +
  16411. + /* port type and index cached to use on port info set becuase
  16412. + * it does not use a port handle
  16413. + */
  16414. + port->type = rmsg->u.port_info_get_reply.port_type;
  16415. + port->index = rmsg->u.port_info_get_reply.port_index;
  16416. +
  16417. + port->minimum_buffer.num =
  16418. + rmsg->u.port_info_get_reply.port.buffer_num_min;
  16419. + port->minimum_buffer.size =
  16420. + rmsg->u.port_info_get_reply.port.buffer_size_min;
  16421. + port->minimum_buffer.alignment =
  16422. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16423. +
  16424. + port->recommended_buffer.alignment =
  16425. + rmsg->u.port_info_get_reply.port.buffer_alignment_min;
  16426. + port->recommended_buffer.num =
  16427. + rmsg->u.port_info_get_reply.port.buffer_num_recommended;
  16428. +
  16429. + port->current_buffer.num = rmsg->u.port_info_get_reply.port.buffer_num;
  16430. + port->current_buffer.size =
  16431. + rmsg->u.port_info_get_reply.port.buffer_size;
  16432. +
  16433. + /* stream format */
  16434. + port->format.type = rmsg->u.port_info_get_reply.format.type;
  16435. + port->format.encoding = rmsg->u.port_info_get_reply.format.encoding;
  16436. + port->format.encoding_variant =
  16437. + rmsg->u.port_info_get_reply.format.encoding_variant;
  16438. + port->format.bitrate = rmsg->u.port_info_get_reply.format.bitrate;
  16439. + port->format.flags = rmsg->u.port_info_get_reply.format.flags;
  16440. +
  16441. + /* elementry stream format */
  16442. + memcpy(&port->es,
  16443. + &rmsg->u.port_info_get_reply.es,
  16444. + sizeof(union mmal_es_specific_format));
  16445. + port->format.es = &port->es;
  16446. +
  16447. + port->format.extradata_size =
  16448. + rmsg->u.port_info_get_reply.format.extradata_size;
  16449. + memcpy(port->format.extradata,
  16450. + rmsg->u.port_info_get_reply.extradata,
  16451. + port->format.extradata_size);
  16452. +
  16453. + pr_debug("received port info\n");
  16454. + dump_port_info(port);
  16455. +
  16456. +release_msg:
  16457. +
  16458. + pr_debug("%s:result:%d component:0x%x port:%d\n",
  16459. + __func__, ret, port->component->handle, port->handle);
  16460. +
  16461. + vchi_held_msg_release(&rmsg_handle);
  16462. +
  16463. + return ret;
  16464. +}
  16465. +
  16466. +/* create comonent on vc */
  16467. +static int create_component(struct vchiq_mmal_instance *instance,
  16468. + struct vchiq_mmal_component *component,
  16469. + const char *name)
  16470. +{
  16471. + int ret;
  16472. + struct mmal_msg m;
  16473. + struct mmal_msg *rmsg;
  16474. + VCHI_HELD_MSG_T rmsg_handle;
  16475. +
  16476. + /* build component create message */
  16477. + m.h.type = MMAL_MSG_TYPE_COMPONENT_CREATE;
  16478. + m.u.component_create.client_component = component;
  16479. + strncpy(m.u.component_create.name, name,
  16480. + sizeof(m.u.component_create.name));
  16481. +
  16482. + ret = send_synchronous_mmal_msg(instance, &m,
  16483. + sizeof(m.u.component_create),
  16484. + &rmsg, &rmsg_handle);
  16485. + if (ret)
  16486. + return ret;
  16487. +
  16488. + if (rmsg->h.type != m.h.type) {
  16489. + /* got an unexpected message type in reply */
  16490. + ret = -EINVAL;
  16491. + goto release_msg;
  16492. + }
  16493. +
  16494. + ret = -rmsg->u.component_create_reply.status;
  16495. + if (ret != MMAL_MSG_STATUS_SUCCESS)
  16496. + goto release_msg;
  16497. +
  16498. + /* a valid component response received */
  16499. + component->handle = rmsg->u.component_create_reply.component_handle;
  16500. + component->inputs = rmsg->u.component_create_reply.input_num;
  16501. + component->outputs = rmsg->u.component_create_reply.output_num;
  16502. + component->clocks = rmsg->u.component_create_reply.clock_num;
  16503. +
  16504. + pr_debug("Component handle:0x%x in:%d out:%d clock:%d\n",
  16505. + component->handle,
  16506. + component->inputs, component->outputs, component->clocks);
  16507. +
  16508. +release_msg:
  16509. + vchi_held_msg_release(&rmsg_handle);
  16510. +
  16511. + return ret;
  16512. +}
  16513. +
  16514. +/* destroys a component on vc */
  16515. +static int destroy_component(struct vchiq_mmal_instance *instance,
  16516. + struct vchiq_mmal_component *component)
  16517. +{
  16518. + int ret;
  16519. + struct mmal_msg m;
  16520. + struct mmal_msg *rmsg;
  16521. + VCHI_HELD_MSG_T rmsg_handle;
  16522. +
  16523. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DESTROY;
  16524. + m.u.component_destroy.component_handle = component->handle;
  16525. +
  16526. + ret = send_synchronous_mmal_msg(instance, &m,
  16527. + sizeof(m.u.component_destroy),
  16528. + &rmsg, &rmsg_handle);
  16529. + if (ret)
  16530. + return ret;
  16531. +
  16532. + if (rmsg->h.type != m.h.type) {
  16533. + /* got an unexpected message type in reply */
  16534. + ret = -EINVAL;
  16535. + goto release_msg;
  16536. + }
  16537. +
  16538. + ret = -rmsg->u.component_destroy_reply.status;
  16539. +
  16540. +release_msg:
  16541. +
  16542. + vchi_held_msg_release(&rmsg_handle);
  16543. +
  16544. + return ret;
  16545. +}
  16546. +
  16547. +/* enable a component on vc */
  16548. +static int enable_component(struct vchiq_mmal_instance *instance,
  16549. + struct vchiq_mmal_component *component)
  16550. +{
  16551. + int ret;
  16552. + struct mmal_msg m;
  16553. + struct mmal_msg *rmsg;
  16554. + VCHI_HELD_MSG_T rmsg_handle;
  16555. +
  16556. + m.h.type = MMAL_MSG_TYPE_COMPONENT_ENABLE;
  16557. + m.u.component_enable.component_handle = component->handle;
  16558. +
  16559. + ret = send_synchronous_mmal_msg(instance, &m,
  16560. + sizeof(m.u.component_enable),
  16561. + &rmsg, &rmsg_handle);
  16562. + if (ret)
  16563. + return ret;
  16564. +
  16565. + if (rmsg->h.type != m.h.type) {
  16566. + /* got an unexpected message type in reply */
  16567. + ret = -EINVAL;
  16568. + goto release_msg;
  16569. + }
  16570. +
  16571. + ret = -rmsg->u.component_enable_reply.status;
  16572. +
  16573. +release_msg:
  16574. + vchi_held_msg_release(&rmsg_handle);
  16575. +
  16576. + return ret;
  16577. +}
  16578. +
  16579. +/* disable a component on vc */
  16580. +static int disable_component(struct vchiq_mmal_instance *instance,
  16581. + struct vchiq_mmal_component *component)
  16582. +{
  16583. + int ret;
  16584. + struct mmal_msg m;
  16585. + struct mmal_msg *rmsg;
  16586. + VCHI_HELD_MSG_T rmsg_handle;
  16587. +
  16588. + m.h.type = MMAL_MSG_TYPE_COMPONENT_DISABLE;
  16589. + m.u.component_disable.component_handle = component->handle;
  16590. +
  16591. + ret = send_synchronous_mmal_msg(instance, &m,
  16592. + sizeof(m.u.component_disable),
  16593. + &rmsg, &rmsg_handle);
  16594. + if (ret)
  16595. + return ret;
  16596. +
  16597. + if (rmsg->h.type != m.h.type) {
  16598. + /* got an unexpected message type in reply */
  16599. + ret = -EINVAL;
  16600. + goto release_msg;
  16601. + }
  16602. +
  16603. + ret = -rmsg->u.component_disable_reply.status;
  16604. +
  16605. +release_msg:
  16606. +
  16607. + vchi_held_msg_release(&rmsg_handle);
  16608. +
  16609. + return ret;
  16610. +}
  16611. +
  16612. +/* get version of mmal implementation */
  16613. +static int get_version(struct vchiq_mmal_instance *instance,
  16614. + u32 *major_out, u32 *minor_out)
  16615. +{
  16616. + int ret;
  16617. + struct mmal_msg m;
  16618. + struct mmal_msg *rmsg;
  16619. + VCHI_HELD_MSG_T rmsg_handle;
  16620. +
  16621. + m.h.type = MMAL_MSG_TYPE_GET_VERSION;
  16622. +
  16623. + ret = send_synchronous_mmal_msg(instance, &m,
  16624. + sizeof(m.u.version),
  16625. + &rmsg, &rmsg_handle);
  16626. + if (ret)
  16627. + return ret;
  16628. +
  16629. + if (rmsg->h.type != m.h.type) {
  16630. + /* got an unexpected message type in reply */
  16631. + ret = -EINVAL;
  16632. + goto release_msg;
  16633. + }
  16634. +
  16635. + *major_out = rmsg->u.version.major;
  16636. + *minor_out = rmsg->u.version.minor;
  16637. +
  16638. +release_msg:
  16639. + vchi_held_msg_release(&rmsg_handle);
  16640. +
  16641. + return ret;
  16642. +}
  16643. +
  16644. +/* do a port action with a port as a parameter */
  16645. +static int port_action_port(struct vchiq_mmal_instance *instance,
  16646. + struct vchiq_mmal_port *port,
  16647. + enum mmal_msg_port_action_type action_type)
  16648. +{
  16649. + int ret;
  16650. + struct mmal_msg m;
  16651. + struct mmal_msg *rmsg;
  16652. + VCHI_HELD_MSG_T rmsg_handle;
  16653. +
  16654. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  16655. + m.u.port_action_port.component_handle = port->component->handle;
  16656. + m.u.port_action_port.port_handle = port->handle;
  16657. + m.u.port_action_port.action = action_type;
  16658. +
  16659. + port_to_mmal_msg(port, &m.u.port_action_port.port);
  16660. +
  16661. + ret = send_synchronous_mmal_msg(instance, &m,
  16662. + sizeof(m.u.port_action_port),
  16663. + &rmsg, &rmsg_handle);
  16664. + if (ret)
  16665. + return ret;
  16666. +
  16667. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  16668. + /* got an unexpected message type in reply */
  16669. + ret = -EINVAL;
  16670. + goto release_msg;
  16671. + }
  16672. +
  16673. + ret = -rmsg->u.port_action_reply.status;
  16674. +
  16675. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)\n",
  16676. + __func__,
  16677. + ret, port->component->handle, port->handle,
  16678. + port_action_type_names[action_type], action_type);
  16679. +
  16680. +release_msg:
  16681. + vchi_held_msg_release(&rmsg_handle);
  16682. +
  16683. + return ret;
  16684. +}
  16685. +
  16686. +/* do a port action with handles as parameters */
  16687. +static int port_action_handle(struct vchiq_mmal_instance *instance,
  16688. + struct vchiq_mmal_port *port,
  16689. + enum mmal_msg_port_action_type action_type,
  16690. + u32 connect_component_handle,
  16691. + u32 connect_port_handle)
  16692. +{
  16693. + int ret;
  16694. + struct mmal_msg m;
  16695. + struct mmal_msg *rmsg;
  16696. + VCHI_HELD_MSG_T rmsg_handle;
  16697. +
  16698. + m.h.type = MMAL_MSG_TYPE_PORT_ACTION;
  16699. +
  16700. + m.u.port_action_handle.component_handle = port->component->handle;
  16701. + m.u.port_action_handle.port_handle = port->handle;
  16702. + m.u.port_action_handle.action = action_type;
  16703. +
  16704. + m.u.port_action_handle.connect_component_handle =
  16705. + connect_component_handle;
  16706. + m.u.port_action_handle.connect_port_handle = connect_port_handle;
  16707. +
  16708. + ret = send_synchronous_mmal_msg(instance, &m,
  16709. + sizeof(m.u.port_action_handle),
  16710. + &rmsg, &rmsg_handle);
  16711. + if (ret)
  16712. + return ret;
  16713. +
  16714. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_ACTION) {
  16715. + /* got an unexpected message type in reply */
  16716. + ret = -EINVAL;
  16717. + goto release_msg;
  16718. + }
  16719. +
  16720. + ret = -rmsg->u.port_action_reply.status;
  16721. +
  16722. + pr_debug("%s:result:%d component:0x%x port:%d action:%s(%d)" \
  16723. + " connect component:0x%x connect port:%d\n",
  16724. + __func__,
  16725. + ret, port->component->handle, port->handle,
  16726. + port_action_type_names[action_type],
  16727. + action_type, connect_component_handle, connect_port_handle);
  16728. +
  16729. +release_msg:
  16730. + vchi_held_msg_release(&rmsg_handle);
  16731. +
  16732. + return ret;
  16733. +}
  16734. +
  16735. +static int port_parameter_set(struct vchiq_mmal_instance *instance,
  16736. + struct vchiq_mmal_port *port,
  16737. + u32 parameter_id, void *value, u32 value_size)
  16738. +{
  16739. + int ret;
  16740. + struct mmal_msg m;
  16741. + struct mmal_msg *rmsg;
  16742. + VCHI_HELD_MSG_T rmsg_handle;
  16743. +
  16744. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_SET;
  16745. +
  16746. + m.u.port_parameter_set.component_handle = port->component->handle;
  16747. + m.u.port_parameter_set.port_handle = port->handle;
  16748. + m.u.port_parameter_set.id = parameter_id;
  16749. + m.u.port_parameter_set.size = (2 * sizeof(u32)) + value_size;
  16750. + memcpy(&m.u.port_parameter_set.value, value, value_size);
  16751. +
  16752. + ret = send_synchronous_mmal_msg(instance, &m,
  16753. + (4 * sizeof(u32)) + value_size,
  16754. + &rmsg, &rmsg_handle);
  16755. + if (ret)
  16756. + return ret;
  16757. +
  16758. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_SET) {
  16759. + /* got an unexpected message type in reply */
  16760. + ret = -EINVAL;
  16761. + goto release_msg;
  16762. + }
  16763. +
  16764. + ret = -rmsg->u.port_parameter_set_reply.status;
  16765. +
  16766. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n",
  16767. + __func__,
  16768. + ret, port->component->handle, port->handle, parameter_id);
  16769. +
  16770. +release_msg:
  16771. + vchi_held_msg_release(&rmsg_handle);
  16772. +
  16773. + return ret;
  16774. +}
  16775. +
  16776. +static int port_parameter_get(struct vchiq_mmal_instance *instance,
  16777. + struct vchiq_mmal_port *port,
  16778. + u32 parameter_id, void *value, u32 *value_size)
  16779. +{
  16780. + int ret;
  16781. + struct mmal_msg m;
  16782. + struct mmal_msg *rmsg;
  16783. + VCHI_HELD_MSG_T rmsg_handle;
  16784. +
  16785. + m.h.type = MMAL_MSG_TYPE_PORT_PARAMETER_GET;
  16786. +
  16787. + m.u.port_parameter_get.component_handle = port->component->handle;
  16788. + m.u.port_parameter_get.port_handle = port->handle;
  16789. + m.u.port_parameter_get.id = parameter_id;
  16790. + m.u.port_parameter_get.size = (2 * sizeof(u32)) + *value_size;
  16791. +
  16792. + ret = send_synchronous_mmal_msg(instance, &m,
  16793. + sizeof(struct
  16794. + mmal_msg_port_parameter_get),
  16795. + &rmsg, &rmsg_handle);
  16796. + if (ret)
  16797. + return ret;
  16798. +
  16799. + if (rmsg->h.type != MMAL_MSG_TYPE_PORT_PARAMETER_GET) {
  16800. + /* got an unexpected message type in reply */
  16801. + pr_err("Incorrect reply type %d\n", rmsg->h.type);
  16802. + ret = -EINVAL;
  16803. + goto release_msg;
  16804. + }
  16805. +
  16806. + ret = -rmsg->u.port_parameter_get_reply.status;
  16807. + if (ret) {
  16808. + /* Copy only as much as we have space for
  16809. + * but report true size of parameter
  16810. + */
  16811. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16812. + *value_size);
  16813. + *value_size = rmsg->u.port_parameter_get_reply.size;
  16814. + } else
  16815. + memcpy(value, &rmsg->u.port_parameter_get_reply.value,
  16816. + rmsg->u.port_parameter_get_reply.size);
  16817. +
  16818. + pr_debug("%s:result:%d component:0x%x port:%d parameter:%d\n", __func__,
  16819. + ret, port->component->handle, port->handle, parameter_id);
  16820. +
  16821. +release_msg:
  16822. + vchi_held_msg_release(&rmsg_handle);
  16823. +
  16824. + return ret;
  16825. +}
  16826. +
  16827. +/* disables a port and drains buffers from it */
  16828. +static int port_disable(struct vchiq_mmal_instance *instance,
  16829. + struct vchiq_mmal_port *port)
  16830. +{
  16831. + int ret;
  16832. + struct list_head *q, *buf_head;
  16833. + unsigned long flags = 0;
  16834. +
  16835. + if (!port->enabled)
  16836. + return 0;
  16837. +
  16838. + port->enabled = false;
  16839. +
  16840. + ret = port_action_port(instance, port,
  16841. + MMAL_MSG_PORT_ACTION_TYPE_DISABLE);
  16842. + if (ret == 0) {
  16843. +
  16844. + /* drain all queued buffers on port */
  16845. + spin_lock_irqsave(&port->slock, flags);
  16846. +
  16847. + list_for_each_safe(buf_head, q, &port->buffers) {
  16848. + struct mmal_buffer *mmalbuf;
  16849. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16850. + list);
  16851. + list_del(buf_head);
  16852. + if (port->buffer_cb)
  16853. + port->buffer_cb(instance,
  16854. + port, 0, mmalbuf, 0, 0,
  16855. + MMAL_TIME_UNKNOWN,
  16856. + MMAL_TIME_UNKNOWN);
  16857. + }
  16858. +
  16859. + spin_unlock_irqrestore(&port->slock, flags);
  16860. +
  16861. + ret = port_info_get(instance, port);
  16862. + }
  16863. +
  16864. + return ret;
  16865. +}
  16866. +
  16867. +/* enable a port */
  16868. +static int port_enable(struct vchiq_mmal_instance *instance,
  16869. + struct vchiq_mmal_port *port)
  16870. +{
  16871. + unsigned int hdr_count;
  16872. + struct list_head *buf_head;
  16873. + int ret;
  16874. +
  16875. + if (port->enabled)
  16876. + return 0;
  16877. +
  16878. + /* ensure there are enough buffers queued to cover the buffer headers */
  16879. + if (port->buffer_cb != NULL) {
  16880. + hdr_count = 0;
  16881. + list_for_each(buf_head, &port->buffers) {
  16882. + hdr_count++;
  16883. + }
  16884. + if (hdr_count < port->current_buffer.num)
  16885. + return -ENOSPC;
  16886. + }
  16887. +
  16888. + ret = port_action_port(instance, port,
  16889. + MMAL_MSG_PORT_ACTION_TYPE_ENABLE);
  16890. + if (ret)
  16891. + goto done;
  16892. +
  16893. + port->enabled = true;
  16894. +
  16895. + if (port->buffer_cb) {
  16896. + /* send buffer headers to videocore */
  16897. + hdr_count = 1;
  16898. + list_for_each(buf_head, &port->buffers) {
  16899. + struct mmal_buffer *mmalbuf;
  16900. + mmalbuf = list_entry(buf_head, struct mmal_buffer,
  16901. + list);
  16902. + ret = buffer_from_host(instance, port, mmalbuf);
  16903. + if (ret)
  16904. + goto done;
  16905. +
  16906. + hdr_count++;
  16907. + if (hdr_count > port->current_buffer.num)
  16908. + break;
  16909. + }
  16910. + }
  16911. +
  16912. + ret = port_info_get(instance, port);
  16913. +
  16914. +done:
  16915. + return ret;
  16916. +}
  16917. +
  16918. +/* ------------------------------------------------------------------
  16919. + * Exported API
  16920. + *------------------------------------------------------------------*/
  16921. +
  16922. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  16923. + struct vchiq_mmal_port *port)
  16924. +{
  16925. + int ret;
  16926. +
  16927. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16928. + return -EINTR;
  16929. +
  16930. + ret = port_info_set(instance, port);
  16931. + if (ret)
  16932. + goto release_unlock;
  16933. +
  16934. + /* read what has actually been set */
  16935. + ret = port_info_get(instance, port);
  16936. +
  16937. +release_unlock:
  16938. + mutex_unlock(&instance->vchiq_mutex);
  16939. +
  16940. + return ret;
  16941. +
  16942. +}
  16943. +
  16944. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  16945. + struct vchiq_mmal_port *port,
  16946. + u32 parameter, void *value, u32 value_size)
  16947. +{
  16948. + int ret;
  16949. +
  16950. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16951. + return -EINTR;
  16952. +
  16953. + ret = port_parameter_set(instance, port, parameter, value, value_size);
  16954. +
  16955. + mutex_unlock(&instance->vchiq_mutex);
  16956. +
  16957. + return ret;
  16958. +}
  16959. +
  16960. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  16961. + struct vchiq_mmal_port *port,
  16962. + u32 parameter, void *value, u32 *value_size)
  16963. +{
  16964. + int ret;
  16965. +
  16966. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16967. + return -EINTR;
  16968. +
  16969. + ret = port_parameter_get(instance, port, parameter, value, value_size);
  16970. +
  16971. + mutex_unlock(&instance->vchiq_mutex);
  16972. +
  16973. + return ret;
  16974. +}
  16975. +
  16976. +/* enable a port
  16977. + *
  16978. + * enables a port and queues buffers for satisfying callbacks if we
  16979. + * provide a callback handler
  16980. + */
  16981. +int vchiq_mmal_port_enable(struct vchiq_mmal_instance *instance,
  16982. + struct vchiq_mmal_port *port,
  16983. + vchiq_mmal_buffer_cb buffer_cb)
  16984. +{
  16985. + int ret;
  16986. +
  16987. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  16988. + return -EINTR;
  16989. +
  16990. + /* already enabled - noop */
  16991. + if (port->enabled) {
  16992. + ret = 0;
  16993. + goto unlock;
  16994. + }
  16995. +
  16996. + port->buffer_cb = buffer_cb;
  16997. +
  16998. + ret = port_enable(instance, port);
  16999. +
  17000. +unlock:
  17001. + mutex_unlock(&instance->vchiq_mutex);
  17002. +
  17003. + return ret;
  17004. +}
  17005. +
  17006. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17007. + struct vchiq_mmal_port *port)
  17008. +{
  17009. + int ret;
  17010. +
  17011. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17012. + return -EINTR;
  17013. +
  17014. + if (!port->enabled) {
  17015. + mutex_unlock(&instance->vchiq_mutex);
  17016. + return 0;
  17017. + }
  17018. +
  17019. + ret = port_disable(instance, port);
  17020. +
  17021. + mutex_unlock(&instance->vchiq_mutex);
  17022. +
  17023. + return ret;
  17024. +}
  17025. +
  17026. +/* ports will be connected in a tunneled manner so data buffers
  17027. + * are not handled by client.
  17028. + */
  17029. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17030. + struct vchiq_mmal_port *src,
  17031. + struct vchiq_mmal_port *dst)
  17032. +{
  17033. + int ret;
  17034. +
  17035. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17036. + return -EINTR;
  17037. +
  17038. + /* disconnect ports if connected */
  17039. + if (src->connected != NULL) {
  17040. + ret = port_disable(instance, src);
  17041. + if (ret) {
  17042. + pr_err("failed disabling src port(%d)\n", ret);
  17043. + goto release_unlock;
  17044. + }
  17045. +
  17046. + /* do not need to disable the destination port as they
  17047. + * are connected and it is done automatically
  17048. + */
  17049. +
  17050. + ret = port_action_handle(instance, src,
  17051. + MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT,
  17052. + src->connected->component->handle,
  17053. + src->connected->handle);
  17054. + if (ret < 0) {
  17055. + pr_err("failed disconnecting src port\n");
  17056. + goto release_unlock;
  17057. + }
  17058. + src->connected->enabled = false;
  17059. + src->connected = NULL;
  17060. + }
  17061. +
  17062. + if (dst == NULL) {
  17063. + /* do not make new connection */
  17064. + ret = 0;
  17065. + pr_debug("not making new connection\n");
  17066. + goto release_unlock;
  17067. + }
  17068. +
  17069. + /* copy src port format to dst */
  17070. + dst->format.encoding = src->format.encoding;
  17071. + dst->es.video.width = src->es.video.width;
  17072. + dst->es.video.height = src->es.video.height;
  17073. + dst->es.video.crop.x = src->es.video.crop.x;
  17074. + dst->es.video.crop.y = src->es.video.crop.y;
  17075. + dst->es.video.crop.width = src->es.video.crop.width;
  17076. + dst->es.video.crop.height = src->es.video.crop.height;
  17077. + dst->es.video.frame_rate.num = src->es.video.frame_rate.num;
  17078. + dst->es.video.frame_rate.den = src->es.video.frame_rate.den;
  17079. +
  17080. + /* set new format */
  17081. + ret = port_info_set(instance, dst);
  17082. + if (ret) {
  17083. + pr_debug("setting port info failed\n");
  17084. + goto release_unlock;
  17085. + }
  17086. +
  17087. + /* read what has actually been set */
  17088. + ret = port_info_get(instance, dst);
  17089. + if (ret) {
  17090. + pr_debug("read back port info failed\n");
  17091. + goto release_unlock;
  17092. + }
  17093. +
  17094. + /* connect two ports together */
  17095. + ret = port_action_handle(instance, src,
  17096. + MMAL_MSG_PORT_ACTION_TYPE_CONNECT,
  17097. + dst->component->handle, dst->handle);
  17098. + if (ret < 0) {
  17099. + pr_debug("connecting port %d:%d to %d:%d failed\n",
  17100. + src->component->handle, src->handle,
  17101. + dst->component->handle, dst->handle);
  17102. + goto release_unlock;
  17103. + }
  17104. + src->connected = dst;
  17105. +
  17106. +release_unlock:
  17107. +
  17108. + mutex_unlock(&instance->vchiq_mutex);
  17109. +
  17110. + return ret;
  17111. +}
  17112. +
  17113. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17114. + struct vchiq_mmal_port *port,
  17115. + struct mmal_buffer *buffer)
  17116. +{
  17117. + unsigned long flags = 0;
  17118. +
  17119. + spin_lock_irqsave(&port->slock, flags);
  17120. + list_add_tail(&buffer->list, &port->buffers);
  17121. + spin_unlock_irqrestore(&port->slock, flags);
  17122. +
  17123. + /* the port previously underflowed because it was missing a
  17124. + * mmal_buffer which has just been added, submit that buffer
  17125. + * to the mmal service.
  17126. + */
  17127. + if (port->buffer_underflow) {
  17128. + port_buffer_from_host(instance, port);
  17129. + port->buffer_underflow--;
  17130. + }
  17131. +
  17132. + return 0;
  17133. +}
  17134. +
  17135. +/* Initialise a mmal component and its ports
  17136. + *
  17137. + */
  17138. +int vchiq_mmal_component_init(struct vchiq_mmal_instance *instance,
  17139. + const char *name,
  17140. + struct vchiq_mmal_component **component_out)
  17141. +{
  17142. + int ret;
  17143. + int idx; /* port index */
  17144. + struct vchiq_mmal_component *component;
  17145. +
  17146. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17147. + return -EINTR;
  17148. +
  17149. + if (instance->component_idx == VCHIQ_MMAL_MAX_COMPONENTS) {
  17150. + ret = -EINVAL; /* todo is this correct error? */
  17151. + goto unlock;
  17152. + }
  17153. +
  17154. + component = &instance->component[instance->component_idx];
  17155. +
  17156. + ret = create_component(instance, component, name);
  17157. + if (ret < 0)
  17158. + goto unlock;
  17159. +
  17160. + /* ports info needs gathering */
  17161. + component->control.type = MMAL_PORT_TYPE_CONTROL;
  17162. + component->control.index = 0;
  17163. + component->control.component = component;
  17164. + spin_lock_init(&component->control.slock);
  17165. + INIT_LIST_HEAD(&component->control.buffers);
  17166. + ret = port_info_get(instance, &component->control);
  17167. + if (ret < 0)
  17168. + goto release_component;
  17169. +
  17170. + for (idx = 0; idx < component->inputs; idx++) {
  17171. + component->input[idx].type = MMAL_PORT_TYPE_INPUT;
  17172. + component->input[idx].index = idx;
  17173. + component->input[idx].component = component;
  17174. + spin_lock_init(&component->input[idx].slock);
  17175. + INIT_LIST_HEAD(&component->input[idx].buffers);
  17176. + ret = port_info_get(instance, &component->input[idx]);
  17177. + if (ret < 0)
  17178. + goto release_component;
  17179. + }
  17180. +
  17181. + for (idx = 0; idx < component->outputs; idx++) {
  17182. + component->output[idx].type = MMAL_PORT_TYPE_OUTPUT;
  17183. + component->output[idx].index = idx;
  17184. + component->output[idx].component = component;
  17185. + spin_lock_init(&component->output[idx].slock);
  17186. + INIT_LIST_HEAD(&component->output[idx].buffers);
  17187. + ret = port_info_get(instance, &component->output[idx]);
  17188. + if (ret < 0)
  17189. + goto release_component;
  17190. + }
  17191. +
  17192. + for (idx = 0; idx < component->clocks; idx++) {
  17193. + component->clock[idx].type = MMAL_PORT_TYPE_CLOCK;
  17194. + component->clock[idx].index = idx;
  17195. + component->clock[idx].component = component;
  17196. + spin_lock_init(&component->clock[idx].slock);
  17197. + INIT_LIST_HEAD(&component->clock[idx].buffers);
  17198. + ret = port_info_get(instance, &component->clock[idx]);
  17199. + if (ret < 0)
  17200. + goto release_component;
  17201. + }
  17202. +
  17203. + instance->component_idx++;
  17204. +
  17205. + *component_out = component;
  17206. +
  17207. + mutex_unlock(&instance->vchiq_mutex);
  17208. +
  17209. + return 0;
  17210. +
  17211. +release_component:
  17212. + destroy_component(instance, component);
  17213. +unlock:
  17214. + mutex_unlock(&instance->vchiq_mutex);
  17215. +
  17216. + return ret;
  17217. +}
  17218. +
  17219. +/*
  17220. + * cause a mmal component to be destroyed
  17221. + */
  17222. +int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance,
  17223. + struct vchiq_mmal_component *component)
  17224. +{
  17225. + int ret;
  17226. +
  17227. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17228. + return -EINTR;
  17229. +
  17230. + if (component->enabled)
  17231. + ret = disable_component(instance, component);
  17232. +
  17233. + ret = destroy_component(instance, component);
  17234. +
  17235. + mutex_unlock(&instance->vchiq_mutex);
  17236. +
  17237. + return ret;
  17238. +}
  17239. +
  17240. +/*
  17241. + * cause a mmal component to be enabled
  17242. + */
  17243. +int vchiq_mmal_component_enable(struct vchiq_mmal_instance *instance,
  17244. + struct vchiq_mmal_component *component)
  17245. +{
  17246. + int ret;
  17247. +
  17248. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17249. + return -EINTR;
  17250. +
  17251. + if (component->enabled) {
  17252. + mutex_unlock(&instance->vchiq_mutex);
  17253. + return 0;
  17254. + }
  17255. +
  17256. + ret = enable_component(instance, component);
  17257. + if (ret == 0)
  17258. + component->enabled = true;
  17259. +
  17260. + mutex_unlock(&instance->vchiq_mutex);
  17261. +
  17262. + return ret;
  17263. +}
  17264. +
  17265. +/*
  17266. + * cause a mmal component to be enabled
  17267. + */
  17268. +int vchiq_mmal_component_disable(struct vchiq_mmal_instance *instance,
  17269. + struct vchiq_mmal_component *component)
  17270. +{
  17271. + int ret;
  17272. +
  17273. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17274. + return -EINTR;
  17275. +
  17276. + if (!component->enabled) {
  17277. + mutex_unlock(&instance->vchiq_mutex);
  17278. + return 0;
  17279. + }
  17280. +
  17281. + ret = disable_component(instance, component);
  17282. + if (ret == 0)
  17283. + component->enabled = false;
  17284. +
  17285. + mutex_unlock(&instance->vchiq_mutex);
  17286. +
  17287. + return ret;
  17288. +}
  17289. +
  17290. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17291. + u32 *major_out, u32 *minor_out)
  17292. +{
  17293. + int ret;
  17294. +
  17295. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17296. + return -EINTR;
  17297. +
  17298. + ret = get_version(instance, major_out, minor_out);
  17299. +
  17300. + mutex_unlock(&instance->vchiq_mutex);
  17301. +
  17302. + return ret;
  17303. +}
  17304. +
  17305. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance)
  17306. +{
  17307. + int status = 0;
  17308. +
  17309. + if (instance == NULL)
  17310. + return -EINVAL;
  17311. +
  17312. + if (mutex_lock_interruptible(&instance->vchiq_mutex))
  17313. + return -EINTR;
  17314. +
  17315. + vchi_service_use(instance->handle);
  17316. +
  17317. + status = vchi_service_close(instance->handle);
  17318. + if (status != 0)
  17319. + pr_err("mmal-vchiq: VCHIQ close failed");
  17320. +
  17321. + mutex_unlock(&instance->vchiq_mutex);
  17322. +
  17323. + vfree(instance->bulk_scratch);
  17324. +
  17325. + kfree(instance);
  17326. +
  17327. + return status;
  17328. +}
  17329. +
  17330. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance)
  17331. +{
  17332. + int status;
  17333. + struct vchiq_mmal_instance *instance;
  17334. + static VCHI_CONNECTION_T *vchi_connection;
  17335. + static VCHI_INSTANCE_T vchi_instance;
  17336. + SERVICE_CREATION_T params = {
  17337. + VCHI_VERSION_EX(VC_MMAL_VER, VC_MMAL_MIN_VER),
  17338. + VC_MMAL_SERVER_NAME,
  17339. + vchi_connection,
  17340. + 0, /* rx fifo size (unused) */
  17341. + 0, /* tx fifo size (unused) */
  17342. + service_callback,
  17343. + NULL, /* service callback parameter */
  17344. + 1, /* unaligned bulk receives */
  17345. + 1, /* unaligned bulk transmits */
  17346. + 0 /* want crc check on bulk transfers */
  17347. + };
  17348. +
  17349. + /* compile time checks to ensure structure size as they are
  17350. + * directly (de)serialised from memory.
  17351. + */
  17352. +
  17353. + /* ensure the header structure has packed to the correct size */
  17354. + BUILD_BUG_ON(sizeof(struct mmal_msg_header) != 24);
  17355. +
  17356. + /* ensure message structure does not exceed maximum length */
  17357. + BUILD_BUG_ON(sizeof(struct mmal_msg) > MMAL_MSG_MAX_SIZE);
  17358. +
  17359. + /* mmal port struct is correct size */
  17360. + BUILD_BUG_ON(sizeof(struct mmal_port) != 64);
  17361. +
  17362. + /* create a vchi instance */
  17363. + status = vchi_initialise(&vchi_instance);
  17364. + if (status) {
  17365. + pr_err("Failed to initialise VCHI instance (status=%d)\n",
  17366. + status);
  17367. + return -EIO;
  17368. + }
  17369. +
  17370. + status = vchi_connect(NULL, 0, vchi_instance);
  17371. + if (status) {
  17372. + pr_err("Failed to connect VCHI instance (status=%d)\n", status);
  17373. + return -EIO;
  17374. + }
  17375. +
  17376. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  17377. + memset(instance, 0, sizeof(*instance));
  17378. +
  17379. + mutex_init(&instance->vchiq_mutex);
  17380. + mutex_init(&instance->bulk_mutex);
  17381. +
  17382. + instance->bulk_scratch = vmalloc(PAGE_SIZE);
  17383. +
  17384. + params.callback_param = instance;
  17385. +
  17386. + status = vchi_service_open(vchi_instance, &params, &instance->handle);
  17387. + if (status) {
  17388. + pr_err("Failed to open VCHI service connection (status=%d)\n",
  17389. + status);
  17390. + goto err_close_services;
  17391. + }
  17392. +
  17393. + vchi_service_release(instance->handle);
  17394. +
  17395. + *out_instance = instance;
  17396. +
  17397. + return 0;
  17398. +
  17399. +err_close_services:
  17400. +
  17401. + vchi_service_close(instance->handle);
  17402. + vfree(instance->bulk_scratch);
  17403. + kfree(instance);
  17404. + return -ENODEV;
  17405. +}
  17406. diff -Nur linux-3.15/drivers/media/platform/bcm2835/mmal-vchiq.h linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h
  17407. --- linux-3.15/drivers/media/platform/bcm2835/mmal-vchiq.h 1970-01-01 01:00:00.000000000 +0100
  17408. +++ linux-rpi/drivers/media/platform/bcm2835/mmal-vchiq.h 2014-06-11 21:03:33.000000000 +0200
  17409. @@ -0,0 +1,178 @@
  17410. +/*
  17411. + * Broadcom BM2835 V4L2 driver
  17412. + *
  17413. + * Copyright © 2013 Raspberry Pi (Trading) Ltd.
  17414. + *
  17415. + * This file is subject to the terms and conditions of the GNU General Public
  17416. + * License. See the file COPYING in the main directory of this archive
  17417. + * for more details.
  17418. + *
  17419. + * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk>
  17420. + * Dave Stevenson <dsteve@broadcom.com>
  17421. + * Simon Mellor <simellor@broadcom.com>
  17422. + * Luke Diamand <luked@broadcom.com>
  17423. + *
  17424. + * MMAL interface to VCHIQ message passing
  17425. + */
  17426. +
  17427. +#ifndef MMAL_VCHIQ_H
  17428. +#define MMAL_VCHIQ_H
  17429. +
  17430. +#include "mmal-msg-format.h"
  17431. +
  17432. +#define MAX_PORT_COUNT 4
  17433. +
  17434. +/* Maximum size of the format extradata. */
  17435. +#define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128
  17436. +
  17437. +struct vchiq_mmal_instance;
  17438. +
  17439. +enum vchiq_mmal_es_type {
  17440. + MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */
  17441. + MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */
  17442. + MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */
  17443. + MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */
  17444. + MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */
  17445. +};
  17446. +
  17447. +/* rectangle, used lots so it gets its own struct */
  17448. +struct vchiq_mmal_rect {
  17449. + s32 x;
  17450. + s32 y;
  17451. + s32 width;
  17452. + s32 height;
  17453. +};
  17454. +
  17455. +struct vchiq_mmal_port_buffer {
  17456. + unsigned int num; /* number of buffers */
  17457. + u32 size; /* size of buffers */
  17458. + u32 alignment; /* alignment of buffers */
  17459. +};
  17460. +
  17461. +struct vchiq_mmal_port;
  17462. +
  17463. +typedef void (*vchiq_mmal_buffer_cb)(
  17464. + struct vchiq_mmal_instance *instance,
  17465. + struct vchiq_mmal_port *port,
  17466. + int status, struct mmal_buffer *buffer,
  17467. + unsigned long length, u32 mmal_flags, s64 dts, s64 pts);
  17468. +
  17469. +struct vchiq_mmal_port {
  17470. + bool enabled;
  17471. + u32 handle;
  17472. + u32 type; /* port type, cached to use on port info set */
  17473. + u32 index; /* port index, cached to use on port info set */
  17474. +
  17475. + /* component port belongs to, allows simple deref */
  17476. + struct vchiq_mmal_component *component;
  17477. +
  17478. + struct vchiq_mmal_port *connected; /* port conencted to */
  17479. +
  17480. + /* buffer info */
  17481. + struct vchiq_mmal_port_buffer minimum_buffer;
  17482. + struct vchiq_mmal_port_buffer recommended_buffer;
  17483. + struct vchiq_mmal_port_buffer current_buffer;
  17484. +
  17485. + /* stream format */
  17486. + struct mmal_es_format format;
  17487. + /* elementry stream format */
  17488. + union mmal_es_specific_format es;
  17489. +
  17490. + /* data buffers to fill */
  17491. + struct list_head buffers;
  17492. + /* lock to serialise adding and removing buffers from list */
  17493. + spinlock_t slock;
  17494. + /* count of how many buffer header refils have failed because
  17495. + * there was no buffer to satisfy them
  17496. + */
  17497. + int buffer_underflow;
  17498. + /* callback on buffer completion */
  17499. + vchiq_mmal_buffer_cb buffer_cb;
  17500. + /* callback context */
  17501. + void *cb_ctx;
  17502. +};
  17503. +
  17504. +struct vchiq_mmal_component {
  17505. + bool enabled;
  17506. + u32 handle; /* VideoCore handle for component */
  17507. + u32 inputs; /* Number of input ports */
  17508. + u32 outputs; /* Number of output ports */
  17509. + u32 clocks; /* Number of clock ports */
  17510. + struct vchiq_mmal_port control; /* control port */
  17511. + struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */
  17512. + struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */
  17513. + struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */
  17514. +};
  17515. +
  17516. +
  17517. +int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance);
  17518. +int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance);
  17519. +
  17520. +/* Initialise a mmal component and its ports
  17521. +*
  17522. +*/
  17523. +int vchiq_mmal_component_init(
  17524. + struct vchiq_mmal_instance *instance,
  17525. + const char *name,
  17526. + struct vchiq_mmal_component **component_out);
  17527. +
  17528. +int vchiq_mmal_component_finalise(
  17529. + struct vchiq_mmal_instance *instance,
  17530. + struct vchiq_mmal_component *component);
  17531. +
  17532. +int vchiq_mmal_component_enable(
  17533. + struct vchiq_mmal_instance *instance,
  17534. + struct vchiq_mmal_component *component);
  17535. +
  17536. +int vchiq_mmal_component_disable(
  17537. + struct vchiq_mmal_instance *instance,
  17538. + struct vchiq_mmal_component *component);
  17539. +
  17540. +
  17541. +
  17542. +/* enable a mmal port
  17543. + *
  17544. + * enables a port and if a buffer callback provided enque buffer
  17545. + * headers as apropriate for the port.
  17546. + */
  17547. +int vchiq_mmal_port_enable(
  17548. + struct vchiq_mmal_instance *instance,
  17549. + struct vchiq_mmal_port *port,
  17550. + vchiq_mmal_buffer_cb buffer_cb);
  17551. +
  17552. +/* disable a port
  17553. + *
  17554. + * disable a port will dequeue any pending buffers
  17555. + */
  17556. +int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance,
  17557. + struct vchiq_mmal_port *port);
  17558. +
  17559. +
  17560. +int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance,
  17561. + struct vchiq_mmal_port *port,
  17562. + u32 parameter,
  17563. + void *value,
  17564. + u32 value_size);
  17565. +
  17566. +int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance,
  17567. + struct vchiq_mmal_port *port,
  17568. + u32 parameter,
  17569. + void *value,
  17570. + u32 *value_size);
  17571. +
  17572. +int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance,
  17573. + struct vchiq_mmal_port *port);
  17574. +
  17575. +int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance,
  17576. + struct vchiq_mmal_port *src,
  17577. + struct vchiq_mmal_port *dst);
  17578. +
  17579. +int vchiq_mmal_version(struct vchiq_mmal_instance *instance,
  17580. + u32 *major_out,
  17581. + u32 *minor_out);
  17582. +
  17583. +int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance,
  17584. + struct vchiq_mmal_port *port,
  17585. + struct mmal_buffer *buf);
  17586. +
  17587. +#endif /* MMAL_VCHIQ_H */
  17588. diff -Nur linux-3.15/drivers/media/platform/Kconfig linux-rpi/drivers/media/platform/Kconfig
  17589. --- linux-3.15/drivers/media/platform/Kconfig 2014-06-08 20:19:54.000000000 +0200
  17590. +++ linux-rpi/drivers/media/platform/Kconfig 2014-06-11 21:05:19.000000000 +0200
  17591. @@ -118,6 +118,7 @@
  17592. source "drivers/media/platform/soc_camera/Kconfig"
  17593. source "drivers/media/platform/exynos4-is/Kconfig"
  17594. source "drivers/media/platform/s5p-tv/Kconfig"
  17595. +source "drivers/media/platform/bcm2835/Kconfig"
  17596. endif # V4L_PLATFORM_DRIVERS
  17597. diff -Nur linux-3.15/drivers/media/platform/Makefile linux-rpi/drivers/media/platform/Makefile
  17598. --- linux-3.15/drivers/media/platform/Makefile 2014-06-08 20:19:54.000000000 +0200
  17599. +++ linux-rpi/drivers/media/platform/Makefile 2014-06-11 21:05:19.000000000 +0200
  17600. @@ -51,4 +51,6 @@
  17601. obj-$(CONFIG_ARCH_OMAP) += omap/
  17602. +obj-$(CONFIG_VIDEO_BCM2835) += bcm2835/
  17603. +
  17604. ccflags-y += -I$(srctree)/drivers/media/i2c
  17605. diff -Nur linux-3.15/drivers/media/usb/dvb-usb-v2/rtl28xxu.c linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
  17606. --- linux-3.15/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-06-08 20:19:54.000000000 +0200
  17607. +++ linux-rpi/drivers/media/usb/dvb-usb-v2/rtl28xxu.c 2014-06-11 21:05:20.000000000 +0200
  17608. @@ -1531,6 +1531,10 @@
  17609. &rtl2832u_props, "Compro VideoMate U620F", NULL) },
  17610. { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
  17611. &rtl2832u_props, "MaxMedia HU394-T", NULL) },
  17612. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xb803 /*USB_PID_AUGUST_DVBT205*/,
  17613. + &rtl2832u_props, "August DVB-T 205", NULL) },
  17614. + { DVB_USB_DEVICE(USB_VID_GTEK, 0xa803 /*USB_PID_AUGUST_DVBT205*/,
  17615. + &rtl2832u_props, "August DVB-T 205", NULL) },
  17616. { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
  17617. &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) },
  17618. { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
  17619. diff -Nur linux-3.15/drivers/misc/Kconfig linux-rpi/drivers/misc/Kconfig
  17620. --- linux-3.15/drivers/misc/Kconfig 2014-06-08 20:19:54.000000000 +0200
  17621. +++ linux-rpi/drivers/misc/Kconfig 2014-06-11 21:05:20.000000000 +0200
  17622. @@ -524,6 +524,7 @@
  17623. source "drivers/misc/altera-stapl/Kconfig"
  17624. source "drivers/misc/mei/Kconfig"
  17625. source "drivers/misc/vmw_vmci/Kconfig"
  17626. +source "drivers/misc/vc04_services/Kconfig"
  17627. source "drivers/misc/mic/Kconfig"
  17628. source "drivers/misc/genwqe/Kconfig"
  17629. source "drivers/misc/echo/Kconfig"
  17630. diff -Nur linux-3.15/drivers/misc/Makefile linux-rpi/drivers/misc/Makefile
  17631. --- linux-3.15/drivers/misc/Makefile 2014-06-08 20:19:54.000000000 +0200
  17632. +++ linux-rpi/drivers/misc/Makefile 2014-06-11 21:05:20.000000000 +0200
  17633. @@ -52,6 +52,7 @@
  17634. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  17635. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  17636. obj-$(CONFIG_SRAM) += sram.o
  17637. +obj-$(CONFIG_BCM2708_VCHIQ) += vc04_services/
  17638. obj-y += mic/
  17639. obj-$(CONFIG_GENWQE) += genwqe/
  17640. obj-$(CONFIG_ECHO) += echo/
  17641. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/connections/connection.h linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h
  17642. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/connections/connection.h 1970-01-01 01:00:00.000000000 +0100
  17643. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/connections/connection.h 2014-06-11 21:03:34.000000000 +0200
  17644. @@ -0,0 +1,328 @@
  17645. +/**
  17646. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17647. + *
  17648. + * Redistribution and use in source and binary forms, with or without
  17649. + * modification, are permitted provided that the following conditions
  17650. + * are met:
  17651. + * 1. Redistributions of source code must retain the above copyright
  17652. + * notice, this list of conditions, and the following disclaimer,
  17653. + * without modification.
  17654. + * 2. Redistributions in binary form must reproduce the above copyright
  17655. + * notice, this list of conditions and the following disclaimer in the
  17656. + * documentation and/or other materials provided with the distribution.
  17657. + * 3. The names of the above-listed copyright holders may not be used
  17658. + * to endorse or promote products derived from this software without
  17659. + * specific prior written permission.
  17660. + *
  17661. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17662. + * GNU General Public License ("GPL") version 2, as published by the Free
  17663. + * Software Foundation.
  17664. + *
  17665. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17666. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17667. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17668. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  17669. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  17670. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  17671. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  17672. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  17673. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  17674. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  17675. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17676. + */
  17677. +
  17678. +#ifndef CONNECTION_H_
  17679. +#define CONNECTION_H_
  17680. +
  17681. +#include <linux/kernel.h>
  17682. +#include <linux/types.h>
  17683. +#include <linux/semaphore.h>
  17684. +
  17685. +#include "interface/vchi/vchi_cfg_internal.h"
  17686. +#include "interface/vchi/vchi_common.h"
  17687. +#include "interface/vchi/message_drivers/message.h"
  17688. +
  17689. +/******************************************************************************
  17690. + Global defs
  17691. + *****************************************************************************/
  17692. +
  17693. +// Opaque handle for a connection / service pair
  17694. +typedef struct opaque_vchi_connection_connected_service_handle_t *VCHI_CONNECTION_SERVICE_HANDLE_T;
  17695. +
  17696. +// opaque handle to the connection state information
  17697. +typedef struct opaque_vchi_connection_info_t VCHI_CONNECTION_STATE_T;
  17698. +
  17699. +typedef struct vchi_connection_t VCHI_CONNECTION_T;
  17700. +
  17701. +
  17702. +/******************************************************************************
  17703. + API
  17704. + *****************************************************************************/
  17705. +
  17706. +// Routine to init a connection with a particular low level driver
  17707. +typedef VCHI_CONNECTION_STATE_T * (*VCHI_CONNECTION_INIT_T)( struct vchi_connection_t * connection,
  17708. + const VCHI_MESSAGE_DRIVER_T * driver );
  17709. +
  17710. +// Routine to control CRC enabling at a connection level
  17711. +typedef int32_t (*VCHI_CONNECTION_CRC_CONTROL_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17712. + VCHI_CRC_CONTROL_T control );
  17713. +
  17714. +// Routine to create a service
  17715. +typedef int32_t (*VCHI_CONNECTION_SERVICE_CONNECT_T)( VCHI_CONNECTION_STATE_T *state_handle,
  17716. + int32_t service_id,
  17717. + uint32_t rx_fifo_size,
  17718. + uint32_t tx_fifo_size,
  17719. + int server,
  17720. + VCHI_CALLBACK_T callback,
  17721. + void *callback_param,
  17722. + int32_t want_crc,
  17723. + int32_t want_unaligned_bulk_rx,
  17724. + int32_t want_unaligned_bulk_tx,
  17725. + VCHI_CONNECTION_SERVICE_HANDLE_T *service_handle );
  17726. +
  17727. +// Routine to close a service
  17728. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DISCONNECT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle );
  17729. +
  17730. +// Routine to queue a message
  17731. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17732. + const void *data,
  17733. + uint32_t data_size,
  17734. + VCHI_FLAGS_T flags,
  17735. + void *msg_handle );
  17736. +
  17737. +// scatter-gather (vector) message queueing
  17738. +typedef int32_t (*VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17739. + VCHI_MSG_VECTOR_T *vector,
  17740. + uint32_t count,
  17741. + VCHI_FLAGS_T flags,
  17742. + void *msg_handle );
  17743. +
  17744. +// Routine to dequeue a message
  17745. +typedef int32_t (*VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17746. + void *data,
  17747. + uint32_t max_data_size_to_read,
  17748. + uint32_t *actual_msg_size,
  17749. + VCHI_FLAGS_T flags );
  17750. +
  17751. +// Routine to peek at a message
  17752. +typedef int32_t (*VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17753. + void **data,
  17754. + uint32_t *msg_size,
  17755. + VCHI_FLAGS_T flags );
  17756. +
  17757. +// Routine to hold a message
  17758. +typedef int32_t (*VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17759. + void **data,
  17760. + uint32_t *msg_size,
  17761. + VCHI_FLAGS_T flags,
  17762. + void **message_handle );
  17763. +
  17764. +// Routine to initialise a received message iterator
  17765. +typedef int32_t (*VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17766. + VCHI_MSG_ITER_T *iter,
  17767. + VCHI_FLAGS_T flags );
  17768. +
  17769. +// Routine to release a held message
  17770. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_RELEASE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17771. + void *message_handle );
  17772. +
  17773. +// Routine to get info on a held message
  17774. +typedef int32_t (*VCHI_CONNECTION_HELD_MSG_INFO_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17775. + void *message_handle,
  17776. + void **data,
  17777. + int32_t *msg_size,
  17778. + uint32_t *tx_timestamp,
  17779. + uint32_t *rx_timestamp );
  17780. +
  17781. +// Routine to check whether the iterator has a next message
  17782. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17783. + const VCHI_MSG_ITER_T *iter );
  17784. +
  17785. +// Routine to advance the iterator
  17786. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_NEXT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17787. + VCHI_MSG_ITER_T *iter,
  17788. + void **data,
  17789. + uint32_t *msg_size );
  17790. +
  17791. +// Routine to remove the last message returned by the iterator
  17792. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_REMOVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17793. + VCHI_MSG_ITER_T *iter );
  17794. +
  17795. +// Routine to hold the last message returned by the iterator
  17796. +typedef int32_t (*VCHI_CONNECTION_MSG_ITER_HOLD_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service,
  17797. + VCHI_MSG_ITER_T *iter,
  17798. + void **msg_handle );
  17799. +
  17800. +// Routine to transmit bulk data
  17801. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17802. + const void *data_src,
  17803. + uint32_t data_size,
  17804. + VCHI_FLAGS_T flags,
  17805. + void *bulk_handle );
  17806. +
  17807. +// Routine to receive data
  17808. +typedef int32_t (*VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T)( VCHI_CONNECTION_SERVICE_HANDLE_T service_handle,
  17809. + void *data_dst,
  17810. + uint32_t data_size,
  17811. + VCHI_FLAGS_T flags,
  17812. + void *bulk_handle );
  17813. +
  17814. +// Routine to report if a server is available
  17815. +typedef int32_t (*VCHI_CONNECTION_SERVER_PRESENT)( VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t peer_flags );
  17816. +
  17817. +// Routine to report the number of RX slots available
  17818. +typedef int (*VCHI_CONNECTION_RX_SLOTS_AVAILABLE)( const VCHI_CONNECTION_STATE_T *state );
  17819. +
  17820. +// Routine to report the RX slot size
  17821. +typedef uint32_t (*VCHI_CONNECTION_RX_SLOT_SIZE)( const VCHI_CONNECTION_STATE_T *state );
  17822. +
  17823. +// Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17824. +typedef void (*VCHI_CONNECTION_RX_BULK_BUFFER_ADDED)(VCHI_CONNECTION_STATE_T *state,
  17825. + int32_t service,
  17826. + uint32_t length,
  17827. + MESSAGE_TX_CHANNEL_T channel,
  17828. + uint32_t channel_params,
  17829. + uint32_t data_length,
  17830. + uint32_t data_offset);
  17831. +
  17832. +// Callback to inform a service that a Xon or Xoff message has been received
  17833. +typedef void (*VCHI_CONNECTION_FLOW_CONTROL)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, int32_t xoff);
  17834. +
  17835. +// Callback to inform a service that a server available reply message has been received
  17836. +typedef void (*VCHI_CONNECTION_SERVER_AVAILABLE_REPLY)(VCHI_CONNECTION_STATE_T *state, int32_t service_id, uint32_t flags);
  17837. +
  17838. +// Callback to indicate that bulk auxiliary messages have arrived
  17839. +typedef void (*VCHI_CONNECTION_BULK_AUX_RECEIVED)(VCHI_CONNECTION_STATE_T *state);
  17840. +
  17841. +// Callback to indicate that bulk auxiliary messages have arrived
  17842. +typedef void (*VCHI_CONNECTION_BULK_AUX_TRANSMITTED)(VCHI_CONNECTION_STATE_T *state, void *handle);
  17843. +
  17844. +// Callback with all the connection info you require
  17845. +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);
  17846. +
  17847. +// Callback to inform of a disconnect
  17848. +typedef void (*VCHI_CONNECTION_DISCONNECT)(VCHI_CONNECTION_STATE_T *state, uint32_t flags);
  17849. +
  17850. +// Callback to inform of a power control request
  17851. +typedef void (*VCHI_CONNECTION_POWER_CONTROL)(VCHI_CONNECTION_STATE_T *state, MESSAGE_TX_CHANNEL_T channel, int32_t enable);
  17852. +
  17853. +// allocate memory suitably aligned for this connection
  17854. +typedef void * (*VCHI_BUFFER_ALLOCATE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, uint32_t * length);
  17855. +
  17856. +// free memory allocated by buffer_allocate
  17857. +typedef void (*VCHI_BUFFER_FREE)(VCHI_CONNECTION_SERVICE_HANDLE_T service_handle, void * address);
  17858. +
  17859. +
  17860. +/******************************************************************************
  17861. + System driver struct
  17862. + *****************************************************************************/
  17863. +
  17864. +struct opaque_vchi_connection_api_t
  17865. +{
  17866. + // Routine to init the connection
  17867. + VCHI_CONNECTION_INIT_T init;
  17868. +
  17869. + // Connection-level CRC control
  17870. + VCHI_CONNECTION_CRC_CONTROL_T crc_control;
  17871. +
  17872. + // Routine to connect to or create service
  17873. + VCHI_CONNECTION_SERVICE_CONNECT_T service_connect;
  17874. +
  17875. + // Routine to disconnect from a service
  17876. + VCHI_CONNECTION_SERVICE_DISCONNECT_T service_disconnect;
  17877. +
  17878. + // Routine to queue a message
  17879. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGE_T service_queue_msg;
  17880. +
  17881. + // scatter-gather (vector) message queue
  17882. + VCHI_CONNECTION_SERVICE_QUEUE_MESSAGEV_T service_queue_msgv;
  17883. +
  17884. + // Routine to dequeue a message
  17885. + VCHI_CONNECTION_SERVICE_DEQUEUE_MESSAGE_T service_dequeue_msg;
  17886. +
  17887. + // Routine to peek at a message
  17888. + VCHI_CONNECTION_SERVICE_PEEK_MESSAGE_T service_peek_msg;
  17889. +
  17890. + // Routine to hold a message
  17891. + VCHI_CONNECTION_SERVICE_HOLD_MESSAGE_T service_hold_msg;
  17892. +
  17893. + // Routine to initialise a received message iterator
  17894. + VCHI_CONNECTION_SERVICE_LOOKAHEAD_MESSAGE_T service_look_ahead_msg;
  17895. +
  17896. + // Routine to release a message
  17897. + VCHI_CONNECTION_HELD_MSG_RELEASE_T held_msg_release;
  17898. +
  17899. + // Routine to get information on a held message
  17900. + VCHI_CONNECTION_HELD_MSG_INFO_T held_msg_info;
  17901. +
  17902. + // Routine to check for next message on iterator
  17903. + VCHI_CONNECTION_MSG_ITER_HAS_NEXT_T msg_iter_has_next;
  17904. +
  17905. + // Routine to get next message on iterator
  17906. + VCHI_CONNECTION_MSG_ITER_NEXT_T msg_iter_next;
  17907. +
  17908. + // Routine to remove the last message returned by iterator
  17909. + VCHI_CONNECTION_MSG_ITER_REMOVE_T msg_iter_remove;
  17910. +
  17911. + // Routine to hold the last message returned by iterator
  17912. + VCHI_CONNECTION_MSG_ITER_HOLD_T msg_iter_hold;
  17913. +
  17914. + // Routine to transmit bulk data
  17915. + VCHI_CONNECTION_BULK_QUEUE_TRANSMIT_T bulk_queue_transmit;
  17916. +
  17917. + // Routine to receive data
  17918. + VCHI_CONNECTION_BULK_QUEUE_RECEIVE_T bulk_queue_receive;
  17919. +
  17920. + // Routine to report the available servers
  17921. + VCHI_CONNECTION_SERVER_PRESENT server_present;
  17922. +
  17923. + // Routine to report the number of RX slots available
  17924. + VCHI_CONNECTION_RX_SLOTS_AVAILABLE connection_rx_slots_available;
  17925. +
  17926. + // Routine to report the RX slot size
  17927. + VCHI_CONNECTION_RX_SLOT_SIZE connection_rx_slot_size;
  17928. +
  17929. + // Callback to indicate that the other side has added a buffer to the rx bulk DMA FIFO
  17930. + VCHI_CONNECTION_RX_BULK_BUFFER_ADDED rx_bulk_buffer_added;
  17931. +
  17932. + // Callback to inform a service that a Xon or Xoff message has been received
  17933. + VCHI_CONNECTION_FLOW_CONTROL flow_control;
  17934. +
  17935. + // Callback to inform a service that a server available reply message has been received
  17936. + VCHI_CONNECTION_SERVER_AVAILABLE_REPLY server_available_reply;
  17937. +
  17938. + // Callback to indicate that bulk auxiliary messages have arrived
  17939. + VCHI_CONNECTION_BULK_AUX_RECEIVED bulk_aux_received;
  17940. +
  17941. + // Callback to indicate that a bulk auxiliary message has been transmitted
  17942. + VCHI_CONNECTION_BULK_AUX_TRANSMITTED bulk_aux_transmitted;
  17943. +
  17944. + // Callback to provide information about the connection
  17945. + VCHI_CONNECTION_INFO connection_info;
  17946. +
  17947. + // Callback to notify that peer has requested disconnect
  17948. + VCHI_CONNECTION_DISCONNECT disconnect;
  17949. +
  17950. + // Callback to notify that peer has requested power change
  17951. + VCHI_CONNECTION_POWER_CONTROL power_control;
  17952. +
  17953. + // allocate memory suitably aligned for this connection
  17954. + VCHI_BUFFER_ALLOCATE buffer_allocate;
  17955. +
  17956. + // free memory allocated by buffer_allocate
  17957. + VCHI_BUFFER_FREE buffer_free;
  17958. +
  17959. +};
  17960. +
  17961. +struct vchi_connection_t {
  17962. + const VCHI_CONNECTION_API_T *api;
  17963. + VCHI_CONNECTION_STATE_T *state;
  17964. +#ifdef VCHI_COARSE_LOCKING
  17965. + struct semaphore sem;
  17966. +#endif
  17967. +};
  17968. +
  17969. +
  17970. +#endif /* CONNECTION_H_ */
  17971. +
  17972. +/****************************** End of file **********************************/
  17973. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h
  17974. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 1970-01-01 01:00:00.000000000 +0100
  17975. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/message_drivers/message.h 2014-06-11 21:03:34.000000000 +0200
  17976. @@ -0,0 +1,204 @@
  17977. +/**
  17978. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  17979. + *
  17980. + * Redistribution and use in source and binary forms, with or without
  17981. + * modification, are permitted provided that the following conditions
  17982. + * are met:
  17983. + * 1. Redistributions of source code must retain the above copyright
  17984. + * notice, this list of conditions, and the following disclaimer,
  17985. + * without modification.
  17986. + * 2. Redistributions in binary form must reproduce the above copyright
  17987. + * notice, this list of conditions and the following disclaimer in the
  17988. + * documentation and/or other materials provided with the distribution.
  17989. + * 3. The names of the above-listed copyright holders may not be used
  17990. + * to endorse or promote products derived from this software without
  17991. + * specific prior written permission.
  17992. + *
  17993. + * ALTERNATIVELY, this software may be distributed under the terms of the
  17994. + * GNU General Public License ("GPL") version 2, as published by the Free
  17995. + * Software Foundation.
  17996. + *
  17997. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  17998. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  17999. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18000. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18001. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18002. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18003. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18004. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18005. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18006. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18007. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18008. + */
  18009. +
  18010. +#ifndef _VCHI_MESSAGE_H_
  18011. +#define _VCHI_MESSAGE_H_
  18012. +
  18013. +#include <linux/kernel.h>
  18014. +#include <linux/types.h>
  18015. +#include <linux/semaphore.h>
  18016. +
  18017. +#include "interface/vchi/vchi_cfg_internal.h"
  18018. +#include "interface/vchi/vchi_common.h"
  18019. +
  18020. +
  18021. +typedef enum message_event_type {
  18022. + MESSAGE_EVENT_NONE,
  18023. + MESSAGE_EVENT_NOP,
  18024. + MESSAGE_EVENT_MESSAGE,
  18025. + MESSAGE_EVENT_SLOT_COMPLETE,
  18026. + MESSAGE_EVENT_RX_BULK_PAUSED,
  18027. + MESSAGE_EVENT_RX_BULK_COMPLETE,
  18028. + MESSAGE_EVENT_TX_COMPLETE,
  18029. + MESSAGE_EVENT_MSG_DISCARDED
  18030. +} MESSAGE_EVENT_TYPE_T;
  18031. +
  18032. +typedef enum vchi_msg_flags
  18033. +{
  18034. + VCHI_MSG_FLAGS_NONE = 0x0,
  18035. + VCHI_MSG_FLAGS_TERMINATE_DMA = 0x1
  18036. +} VCHI_MSG_FLAGS_T;
  18037. +
  18038. +typedef enum message_tx_channel
  18039. +{
  18040. + MESSAGE_TX_CHANNEL_MESSAGE = 0,
  18041. + MESSAGE_TX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18042. +} MESSAGE_TX_CHANNEL_T;
  18043. +
  18044. +// Macros used for cycling through bulk channels
  18045. +#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)
  18046. +#define MESSAGE_TX_CHANNEL_BULK_NEXT(c) (MESSAGE_TX_CHANNEL_BULK+((c)-MESSAGE_TX_CHANNEL_BULK+1)%VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION)
  18047. +
  18048. +typedef enum message_rx_channel
  18049. +{
  18050. + MESSAGE_RX_CHANNEL_MESSAGE = 0,
  18051. + MESSAGE_RX_CHANNEL_BULK = 1 // drivers may provide multiple bulk channels, from 1 upwards
  18052. +} MESSAGE_RX_CHANNEL_T;
  18053. +
  18054. +// Message receive slot information
  18055. +typedef struct rx_msg_slot_info {
  18056. +
  18057. + struct rx_msg_slot_info *next;
  18058. + //struct slot_info *prev;
  18059. +#if !defined VCHI_COARSE_LOCKING
  18060. + struct semaphore sem;
  18061. +#endif
  18062. +
  18063. + uint8_t *addr; // base address of slot
  18064. + uint32_t len; // length of slot in bytes
  18065. +
  18066. + uint32_t write_ptr; // hardware causes this to advance
  18067. + uint32_t read_ptr; // this module does the reading
  18068. + int active; // is this slot in the hardware dma fifo?
  18069. + uint32_t msgs_parsed; // count how many messages are in this slot
  18070. + uint32_t msgs_released; // how many messages have been released
  18071. + void *state; // connection state information
  18072. + uint8_t ref_count[VCHI_MAX_SERVICES_PER_CONNECTION]; // reference count for slots held by services
  18073. +} RX_MSG_SLOTINFO_T;
  18074. +
  18075. +// The message driver no longer needs to know about the fields of RX_BULK_SLOTINFO_T - sort this out.
  18076. +// In particular, it mustn't use addr and len - they're the client buffer, but the message
  18077. +// driver will be tasked with sending the aligned core section.
  18078. +typedef struct rx_bulk_slotinfo_t {
  18079. + struct rx_bulk_slotinfo_t *next;
  18080. +
  18081. + struct semaphore *blocking;
  18082. +
  18083. + // needed by DMA
  18084. + void *addr;
  18085. + uint32_t len;
  18086. +
  18087. + // needed for the callback
  18088. + void *service;
  18089. + void *handle;
  18090. + VCHI_FLAGS_T flags;
  18091. +} RX_BULK_SLOTINFO_T;
  18092. +
  18093. +
  18094. +/* ----------------------------------------------------------------------
  18095. + * each connection driver will have a pool of the following struct.
  18096. + *
  18097. + * the pool will be managed by vchi_qman_*
  18098. + * this means there will be multiple queues (single linked lists)
  18099. + * a given struct message_info will be on exactly one of these queues
  18100. + * at any one time
  18101. + * -------------------------------------------------------------------- */
  18102. +typedef struct rx_message_info {
  18103. +
  18104. + struct message_info *next;
  18105. + //struct message_info *prev;
  18106. +
  18107. + uint8_t *addr;
  18108. + uint32_t len;
  18109. + RX_MSG_SLOTINFO_T *slot; // points to whichever slot contains this message
  18110. + uint32_t tx_timestamp;
  18111. + uint32_t rx_timestamp;
  18112. +
  18113. +} RX_MESSAGE_INFO_T;
  18114. +
  18115. +typedef struct {
  18116. + MESSAGE_EVENT_TYPE_T type;
  18117. +
  18118. + struct {
  18119. + // for messages
  18120. + void *addr; // address of message
  18121. + uint16_t slot_delta; // whether this message indicated slot delta
  18122. + uint32_t len; // length of message
  18123. + RX_MSG_SLOTINFO_T *slot; // slot this message is in
  18124. + int32_t service; // service id this message is destined for
  18125. + uint32_t tx_timestamp; // timestamp from the header
  18126. + uint32_t rx_timestamp; // timestamp when we parsed it
  18127. + } message;
  18128. +
  18129. + // FIXME: cleanup slot reporting...
  18130. + RX_MSG_SLOTINFO_T *rx_msg;
  18131. + RX_BULK_SLOTINFO_T *rx_bulk;
  18132. + void *tx_handle;
  18133. + MESSAGE_TX_CHANNEL_T tx_channel;
  18134. +
  18135. +} MESSAGE_EVENT_T;
  18136. +
  18137. +
  18138. +// callbacks
  18139. +typedef void VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T( void *state );
  18140. +
  18141. +typedef struct {
  18142. + VCHI_MESSAGE_DRIVER_EVENT_CALLBACK_T *event_callback;
  18143. +} VCHI_MESSAGE_DRIVER_OPEN_T;
  18144. +
  18145. +
  18146. +// handle to this instance of message driver (as returned by ->open)
  18147. +typedef struct opaque_mhandle_t *VCHI_MDRIVER_HANDLE_T;
  18148. +
  18149. +struct opaque_vchi_message_driver_t {
  18150. + VCHI_MDRIVER_HANDLE_T *(*open)( VCHI_MESSAGE_DRIVER_OPEN_T *params, void *state );
  18151. + int32_t (*suspending)( VCHI_MDRIVER_HANDLE_T *handle );
  18152. + int32_t (*resumed)( VCHI_MDRIVER_HANDLE_T *handle );
  18153. + int32_t (*power_control)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T, int32_t enable );
  18154. + int32_t (*add_msg_rx_slot)( VCHI_MDRIVER_HANDLE_T *handle, RX_MSG_SLOTINFO_T *slot ); // rx message
  18155. + int32_t (*add_bulk_rx)( VCHI_MDRIVER_HANDLE_T *handle, void *data, uint32_t len, RX_BULK_SLOTINFO_T *slot ); // rx data (bulk)
  18156. + 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)
  18157. + void (*next_event)( VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_EVENT_T *event ); // get the next event from message_driver
  18158. + int32_t (*enable)( VCHI_MDRIVER_HANDLE_T *handle );
  18159. + int32_t (*form_message)( VCHI_MDRIVER_HANDLE_T *handle, int32_t service_id, VCHI_MSG_VECTOR_T *vector, uint32_t count, void
  18160. + *address, uint32_t length_avail, uint32_t max_total_length, int32_t pad_to_fill, int32_t allow_partial );
  18161. +
  18162. + int32_t (*update_message)( VCHI_MDRIVER_HANDLE_T *handle, void *dest, int16_t *slot_count );
  18163. + int32_t (*buffer_aligned)( VCHI_MDRIVER_HANDLE_T *handle, int tx, int uncached, const void *address, const uint32_t length );
  18164. + void * (*allocate_buffer)( VCHI_MDRIVER_HANDLE_T *handle, uint32_t *length );
  18165. + void (*free_buffer)( VCHI_MDRIVER_HANDLE_T *handle, void *address );
  18166. + int (*rx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18167. + int (*tx_slot_size)( VCHI_MDRIVER_HANDLE_T *handle, int msg_size );
  18168. +
  18169. + int32_t (*tx_supports_terminate)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18170. + uint32_t (*tx_bulk_chunk_size)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18171. + int (*tx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_TX_CHANNEL_T channel );
  18172. + int (*rx_alignment)( const VCHI_MDRIVER_HANDLE_T *handle, MESSAGE_RX_CHANNEL_T channel );
  18173. + 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 );
  18174. + void (*debug)( VCHI_MDRIVER_HANDLE_T *handle );
  18175. +};
  18176. +
  18177. +
  18178. +#endif // _VCHI_MESSAGE_H_
  18179. +
  18180. +/****************************** End of file ***********************************/
  18181. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h
  18182. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 1970-01-01 01:00:00.000000000 +0100
  18183. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg.h 2014-06-11 21:03:34.000000000 +0200
  18184. @@ -0,0 +1,224 @@
  18185. +/**
  18186. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18187. + *
  18188. + * Redistribution and use in source and binary forms, with or without
  18189. + * modification, are permitted provided that the following conditions
  18190. + * are met:
  18191. + * 1. Redistributions of source code must retain the above copyright
  18192. + * notice, this list of conditions, and the following disclaimer,
  18193. + * without modification.
  18194. + * 2. Redistributions in binary form must reproduce the above copyright
  18195. + * notice, this list of conditions and the following disclaimer in the
  18196. + * documentation and/or other materials provided with the distribution.
  18197. + * 3. The names of the above-listed copyright holders may not be used
  18198. + * to endorse or promote products derived from this software without
  18199. + * specific prior written permission.
  18200. + *
  18201. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18202. + * GNU General Public License ("GPL") version 2, as published by the Free
  18203. + * Software Foundation.
  18204. + *
  18205. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18206. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18207. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18208. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18209. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18210. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18211. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18212. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18213. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18214. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18215. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18216. + */
  18217. +
  18218. +#ifndef VCHI_CFG_H_
  18219. +#define VCHI_CFG_H_
  18220. +
  18221. +/****************************************************************************************
  18222. + * Defines in this first section are part of the VCHI API and may be examined by VCHI
  18223. + * services.
  18224. + ***************************************************************************************/
  18225. +
  18226. +/* Required alignment of base addresses for bulk transfer, if unaligned transfers are not enabled */
  18227. +/* Really determined by the message driver, and should be available from a run-time call. */
  18228. +#ifndef VCHI_BULK_ALIGN
  18229. +# if __VCCOREVER__ >= 0x04000000
  18230. +# define VCHI_BULK_ALIGN 32 // Allows for the need to do cache cleans
  18231. +# else
  18232. +# define VCHI_BULK_ALIGN 16
  18233. +# endif
  18234. +#endif
  18235. +
  18236. +/* Required length multiple for bulk transfers, if unaligned transfers are not enabled */
  18237. +/* May be less than or greater than VCHI_BULK_ALIGN */
  18238. +/* Really determined by the message driver, and should be available from a run-time call. */
  18239. +#ifndef VCHI_BULK_GRANULARITY
  18240. +# if __VCCOREVER__ >= 0x04000000
  18241. +# define VCHI_BULK_GRANULARITY 32 // Allows for the need to do cache cleans
  18242. +# else
  18243. +# define VCHI_BULK_GRANULARITY 16
  18244. +# endif
  18245. +#endif
  18246. +
  18247. +/* The largest possible message to be queued with vchi_msg_queue. */
  18248. +#ifndef VCHI_MAX_MSG_SIZE
  18249. +# if defined VCHI_LOCAL_HOST_PORT
  18250. +# define VCHI_MAX_MSG_SIZE 16384 // makes file transfers fast, but should they be using bulk?
  18251. +# else
  18252. +# define VCHI_MAX_MSG_SIZE 4096 // NOTE: THIS MUST BE LARGER THAN OR EQUAL TO THE SIZE OF THE KHRONOS MERGE BUFFER!!
  18253. +# endif
  18254. +#endif
  18255. +
  18256. +/******************************************************************************************
  18257. + * Defines below are system configuration options, and should not be used by VCHI services.
  18258. + *****************************************************************************************/
  18259. +
  18260. +/* How many connections can we support? A localhost implementation uses 2 connections,
  18261. + * 1 for host-app, 1 for VMCS, and these are hooked together by a loopback MPHI VCFW
  18262. + * driver. */
  18263. +#ifndef VCHI_MAX_NUM_CONNECTIONS
  18264. +# define VCHI_MAX_NUM_CONNECTIONS 3
  18265. +#endif
  18266. +
  18267. +/* How many services can we open per connection? Extending this doesn't cost processing time, just a small
  18268. + * amount of static memory. */
  18269. +#ifndef VCHI_MAX_SERVICES_PER_CONNECTION
  18270. +# define VCHI_MAX_SERVICES_PER_CONNECTION 36
  18271. +#endif
  18272. +
  18273. +/* Adjust if using a message driver that supports more logical TX channels */
  18274. +#ifndef VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION
  18275. +# define VCHI_MAX_BULK_TX_CHANNELS_PER_CONNECTION 9 // 1 MPHI + 8 CCP2 logical channels
  18276. +#endif
  18277. +
  18278. +/* Adjust if using a message driver that supports more logical RX channels */
  18279. +#ifndef VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION
  18280. +# define VCHI_MAX_BULK_RX_CHANNELS_PER_CONNECTION 1 // 1 MPHI
  18281. +#endif
  18282. +
  18283. +/* How many receive slots do we use. This times VCHI_MAX_MSG_SIZE gives the effective
  18284. + * receive queue space, less message headers. */
  18285. +#ifndef VCHI_NUM_READ_SLOTS
  18286. +# if defined(VCHI_LOCAL_HOST_PORT)
  18287. +# define VCHI_NUM_READ_SLOTS 4
  18288. +# else
  18289. +# define VCHI_NUM_READ_SLOTS 48
  18290. +# endif
  18291. +#endif
  18292. +
  18293. +/* Do we utilise overrun facility for receive message slots? Can aid peer transmit
  18294. + * performance. Only define on VideoCore end, talking to host.
  18295. + */
  18296. +//#define VCHI_MSG_RX_OVERRUN
  18297. +
  18298. +/* How many transmit slots do we use. Generally don't need many, as the hardware driver
  18299. + * underneath VCHI will usually have its own buffering. */
  18300. +#ifndef VCHI_NUM_WRITE_SLOTS
  18301. +# define VCHI_NUM_WRITE_SLOTS 4
  18302. +#endif
  18303. +
  18304. +/* If a service has held or queued received messages in VCHI_XOFF_THRESHOLD or more slots,
  18305. + * then it's taking up too much buffer space, and the peer service will be told to stop
  18306. + * transmitting with an XOFF message. For this to be effective, the VCHI_NUM_READ_SLOTS
  18307. + * needs to be considerably bigger than VCHI_NUM_WRITE_SLOTS, or the transmit latency
  18308. + * is too high. */
  18309. +#ifndef VCHI_XOFF_THRESHOLD
  18310. +# define VCHI_XOFF_THRESHOLD (VCHI_NUM_READ_SLOTS / 2)
  18311. +#endif
  18312. +
  18313. +/* After we've sent an XOFF, the peer will be told to resume transmission once the local
  18314. + * service has dequeued/released enough messages that it's now occupying
  18315. + * VCHI_XON_THRESHOLD slots or fewer. */
  18316. +#ifndef VCHI_XON_THRESHOLD
  18317. +# define VCHI_XON_THRESHOLD (VCHI_NUM_READ_SLOTS / 4)
  18318. +#endif
  18319. +
  18320. +/* A size below which a bulk transfer omits the handshake completely and always goes
  18321. + * via the message channel, if bulk auxiliary is being sent on that service. (The user
  18322. + * can guarantee this by enabling unaligned transmits).
  18323. + * Not API. */
  18324. +#ifndef VCHI_MIN_BULK_SIZE
  18325. +# define VCHI_MIN_BULK_SIZE ( VCHI_MAX_MSG_SIZE / 2 < 4096 ? VCHI_MAX_MSG_SIZE / 2 : 4096 )
  18326. +#endif
  18327. +
  18328. +/* Maximum size of bulk transmission chunks, for each interface type. A trade-off between
  18329. + * speed and latency; the smaller the chunk size the better change of messages and other
  18330. + * bulk transmissions getting in when big bulk transfers are happening. Set to 0 to not
  18331. + * break transmissions into chunks.
  18332. + */
  18333. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_MPHI
  18334. +# define VCHI_MAX_BULK_CHUNK_SIZE_MPHI (16 * 1024)
  18335. +#endif
  18336. +
  18337. +/* NB Chunked CCP2 transmissions violate the letter of the CCP2 spec by using "JPEG8" mode
  18338. + * with multiple-line frames. Only use if the receiver can cope. */
  18339. +#ifndef VCHI_MAX_BULK_CHUNK_SIZE_CCP2
  18340. +# define VCHI_MAX_BULK_CHUNK_SIZE_CCP2 0
  18341. +#endif
  18342. +
  18343. +/* How many TX messages can we have pending in our transmit slots. Once exhausted,
  18344. + * vchi_msg_queue will be blocked. */
  18345. +#ifndef VCHI_TX_MSG_QUEUE_SIZE
  18346. +# define VCHI_TX_MSG_QUEUE_SIZE 256
  18347. +#endif
  18348. +
  18349. +/* How many RX messages can we have parsed in the receive slots. Once exhausted, parsing
  18350. + * will be suspended until older messages are dequeued/released. */
  18351. +#ifndef VCHI_RX_MSG_QUEUE_SIZE
  18352. +# define VCHI_RX_MSG_QUEUE_SIZE 256
  18353. +#endif
  18354. +
  18355. +/* Really should be able to cope if we run out of received message descriptors, by
  18356. + * suspending parsing as the comment above says, but we don't. This sweeps the issue
  18357. + * under the carpet. */
  18358. +#if VCHI_RX_MSG_QUEUE_SIZE < (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18359. +# undef VCHI_RX_MSG_QUEUE_SIZE
  18360. +# define VCHI_RX_MSG_QUEUE_SIZE (VCHI_MAX_MSG_SIZE/16 + 1) * VCHI_NUM_READ_SLOTS
  18361. +#endif
  18362. +
  18363. +/* How many bulk transmits can we have pending. Once exhausted, vchi_bulk_queue_transmit
  18364. + * will be blocked. */
  18365. +#ifndef VCHI_TX_BULK_QUEUE_SIZE
  18366. +# define VCHI_TX_BULK_QUEUE_SIZE 64
  18367. +#endif
  18368. +
  18369. +/* How many bulk receives can we have pending. Once exhausted, vchi_bulk_queue_receive
  18370. + * will be blocked. */
  18371. +#ifndef VCHI_RX_BULK_QUEUE_SIZE
  18372. +# define VCHI_RX_BULK_QUEUE_SIZE 64
  18373. +#endif
  18374. +
  18375. +/* A limit on how many outstanding bulk requests we expect the peer to give us. If
  18376. + * the peer asks for more than this, VCHI will fail and assert. The number is determined
  18377. + * by the peer's hardware - it's the number of outstanding requests that can be queued
  18378. + * on all bulk channels. VC3's MPHI peripheral allows 16. */
  18379. +#ifndef VCHI_MAX_PEER_BULK_REQUESTS
  18380. +# define VCHI_MAX_PEER_BULK_REQUESTS 32
  18381. +#endif
  18382. +
  18383. +/* Define VCHI_CCP2TX_MANUAL_POWER if the host tells us when to turn the CCP2
  18384. + * transmitter on and off.
  18385. + */
  18386. +/*#define VCHI_CCP2TX_MANUAL_POWER*/
  18387. +
  18388. +#ifndef VCHI_CCP2TX_MANUAL_POWER
  18389. +
  18390. +/* Timeout (in milliseconds) for putting the CCP2TX interface into IDLE state. Set
  18391. + * negative for no IDLE.
  18392. + */
  18393. +# ifndef VCHI_CCP2TX_IDLE_TIMEOUT
  18394. +# define VCHI_CCP2TX_IDLE_TIMEOUT 5
  18395. +# endif
  18396. +
  18397. +/* Timeout (in milliseconds) for putting the CCP2TX interface into OFF state. Set
  18398. + * negative for no OFF.
  18399. + */
  18400. +# ifndef VCHI_CCP2TX_OFF_TIMEOUT
  18401. +# define VCHI_CCP2TX_OFF_TIMEOUT 1000
  18402. +# endif
  18403. +
  18404. +#endif /* VCHI_CCP2TX_MANUAL_POWER */
  18405. +
  18406. +#endif /* VCHI_CFG_H_ */
  18407. +
  18408. +/****************************** End of file **********************************/
  18409. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h
  18410. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 1970-01-01 01:00:00.000000000 +0100
  18411. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_cfg_internal.h 2014-06-11 21:03:34.000000000 +0200
  18412. @@ -0,0 +1,71 @@
  18413. +/**
  18414. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18415. + *
  18416. + * Redistribution and use in source and binary forms, with or without
  18417. + * modification, are permitted provided that the following conditions
  18418. + * are met:
  18419. + * 1. Redistributions of source code must retain the above copyright
  18420. + * notice, this list of conditions, and the following disclaimer,
  18421. + * without modification.
  18422. + * 2. Redistributions in binary form must reproduce the above copyright
  18423. + * notice, this list of conditions and the following disclaimer in the
  18424. + * documentation and/or other materials provided with the distribution.
  18425. + * 3. The names of the above-listed copyright holders may not be used
  18426. + * to endorse or promote products derived from this software without
  18427. + * specific prior written permission.
  18428. + *
  18429. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18430. + * GNU General Public License ("GPL") version 2, as published by the Free
  18431. + * Software Foundation.
  18432. + *
  18433. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18434. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18435. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18436. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18437. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18438. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18439. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18440. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18441. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18442. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18443. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18444. + */
  18445. +
  18446. +#ifndef VCHI_CFG_INTERNAL_H_
  18447. +#define VCHI_CFG_INTERNAL_H_
  18448. +
  18449. +/****************************************************************************************
  18450. + * Control optimisation attempts.
  18451. + ***************************************************************************************/
  18452. +
  18453. +// Don't use lots of short-term locks - use great long ones, reducing the overall locks-per-second
  18454. +#define VCHI_COARSE_LOCKING
  18455. +
  18456. +// Avoid lock then unlock on exit from blocking queue operations (msg tx, bulk rx/tx)
  18457. +// (only relevant if VCHI_COARSE_LOCKING)
  18458. +#define VCHI_ELIDE_BLOCK_EXIT_LOCK
  18459. +
  18460. +// Avoid lock on non-blocking peek
  18461. +// (only relevant if VCHI_COARSE_LOCKING)
  18462. +#define VCHI_AVOID_PEEK_LOCK
  18463. +
  18464. +// Use one slot-handler thread per connection, rather than 1 thread dealing with all connections in rotation.
  18465. +#define VCHI_MULTIPLE_HANDLER_THREADS
  18466. +
  18467. +// Put free descriptors onto the head of the free queue, rather than the tail, so that we don't thrash
  18468. +// our way through the pool of descriptors.
  18469. +#define VCHI_PUSH_FREE_DESCRIPTORS_ONTO_HEAD
  18470. +
  18471. +// Don't issue a MSG_AVAILABLE callback for every single message. Possibly only safe if VCHI_COARSE_LOCKING.
  18472. +#define VCHI_FEWER_MSG_AVAILABLE_CALLBACKS
  18473. +
  18474. +// Don't use message descriptors for TX messages that don't need them
  18475. +#define VCHI_MINIMISE_TX_MSG_DESCRIPTORS
  18476. +
  18477. +// Nano-locks for multiqueue
  18478. +//#define VCHI_MQUEUE_NANOLOCKS
  18479. +
  18480. +// Lock-free(er) dequeuing
  18481. +//#define VCHI_RX_NANOLOCKS
  18482. +
  18483. +#endif /*VCHI_CFG_INTERNAL_H_*/
  18484. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_common.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h
  18485. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_common.h 1970-01-01 01:00:00.000000000 +0100
  18486. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_common.h 2014-06-11 21:03:34.000000000 +0200
  18487. @@ -0,0 +1,163 @@
  18488. +/**
  18489. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18490. + *
  18491. + * Redistribution and use in source and binary forms, with or without
  18492. + * modification, are permitted provided that the following conditions
  18493. + * are met:
  18494. + * 1. Redistributions of source code must retain the above copyright
  18495. + * notice, this list of conditions, and the following disclaimer,
  18496. + * without modification.
  18497. + * 2. Redistributions in binary form must reproduce the above copyright
  18498. + * notice, this list of conditions and the following disclaimer in the
  18499. + * documentation and/or other materials provided with the distribution.
  18500. + * 3. The names of the above-listed copyright holders may not be used
  18501. + * to endorse or promote products derived from this software without
  18502. + * specific prior written permission.
  18503. + *
  18504. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18505. + * GNU General Public License ("GPL") version 2, as published by the Free
  18506. + * Software Foundation.
  18507. + *
  18508. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18509. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18510. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18511. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18512. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18513. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18514. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18515. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18516. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18517. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18518. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18519. + */
  18520. +
  18521. +#ifndef VCHI_COMMON_H_
  18522. +#define VCHI_COMMON_H_
  18523. +
  18524. +
  18525. +//flags used when sending messages (must be bitmapped)
  18526. +typedef enum
  18527. +{
  18528. + VCHI_FLAGS_NONE = 0x0,
  18529. + 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)
  18530. + VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE = 0x2, // run a callback when message sent
  18531. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED = 0x4, // return once the transfer is in a queue ready to go
  18532. + VCHI_FLAGS_ALLOW_PARTIAL = 0x8,
  18533. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ = 0x10,
  18534. + VCHI_FLAGS_CALLBACK_WHEN_DATA_READ = 0x20,
  18535. +
  18536. + VCHI_FLAGS_ALIGN_SLOT = 0x000080, // internal use only
  18537. + VCHI_FLAGS_BULK_AUX_QUEUED = 0x010000, // internal use only
  18538. + VCHI_FLAGS_BULK_AUX_COMPLETE = 0x020000, // internal use only
  18539. + VCHI_FLAGS_BULK_DATA_QUEUED = 0x040000, // internal use only
  18540. + VCHI_FLAGS_BULK_DATA_COMPLETE = 0x080000, // internal use only
  18541. + VCHI_FLAGS_INTERNAL = 0xFF0000
  18542. +} VCHI_FLAGS_T;
  18543. +
  18544. +// constants for vchi_crc_control()
  18545. +typedef enum {
  18546. + VCHI_CRC_NOTHING = -1,
  18547. + VCHI_CRC_PER_SERVICE = 0,
  18548. + VCHI_CRC_EVERYTHING = 1,
  18549. +} VCHI_CRC_CONTROL_T;
  18550. +
  18551. +//callback reasons when an event occurs on a service
  18552. +typedef enum
  18553. +{
  18554. + VCHI_CALLBACK_REASON_MIN,
  18555. +
  18556. + //This indicates that there is data available
  18557. + //handle is the msg id that was transmitted with the data
  18558. + // When a message is received and there was no FULL message available previously, send callback
  18559. + // Tasks get kicked by the callback, reset their event and try and read from the fifo until it fails
  18560. + VCHI_CALLBACK_MSG_AVAILABLE,
  18561. + VCHI_CALLBACK_MSG_SENT,
  18562. + VCHI_CALLBACK_MSG_SPACE_AVAILABLE, // XXX not yet implemented
  18563. +
  18564. + // This indicates that a transfer from the other side has completed
  18565. + VCHI_CALLBACK_BULK_RECEIVED,
  18566. + //This indicates that data queued up to be sent has now gone
  18567. + //handle is the msg id that was used when sending the data
  18568. + VCHI_CALLBACK_BULK_SENT,
  18569. + VCHI_CALLBACK_BULK_RX_SPACE_AVAILABLE, // XXX not yet implemented
  18570. + VCHI_CALLBACK_BULK_TX_SPACE_AVAILABLE, // XXX not yet implemented
  18571. +
  18572. + VCHI_CALLBACK_SERVICE_CLOSED,
  18573. +
  18574. + // this side has sent XOFF to peer due to lack of data consumption by service
  18575. + // (suggests the service may need to take some recovery action if it has
  18576. + // been deliberately holding off consuming data)
  18577. + VCHI_CALLBACK_SENT_XOFF,
  18578. + VCHI_CALLBACK_SENT_XON,
  18579. +
  18580. + // indicates that a bulk transfer has finished reading the source buffer
  18581. + VCHI_CALLBACK_BULK_DATA_READ,
  18582. +
  18583. + // power notification events (currently host side only)
  18584. + VCHI_CALLBACK_PEER_OFF,
  18585. + VCHI_CALLBACK_PEER_SUSPENDED,
  18586. + VCHI_CALLBACK_PEER_ON,
  18587. + VCHI_CALLBACK_PEER_RESUMED,
  18588. + VCHI_CALLBACK_FORCED_POWER_OFF,
  18589. +
  18590. +#ifdef USE_VCHIQ_ARM
  18591. + // some extra notifications provided by vchiq_arm
  18592. + VCHI_CALLBACK_SERVICE_OPENED,
  18593. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  18594. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  18595. +#endif
  18596. +
  18597. + VCHI_CALLBACK_REASON_MAX
  18598. +} VCHI_CALLBACK_REASON_T;
  18599. +
  18600. +//Calback used by all services / bulk transfers
  18601. +typedef void (*VCHI_CALLBACK_T)( void *callback_param, //my service local param
  18602. + VCHI_CALLBACK_REASON_T reason,
  18603. + void *handle ); //for transmitting msg's only
  18604. +
  18605. +
  18606. +
  18607. +/*
  18608. + * Define vector struct for scatter-gather (vector) operations
  18609. + * Vectors can be nested - if a vector element has negative length, then
  18610. + * the data pointer is treated as pointing to another vector array, with
  18611. + * '-vec_len' elements. Thus to append a header onto an existing vector,
  18612. + * you can do this:
  18613. + *
  18614. + * void foo(const VCHI_MSG_VECTOR_T *v, int n)
  18615. + * {
  18616. + * VCHI_MSG_VECTOR_T nv[2];
  18617. + * nv[0].vec_base = my_header;
  18618. + * nv[0].vec_len = sizeof my_header;
  18619. + * nv[1].vec_base = v;
  18620. + * nv[1].vec_len = -n;
  18621. + * ...
  18622. + *
  18623. + */
  18624. +typedef struct vchi_msg_vector {
  18625. + const void *vec_base;
  18626. + int32_t vec_len;
  18627. +} VCHI_MSG_VECTOR_T;
  18628. +
  18629. +// Opaque type for a connection API
  18630. +typedef struct opaque_vchi_connection_api_t VCHI_CONNECTION_API_T;
  18631. +
  18632. +// Opaque type for a message driver
  18633. +typedef struct opaque_vchi_message_driver_t VCHI_MESSAGE_DRIVER_T;
  18634. +
  18635. +
  18636. +// Iterator structure for reading ahead through received message queue. Allocated by client,
  18637. +// initialised by vchi_msg_look_ahead. Fields are for internal VCHI use only.
  18638. +// Iterates over messages in queue at the instant of the call to vchi_msg_lookahead -
  18639. +// will not proceed to messages received since. Behaviour is undefined if an iterator
  18640. +// is used again after messages for that service are removed/dequeued by any
  18641. +// means other than vchi_msg_iter_... calls on the iterator itself.
  18642. +typedef struct {
  18643. + struct opaque_vchi_service_t *service;
  18644. + void *last;
  18645. + void *next;
  18646. + void *remove;
  18647. +} VCHI_MSG_ITER_T;
  18648. +
  18649. +
  18650. +#endif // VCHI_COMMON_H_
  18651. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h
  18652. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi.h 1970-01-01 01:00:00.000000000 +0100
  18653. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi.h 2014-06-11 21:03:34.000000000 +0200
  18654. @@ -0,0 +1,373 @@
  18655. +/**
  18656. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  18657. + *
  18658. + * Redistribution and use in source and binary forms, with or without
  18659. + * modification, are permitted provided that the following conditions
  18660. + * are met:
  18661. + * 1. Redistributions of source code must retain the above copyright
  18662. + * notice, this list of conditions, and the following disclaimer,
  18663. + * without modification.
  18664. + * 2. Redistributions in binary form must reproduce the above copyright
  18665. + * notice, this list of conditions and the following disclaimer in the
  18666. + * documentation and/or other materials provided with the distribution.
  18667. + * 3. The names of the above-listed copyright holders may not be used
  18668. + * to endorse or promote products derived from this software without
  18669. + * specific prior written permission.
  18670. + *
  18671. + * ALTERNATIVELY, this software may be distributed under the terms of the
  18672. + * GNU General Public License ("GPL") version 2, as published by the Free
  18673. + * Software Foundation.
  18674. + *
  18675. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  18676. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  18677. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18678. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18679. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18680. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18681. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18682. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  18683. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  18684. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  18685. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18686. + */
  18687. +
  18688. +#ifndef VCHI_H_
  18689. +#define VCHI_H_
  18690. +
  18691. +#include "interface/vchi/vchi_cfg.h"
  18692. +#include "interface/vchi/vchi_common.h"
  18693. +#include "interface/vchi/connections/connection.h"
  18694. +#include "vchi_mh.h"
  18695. +
  18696. +
  18697. +/******************************************************************************
  18698. + Global defs
  18699. + *****************************************************************************/
  18700. +
  18701. +#define VCHI_BULK_ROUND_UP(x) ((((unsigned long)(x))+VCHI_BULK_ALIGN-1) & ~(VCHI_BULK_ALIGN-1))
  18702. +#define VCHI_BULK_ROUND_DOWN(x) (((unsigned long)(x)) & ~(VCHI_BULK_ALIGN-1))
  18703. +#define VCHI_BULK_ALIGN_NBYTES(x) (VCHI_BULK_ALIGNED(x) ? 0 : (VCHI_BULK_ALIGN - ((unsigned long)(x) & (VCHI_BULK_ALIGN-1))))
  18704. +
  18705. +#ifdef USE_VCHIQ_ARM
  18706. +#define VCHI_BULK_ALIGNED(x) 1
  18707. +#else
  18708. +#define VCHI_BULK_ALIGNED(x) (((unsigned long)(x) & (VCHI_BULK_ALIGN-1)) == 0)
  18709. +#endif
  18710. +
  18711. +struct vchi_version {
  18712. + uint32_t version;
  18713. + uint32_t version_min;
  18714. +};
  18715. +#define VCHI_VERSION(v_) { v_, v_ }
  18716. +#define VCHI_VERSION_EX(v_, m_) { v_, m_ }
  18717. +
  18718. +typedef enum
  18719. +{
  18720. + VCHI_VEC_POINTER,
  18721. + VCHI_VEC_HANDLE,
  18722. + VCHI_VEC_LIST
  18723. +} VCHI_MSG_VECTOR_TYPE_T;
  18724. +
  18725. +typedef struct vchi_msg_vector_ex {
  18726. +
  18727. + VCHI_MSG_VECTOR_TYPE_T type;
  18728. + union
  18729. + {
  18730. + // a memory handle
  18731. + struct
  18732. + {
  18733. + VCHI_MEM_HANDLE_T handle;
  18734. + uint32_t offset;
  18735. + int32_t vec_len;
  18736. + } handle;
  18737. +
  18738. + // an ordinary data pointer
  18739. + struct
  18740. + {
  18741. + const void *vec_base;
  18742. + int32_t vec_len;
  18743. + } ptr;
  18744. +
  18745. + // a nested vector list
  18746. + struct
  18747. + {
  18748. + struct vchi_msg_vector_ex *vec;
  18749. + uint32_t vec_len;
  18750. + } list;
  18751. + } u;
  18752. +} VCHI_MSG_VECTOR_EX_T;
  18753. +
  18754. +
  18755. +// Construct an entry in a msg vector for a pointer (p) of length (l)
  18756. +#define VCHI_VEC_POINTER(p,l) VCHI_VEC_POINTER, { { (VCHI_MEM_HANDLE_T)(p), (l) } }
  18757. +
  18758. +// Construct an entry in a msg vector for a message handle (h), starting at offset (o) of length (l)
  18759. +#define VCHI_VEC_HANDLE(h,o,l) VCHI_VEC_HANDLE, { { (h), (o), (l) } }
  18760. +
  18761. +// Macros to manipulate 'FOURCC' values
  18762. +#define MAKE_FOURCC(x) ((int32_t)( (x[0] << 24) | (x[1] << 16) | (x[2] << 8) | x[3] ))
  18763. +#define FOURCC_TO_CHAR(x) (x >> 24) & 0xFF,(x >> 16) & 0xFF,(x >> 8) & 0xFF, x & 0xFF
  18764. +
  18765. +
  18766. +// Opaque service information
  18767. +struct opaque_vchi_service_t;
  18768. +
  18769. +// Descriptor for a held message. Allocated by client, initialised by vchi_msg_hold,
  18770. +// vchi_msg_iter_hold or vchi_msg_iter_hold_next. Fields are for internal VCHI use only.
  18771. +typedef struct
  18772. +{
  18773. + struct opaque_vchi_service_t *service;
  18774. + void *message;
  18775. +} VCHI_HELD_MSG_T;
  18776. +
  18777. +
  18778. +
  18779. +// structure used to provide the information needed to open a server or a client
  18780. +typedef struct {
  18781. + struct vchi_version version;
  18782. + int32_t service_id;
  18783. + VCHI_CONNECTION_T *connection;
  18784. + uint32_t rx_fifo_size;
  18785. + uint32_t tx_fifo_size;
  18786. + VCHI_CALLBACK_T callback;
  18787. + void *callback_param;
  18788. + /* client intends to receive bulk transfers of
  18789. + odd lengths or into unaligned buffers */
  18790. + int32_t want_unaligned_bulk_rx;
  18791. + /* client intends to transmit bulk transfers of
  18792. + odd lengths or out of unaligned buffers */
  18793. + int32_t want_unaligned_bulk_tx;
  18794. + /* client wants to check CRCs on (bulk) xfers.
  18795. + Only needs to be set at 1 end - will do both directions. */
  18796. + int32_t want_crc;
  18797. +} SERVICE_CREATION_T;
  18798. +
  18799. +// Opaque handle for a VCHI instance
  18800. +typedef struct opaque_vchi_instance_handle_t *VCHI_INSTANCE_T;
  18801. +
  18802. +// Opaque handle for a server or client
  18803. +typedef struct opaque_vchi_service_handle_t *VCHI_SERVICE_HANDLE_T;
  18804. +
  18805. +// Service registration & startup
  18806. +typedef void (*VCHI_SERVICE_INIT)(VCHI_INSTANCE_T initialise_instance, VCHI_CONNECTION_T **connections, uint32_t num_connections);
  18807. +
  18808. +typedef struct service_info_tag {
  18809. + const char * const vll_filename; /* VLL to load to start this service. This is an empty string if VLL is "static" */
  18810. + VCHI_SERVICE_INIT init; /* Service initialisation function */
  18811. + void *vll_handle; /* VLL handle; NULL when unloaded or a "static VLL" in build */
  18812. +} SERVICE_INFO_T;
  18813. +
  18814. +/******************************************************************************
  18815. + Global funcs - implementation is specific to which side you are on (local / remote)
  18816. + *****************************************************************************/
  18817. +
  18818. +#ifdef __cplusplus
  18819. +extern "C" {
  18820. +#endif
  18821. +
  18822. +extern /*@observer@*/ VCHI_CONNECTION_T * vchi_create_connection( const VCHI_CONNECTION_API_T * function_table,
  18823. + const VCHI_MESSAGE_DRIVER_T * low_level);
  18824. +
  18825. +
  18826. +// Routine used to initialise the vchi on both local + remote connections
  18827. +extern int32_t vchi_initialise( VCHI_INSTANCE_T *instance_handle );
  18828. +
  18829. +extern int32_t vchi_exit( void );
  18830. +
  18831. +extern int32_t vchi_connect( VCHI_CONNECTION_T **connections,
  18832. + const uint32_t num_connections,
  18833. + VCHI_INSTANCE_T instance_handle );
  18834. +
  18835. +//When this is called, ensure that all services have no data pending.
  18836. +//Bulk transfers can remain 'queued'
  18837. +extern int32_t vchi_disconnect( VCHI_INSTANCE_T instance_handle );
  18838. +
  18839. +// Global control over bulk CRC checking
  18840. +extern int32_t vchi_crc_control( VCHI_CONNECTION_T *connection,
  18841. + VCHI_CRC_CONTROL_T control );
  18842. +
  18843. +// helper functions
  18844. +extern void * vchi_allocate_buffer(VCHI_SERVICE_HANDLE_T handle, uint32_t *length);
  18845. +extern void vchi_free_buffer(VCHI_SERVICE_HANDLE_T handle, void *address);
  18846. +extern uint32_t vchi_current_time(VCHI_INSTANCE_T instance_handle);
  18847. +
  18848. +
  18849. +/******************************************************************************
  18850. + Global service API
  18851. + *****************************************************************************/
  18852. +// Routine to create a named service
  18853. +extern int32_t vchi_service_create( VCHI_INSTANCE_T instance_handle,
  18854. + SERVICE_CREATION_T *setup,
  18855. + VCHI_SERVICE_HANDLE_T *handle );
  18856. +
  18857. +// Routine to destory a service
  18858. +extern int32_t vchi_service_destroy( const VCHI_SERVICE_HANDLE_T handle );
  18859. +
  18860. +// Routine to open a named service
  18861. +extern int32_t vchi_service_open( VCHI_INSTANCE_T instance_handle,
  18862. + SERVICE_CREATION_T *setup,
  18863. + VCHI_SERVICE_HANDLE_T *handle);
  18864. +
  18865. +extern int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle,
  18866. + short *peer_version );
  18867. +
  18868. +// Routine to close a named service
  18869. +extern int32_t vchi_service_close( const VCHI_SERVICE_HANDLE_T handle );
  18870. +
  18871. +// Routine to increment ref count on a named service
  18872. +extern int32_t vchi_service_use( const VCHI_SERVICE_HANDLE_T handle );
  18873. +
  18874. +// Routine to decrement ref count on a named service
  18875. +extern int32_t vchi_service_release( const VCHI_SERVICE_HANDLE_T handle );
  18876. +
  18877. +// Routine to send a message accross a service
  18878. +extern int32_t vchi_msg_queue( VCHI_SERVICE_HANDLE_T handle,
  18879. + const void *data,
  18880. + uint32_t data_size,
  18881. + VCHI_FLAGS_T flags,
  18882. + void *msg_handle );
  18883. +
  18884. +// scatter-gather (vector) and send message
  18885. +int32_t vchi_msg_queuev_ex( VCHI_SERVICE_HANDLE_T handle,
  18886. + VCHI_MSG_VECTOR_EX_T *vector,
  18887. + uint32_t count,
  18888. + VCHI_FLAGS_T flags,
  18889. + void *msg_handle );
  18890. +
  18891. +// legacy scatter-gather (vector) and send message, only handles pointers
  18892. +int32_t vchi_msg_queuev( VCHI_SERVICE_HANDLE_T handle,
  18893. + VCHI_MSG_VECTOR_T *vector,
  18894. + uint32_t count,
  18895. + VCHI_FLAGS_T flags,
  18896. + void *msg_handle );
  18897. +
  18898. +// Routine to receive a msg from a service
  18899. +// Dequeue is equivalent to hold, copy into client buffer, release
  18900. +extern int32_t vchi_msg_dequeue( VCHI_SERVICE_HANDLE_T handle,
  18901. + void *data,
  18902. + uint32_t max_data_size_to_read,
  18903. + uint32_t *actual_msg_size,
  18904. + VCHI_FLAGS_T flags );
  18905. +
  18906. +// Routine to look at a message in place.
  18907. +// The message is not dequeued, so a subsequent call to peek or dequeue
  18908. +// will return the same message.
  18909. +extern int32_t vchi_msg_peek( VCHI_SERVICE_HANDLE_T handle,
  18910. + void **data,
  18911. + uint32_t *msg_size,
  18912. + VCHI_FLAGS_T flags );
  18913. +
  18914. +// Routine to remove a message after it has been read in place with peek
  18915. +// The first message on the queue is dequeued.
  18916. +extern int32_t vchi_msg_remove( VCHI_SERVICE_HANDLE_T handle );
  18917. +
  18918. +// Routine to look at a message in place.
  18919. +// The message is dequeued, so the caller is left holding it; the descriptor is
  18920. +// filled in and must be released when the user has finished with the message.
  18921. +extern int32_t vchi_msg_hold( VCHI_SERVICE_HANDLE_T handle,
  18922. + void **data, // } may be NULL, as info can be
  18923. + uint32_t *msg_size, // } obtained from HELD_MSG_T
  18924. + VCHI_FLAGS_T flags,
  18925. + VCHI_HELD_MSG_T *message_descriptor );
  18926. +
  18927. +// Initialise an iterator to look through messages in place
  18928. +extern int32_t vchi_msg_look_ahead( VCHI_SERVICE_HANDLE_T handle,
  18929. + VCHI_MSG_ITER_T *iter,
  18930. + VCHI_FLAGS_T flags );
  18931. +
  18932. +/******************************************************************************
  18933. + Global service support API - operations on held messages and message iterators
  18934. + *****************************************************************************/
  18935. +
  18936. +// Routine to get the address of a held message
  18937. +extern void *vchi_held_msg_ptr( const VCHI_HELD_MSG_T *message );
  18938. +
  18939. +// Routine to get the size of a held message
  18940. +extern int32_t vchi_held_msg_size( const VCHI_HELD_MSG_T *message );
  18941. +
  18942. +// Routine to get the transmit timestamp as written into the header by the peer
  18943. +extern uint32_t vchi_held_msg_tx_timestamp( const VCHI_HELD_MSG_T *message );
  18944. +
  18945. +// Routine to get the reception timestamp, written as we parsed the header
  18946. +extern uint32_t vchi_held_msg_rx_timestamp( const VCHI_HELD_MSG_T *message );
  18947. +
  18948. +// Routine to release a held message after it has been processed
  18949. +extern int32_t vchi_held_msg_release( VCHI_HELD_MSG_T *message );
  18950. +
  18951. +// Indicates whether the iterator has a next message.
  18952. +extern int32_t vchi_msg_iter_has_next( const VCHI_MSG_ITER_T *iter );
  18953. +
  18954. +// Return the pointer and length for the next message and advance the iterator.
  18955. +extern int32_t vchi_msg_iter_next( VCHI_MSG_ITER_T *iter,
  18956. + void **data,
  18957. + uint32_t *msg_size );
  18958. +
  18959. +// Remove the last message returned by vchi_msg_iter_next.
  18960. +// Can only be called once after each call to vchi_msg_iter_next.
  18961. +extern int32_t vchi_msg_iter_remove( VCHI_MSG_ITER_T *iter );
  18962. +
  18963. +// Hold the last message returned by vchi_msg_iter_next.
  18964. +// Can only be called once after each call to vchi_msg_iter_next.
  18965. +extern int32_t vchi_msg_iter_hold( VCHI_MSG_ITER_T *iter,
  18966. + VCHI_HELD_MSG_T *message );
  18967. +
  18968. +// Return information for the next message, and hold it, advancing the iterator.
  18969. +extern int32_t vchi_msg_iter_hold_next( VCHI_MSG_ITER_T *iter,
  18970. + void **data, // } may be NULL
  18971. + uint32_t *msg_size, // }
  18972. + VCHI_HELD_MSG_T *message );
  18973. +
  18974. +
  18975. +/******************************************************************************
  18976. + Global bulk API
  18977. + *****************************************************************************/
  18978. +
  18979. +// Routine to prepare interface for a transfer from the other side
  18980. +extern int32_t vchi_bulk_queue_receive( VCHI_SERVICE_HANDLE_T handle,
  18981. + void *data_dst,
  18982. + uint32_t data_size,
  18983. + VCHI_FLAGS_T flags,
  18984. + void *transfer_handle );
  18985. +
  18986. +
  18987. +// Prepare interface for a transfer from the other side into relocatable memory.
  18988. +int32_t vchi_bulk_queue_receive_reloc( const VCHI_SERVICE_HANDLE_T handle,
  18989. + VCHI_MEM_HANDLE_T h_dst,
  18990. + uint32_t offset,
  18991. + uint32_t data_size,
  18992. + const VCHI_FLAGS_T flags,
  18993. + void * const bulk_handle );
  18994. +
  18995. +// Routine to queue up data ready for transfer to the other (once they have signalled they are ready)
  18996. +extern int32_t vchi_bulk_queue_transmit( VCHI_SERVICE_HANDLE_T handle,
  18997. + const void *data_src,
  18998. + uint32_t data_size,
  18999. + VCHI_FLAGS_T flags,
  19000. + void *transfer_handle );
  19001. +
  19002. +
  19003. +/******************************************************************************
  19004. + Configuration plumbing
  19005. + *****************************************************************************/
  19006. +
  19007. +// function prototypes for the different mid layers (the state info gives the different physical connections)
  19008. +extern const VCHI_CONNECTION_API_T *single_get_func_table( void );
  19009. +//extern const VCHI_CONNECTION_API_T *local_server_get_func_table( void );
  19010. +//extern const VCHI_CONNECTION_API_T *local_client_get_func_table( void );
  19011. +
  19012. +// declare all message drivers here
  19013. +const VCHI_MESSAGE_DRIVER_T *vchi_mphi_message_driver_func_table( void );
  19014. +
  19015. +#ifdef __cplusplus
  19016. +}
  19017. +#endif
  19018. +
  19019. +extern int32_t vchi_bulk_queue_transmit_reloc( VCHI_SERVICE_HANDLE_T handle,
  19020. + VCHI_MEM_HANDLE_T h_src,
  19021. + uint32_t offset,
  19022. + uint32_t data_size,
  19023. + VCHI_FLAGS_T flags,
  19024. + void *transfer_handle );
  19025. +#endif /* VCHI_H_ */
  19026. +
  19027. +/****************************** End of file **********************************/
  19028. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_mh.h linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h
  19029. --- linux-3.15/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 1970-01-01 01:00:00.000000000 +0100
  19030. +++ linux-rpi/drivers/misc/vc04_services/interface/vchi/vchi_mh.h 2014-06-11 21:03:34.000000000 +0200
  19031. @@ -0,0 +1,42 @@
  19032. +/**
  19033. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19034. + *
  19035. + * Redistribution and use in source and binary forms, with or without
  19036. + * modification, are permitted provided that the following conditions
  19037. + * are met:
  19038. + * 1. Redistributions of source code must retain the above copyright
  19039. + * notice, this list of conditions, and the following disclaimer,
  19040. + * without modification.
  19041. + * 2. Redistributions in binary form must reproduce the above copyright
  19042. + * notice, this list of conditions and the following disclaimer in the
  19043. + * documentation and/or other materials provided with the distribution.
  19044. + * 3. The names of the above-listed copyright holders may not be used
  19045. + * to endorse or promote products derived from this software without
  19046. + * specific prior written permission.
  19047. + *
  19048. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19049. + * GNU General Public License ("GPL") version 2, as published by the Free
  19050. + * Software Foundation.
  19051. + *
  19052. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19053. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19054. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19055. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19056. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19057. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19058. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19059. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19060. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19061. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19062. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19063. + */
  19064. +
  19065. +#ifndef VCHI_MH_H_
  19066. +#define VCHI_MH_H_
  19067. +
  19068. +#include <linux/types.h>
  19069. +
  19070. +typedef int32_t VCHI_MEM_HANDLE_T;
  19071. +#define VCHI_MEM_HANDLE_INVALID 0
  19072. +
  19073. +#endif
  19074. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
  19075. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 1970-01-01 01:00:00.000000000 +0100
  19076. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c 2014-06-11 21:03:34.000000000 +0200
  19077. @@ -0,0 +1,562 @@
  19078. +/**
  19079. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19080. + *
  19081. + * Redistribution and use in source and binary forms, with or without
  19082. + * modification, are permitted provided that the following conditions
  19083. + * are met:
  19084. + * 1. Redistributions of source code must retain the above copyright
  19085. + * notice, this list of conditions, and the following disclaimer,
  19086. + * without modification.
  19087. + * 2. Redistributions in binary form must reproduce the above copyright
  19088. + * notice, this list of conditions and the following disclaimer in the
  19089. + * documentation and/or other materials provided with the distribution.
  19090. + * 3. The names of the above-listed copyright holders may not be used
  19091. + * to endorse or promote products derived from this software without
  19092. + * specific prior written permission.
  19093. + *
  19094. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19095. + * GNU General Public License ("GPL") version 2, as published by the Free
  19096. + * Software Foundation.
  19097. + *
  19098. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19099. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19100. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19101. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19102. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19103. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19104. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19105. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19106. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19107. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19108. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19109. + */
  19110. +
  19111. +#include <linux/kernel.h>
  19112. +#include <linux/types.h>
  19113. +#include <linux/errno.h>
  19114. +#include <linux/interrupt.h>
  19115. +#include <linux/irq.h>
  19116. +#include <linux/pagemap.h>
  19117. +#include <linux/dma-mapping.h>
  19118. +#include <linux/version.h>
  19119. +#include <linux/io.h>
  19120. +#include <linux/uaccess.h>
  19121. +#include <asm/pgtable.h>
  19122. +
  19123. +#include <mach/irqs.h>
  19124. +
  19125. +#include <mach/platform.h>
  19126. +#include <mach/vcio.h>
  19127. +
  19128. +#define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
  19129. +
  19130. +#define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0
  19131. +#define VCHIQ_ARM_ADDRESS(x) ((void *)__virt_to_bus((unsigned)x))
  19132. +
  19133. +#include "vchiq_arm.h"
  19134. +#include "vchiq_2835.h"
  19135. +#include "vchiq_connected.h"
  19136. +#include "vchiq_killable.h"
  19137. +
  19138. +#define MAX_FRAGMENTS (VCHIQ_NUM_CURRENT_BULKS * 2)
  19139. +
  19140. +typedef struct vchiq_2835_state_struct {
  19141. + int inited;
  19142. + VCHIQ_ARM_STATE_T arm_state;
  19143. +} VCHIQ_2835_ARM_STATE_T;
  19144. +
  19145. +static char *g_slot_mem;
  19146. +static int g_slot_mem_size;
  19147. +dma_addr_t g_slot_phys;
  19148. +static FRAGMENTS_T *g_fragments_base;
  19149. +static FRAGMENTS_T *g_free_fragments;
  19150. +struct semaphore g_free_fragments_sema;
  19151. +
  19152. +extern int vchiq_arm_log_level;
  19153. +
  19154. +static DEFINE_SEMAPHORE(g_free_fragments_mutex);
  19155. +
  19156. +static irqreturn_t
  19157. +vchiq_doorbell_irq(int irq, void *dev_id);
  19158. +
  19159. +static int
  19160. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19161. + struct task_struct *task, PAGELIST_T ** ppagelist);
  19162. +
  19163. +static void
  19164. +free_pagelist(PAGELIST_T *pagelist, int actual);
  19165. +
  19166. +int __init
  19167. +vchiq_platform_init(VCHIQ_STATE_T *state)
  19168. +{
  19169. + VCHIQ_SLOT_ZERO_T *vchiq_slot_zero;
  19170. + int frag_mem_size;
  19171. + int err;
  19172. + int i;
  19173. +
  19174. + /* Allocate space for the channels in coherent memory */
  19175. + g_slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
  19176. + frag_mem_size = PAGE_ALIGN(sizeof(FRAGMENTS_T) * MAX_FRAGMENTS);
  19177. +
  19178. + g_slot_mem = dma_alloc_coherent(NULL, g_slot_mem_size + frag_mem_size,
  19179. + &g_slot_phys, GFP_ATOMIC);
  19180. +
  19181. + if (!g_slot_mem) {
  19182. + vchiq_log_error(vchiq_arm_log_level,
  19183. + "Unable to allocate channel memory");
  19184. + err = -ENOMEM;
  19185. + goto failed_alloc;
  19186. + }
  19187. +
  19188. + WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) != 0);
  19189. +
  19190. + vchiq_slot_zero = vchiq_init_slots(g_slot_mem, g_slot_mem_size);
  19191. + if (!vchiq_slot_zero) {
  19192. + err = -EINVAL;
  19193. + goto failed_init_slots;
  19194. + }
  19195. +
  19196. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
  19197. + (int)g_slot_phys + g_slot_mem_size;
  19198. + vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
  19199. + MAX_FRAGMENTS;
  19200. +
  19201. + g_fragments_base = (FRAGMENTS_T *)(g_slot_mem + g_slot_mem_size);
  19202. + g_slot_mem_size += frag_mem_size;
  19203. +
  19204. + g_free_fragments = g_fragments_base;
  19205. + for (i = 0; i < (MAX_FRAGMENTS - 1); i++) {
  19206. + *(FRAGMENTS_T **)&g_fragments_base[i] =
  19207. + &g_fragments_base[i + 1];
  19208. + }
  19209. + *(FRAGMENTS_T **)&g_fragments_base[i] = NULL;
  19210. + sema_init(&g_free_fragments_sema, MAX_FRAGMENTS);
  19211. +
  19212. + if (vchiq_init_state(state, vchiq_slot_zero, 0/*slave*/) !=
  19213. + VCHIQ_SUCCESS) {
  19214. + err = -EINVAL;
  19215. + goto failed_vchiq_init;
  19216. + }
  19217. +
  19218. + err = request_irq(VCHIQ_DOORBELL_IRQ, vchiq_doorbell_irq,
  19219. + IRQF_IRQPOLL, "VCHIQ doorbell",
  19220. + state);
  19221. + if (err < 0) {
  19222. + vchiq_log_error(vchiq_arm_log_level, "%s: failed to register "
  19223. + "irq=%d err=%d", __func__,
  19224. + VCHIQ_DOORBELL_IRQ, err);
  19225. + goto failed_request_irq;
  19226. + }
  19227. +
  19228. + /* Send the base address of the slots to VideoCore */
  19229. +
  19230. + dsb(); /* Ensure all writes have completed */
  19231. +
  19232. + bcm_mailbox_write(MBOX_CHAN_VCHIQ, (unsigned int)g_slot_phys);
  19233. +
  19234. + vchiq_log_info(vchiq_arm_log_level,
  19235. + "vchiq_init - done (slots %x, phys %x)",
  19236. + (unsigned int)vchiq_slot_zero, g_slot_phys);
  19237. +
  19238. + vchiq_call_connected_callbacks();
  19239. +
  19240. + return 0;
  19241. +
  19242. +failed_request_irq:
  19243. +failed_vchiq_init:
  19244. +failed_init_slots:
  19245. + dma_free_coherent(NULL, g_slot_mem_size, g_slot_mem, g_slot_phys);
  19246. +
  19247. +failed_alloc:
  19248. + return err;
  19249. +}
  19250. +
  19251. +void __exit
  19252. +vchiq_platform_exit(VCHIQ_STATE_T *state)
  19253. +{
  19254. + free_irq(VCHIQ_DOORBELL_IRQ, state);
  19255. + dma_free_coherent(NULL, g_slot_mem_size,
  19256. + g_slot_mem, g_slot_phys);
  19257. +}
  19258. +
  19259. +
  19260. +VCHIQ_STATUS_T
  19261. +vchiq_platform_init_state(VCHIQ_STATE_T *state)
  19262. +{
  19263. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  19264. + state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL);
  19265. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1;
  19266. + status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state);
  19267. + if(status != VCHIQ_SUCCESS)
  19268. + {
  19269. + ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0;
  19270. + }
  19271. + return status;
  19272. +}
  19273. +
  19274. +VCHIQ_ARM_STATE_T*
  19275. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state)
  19276. +{
  19277. + if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited)
  19278. + {
  19279. + BUG();
  19280. + }
  19281. + return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state;
  19282. +}
  19283. +
  19284. +void
  19285. +remote_event_signal(REMOTE_EVENT_T *event)
  19286. +{
  19287. + wmb();
  19288. +
  19289. + event->fired = 1;
  19290. +
  19291. + dsb(); /* data barrier operation */
  19292. +
  19293. + if (event->armed) {
  19294. + /* trigger vc interrupt */
  19295. +
  19296. + writel(0, __io_address(ARM_0_BELL2));
  19297. + }
  19298. +}
  19299. +
  19300. +int
  19301. +vchiq_copy_from_user(void *dst, const void *src, int size)
  19302. +{
  19303. + if ((uint32_t)src < TASK_SIZE) {
  19304. + return copy_from_user(dst, src, size);
  19305. + } else {
  19306. + memcpy(dst, src, size);
  19307. + return 0;
  19308. + }
  19309. +}
  19310. +
  19311. +VCHIQ_STATUS_T
  19312. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk, VCHI_MEM_HANDLE_T memhandle,
  19313. + void *offset, int size, int dir)
  19314. +{
  19315. + PAGELIST_T *pagelist;
  19316. + int ret;
  19317. +
  19318. + WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID);
  19319. +
  19320. + ret = create_pagelist((char __user *)offset, size,
  19321. + (dir == VCHIQ_BULK_RECEIVE)
  19322. + ? PAGELIST_READ
  19323. + : PAGELIST_WRITE,
  19324. + current,
  19325. + &pagelist);
  19326. + if (ret != 0)
  19327. + return VCHIQ_ERROR;
  19328. +
  19329. + bulk->handle = memhandle;
  19330. + bulk->data = VCHIQ_ARM_ADDRESS(pagelist);
  19331. +
  19332. + /* Store the pagelist address in remote_data, which isn't used by the
  19333. + slave. */
  19334. + bulk->remote_data = pagelist;
  19335. +
  19336. + return VCHIQ_SUCCESS;
  19337. +}
  19338. +
  19339. +void
  19340. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk)
  19341. +{
  19342. + if (bulk && bulk->remote_data && bulk->actual)
  19343. + free_pagelist((PAGELIST_T *)bulk->remote_data, bulk->actual);
  19344. +}
  19345. +
  19346. +void
  19347. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk)
  19348. +{
  19349. + /*
  19350. + * This should only be called on the master (VideoCore) side, but
  19351. + * provide an implementation to avoid the need for ifdefery.
  19352. + */
  19353. + BUG();
  19354. +}
  19355. +
  19356. +void
  19357. +vchiq_dump_platform_state(void *dump_context)
  19358. +{
  19359. + char buf[80];
  19360. + int len;
  19361. + len = snprintf(buf, sizeof(buf),
  19362. + " Platform: 2835 (VC master)");
  19363. + vchiq_dump(dump_context, buf, len + 1);
  19364. +}
  19365. +
  19366. +VCHIQ_STATUS_T
  19367. +vchiq_platform_suspend(VCHIQ_STATE_T *state)
  19368. +{
  19369. + return VCHIQ_ERROR;
  19370. +}
  19371. +
  19372. +VCHIQ_STATUS_T
  19373. +vchiq_platform_resume(VCHIQ_STATE_T *state)
  19374. +{
  19375. + return VCHIQ_SUCCESS;
  19376. +}
  19377. +
  19378. +void
  19379. +vchiq_platform_paused(VCHIQ_STATE_T *state)
  19380. +{
  19381. +}
  19382. +
  19383. +void
  19384. +vchiq_platform_resumed(VCHIQ_STATE_T *state)
  19385. +{
  19386. +}
  19387. +
  19388. +int
  19389. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T* state)
  19390. +{
  19391. + return 1; // autosuspend not supported - videocore always wanted
  19392. +}
  19393. +
  19394. +int
  19395. +vchiq_platform_use_suspend_timer(void)
  19396. +{
  19397. + return 0;
  19398. +}
  19399. +void
  19400. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state)
  19401. +{
  19402. + vchiq_log_info((vchiq_arm_log_level>=VCHIQ_LOG_INFO),"Suspend timer not in use");
  19403. +}
  19404. +void
  19405. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state)
  19406. +{
  19407. + (void)state;
  19408. +}
  19409. +/*
  19410. + * Local functions
  19411. + */
  19412. +
  19413. +static irqreturn_t
  19414. +vchiq_doorbell_irq(int irq, void *dev_id)
  19415. +{
  19416. + VCHIQ_STATE_T *state = dev_id;
  19417. + irqreturn_t ret = IRQ_NONE;
  19418. + unsigned int status;
  19419. +
  19420. + /* Read (and clear) the doorbell */
  19421. + status = readl(__io_address(ARM_0_BELL0));
  19422. +
  19423. + if (status & 0x4) { /* Was the doorbell rung? */
  19424. + remote_event_pollall(state);
  19425. + ret = IRQ_HANDLED;
  19426. + }
  19427. +
  19428. + return ret;
  19429. +}
  19430. +
  19431. +/* There is a potential problem with partial cache lines (pages?)
  19432. +** at the ends of the block when reading. If the CPU accessed anything in
  19433. +** the same line (page?) then it may have pulled old data into the cache,
  19434. +** obscuring the new data underneath. We can solve this by transferring the
  19435. +** partial cache lines separately, and allowing the ARM to copy into the
  19436. +** cached area.
  19437. +
  19438. +** N.B. This implementation plays slightly fast and loose with the Linux
  19439. +** driver programming rules, e.g. its use of __virt_to_bus instead of
  19440. +** dma_map_single, but it isn't a multi-platform driver and it benefits
  19441. +** from increased speed as a result.
  19442. +*/
  19443. +
  19444. +static int
  19445. +create_pagelist(char __user *buf, size_t count, unsigned short type,
  19446. + struct task_struct *task, PAGELIST_T ** ppagelist)
  19447. +{
  19448. + PAGELIST_T *pagelist;
  19449. + struct page **pages;
  19450. + struct page *page;
  19451. + unsigned long *addrs;
  19452. + unsigned int num_pages, offset, i;
  19453. + char *addr, *base_addr, *next_addr;
  19454. + int run, addridx, actual_pages;
  19455. + unsigned long *need_release;
  19456. +
  19457. + offset = (unsigned int)buf & (PAGE_SIZE - 1);
  19458. + num_pages = (count + offset + PAGE_SIZE - 1) / PAGE_SIZE;
  19459. +
  19460. + *ppagelist = NULL;
  19461. +
  19462. + /* Allocate enough storage to hold the page pointers and the page
  19463. + ** list
  19464. + */
  19465. + pagelist = kmalloc(sizeof(PAGELIST_T) +
  19466. + (num_pages * sizeof(unsigned long)) +
  19467. + sizeof(unsigned long) +
  19468. + (num_pages * sizeof(pages[0])),
  19469. + GFP_KERNEL);
  19470. +
  19471. + vchiq_log_trace(vchiq_arm_log_level,
  19472. + "create_pagelist - %x", (unsigned int)pagelist);
  19473. + if (!pagelist)
  19474. + return -ENOMEM;
  19475. +
  19476. + addrs = pagelist->addrs;
  19477. + need_release = (unsigned long *)(addrs + num_pages);
  19478. + pages = (struct page **)(addrs + num_pages + 1);
  19479. +
  19480. + if (is_vmalloc_addr(buf)) {
  19481. + for (actual_pages = 0; actual_pages < num_pages; actual_pages++) {
  19482. + pages[actual_pages] = vmalloc_to_page(buf + (actual_pages * PAGE_SIZE));
  19483. + }
  19484. + *need_release = 0; /* do not try and release vmalloc pages */
  19485. + } else {
  19486. + down_read(&task->mm->mmap_sem);
  19487. + actual_pages = get_user_pages(task, task->mm,
  19488. + (unsigned long)buf & ~(PAGE_SIZE - 1),
  19489. + num_pages,
  19490. + (type == PAGELIST_READ) /*Write */ ,
  19491. + 0 /*Force */ ,
  19492. + pages,
  19493. + NULL /*vmas */);
  19494. + up_read(&task->mm->mmap_sem);
  19495. +
  19496. + if (actual_pages != num_pages) {
  19497. + vchiq_log_info(vchiq_arm_log_level,
  19498. + "create_pagelist - only %d/%d pages locked",
  19499. + actual_pages,
  19500. + num_pages);
  19501. +
  19502. + /* This is probably due to the process being killed */
  19503. + while (actual_pages > 0)
  19504. + {
  19505. + actual_pages--;
  19506. + page_cache_release(pages[actual_pages]);
  19507. + }
  19508. + kfree(pagelist);
  19509. + if (actual_pages == 0)
  19510. + actual_pages = -ENOMEM;
  19511. + return actual_pages;
  19512. + }
  19513. + *need_release = 1; /* release user pages */
  19514. + }
  19515. +
  19516. + pagelist->length = count;
  19517. + pagelist->type = type;
  19518. + pagelist->offset = offset;
  19519. +
  19520. + /* Group the pages into runs of contiguous pages */
  19521. +
  19522. + base_addr = VCHIQ_ARM_ADDRESS(page_address(pages[0]));
  19523. + next_addr = base_addr + PAGE_SIZE;
  19524. + addridx = 0;
  19525. + run = 0;
  19526. +
  19527. + for (i = 1; i < num_pages; i++) {
  19528. + addr = VCHIQ_ARM_ADDRESS(page_address(pages[i]));
  19529. + if ((addr == next_addr) && (run < (PAGE_SIZE - 1))) {
  19530. + next_addr += PAGE_SIZE;
  19531. + run++;
  19532. + } else {
  19533. + addrs[addridx] = (unsigned long)base_addr + run;
  19534. + addridx++;
  19535. + base_addr = addr;
  19536. + next_addr = addr + PAGE_SIZE;
  19537. + run = 0;
  19538. + }
  19539. + }
  19540. +
  19541. + addrs[addridx] = (unsigned long)base_addr + run;
  19542. + addridx++;
  19543. +
  19544. + /* Partial cache lines (fragments) require special measures */
  19545. + if ((type == PAGELIST_READ) &&
  19546. + ((pagelist->offset & (CACHE_LINE_SIZE - 1)) ||
  19547. + ((pagelist->offset + pagelist->length) &
  19548. + (CACHE_LINE_SIZE - 1)))) {
  19549. + FRAGMENTS_T *fragments;
  19550. +
  19551. + if (down_interruptible(&g_free_fragments_sema) != 0) {
  19552. + kfree(pagelist);
  19553. + return -EINTR;
  19554. + }
  19555. +
  19556. + WARN_ON(g_free_fragments == NULL);
  19557. +
  19558. + down(&g_free_fragments_mutex);
  19559. + fragments = (FRAGMENTS_T *) g_free_fragments;
  19560. + WARN_ON(fragments == NULL);
  19561. + g_free_fragments = *(FRAGMENTS_T **) g_free_fragments;
  19562. + up(&g_free_fragments_mutex);
  19563. + pagelist->type =
  19564. + PAGELIST_READ_WITH_FRAGMENTS + (fragments -
  19565. + g_fragments_base);
  19566. + }
  19567. +
  19568. + for (page = virt_to_page(pagelist);
  19569. + page <= virt_to_page(addrs + num_pages - 1); page++) {
  19570. + flush_dcache_page(page);
  19571. + }
  19572. +
  19573. + *ppagelist = pagelist;
  19574. +
  19575. + return 0;
  19576. +}
  19577. +
  19578. +static void
  19579. +free_pagelist(PAGELIST_T *pagelist, int actual)
  19580. +{
  19581. + unsigned long *need_release;
  19582. + struct page **pages;
  19583. + unsigned int num_pages, i;
  19584. +
  19585. + vchiq_log_trace(vchiq_arm_log_level,
  19586. + "free_pagelist - %x, %d", (unsigned int)pagelist, actual);
  19587. +
  19588. + num_pages =
  19589. + (pagelist->length + pagelist->offset + PAGE_SIZE - 1) /
  19590. + PAGE_SIZE;
  19591. +
  19592. + need_release = (unsigned long *)(pagelist->addrs + num_pages);
  19593. + pages = (struct page **)(pagelist->addrs + num_pages + 1);
  19594. +
  19595. + /* Deal with any partial cache lines (fragments) */
  19596. + if (pagelist->type >= PAGELIST_READ_WITH_FRAGMENTS) {
  19597. + FRAGMENTS_T *fragments = g_fragments_base +
  19598. + (pagelist->type - PAGELIST_READ_WITH_FRAGMENTS);
  19599. + int head_bytes, tail_bytes;
  19600. + head_bytes = (CACHE_LINE_SIZE - pagelist->offset) &
  19601. + (CACHE_LINE_SIZE - 1);
  19602. + tail_bytes = (pagelist->offset + actual) &
  19603. + (CACHE_LINE_SIZE - 1);
  19604. +
  19605. + if ((actual >= 0) && (head_bytes != 0)) {
  19606. + if (head_bytes > actual)
  19607. + head_bytes = actual;
  19608. +
  19609. + memcpy((char *)page_address(pages[0]) +
  19610. + pagelist->offset,
  19611. + fragments->headbuf,
  19612. + head_bytes);
  19613. + }
  19614. + if ((actual >= 0) && (head_bytes < actual) &&
  19615. + (tail_bytes != 0)) {
  19616. + memcpy((char *)page_address(pages[num_pages - 1]) +
  19617. + ((pagelist->offset + actual) &
  19618. + (PAGE_SIZE - 1) & ~(CACHE_LINE_SIZE - 1)),
  19619. + fragments->tailbuf, tail_bytes);
  19620. + }
  19621. +
  19622. + down(&g_free_fragments_mutex);
  19623. + *(FRAGMENTS_T **) fragments = g_free_fragments;
  19624. + g_free_fragments = fragments;
  19625. + up(&g_free_fragments_mutex);
  19626. + up(&g_free_fragments_sema);
  19627. + }
  19628. +
  19629. + if (*need_release) {
  19630. + for (i = 0; i < num_pages; i++) {
  19631. + if (pagelist->type != PAGELIST_WRITE)
  19632. + set_page_dirty(pages[i]);
  19633. +
  19634. + page_cache_release(pages[i]);
  19635. + }
  19636. + }
  19637. +
  19638. + kfree(pagelist);
  19639. +}
  19640. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h
  19641. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 1970-01-01 01:00:00.000000000 +0100
  19642. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_2835.h 2014-06-11 21:03:34.000000000 +0200
  19643. @@ -0,0 +1,42 @@
  19644. +/**
  19645. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19646. + *
  19647. + * Redistribution and use in source and binary forms, with or without
  19648. + * modification, are permitted provided that the following conditions
  19649. + * are met:
  19650. + * 1. Redistributions of source code must retain the above copyright
  19651. + * notice, this list of conditions, and the following disclaimer,
  19652. + * without modification.
  19653. + * 2. Redistributions in binary form must reproduce the above copyright
  19654. + * notice, this list of conditions and the following disclaimer in the
  19655. + * documentation and/or other materials provided with the distribution.
  19656. + * 3. The names of the above-listed copyright holders may not be used
  19657. + * to endorse or promote products derived from this software without
  19658. + * specific prior written permission.
  19659. + *
  19660. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19661. + * GNU General Public License ("GPL") version 2, as published by the Free
  19662. + * Software Foundation.
  19663. + *
  19664. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19665. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19666. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19667. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19668. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19669. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19670. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19671. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19672. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19673. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19674. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19675. + */
  19676. +
  19677. +#ifndef VCHIQ_2835_H
  19678. +#define VCHIQ_2835_H
  19679. +
  19680. +#include "vchiq_pagelist.h"
  19681. +
  19682. +#define VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX 0
  19683. +#define VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX 1
  19684. +
  19685. +#endif /* VCHIQ_2835_H */
  19686. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c
  19687. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 1970-01-01 01:00:00.000000000 +0100
  19688. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.c 2014-06-11 21:05:20.000000000 +0200
  19689. @@ -0,0 +1,2814 @@
  19690. +/**
  19691. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  19692. + *
  19693. + * Redistribution and use in source and binary forms, with or without
  19694. + * modification, are permitted provided that the following conditions
  19695. + * are met:
  19696. + * 1. Redistributions of source code must retain the above copyright
  19697. + * notice, this list of conditions, and the following disclaimer,
  19698. + * without modification.
  19699. + * 2. Redistributions in binary form must reproduce the above copyright
  19700. + * notice, this list of conditions and the following disclaimer in the
  19701. + * documentation and/or other materials provided with the distribution.
  19702. + * 3. The names of the above-listed copyright holders may not be used
  19703. + * to endorse or promote products derived from this software without
  19704. + * specific prior written permission.
  19705. + *
  19706. + * ALTERNATIVELY, this software may be distributed under the terms of the
  19707. + * GNU General Public License ("GPL") version 2, as published by the Free
  19708. + * Software Foundation.
  19709. + *
  19710. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  19711. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  19712. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19713. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  19714. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19715. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19716. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  19717. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  19718. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  19719. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  19720. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  19721. + */
  19722. +
  19723. +#include <linux/kernel.h>
  19724. +#include <linux/module.h>
  19725. +#include <linux/types.h>
  19726. +#include <linux/errno.h>
  19727. +#include <linux/cdev.h>
  19728. +#include <linux/fs.h>
  19729. +#include <linux/device.h>
  19730. +#include <linux/mm.h>
  19731. +#include <linux/highmem.h>
  19732. +#include <linux/pagemap.h>
  19733. +#include <linux/bug.h>
  19734. +#include <linux/semaphore.h>
  19735. +#include <linux/list.h>
  19736. +#include <linux/proc_fs.h>
  19737. +
  19738. +#include "vchiq_core.h"
  19739. +#include "vchiq_ioctl.h"
  19740. +#include "vchiq_arm.h"
  19741. +#include "vchiq_killable.h"
  19742. +
  19743. +#define DEVICE_NAME "vchiq"
  19744. +
  19745. +/* Override the default prefix, which would be vchiq_arm (from the filename) */
  19746. +#undef MODULE_PARAM_PREFIX
  19747. +#define MODULE_PARAM_PREFIX DEVICE_NAME "."
  19748. +
  19749. +#define VCHIQ_MINOR 0
  19750. +
  19751. +/* Some per-instance constants */
  19752. +#define MAX_COMPLETIONS 16
  19753. +#define MAX_SERVICES 64
  19754. +#define MAX_ELEMENTS 8
  19755. +#define MSG_QUEUE_SIZE 64
  19756. +
  19757. +#define KEEPALIVE_VER 1
  19758. +#define KEEPALIVE_VER_MIN KEEPALIVE_VER
  19759. +
  19760. +/* Run time control of log level, based on KERN_XXX level. */
  19761. +int vchiq_arm_log_level = VCHIQ_LOG_DEFAULT;
  19762. +int vchiq_susp_log_level = VCHIQ_LOG_ERROR;
  19763. +
  19764. +#define SUSPEND_TIMER_TIMEOUT_MS 100
  19765. +#define SUSPEND_RETRY_TIMER_TIMEOUT_MS 1000
  19766. +
  19767. +#define VC_SUSPEND_NUM_OFFSET 3 /* number of values before idle which are -ve */
  19768. +static const char *const suspend_state_names[] = {
  19769. + "VC_SUSPEND_FORCE_CANCELED",
  19770. + "VC_SUSPEND_REJECTED",
  19771. + "VC_SUSPEND_FAILED",
  19772. + "VC_SUSPEND_IDLE",
  19773. + "VC_SUSPEND_REQUESTED",
  19774. + "VC_SUSPEND_IN_PROGRESS",
  19775. + "VC_SUSPEND_SUSPENDED"
  19776. +};
  19777. +#define VC_RESUME_NUM_OFFSET 1 /* number of values before idle which are -ve */
  19778. +static const char *const resume_state_names[] = {
  19779. + "VC_RESUME_FAILED",
  19780. + "VC_RESUME_IDLE",
  19781. + "VC_RESUME_REQUESTED",
  19782. + "VC_RESUME_IN_PROGRESS",
  19783. + "VC_RESUME_RESUMED"
  19784. +};
  19785. +/* The number of times we allow force suspend to timeout before actually
  19786. +** _forcing_ suspend. This is to cater for SW which fails to release vchiq
  19787. +** correctly - we don't want to prevent ARM suspend indefinitely in this case.
  19788. +*/
  19789. +#define FORCE_SUSPEND_FAIL_MAX 8
  19790. +
  19791. +/* The time in ms allowed for videocore to go idle when force suspend has been
  19792. + * requested */
  19793. +#define FORCE_SUSPEND_TIMEOUT_MS 200
  19794. +
  19795. +
  19796. +static void suspend_timer_callback(unsigned long context);
  19797. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance);
  19798. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance);
  19799. +
  19800. +
  19801. +typedef struct user_service_struct {
  19802. + VCHIQ_SERVICE_T *service;
  19803. + void *userdata;
  19804. + VCHIQ_INSTANCE_T instance;
  19805. + int is_vchi;
  19806. + int dequeue_pending;
  19807. + int message_available_pos;
  19808. + int msg_insert;
  19809. + int msg_remove;
  19810. + struct semaphore insert_event;
  19811. + struct semaphore remove_event;
  19812. + VCHIQ_HEADER_T * msg_queue[MSG_QUEUE_SIZE];
  19813. +} USER_SERVICE_T;
  19814. +
  19815. +struct bulk_waiter_node {
  19816. + struct bulk_waiter bulk_waiter;
  19817. + int pid;
  19818. + struct list_head list;
  19819. +};
  19820. +
  19821. +struct vchiq_instance_struct {
  19822. + VCHIQ_STATE_T *state;
  19823. + VCHIQ_COMPLETION_DATA_T completions[MAX_COMPLETIONS];
  19824. + int completion_insert;
  19825. + int completion_remove;
  19826. + struct semaphore insert_event;
  19827. + struct semaphore remove_event;
  19828. + struct mutex completion_mutex;
  19829. +
  19830. + int connected;
  19831. + int closing;
  19832. + int pid;
  19833. + int mark;
  19834. +
  19835. + struct list_head bulk_waiter_list;
  19836. + struct mutex bulk_waiter_list_mutex;
  19837. +
  19838. + struct proc_dir_entry *proc_entry;
  19839. +};
  19840. +
  19841. +typedef struct dump_context_struct {
  19842. + char __user *buf;
  19843. + size_t actual;
  19844. + size_t space;
  19845. + loff_t offset;
  19846. +} DUMP_CONTEXT_T;
  19847. +
  19848. +static struct cdev vchiq_cdev;
  19849. +static dev_t vchiq_devid;
  19850. +static VCHIQ_STATE_T g_state;
  19851. +static struct class *vchiq_class;
  19852. +static struct device *vchiq_dev;
  19853. +static DEFINE_SPINLOCK(msg_queue_spinlock);
  19854. +
  19855. +static const char *const ioctl_names[] = {
  19856. + "CONNECT",
  19857. + "SHUTDOWN",
  19858. + "CREATE_SERVICE",
  19859. + "REMOVE_SERVICE",
  19860. + "QUEUE_MESSAGE",
  19861. + "QUEUE_BULK_TRANSMIT",
  19862. + "QUEUE_BULK_RECEIVE",
  19863. + "AWAIT_COMPLETION",
  19864. + "DEQUEUE_MESSAGE",
  19865. + "GET_CLIENT_ID",
  19866. + "GET_CONFIG",
  19867. + "CLOSE_SERVICE",
  19868. + "USE_SERVICE",
  19869. + "RELEASE_SERVICE",
  19870. + "SET_SERVICE_OPTION",
  19871. + "DUMP_PHYS_MEM"
  19872. +};
  19873. +
  19874. +vchiq_static_assert((sizeof(ioctl_names)/sizeof(ioctl_names[0])) ==
  19875. + (VCHIQ_IOC_MAX + 1));
  19876. +
  19877. +static void
  19878. +dump_phys_mem(void *virt_addr, uint32_t num_bytes);
  19879. +
  19880. +/****************************************************************************
  19881. +*
  19882. +* add_completion
  19883. +*
  19884. +***************************************************************************/
  19885. +
  19886. +static VCHIQ_STATUS_T
  19887. +add_completion(VCHIQ_INSTANCE_T instance, VCHIQ_REASON_T reason,
  19888. + VCHIQ_HEADER_T *header, USER_SERVICE_T *user_service,
  19889. + void *bulk_userdata)
  19890. +{
  19891. + VCHIQ_COMPLETION_DATA_T *completion;
  19892. + DEBUG_INITIALISE(g_state.local)
  19893. +
  19894. + while (instance->completion_insert ==
  19895. + (instance->completion_remove + MAX_COMPLETIONS)) {
  19896. + /* Out of space - wait for the client */
  19897. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19898. + vchiq_log_trace(vchiq_arm_log_level,
  19899. + "add_completion - completion queue full");
  19900. + DEBUG_COUNT(COMPLETION_QUEUE_FULL_COUNT);
  19901. + if (down_interruptible(&instance->remove_event) != 0) {
  19902. + vchiq_log_info(vchiq_arm_log_level,
  19903. + "service_callback interrupted");
  19904. + return VCHIQ_RETRY;
  19905. + } else if (instance->closing) {
  19906. + vchiq_log_info(vchiq_arm_log_level,
  19907. + "service_callback closing");
  19908. + return VCHIQ_ERROR;
  19909. + }
  19910. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19911. + }
  19912. +
  19913. + completion =
  19914. + &instance->completions[instance->completion_insert &
  19915. + (MAX_COMPLETIONS - 1)];
  19916. +
  19917. + completion->header = header;
  19918. + completion->reason = reason;
  19919. + /* N.B. service_userdata is updated while processing AWAIT_COMPLETION */
  19920. + completion->service_userdata = user_service->service;
  19921. + completion->bulk_userdata = bulk_userdata;
  19922. +
  19923. + if (reason == VCHIQ_SERVICE_CLOSED)
  19924. + /* Take an extra reference, to be held until
  19925. + this CLOSED notification is delivered. */
  19926. + lock_service(user_service->service);
  19927. +
  19928. + /* A write barrier is needed here to ensure that the entire completion
  19929. + record is written out before the insert point. */
  19930. + wmb();
  19931. +
  19932. + if (reason == VCHIQ_MESSAGE_AVAILABLE)
  19933. + user_service->message_available_pos =
  19934. + instance->completion_insert;
  19935. + instance->completion_insert++;
  19936. +
  19937. + up(&instance->insert_event);
  19938. +
  19939. + return VCHIQ_SUCCESS;
  19940. +}
  19941. +
  19942. +/****************************************************************************
  19943. +*
  19944. +* service_callback
  19945. +*
  19946. +***************************************************************************/
  19947. +
  19948. +static VCHIQ_STATUS_T
  19949. +service_callback(VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header,
  19950. + VCHIQ_SERVICE_HANDLE_T handle, void *bulk_userdata)
  19951. +{
  19952. + /* How do we ensure the callback goes to the right client?
  19953. + ** The service_user data points to a USER_SERVICE_T record containing
  19954. + ** the original callback and the user state structure, which contains a
  19955. + ** circular buffer for completion records.
  19956. + */
  19957. + USER_SERVICE_T *user_service;
  19958. + VCHIQ_SERVICE_T *service;
  19959. + VCHIQ_INSTANCE_T instance;
  19960. + DEBUG_INITIALISE(g_state.local)
  19961. +
  19962. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19963. +
  19964. + service = handle_to_service(handle);
  19965. + BUG_ON(!service);
  19966. + user_service = (USER_SERVICE_T *)service->base.userdata;
  19967. + instance = user_service->instance;
  19968. +
  19969. + if (!instance || instance->closing)
  19970. + return VCHIQ_SUCCESS;
  19971. +
  19972. + vchiq_log_trace(vchiq_arm_log_level,
  19973. + "service_callback - service %lx(%d), reason %d, header %lx, "
  19974. + "instance %lx, bulk_userdata %lx",
  19975. + (unsigned long)user_service,
  19976. + service->localport,
  19977. + reason, (unsigned long)header,
  19978. + (unsigned long)instance, (unsigned long)bulk_userdata);
  19979. +
  19980. + if (header && user_service->is_vchi) {
  19981. + spin_lock(&msg_queue_spinlock);
  19982. + while (user_service->msg_insert ==
  19983. + (user_service->msg_remove + MSG_QUEUE_SIZE)) {
  19984. + spin_unlock(&msg_queue_spinlock);
  19985. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19986. + DEBUG_COUNT(MSG_QUEUE_FULL_COUNT);
  19987. + vchiq_log_trace(vchiq_arm_log_level,
  19988. + "service_callback - msg queue full");
  19989. + /* If there is no MESSAGE_AVAILABLE in the completion
  19990. + ** queue, add one
  19991. + */
  19992. + if ((user_service->message_available_pos -
  19993. + instance->completion_remove) < 0) {
  19994. + VCHIQ_STATUS_T status;
  19995. + vchiq_log_info(vchiq_arm_log_level,
  19996. + "Inserting extra MESSAGE_AVAILABLE");
  19997. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  19998. + status = add_completion(instance, reason,
  19999. + NULL, user_service, bulk_userdata);
  20000. + if (status != VCHIQ_SUCCESS) {
  20001. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20002. + return status;
  20003. + }
  20004. + }
  20005. +
  20006. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20007. + if (down_interruptible(&user_service->remove_event)
  20008. + != 0) {
  20009. + vchiq_log_info(vchiq_arm_log_level,
  20010. + "service_callback interrupted");
  20011. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20012. + return VCHIQ_RETRY;
  20013. + } else if (instance->closing) {
  20014. + vchiq_log_info(vchiq_arm_log_level,
  20015. + "service_callback closing");
  20016. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20017. + return VCHIQ_ERROR;
  20018. + }
  20019. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20020. + spin_lock(&msg_queue_spinlock);
  20021. + }
  20022. +
  20023. + user_service->msg_queue[user_service->msg_insert &
  20024. + (MSG_QUEUE_SIZE - 1)] = header;
  20025. + user_service->msg_insert++;
  20026. + spin_unlock(&msg_queue_spinlock);
  20027. +
  20028. + up(&user_service->insert_event);
  20029. +
  20030. + /* If there is a thread waiting in DEQUEUE_MESSAGE, or if
  20031. + ** there is a MESSAGE_AVAILABLE in the completion queue then
  20032. + ** bypass the completion queue.
  20033. + */
  20034. + if (((user_service->message_available_pos -
  20035. + instance->completion_remove) >= 0) ||
  20036. + user_service->dequeue_pending) {
  20037. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20038. + user_service->dequeue_pending = 0;
  20039. + return VCHIQ_SUCCESS;
  20040. + }
  20041. +
  20042. + header = NULL;
  20043. + }
  20044. + DEBUG_TRACE(SERVICE_CALLBACK_LINE);
  20045. +
  20046. + return add_completion(instance, reason, header, user_service,
  20047. + bulk_userdata);
  20048. +}
  20049. +
  20050. +/****************************************************************************
  20051. +*
  20052. +* user_service_free
  20053. +*
  20054. +***************************************************************************/
  20055. +static void
  20056. +user_service_free(void *userdata)
  20057. +{
  20058. + kfree(userdata);
  20059. +}
  20060. +
  20061. +/****************************************************************************
  20062. +*
  20063. +* vchiq_ioctl
  20064. +*
  20065. +***************************************************************************/
  20066. +
  20067. +static long
  20068. +vchiq_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  20069. +{
  20070. + VCHIQ_INSTANCE_T instance = file->private_data;
  20071. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  20072. + VCHIQ_SERVICE_T *service = NULL;
  20073. + long ret = 0;
  20074. + int i, rc;
  20075. + DEBUG_INITIALISE(g_state.local)
  20076. +
  20077. + vchiq_log_trace(vchiq_arm_log_level,
  20078. + "vchiq_ioctl - instance %x, cmd %s, arg %lx",
  20079. + (unsigned int)instance,
  20080. + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) &&
  20081. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ?
  20082. + ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg);
  20083. +
  20084. + switch (cmd) {
  20085. + case VCHIQ_IOC_SHUTDOWN:
  20086. + if (!instance->connected)
  20087. + break;
  20088. +
  20089. + /* Remove all services */
  20090. + i = 0;
  20091. + while ((service = next_service_by_instance(instance->state,
  20092. + instance, &i)) != NULL) {
  20093. + status = vchiq_remove_service(service->handle);
  20094. + unlock_service(service);
  20095. + if (status != VCHIQ_SUCCESS)
  20096. + break;
  20097. + }
  20098. + service = NULL;
  20099. +
  20100. + if (status == VCHIQ_SUCCESS) {
  20101. + /* Wake the completion thread and ask it to exit */
  20102. + instance->closing = 1;
  20103. + up(&instance->insert_event);
  20104. + }
  20105. +
  20106. + break;
  20107. +
  20108. + case VCHIQ_IOC_CONNECT:
  20109. + if (instance->connected) {
  20110. + ret = -EINVAL;
  20111. + break;
  20112. + }
  20113. + rc = mutex_lock_interruptible(&instance->state->mutex);
  20114. + if (rc != 0) {
  20115. + vchiq_log_error(vchiq_arm_log_level,
  20116. + "vchiq: connect: could not lock mutex for "
  20117. + "state %d: %d",
  20118. + instance->state->id, rc);
  20119. + ret = -EINTR;
  20120. + break;
  20121. + }
  20122. + status = vchiq_connect_internal(instance->state, instance);
  20123. + mutex_unlock(&instance->state->mutex);
  20124. +
  20125. + if (status == VCHIQ_SUCCESS)
  20126. + instance->connected = 1;
  20127. + else
  20128. + vchiq_log_error(vchiq_arm_log_level,
  20129. + "vchiq: could not connect: %d", status);
  20130. + break;
  20131. +
  20132. + case VCHIQ_IOC_CREATE_SERVICE: {
  20133. + VCHIQ_CREATE_SERVICE_T args;
  20134. + USER_SERVICE_T *user_service = NULL;
  20135. + void *userdata;
  20136. + int srvstate;
  20137. +
  20138. + if (copy_from_user
  20139. + (&args, (const void __user *)arg,
  20140. + sizeof(args)) != 0) {
  20141. + ret = -EFAULT;
  20142. + break;
  20143. + }
  20144. +
  20145. + user_service = kmalloc(sizeof(USER_SERVICE_T), GFP_KERNEL);
  20146. + if (!user_service) {
  20147. + ret = -ENOMEM;
  20148. + break;
  20149. + }
  20150. +
  20151. + if (args.is_open) {
  20152. + if (!instance->connected) {
  20153. + ret = -ENOTCONN;
  20154. + kfree(user_service);
  20155. + break;
  20156. + }
  20157. + srvstate = VCHIQ_SRVSTATE_OPENING;
  20158. + } else {
  20159. + srvstate =
  20160. + instance->connected ?
  20161. + VCHIQ_SRVSTATE_LISTENING :
  20162. + VCHIQ_SRVSTATE_HIDDEN;
  20163. + }
  20164. +
  20165. + userdata = args.params.userdata;
  20166. + args.params.callback = service_callback;
  20167. + args.params.userdata = user_service;
  20168. + service = vchiq_add_service_internal(
  20169. + instance->state,
  20170. + &args.params, srvstate,
  20171. + instance, user_service_free);
  20172. +
  20173. + if (service != NULL) {
  20174. + user_service->service = service;
  20175. + user_service->userdata = userdata;
  20176. + user_service->instance = instance;
  20177. + user_service->is_vchi = args.is_vchi;
  20178. + user_service->dequeue_pending = 0;
  20179. + user_service->message_available_pos =
  20180. + instance->completion_remove - 1;
  20181. + user_service->msg_insert = 0;
  20182. + user_service->msg_remove = 0;
  20183. + sema_init(&user_service->insert_event, 0);
  20184. + sema_init(&user_service->remove_event, 0);
  20185. +
  20186. + if (args.is_open) {
  20187. + status = vchiq_open_service_internal
  20188. + (service, instance->pid);
  20189. + if (status != VCHIQ_SUCCESS) {
  20190. + vchiq_remove_service(service->handle);
  20191. + service = NULL;
  20192. + ret = (status == VCHIQ_RETRY) ?
  20193. + -EINTR : -EIO;
  20194. + break;
  20195. + }
  20196. + }
  20197. +
  20198. + if (copy_to_user((void __user *)
  20199. + &(((VCHIQ_CREATE_SERVICE_T __user *)
  20200. + arg)->handle),
  20201. + (const void *)&service->handle,
  20202. + sizeof(service->handle)) != 0) {
  20203. + ret = -EFAULT;
  20204. + vchiq_remove_service(service->handle);
  20205. + }
  20206. +
  20207. + service = NULL;
  20208. + } else {
  20209. + ret = -EEXIST;
  20210. + kfree(user_service);
  20211. + }
  20212. + } break;
  20213. +
  20214. + case VCHIQ_IOC_CLOSE_SERVICE: {
  20215. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20216. +
  20217. + service = find_service_for_instance(instance, handle);
  20218. + if (service != NULL)
  20219. + status = vchiq_close_service(service->handle);
  20220. + else
  20221. + ret = -EINVAL;
  20222. + } break;
  20223. +
  20224. + case VCHIQ_IOC_REMOVE_SERVICE: {
  20225. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20226. +
  20227. + service = find_service_for_instance(instance, handle);
  20228. + if (service != NULL)
  20229. + status = vchiq_remove_service(service->handle);
  20230. + else
  20231. + ret = -EINVAL;
  20232. + } break;
  20233. +
  20234. + case VCHIQ_IOC_USE_SERVICE:
  20235. + case VCHIQ_IOC_RELEASE_SERVICE: {
  20236. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20237. +
  20238. + service = find_service_for_instance(instance, handle);
  20239. + if (service != NULL) {
  20240. + status = (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20241. + vchiq_use_service_internal(service) :
  20242. + vchiq_release_service_internal(service);
  20243. + if (status != VCHIQ_SUCCESS) {
  20244. + vchiq_log_error(vchiq_susp_log_level,
  20245. + "%s: cmd %s returned error %d for "
  20246. + "service %c%c%c%c:%03d",
  20247. + __func__,
  20248. + (cmd == VCHIQ_IOC_USE_SERVICE) ?
  20249. + "VCHIQ_IOC_USE_SERVICE" :
  20250. + "VCHIQ_IOC_RELEASE_SERVICE",
  20251. + status,
  20252. + VCHIQ_FOURCC_AS_4CHARS(
  20253. + service->base.fourcc),
  20254. + service->client_id);
  20255. + ret = -EINVAL;
  20256. + }
  20257. + } else
  20258. + ret = -EINVAL;
  20259. + } break;
  20260. +
  20261. + case VCHIQ_IOC_QUEUE_MESSAGE: {
  20262. + VCHIQ_QUEUE_MESSAGE_T args;
  20263. + if (copy_from_user
  20264. + (&args, (const void __user *)arg,
  20265. + sizeof(args)) != 0) {
  20266. + ret = -EFAULT;
  20267. + break;
  20268. + }
  20269. +
  20270. + service = find_service_for_instance(instance, args.handle);
  20271. +
  20272. + if ((service != NULL) && (args.count <= MAX_ELEMENTS)) {
  20273. + /* Copy elements into kernel space */
  20274. + VCHIQ_ELEMENT_T elements[MAX_ELEMENTS];
  20275. + if (copy_from_user(elements, args.elements,
  20276. + args.count * sizeof(VCHIQ_ELEMENT_T)) == 0)
  20277. + status = vchiq_queue_message
  20278. + (args.handle,
  20279. + elements, args.count);
  20280. + else
  20281. + ret = -EFAULT;
  20282. + } else {
  20283. + ret = -EINVAL;
  20284. + }
  20285. + } break;
  20286. +
  20287. + case VCHIQ_IOC_QUEUE_BULK_TRANSMIT:
  20288. + case VCHIQ_IOC_QUEUE_BULK_RECEIVE: {
  20289. + VCHIQ_QUEUE_BULK_TRANSFER_T args;
  20290. + struct bulk_waiter_node *waiter = NULL;
  20291. + VCHIQ_BULK_DIR_T dir =
  20292. + (cmd == VCHIQ_IOC_QUEUE_BULK_TRANSMIT) ?
  20293. + VCHIQ_BULK_TRANSMIT : VCHIQ_BULK_RECEIVE;
  20294. +
  20295. + if (copy_from_user
  20296. + (&args, (const void __user *)arg,
  20297. + sizeof(args)) != 0) {
  20298. + ret = -EFAULT;
  20299. + break;
  20300. + }
  20301. +
  20302. + service = find_service_for_instance(instance, args.handle);
  20303. + if (!service) {
  20304. + ret = -EINVAL;
  20305. + break;
  20306. + }
  20307. +
  20308. + if (args.mode == VCHIQ_BULK_MODE_BLOCKING) {
  20309. + waiter = kzalloc(sizeof(struct bulk_waiter_node),
  20310. + GFP_KERNEL);
  20311. + if (!waiter) {
  20312. + ret = -ENOMEM;
  20313. + break;
  20314. + }
  20315. + args.userdata = &waiter->bulk_waiter;
  20316. + } else if (args.mode == VCHIQ_BULK_MODE_WAITING) {
  20317. + struct list_head *pos;
  20318. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20319. + list_for_each(pos, &instance->bulk_waiter_list) {
  20320. + if (list_entry(pos, struct bulk_waiter_node,
  20321. + list)->pid == current->pid) {
  20322. + waiter = list_entry(pos,
  20323. + struct bulk_waiter_node,
  20324. + list);
  20325. + list_del(pos);
  20326. + break;
  20327. + }
  20328. +
  20329. + }
  20330. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20331. + if (!waiter) {
  20332. + vchiq_log_error(vchiq_arm_log_level,
  20333. + "no bulk_waiter found for pid %d",
  20334. + current->pid);
  20335. + ret = -ESRCH;
  20336. + break;
  20337. + }
  20338. + vchiq_log_info(vchiq_arm_log_level,
  20339. + "found bulk_waiter %x for pid %d",
  20340. + (unsigned int)waiter, current->pid);
  20341. + args.userdata = &waiter->bulk_waiter;
  20342. + }
  20343. + status = vchiq_bulk_transfer
  20344. + (args.handle,
  20345. + VCHI_MEM_HANDLE_INVALID,
  20346. + args.data, args.size,
  20347. + args.userdata, args.mode,
  20348. + dir);
  20349. + if (!waiter)
  20350. + break;
  20351. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  20352. + !waiter->bulk_waiter.bulk) {
  20353. + if (waiter->bulk_waiter.bulk) {
  20354. + /* Cancel the signal when the transfer
  20355. + ** completes. */
  20356. + spin_lock(&bulk_waiter_spinlock);
  20357. + waiter->bulk_waiter.bulk->userdata = NULL;
  20358. + spin_unlock(&bulk_waiter_spinlock);
  20359. + }
  20360. + kfree(waiter);
  20361. + } else {
  20362. + const VCHIQ_BULK_MODE_T mode_waiting =
  20363. + VCHIQ_BULK_MODE_WAITING;
  20364. + waiter->pid = current->pid;
  20365. + mutex_lock(&instance->bulk_waiter_list_mutex);
  20366. + list_add(&waiter->list, &instance->bulk_waiter_list);
  20367. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  20368. + vchiq_log_info(vchiq_arm_log_level,
  20369. + "saved bulk_waiter %x for pid %d",
  20370. + (unsigned int)waiter, current->pid);
  20371. +
  20372. + if (copy_to_user((void __user *)
  20373. + &(((VCHIQ_QUEUE_BULK_TRANSFER_T __user *)
  20374. + arg)->mode),
  20375. + (const void *)&mode_waiting,
  20376. + sizeof(mode_waiting)) != 0)
  20377. + ret = -EFAULT;
  20378. + }
  20379. + } break;
  20380. +
  20381. + case VCHIQ_IOC_AWAIT_COMPLETION: {
  20382. + VCHIQ_AWAIT_COMPLETION_T args;
  20383. +
  20384. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20385. + if (!instance->connected) {
  20386. + ret = -ENOTCONN;
  20387. + break;
  20388. + }
  20389. +
  20390. + if (copy_from_user(&args, (const void __user *)arg,
  20391. + sizeof(args)) != 0) {
  20392. + ret = -EFAULT;
  20393. + break;
  20394. + }
  20395. +
  20396. + mutex_lock(&instance->completion_mutex);
  20397. +
  20398. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20399. + while ((instance->completion_remove ==
  20400. + instance->completion_insert)
  20401. + && !instance->closing) {
  20402. + int rc;
  20403. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20404. + mutex_unlock(&instance->completion_mutex);
  20405. + rc = down_interruptible(&instance->insert_event);
  20406. + mutex_lock(&instance->completion_mutex);
  20407. + if (rc != 0) {
  20408. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20409. + vchiq_log_info(vchiq_arm_log_level,
  20410. + "AWAIT_COMPLETION interrupted");
  20411. + ret = -EINTR;
  20412. + break;
  20413. + }
  20414. + }
  20415. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20416. +
  20417. + /* A read memory barrier is needed to stop prefetch of a stale
  20418. + ** completion record
  20419. + */
  20420. + rmb();
  20421. +
  20422. + if (ret == 0) {
  20423. + int msgbufcount = args.msgbufcount;
  20424. + for (ret = 0; ret < args.count; ret++) {
  20425. + VCHIQ_COMPLETION_DATA_T *completion;
  20426. + VCHIQ_SERVICE_T *service;
  20427. + USER_SERVICE_T *user_service;
  20428. + VCHIQ_HEADER_T *header;
  20429. + if (instance->completion_remove ==
  20430. + instance->completion_insert)
  20431. + break;
  20432. + completion = &instance->completions[
  20433. + instance->completion_remove &
  20434. + (MAX_COMPLETIONS - 1)];
  20435. +
  20436. + service = completion->service_userdata;
  20437. + user_service = service->base.userdata;
  20438. + completion->service_userdata =
  20439. + user_service->userdata;
  20440. +
  20441. + header = completion->header;
  20442. + if (header) {
  20443. + void __user *msgbuf;
  20444. + int msglen;
  20445. +
  20446. + msglen = header->size +
  20447. + sizeof(VCHIQ_HEADER_T);
  20448. + /* This must be a VCHIQ-style service */
  20449. + if (args.msgbufsize < msglen) {
  20450. + vchiq_log_error(
  20451. + vchiq_arm_log_level,
  20452. + "header %x: msgbufsize"
  20453. + " %x < msglen %x",
  20454. + (unsigned int)header,
  20455. + args.msgbufsize,
  20456. + msglen);
  20457. + WARN(1, "invalid message "
  20458. + "size\n");
  20459. + if (ret == 0)
  20460. + ret = -EMSGSIZE;
  20461. + break;
  20462. + }
  20463. + if (msgbufcount <= 0)
  20464. + /* Stall here for lack of a
  20465. + ** buffer for the message. */
  20466. + break;
  20467. + /* Get the pointer from user space */
  20468. + msgbufcount--;
  20469. + if (copy_from_user(&msgbuf,
  20470. + (const void __user *)
  20471. + &args.msgbufs[msgbufcount],
  20472. + sizeof(msgbuf)) != 0) {
  20473. + if (ret == 0)
  20474. + ret = -EFAULT;
  20475. + break;
  20476. + }
  20477. +
  20478. + /* Copy the message to user space */
  20479. + if (copy_to_user(msgbuf, header,
  20480. + msglen) != 0) {
  20481. + if (ret == 0)
  20482. + ret = -EFAULT;
  20483. + break;
  20484. + }
  20485. +
  20486. + /* Now it has been copied, the message
  20487. + ** can be released. */
  20488. + vchiq_release_message(service->handle,
  20489. + header);
  20490. +
  20491. + /* The completion must point to the
  20492. + ** msgbuf. */
  20493. + completion->header = msgbuf;
  20494. + }
  20495. +
  20496. + if (completion->reason ==
  20497. + VCHIQ_SERVICE_CLOSED)
  20498. + unlock_service(service);
  20499. +
  20500. + if (copy_to_user((void __user *)(
  20501. + (size_t)args.buf +
  20502. + ret * sizeof(VCHIQ_COMPLETION_DATA_T)),
  20503. + completion,
  20504. + sizeof(VCHIQ_COMPLETION_DATA_T)) != 0) {
  20505. + if (ret == 0)
  20506. + ret = -EFAULT;
  20507. + break;
  20508. + }
  20509. +
  20510. + instance->completion_remove++;
  20511. + }
  20512. +
  20513. + if (msgbufcount != args.msgbufcount) {
  20514. + if (copy_to_user((void __user *)
  20515. + &((VCHIQ_AWAIT_COMPLETION_T *)arg)->
  20516. + msgbufcount,
  20517. + &msgbufcount,
  20518. + sizeof(msgbufcount)) != 0) {
  20519. + ret = -EFAULT;
  20520. + }
  20521. + }
  20522. + }
  20523. +
  20524. + if (ret != 0)
  20525. + up(&instance->remove_event);
  20526. + mutex_unlock(&instance->completion_mutex);
  20527. + DEBUG_TRACE(AWAIT_COMPLETION_LINE);
  20528. + } break;
  20529. +
  20530. + case VCHIQ_IOC_DEQUEUE_MESSAGE: {
  20531. + VCHIQ_DEQUEUE_MESSAGE_T args;
  20532. + USER_SERVICE_T *user_service;
  20533. + VCHIQ_HEADER_T *header;
  20534. +
  20535. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20536. + if (copy_from_user
  20537. + (&args, (const void __user *)arg,
  20538. + sizeof(args)) != 0) {
  20539. + ret = -EFAULT;
  20540. + break;
  20541. + }
  20542. + service = find_service_for_instance(instance, args.handle);
  20543. + if (!service) {
  20544. + ret = -EINVAL;
  20545. + break;
  20546. + }
  20547. + user_service = (USER_SERVICE_T *)service->base.userdata;
  20548. + if (user_service->is_vchi == 0) {
  20549. + ret = -EINVAL;
  20550. + break;
  20551. + }
  20552. +
  20553. + spin_lock(&msg_queue_spinlock);
  20554. + if (user_service->msg_remove == user_service->msg_insert) {
  20555. + if (!args.blocking) {
  20556. + spin_unlock(&msg_queue_spinlock);
  20557. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20558. + ret = -EWOULDBLOCK;
  20559. + break;
  20560. + }
  20561. + user_service->dequeue_pending = 1;
  20562. + do {
  20563. + spin_unlock(&msg_queue_spinlock);
  20564. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20565. + if (down_interruptible(
  20566. + &user_service->insert_event) != 0) {
  20567. + vchiq_log_info(vchiq_arm_log_level,
  20568. + "DEQUEUE_MESSAGE interrupted");
  20569. + ret = -EINTR;
  20570. + break;
  20571. + }
  20572. + spin_lock(&msg_queue_spinlock);
  20573. + } while (user_service->msg_remove ==
  20574. + user_service->msg_insert);
  20575. +
  20576. + if (ret)
  20577. + break;
  20578. + }
  20579. +
  20580. + BUG_ON((int)(user_service->msg_insert -
  20581. + user_service->msg_remove) < 0);
  20582. +
  20583. + header = user_service->msg_queue[user_service->msg_remove &
  20584. + (MSG_QUEUE_SIZE - 1)];
  20585. + user_service->msg_remove++;
  20586. + spin_unlock(&msg_queue_spinlock);
  20587. +
  20588. + up(&user_service->remove_event);
  20589. + if (header == NULL)
  20590. + ret = -ENOTCONN;
  20591. + else if (header->size <= args.bufsize) {
  20592. + /* Copy to user space if msgbuf is not NULL */
  20593. + if ((args.buf == NULL) ||
  20594. + (copy_to_user((void __user *)args.buf,
  20595. + header->data,
  20596. + header->size) == 0)) {
  20597. + ret = header->size;
  20598. + vchiq_release_message(
  20599. + service->handle,
  20600. + header);
  20601. + } else
  20602. + ret = -EFAULT;
  20603. + } else {
  20604. + vchiq_log_error(vchiq_arm_log_level,
  20605. + "header %x: bufsize %x < size %x",
  20606. + (unsigned int)header, args.bufsize,
  20607. + header->size);
  20608. + WARN(1, "invalid size\n");
  20609. + ret = -EMSGSIZE;
  20610. + }
  20611. + DEBUG_TRACE(DEQUEUE_MESSAGE_LINE);
  20612. + } break;
  20613. +
  20614. + case VCHIQ_IOC_GET_CLIENT_ID: {
  20615. + VCHIQ_SERVICE_HANDLE_T handle = (VCHIQ_SERVICE_HANDLE_T)arg;
  20616. +
  20617. + ret = vchiq_get_client_id(handle);
  20618. + } break;
  20619. +
  20620. + case VCHIQ_IOC_GET_CONFIG: {
  20621. + VCHIQ_GET_CONFIG_T args;
  20622. + VCHIQ_CONFIG_T config;
  20623. +
  20624. + if (copy_from_user(&args, (const void __user *)arg,
  20625. + sizeof(args)) != 0) {
  20626. + ret = -EFAULT;
  20627. + break;
  20628. + }
  20629. + if (args.config_size > sizeof(config)) {
  20630. + ret = -EINVAL;
  20631. + break;
  20632. + }
  20633. + status = vchiq_get_config(instance, args.config_size, &config);
  20634. + if (status == VCHIQ_SUCCESS) {
  20635. + if (copy_to_user((void __user *)args.pconfig,
  20636. + &config, args.config_size) != 0) {
  20637. + ret = -EFAULT;
  20638. + break;
  20639. + }
  20640. + }
  20641. + } break;
  20642. +
  20643. + case VCHIQ_IOC_SET_SERVICE_OPTION: {
  20644. + VCHIQ_SET_SERVICE_OPTION_T args;
  20645. +
  20646. + if (copy_from_user(
  20647. + &args, (const void __user *)arg,
  20648. + sizeof(args)) != 0) {
  20649. + ret = -EFAULT;
  20650. + break;
  20651. + }
  20652. +
  20653. + service = find_service_for_instance(instance, args.handle);
  20654. + if (!service) {
  20655. + ret = -EINVAL;
  20656. + break;
  20657. + }
  20658. +
  20659. + status = vchiq_set_service_option(
  20660. + args.handle, args.option, args.value);
  20661. + } break;
  20662. +
  20663. + case VCHIQ_IOC_DUMP_PHYS_MEM: {
  20664. + VCHIQ_DUMP_MEM_T args;
  20665. +
  20666. + if (copy_from_user
  20667. + (&args, (const void __user *)arg,
  20668. + sizeof(args)) != 0) {
  20669. + ret = -EFAULT;
  20670. + break;
  20671. + }
  20672. + dump_phys_mem(args.virt_addr, args.num_bytes);
  20673. + } break;
  20674. +
  20675. + default:
  20676. + ret = -ENOTTY;
  20677. + break;
  20678. + }
  20679. +
  20680. + if (service)
  20681. + unlock_service(service);
  20682. +
  20683. + if (ret == 0) {
  20684. + if (status == VCHIQ_ERROR)
  20685. + ret = -EIO;
  20686. + else if (status == VCHIQ_RETRY)
  20687. + ret = -EINTR;
  20688. + }
  20689. +
  20690. + if ((status == VCHIQ_SUCCESS) && (ret < 0) && (ret != -EINTR) &&
  20691. + (ret != -EWOULDBLOCK))
  20692. + vchiq_log_info(vchiq_arm_log_level,
  20693. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20694. + (unsigned long)instance,
  20695. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20696. + ioctl_names[_IOC_NR(cmd)] :
  20697. + "<invalid>",
  20698. + status, ret);
  20699. + else
  20700. + vchiq_log_trace(vchiq_arm_log_level,
  20701. + " ioctl instance %lx, cmd %s -> status %d, %ld",
  20702. + (unsigned long)instance,
  20703. + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX) ?
  20704. + ioctl_names[_IOC_NR(cmd)] :
  20705. + "<invalid>",
  20706. + status, ret);
  20707. +
  20708. + return ret;
  20709. +}
  20710. +
  20711. +/****************************************************************************
  20712. +*
  20713. +* vchiq_open
  20714. +*
  20715. +***************************************************************************/
  20716. +
  20717. +static int
  20718. +vchiq_open(struct inode *inode, struct file *file)
  20719. +{
  20720. + int dev = iminor(inode) & 0x0f;
  20721. + vchiq_log_info(vchiq_arm_log_level, "vchiq_open");
  20722. + switch (dev) {
  20723. + case VCHIQ_MINOR: {
  20724. + int ret;
  20725. + VCHIQ_STATE_T *state = vchiq_get_state();
  20726. + VCHIQ_INSTANCE_T instance;
  20727. +
  20728. + if (!state) {
  20729. + vchiq_log_error(vchiq_arm_log_level,
  20730. + "vchiq has no connection to VideoCore");
  20731. + return -ENOTCONN;
  20732. + }
  20733. +
  20734. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  20735. + if (!instance)
  20736. + return -ENOMEM;
  20737. +
  20738. + instance->state = state;
  20739. + instance->pid = current->tgid;
  20740. +
  20741. + ret = vchiq_proc_add_instance(instance);
  20742. + if (ret != 0) {
  20743. + kfree(instance);
  20744. + return ret;
  20745. + }
  20746. +
  20747. + sema_init(&instance->insert_event, 0);
  20748. + sema_init(&instance->remove_event, 0);
  20749. + mutex_init(&instance->completion_mutex);
  20750. + mutex_init(&instance->bulk_waiter_list_mutex);
  20751. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  20752. +
  20753. + file->private_data = instance;
  20754. + } break;
  20755. +
  20756. + default:
  20757. + vchiq_log_error(vchiq_arm_log_level,
  20758. + "Unknown minor device: %d", dev);
  20759. + return -ENXIO;
  20760. + }
  20761. +
  20762. + return 0;
  20763. +}
  20764. +
  20765. +/****************************************************************************
  20766. +*
  20767. +* vchiq_release
  20768. +*
  20769. +***************************************************************************/
  20770. +
  20771. +static int
  20772. +vchiq_release(struct inode *inode, struct file *file)
  20773. +{
  20774. + int dev = iminor(inode) & 0x0f;
  20775. + int ret = 0;
  20776. + switch (dev) {
  20777. + case VCHIQ_MINOR: {
  20778. + VCHIQ_INSTANCE_T instance = file->private_data;
  20779. + VCHIQ_STATE_T *state = vchiq_get_state();
  20780. + VCHIQ_SERVICE_T *service;
  20781. + int i;
  20782. +
  20783. + vchiq_log_info(vchiq_arm_log_level,
  20784. + "vchiq_release: instance=%lx",
  20785. + (unsigned long)instance);
  20786. +
  20787. + if (!state) {
  20788. + ret = -EPERM;
  20789. + goto out;
  20790. + }
  20791. +
  20792. + /* Ensure videocore is awake to allow termination. */
  20793. + vchiq_use_internal(instance->state, NULL,
  20794. + USE_TYPE_VCHIQ);
  20795. +
  20796. + mutex_lock(&instance->completion_mutex);
  20797. +
  20798. + /* Wake the completion thread and ask it to exit */
  20799. + instance->closing = 1;
  20800. + up(&instance->insert_event);
  20801. +
  20802. + mutex_unlock(&instance->completion_mutex);
  20803. +
  20804. + /* Wake the slot handler if the completion queue is full. */
  20805. + up(&instance->remove_event);
  20806. +
  20807. + /* Mark all services for termination... */
  20808. + i = 0;
  20809. + while ((service = next_service_by_instance(state, instance,
  20810. + &i)) != NULL) {
  20811. + USER_SERVICE_T *user_service = service->base.userdata;
  20812. +
  20813. + /* Wake the slot handler if the msg queue is full. */
  20814. + up(&user_service->remove_event);
  20815. +
  20816. + vchiq_terminate_service_internal(service);
  20817. + unlock_service(service);
  20818. + }
  20819. +
  20820. + /* ...and wait for them to die */
  20821. + i = 0;
  20822. + while ((service = next_service_by_instance(state, instance, &i))
  20823. + != NULL) {
  20824. + USER_SERVICE_T *user_service = service->base.userdata;
  20825. +
  20826. + down(&service->remove_event);
  20827. +
  20828. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  20829. +
  20830. + spin_lock(&msg_queue_spinlock);
  20831. +
  20832. + while (user_service->msg_remove !=
  20833. + user_service->msg_insert) {
  20834. + VCHIQ_HEADER_T *header = user_service->
  20835. + msg_queue[user_service->msg_remove &
  20836. + (MSG_QUEUE_SIZE - 1)];
  20837. + user_service->msg_remove++;
  20838. + spin_unlock(&msg_queue_spinlock);
  20839. +
  20840. + if (header)
  20841. + vchiq_release_message(
  20842. + service->handle,
  20843. + header);
  20844. + spin_lock(&msg_queue_spinlock);
  20845. + }
  20846. +
  20847. + spin_unlock(&msg_queue_spinlock);
  20848. +
  20849. + unlock_service(service);
  20850. + }
  20851. +
  20852. + /* Release any closed services */
  20853. + while (instance->completion_remove !=
  20854. + instance->completion_insert) {
  20855. + VCHIQ_COMPLETION_DATA_T *completion;
  20856. + VCHIQ_SERVICE_T *service;
  20857. + completion = &instance->completions[
  20858. + instance->completion_remove &
  20859. + (MAX_COMPLETIONS - 1)];
  20860. + service = completion->service_userdata;
  20861. + if (completion->reason == VCHIQ_SERVICE_CLOSED)
  20862. + unlock_service(service);
  20863. + instance->completion_remove++;
  20864. + }
  20865. +
  20866. + /* Release the PEER service count. */
  20867. + vchiq_release_internal(instance->state, NULL);
  20868. +
  20869. + {
  20870. + struct list_head *pos, *next;
  20871. + list_for_each_safe(pos, next,
  20872. + &instance->bulk_waiter_list) {
  20873. + struct bulk_waiter_node *waiter;
  20874. + waiter = list_entry(pos,
  20875. + struct bulk_waiter_node,
  20876. + list);
  20877. + list_del(pos);
  20878. + vchiq_log_info(vchiq_arm_log_level,
  20879. + "bulk_waiter - cleaned up %x "
  20880. + "for pid %d",
  20881. + (unsigned int)waiter, waiter->pid);
  20882. + kfree(waiter);
  20883. + }
  20884. + }
  20885. +
  20886. + vchiq_proc_remove_instance(instance);
  20887. +
  20888. + kfree(instance);
  20889. + file->private_data = NULL;
  20890. + } break;
  20891. +
  20892. + default:
  20893. + vchiq_log_error(vchiq_arm_log_level,
  20894. + "Unknown minor device: %d", dev);
  20895. + ret = -ENXIO;
  20896. + }
  20897. +
  20898. +out:
  20899. + return ret;
  20900. +}
  20901. +
  20902. +/****************************************************************************
  20903. +*
  20904. +* vchiq_dump
  20905. +*
  20906. +***************************************************************************/
  20907. +
  20908. +void
  20909. +vchiq_dump(void *dump_context, const char *str, int len)
  20910. +{
  20911. + DUMP_CONTEXT_T *context = (DUMP_CONTEXT_T *)dump_context;
  20912. +
  20913. + if (context->actual < context->space) {
  20914. + int copy_bytes;
  20915. + if (context->offset > 0) {
  20916. + int skip_bytes = min(len, (int)context->offset);
  20917. + str += skip_bytes;
  20918. + len -= skip_bytes;
  20919. + context->offset -= skip_bytes;
  20920. + if (context->offset > 0)
  20921. + return;
  20922. + }
  20923. + copy_bytes = min(len, (int)(context->space - context->actual));
  20924. + if (copy_bytes == 0)
  20925. + return;
  20926. + if (copy_to_user(context->buf + context->actual, str,
  20927. + copy_bytes))
  20928. + context->actual = -EFAULT;
  20929. + context->actual += copy_bytes;
  20930. + len -= copy_bytes;
  20931. +
  20932. + /* If tne terminating NUL is included in the length, then it
  20933. + ** marks the end of a line and should be replaced with a
  20934. + ** carriage return. */
  20935. + if ((len == 0) && (str[copy_bytes - 1] == '\0')) {
  20936. + char cr = '\n';
  20937. + if (copy_to_user(context->buf + context->actual - 1,
  20938. + &cr, 1))
  20939. + context->actual = -EFAULT;
  20940. + }
  20941. + }
  20942. +}
  20943. +
  20944. +/****************************************************************************
  20945. +*
  20946. +* vchiq_dump_platform_instance_state
  20947. +*
  20948. +***************************************************************************/
  20949. +
  20950. +void
  20951. +vchiq_dump_platform_instances(void *dump_context)
  20952. +{
  20953. + VCHIQ_STATE_T *state = vchiq_get_state();
  20954. + char buf[80];
  20955. + int len;
  20956. + int i;
  20957. +
  20958. + /* There is no list of instances, so instead scan all services,
  20959. + marking those that have been dumped. */
  20960. +
  20961. + for (i = 0; i < state->unused_service; i++) {
  20962. + VCHIQ_SERVICE_T *service = state->services[i];
  20963. + VCHIQ_INSTANCE_T instance;
  20964. +
  20965. + if (service && (service->base.callback == service_callback)) {
  20966. + instance = service->instance;
  20967. + if (instance)
  20968. + instance->mark = 0;
  20969. + }
  20970. + }
  20971. +
  20972. + for (i = 0; i < state->unused_service; i++) {
  20973. + VCHIQ_SERVICE_T *service = state->services[i];
  20974. + VCHIQ_INSTANCE_T instance;
  20975. +
  20976. + if (service && (service->base.callback == service_callback)) {
  20977. + instance = service->instance;
  20978. + if (instance && !instance->mark) {
  20979. + len = snprintf(buf, sizeof(buf),
  20980. + "Instance %x: pid %d,%s completions "
  20981. + "%d/%d",
  20982. + (unsigned int)instance, instance->pid,
  20983. + instance->connected ? " connected, " :
  20984. + "",
  20985. + instance->completion_insert -
  20986. + instance->completion_remove,
  20987. + MAX_COMPLETIONS);
  20988. +
  20989. + vchiq_dump(dump_context, buf, len + 1);
  20990. +
  20991. + instance->mark = 1;
  20992. + }
  20993. + }
  20994. + }
  20995. +}
  20996. +
  20997. +/****************************************************************************
  20998. +*
  20999. +* vchiq_dump_platform_service_state
  21000. +*
  21001. +***************************************************************************/
  21002. +
  21003. +void
  21004. +vchiq_dump_platform_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  21005. +{
  21006. + USER_SERVICE_T *user_service = (USER_SERVICE_T *)service->base.userdata;
  21007. + char buf[80];
  21008. + int len;
  21009. +
  21010. + len = snprintf(buf, sizeof(buf), " instance %x",
  21011. + (unsigned int)service->instance);
  21012. +
  21013. + if ((service->base.callback == service_callback) &&
  21014. + user_service->is_vchi) {
  21015. + len += snprintf(buf + len, sizeof(buf) - len,
  21016. + ", %d/%d messages",
  21017. + user_service->msg_insert - user_service->msg_remove,
  21018. + MSG_QUEUE_SIZE);
  21019. +
  21020. + if (user_service->dequeue_pending)
  21021. + len += snprintf(buf + len, sizeof(buf) - len,
  21022. + " (dequeue pending)");
  21023. + }
  21024. +
  21025. + vchiq_dump(dump_context, buf, len + 1);
  21026. +}
  21027. +
  21028. +/****************************************************************************
  21029. +*
  21030. +* dump_user_mem
  21031. +*
  21032. +***************************************************************************/
  21033. +
  21034. +static void
  21035. +dump_phys_mem(void *virt_addr, uint32_t num_bytes)
  21036. +{
  21037. + int rc;
  21038. + uint8_t *end_virt_addr = virt_addr + num_bytes;
  21039. + int num_pages;
  21040. + int offset;
  21041. + int end_offset;
  21042. + int page_idx;
  21043. + int prev_idx;
  21044. + struct page *page;
  21045. + struct page **pages;
  21046. + uint8_t *kmapped_virt_ptr;
  21047. +
  21048. + /* Align virtAddr and endVirtAddr to 16 byte boundaries. */
  21049. +
  21050. + virt_addr = (void *)((unsigned long)virt_addr & ~0x0fuL);
  21051. + end_virt_addr = (void *)(((unsigned long)end_virt_addr + 15uL) &
  21052. + ~0x0fuL);
  21053. +
  21054. + offset = (int)(long)virt_addr & (PAGE_SIZE - 1);
  21055. + end_offset = (int)(long)end_virt_addr & (PAGE_SIZE - 1);
  21056. +
  21057. + num_pages = (offset + num_bytes + PAGE_SIZE - 1) / PAGE_SIZE;
  21058. +
  21059. + pages = kmalloc(sizeof(struct page *) * num_pages, GFP_KERNEL);
  21060. + if (pages == NULL) {
  21061. + vchiq_log_error(vchiq_arm_log_level,
  21062. + "Unable to allocation memory for %d pages\n",
  21063. + num_pages);
  21064. + return;
  21065. + }
  21066. +
  21067. + down_read(&current->mm->mmap_sem);
  21068. + rc = get_user_pages(current, /* task */
  21069. + current->mm, /* mm */
  21070. + (unsigned long)virt_addr, /* start */
  21071. + num_pages, /* len */
  21072. + 0, /* write */
  21073. + 0, /* force */
  21074. + pages, /* pages (array of page pointers) */
  21075. + NULL); /* vmas */
  21076. + up_read(&current->mm->mmap_sem);
  21077. +
  21078. + prev_idx = -1;
  21079. + page = NULL;
  21080. +
  21081. + while (offset < end_offset) {
  21082. +
  21083. + int page_offset = offset % PAGE_SIZE;
  21084. + page_idx = offset / PAGE_SIZE;
  21085. +
  21086. + if (page_idx != prev_idx) {
  21087. +
  21088. + if (page != NULL)
  21089. + kunmap(page);
  21090. + page = pages[page_idx];
  21091. + kmapped_virt_ptr = kmap(page);
  21092. +
  21093. + prev_idx = page_idx;
  21094. + }
  21095. +
  21096. + if (vchiq_arm_log_level >= VCHIQ_LOG_TRACE)
  21097. + vchiq_log_dump_mem("ph",
  21098. + (uint32_t)(unsigned long)&kmapped_virt_ptr[
  21099. + page_offset],
  21100. + &kmapped_virt_ptr[page_offset], 16);
  21101. +
  21102. + offset += 16;
  21103. + }
  21104. + if (page != NULL)
  21105. + kunmap(page);
  21106. +
  21107. + for (page_idx = 0; page_idx < num_pages; page_idx++)
  21108. + page_cache_release(pages[page_idx]);
  21109. +
  21110. + kfree(pages);
  21111. +}
  21112. +
  21113. +/****************************************************************************
  21114. +*
  21115. +* vchiq_read
  21116. +*
  21117. +***************************************************************************/
  21118. +
  21119. +static ssize_t
  21120. +vchiq_read(struct file *file, char __user *buf,
  21121. + size_t count, loff_t *ppos)
  21122. +{
  21123. + DUMP_CONTEXT_T context;
  21124. + context.buf = buf;
  21125. + context.actual = 0;
  21126. + context.space = count;
  21127. + context.offset = *ppos;
  21128. +
  21129. + vchiq_dump_state(&context, &g_state);
  21130. +
  21131. + *ppos += context.actual;
  21132. +
  21133. + return context.actual;
  21134. +}
  21135. +
  21136. +VCHIQ_STATE_T *
  21137. +vchiq_get_state(void)
  21138. +{
  21139. +
  21140. + if (g_state.remote == NULL)
  21141. + printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__);
  21142. + else if (g_state.remote->initialised != 1)
  21143. + printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n",
  21144. + __func__, g_state.remote->initialised);
  21145. +
  21146. + return ((g_state.remote != NULL) &&
  21147. + (g_state.remote->initialised == 1)) ? &g_state : NULL;
  21148. +}
  21149. +
  21150. +static const struct file_operations
  21151. +vchiq_fops = {
  21152. + .owner = THIS_MODULE,
  21153. + .unlocked_ioctl = vchiq_ioctl,
  21154. + .open = vchiq_open,
  21155. + .release = vchiq_release,
  21156. + .read = vchiq_read
  21157. +};
  21158. +
  21159. +/*
  21160. + * Autosuspend related functionality
  21161. + */
  21162. +
  21163. +int
  21164. +vchiq_videocore_wanted(VCHIQ_STATE_T *state)
  21165. +{
  21166. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21167. + if (!arm_state)
  21168. + /* autosuspend not supported - always return wanted */
  21169. + return 1;
  21170. + else if (arm_state->blocked_count)
  21171. + return 1;
  21172. + else if (!arm_state->videocore_use_count)
  21173. + /* usage count zero - check for override unless we're forcing */
  21174. + if (arm_state->resume_blocked)
  21175. + return 0;
  21176. + else
  21177. + return vchiq_platform_videocore_wanted(state);
  21178. + else
  21179. + /* non-zero usage count - videocore still required */
  21180. + return 1;
  21181. +}
  21182. +
  21183. +static VCHIQ_STATUS_T
  21184. +vchiq_keepalive_vchiq_callback(VCHIQ_REASON_T reason,
  21185. + VCHIQ_HEADER_T *header,
  21186. + VCHIQ_SERVICE_HANDLE_T service_user,
  21187. + void *bulk_user)
  21188. +{
  21189. + vchiq_log_error(vchiq_susp_log_level,
  21190. + "%s callback reason %d", __func__, reason);
  21191. + return 0;
  21192. +}
  21193. +
  21194. +static int
  21195. +vchiq_keepalive_thread_func(void *v)
  21196. +{
  21197. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  21198. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21199. +
  21200. + VCHIQ_STATUS_T status;
  21201. + VCHIQ_INSTANCE_T instance;
  21202. + VCHIQ_SERVICE_HANDLE_T ka_handle;
  21203. +
  21204. + VCHIQ_SERVICE_PARAMS_T params = {
  21205. + .fourcc = VCHIQ_MAKE_FOURCC('K', 'E', 'E', 'P'),
  21206. + .callback = vchiq_keepalive_vchiq_callback,
  21207. + .version = KEEPALIVE_VER,
  21208. + .version_min = KEEPALIVE_VER_MIN
  21209. + };
  21210. +
  21211. + status = vchiq_initialise(&instance);
  21212. + if (status != VCHIQ_SUCCESS) {
  21213. + vchiq_log_error(vchiq_susp_log_level,
  21214. + "%s vchiq_initialise failed %d", __func__, status);
  21215. + goto exit;
  21216. + }
  21217. +
  21218. + status = vchiq_connect(instance);
  21219. + if (status != VCHIQ_SUCCESS) {
  21220. + vchiq_log_error(vchiq_susp_log_level,
  21221. + "%s vchiq_connect failed %d", __func__, status);
  21222. + goto shutdown;
  21223. + }
  21224. +
  21225. + status = vchiq_add_service(instance, &params, &ka_handle);
  21226. + if (status != VCHIQ_SUCCESS) {
  21227. + vchiq_log_error(vchiq_susp_log_level,
  21228. + "%s vchiq_open_service failed %d", __func__, status);
  21229. + goto shutdown;
  21230. + }
  21231. +
  21232. + while (1) {
  21233. + long rc = 0, uc = 0;
  21234. + if (wait_for_completion_interruptible(&arm_state->ka_evt)
  21235. + != 0) {
  21236. + vchiq_log_error(vchiq_susp_log_level,
  21237. + "%s interrupted", __func__);
  21238. + flush_signals(current);
  21239. + continue;
  21240. + }
  21241. +
  21242. + /* read and clear counters. Do release_count then use_count to
  21243. + * prevent getting more releases than uses */
  21244. + rc = atomic_xchg(&arm_state->ka_release_count, 0);
  21245. + uc = atomic_xchg(&arm_state->ka_use_count, 0);
  21246. +
  21247. + /* Call use/release service the requisite number of times.
  21248. + * Process use before release so use counts don't go negative */
  21249. + while (uc--) {
  21250. + atomic_inc(&arm_state->ka_use_ack_count);
  21251. + status = vchiq_use_service(ka_handle);
  21252. + if (status != VCHIQ_SUCCESS) {
  21253. + vchiq_log_error(vchiq_susp_log_level,
  21254. + "%s vchiq_use_service error %d",
  21255. + __func__, status);
  21256. + }
  21257. + }
  21258. + while (rc--) {
  21259. + status = vchiq_release_service(ka_handle);
  21260. + if (status != VCHIQ_SUCCESS) {
  21261. + vchiq_log_error(vchiq_susp_log_level,
  21262. + "%s vchiq_release_service error %d",
  21263. + __func__, status);
  21264. + }
  21265. + }
  21266. + }
  21267. +
  21268. +shutdown:
  21269. + vchiq_shutdown(instance);
  21270. +exit:
  21271. + return 0;
  21272. +}
  21273. +
  21274. +
  21275. +
  21276. +VCHIQ_STATUS_T
  21277. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state)
  21278. +{
  21279. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  21280. +
  21281. + if (arm_state) {
  21282. + rwlock_init(&arm_state->susp_res_lock);
  21283. +
  21284. + init_completion(&arm_state->ka_evt);
  21285. + atomic_set(&arm_state->ka_use_count, 0);
  21286. + atomic_set(&arm_state->ka_use_ack_count, 0);
  21287. + atomic_set(&arm_state->ka_release_count, 0);
  21288. +
  21289. + init_completion(&arm_state->vc_suspend_complete);
  21290. +
  21291. + init_completion(&arm_state->vc_resume_complete);
  21292. + /* Initialise to 'done' state. We only want to block on resume
  21293. + * completion while videocore is suspended. */
  21294. + set_resume_state(arm_state, VC_RESUME_RESUMED);
  21295. +
  21296. + init_completion(&arm_state->resume_blocker);
  21297. + /* Initialise to 'done' state. We only want to block on this
  21298. + * completion while resume is blocked */
  21299. + complete_all(&arm_state->resume_blocker);
  21300. +
  21301. + init_completion(&arm_state->blocked_blocker);
  21302. + /* Initialise to 'done' state. We only want to block on this
  21303. + * completion while things are waiting on the resume blocker */
  21304. + complete_all(&arm_state->blocked_blocker);
  21305. +
  21306. + arm_state->suspend_timer_timeout = SUSPEND_TIMER_TIMEOUT_MS;
  21307. + arm_state->suspend_timer_running = 0;
  21308. + init_timer(&arm_state->suspend_timer);
  21309. + arm_state->suspend_timer.data = (unsigned long)(state);
  21310. + arm_state->suspend_timer.function = suspend_timer_callback;
  21311. +
  21312. + arm_state->first_connect = 0;
  21313. +
  21314. + }
  21315. + return status;
  21316. +}
  21317. +
  21318. +/*
  21319. +** Functions to modify the state variables;
  21320. +** set_suspend_state
  21321. +** set_resume_state
  21322. +**
  21323. +** There are more state variables than we might like, so ensure they remain in
  21324. +** step. Suspend and resume state are maintained separately, since most of
  21325. +** these state machines can operate independently. However, there are a few
  21326. +** states where state transitions in one state machine cause a reset to the
  21327. +** other state machine. In addition, there are some completion events which
  21328. +** need to occur on state machine reset and end-state(s), so these are also
  21329. +** dealt with in these functions.
  21330. +**
  21331. +** In all states we set the state variable according to the input, but in some
  21332. +** cases we perform additional steps outlined below;
  21333. +**
  21334. +** VC_SUSPEND_IDLE - Initialise the suspend completion at the same time.
  21335. +** The suspend completion is completed after any suspend
  21336. +** attempt. When we reset the state machine we also reset
  21337. +** the completion. This reset occurs when videocore is
  21338. +** resumed, and also if we initiate suspend after a suspend
  21339. +** failure.
  21340. +**
  21341. +** VC_SUSPEND_IN_PROGRESS - This state is considered the point of no return for
  21342. +** suspend - ie from this point on we must try to suspend
  21343. +** before resuming can occur. We therefore also reset the
  21344. +** resume state machine to VC_RESUME_IDLE in this state.
  21345. +**
  21346. +** VC_SUSPEND_SUSPENDED - Suspend has completed successfully. Also call
  21347. +** complete_all on the suspend completion to notify
  21348. +** anything waiting for suspend to happen.
  21349. +**
  21350. +** VC_SUSPEND_REJECTED - Videocore rejected suspend. Videocore will also
  21351. +** initiate resume, so no need to alter resume state.
  21352. +** We call complete_all on the suspend completion to notify
  21353. +** of suspend rejection.
  21354. +**
  21355. +** VC_SUSPEND_FAILED - We failed to initiate videocore suspend. We notify the
  21356. +** suspend completion and reset the resume state machine.
  21357. +**
  21358. +** VC_RESUME_IDLE - Initialise the resume completion at the same time. The
  21359. +** resume completion is in it's 'done' state whenever
  21360. +** videcore is running. Therfore, the VC_RESUME_IDLE state
  21361. +** implies that videocore is suspended.
  21362. +** Hence, any thread which needs to wait until videocore is
  21363. +** running can wait on this completion - it will only block
  21364. +** if videocore is suspended.
  21365. +**
  21366. +** VC_RESUME_RESUMED - Resume has completed successfully. Videocore is running.
  21367. +** Call complete_all on the resume completion to unblock
  21368. +** any threads waiting for resume. Also reset the suspend
  21369. +** state machine to it's idle state.
  21370. +**
  21371. +** VC_RESUME_FAILED - Currently unused - no mechanism to fail resume exists.
  21372. +*/
  21373. +
  21374. +inline void
  21375. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  21376. + enum vc_suspend_status new_state)
  21377. +{
  21378. + /* set the state in all cases */
  21379. + arm_state->vc_suspend_state = new_state;
  21380. +
  21381. + /* state specific additional actions */
  21382. + switch (new_state) {
  21383. + case VC_SUSPEND_FORCE_CANCELED:
  21384. + complete_all(&arm_state->vc_suspend_complete);
  21385. + break;
  21386. + case VC_SUSPEND_REJECTED:
  21387. + complete_all(&arm_state->vc_suspend_complete);
  21388. + break;
  21389. + case VC_SUSPEND_FAILED:
  21390. + complete_all(&arm_state->vc_suspend_complete);
  21391. + arm_state->vc_resume_state = VC_RESUME_RESUMED;
  21392. + complete_all(&arm_state->vc_resume_complete);
  21393. + break;
  21394. + case VC_SUSPEND_IDLE:
  21395. + reinit_completion(&arm_state->vc_suspend_complete);
  21396. + break;
  21397. + case VC_SUSPEND_REQUESTED:
  21398. + break;
  21399. + case VC_SUSPEND_IN_PROGRESS:
  21400. + set_resume_state(arm_state, VC_RESUME_IDLE);
  21401. + break;
  21402. + case VC_SUSPEND_SUSPENDED:
  21403. + complete_all(&arm_state->vc_suspend_complete);
  21404. + break;
  21405. + default:
  21406. + BUG();
  21407. + break;
  21408. + }
  21409. +}
  21410. +
  21411. +inline void
  21412. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  21413. + enum vc_resume_status new_state)
  21414. +{
  21415. + /* set the state in all cases */
  21416. + arm_state->vc_resume_state = new_state;
  21417. +
  21418. + /* state specific additional actions */
  21419. + switch (new_state) {
  21420. + case VC_RESUME_FAILED:
  21421. + break;
  21422. + case VC_RESUME_IDLE:
  21423. + reinit_completion(&arm_state->vc_resume_complete);
  21424. + break;
  21425. + case VC_RESUME_REQUESTED:
  21426. + break;
  21427. + case VC_RESUME_IN_PROGRESS:
  21428. + break;
  21429. + case VC_RESUME_RESUMED:
  21430. + complete_all(&arm_state->vc_resume_complete);
  21431. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21432. + break;
  21433. + default:
  21434. + BUG();
  21435. + break;
  21436. + }
  21437. +}
  21438. +
  21439. +
  21440. +/* should be called with the write lock held */
  21441. +inline void
  21442. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21443. +{
  21444. + del_timer(&arm_state->suspend_timer);
  21445. + arm_state->suspend_timer.expires = jiffies +
  21446. + msecs_to_jiffies(arm_state->
  21447. + suspend_timer_timeout);
  21448. + add_timer(&arm_state->suspend_timer);
  21449. + arm_state->suspend_timer_running = 1;
  21450. +}
  21451. +
  21452. +/* should be called with the write lock held */
  21453. +static inline void
  21454. +stop_suspend_timer(VCHIQ_ARM_STATE_T *arm_state)
  21455. +{
  21456. + if (arm_state->suspend_timer_running) {
  21457. + del_timer(&arm_state->suspend_timer);
  21458. + arm_state->suspend_timer_running = 0;
  21459. + }
  21460. +}
  21461. +
  21462. +static inline int
  21463. +need_resume(VCHIQ_STATE_T *state)
  21464. +{
  21465. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21466. + return (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) &&
  21467. + (arm_state->vc_resume_state < VC_RESUME_REQUESTED) &&
  21468. + vchiq_videocore_wanted(state);
  21469. +}
  21470. +
  21471. +static int
  21472. +block_resume(VCHIQ_ARM_STATE_T *arm_state)
  21473. +{
  21474. + int status = VCHIQ_SUCCESS;
  21475. + const unsigned long timeout_val =
  21476. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS);
  21477. + int resume_count = 0;
  21478. +
  21479. + /* Allow any threads which were blocked by the last force suspend to
  21480. + * complete if they haven't already. Only give this one shot; if
  21481. + * blocked_count is incremented after blocked_blocker is completed
  21482. + * (which only happens when blocked_count hits 0) then those threads
  21483. + * will have to wait until next time around */
  21484. + if (arm_state->blocked_count) {
  21485. + reinit_completion(&arm_state->blocked_blocker);
  21486. + write_unlock_bh(&arm_state->susp_res_lock);
  21487. + vchiq_log_info(vchiq_susp_log_level, "%s wait for previously "
  21488. + "blocked clients", __func__);
  21489. + if (wait_for_completion_interruptible_timeout(
  21490. + &arm_state->blocked_blocker, timeout_val)
  21491. + <= 0) {
  21492. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  21493. + "previously blocked clients failed" , __func__);
  21494. + status = VCHIQ_ERROR;
  21495. + write_lock_bh(&arm_state->susp_res_lock);
  21496. + goto out;
  21497. + }
  21498. + vchiq_log_info(vchiq_susp_log_level, "%s previously blocked "
  21499. + "clients resumed", __func__);
  21500. + write_lock_bh(&arm_state->susp_res_lock);
  21501. + }
  21502. +
  21503. + /* We need to wait for resume to complete if it's in process */
  21504. + while (arm_state->vc_resume_state != VC_RESUME_RESUMED &&
  21505. + arm_state->vc_resume_state > VC_RESUME_IDLE) {
  21506. + if (resume_count > 1) {
  21507. + status = VCHIQ_ERROR;
  21508. + vchiq_log_error(vchiq_susp_log_level, "%s waited too "
  21509. + "many times for resume" , __func__);
  21510. + goto out;
  21511. + }
  21512. + write_unlock_bh(&arm_state->susp_res_lock);
  21513. + vchiq_log_info(vchiq_susp_log_level, "%s wait for resume",
  21514. + __func__);
  21515. + if (wait_for_completion_interruptible_timeout(
  21516. + &arm_state->vc_resume_complete, timeout_val)
  21517. + <= 0) {
  21518. + vchiq_log_error(vchiq_susp_log_level, "%s wait for "
  21519. + "resume failed (%s)", __func__,
  21520. + resume_state_names[arm_state->vc_resume_state +
  21521. + VC_RESUME_NUM_OFFSET]);
  21522. + status = VCHIQ_ERROR;
  21523. + write_lock_bh(&arm_state->susp_res_lock);
  21524. + goto out;
  21525. + }
  21526. + vchiq_log_info(vchiq_susp_log_level, "%s resumed", __func__);
  21527. + write_lock_bh(&arm_state->susp_res_lock);
  21528. + resume_count++;
  21529. + }
  21530. + reinit_completion(&arm_state->resume_blocker);
  21531. + arm_state->resume_blocked = 1;
  21532. +
  21533. +out:
  21534. + return status;
  21535. +}
  21536. +
  21537. +static inline void
  21538. +unblock_resume(VCHIQ_ARM_STATE_T *arm_state)
  21539. +{
  21540. + complete_all(&arm_state->resume_blocker);
  21541. + arm_state->resume_blocked = 0;
  21542. +}
  21543. +
  21544. +/* Initiate suspend via slot handler. Should be called with the write lock
  21545. + * held */
  21546. +VCHIQ_STATUS_T
  21547. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state)
  21548. +{
  21549. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21550. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21551. +
  21552. + if (!arm_state)
  21553. + goto out;
  21554. +
  21555. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21556. + status = VCHIQ_SUCCESS;
  21557. +
  21558. +
  21559. + switch (arm_state->vc_suspend_state) {
  21560. + case VC_SUSPEND_REQUESTED:
  21561. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already "
  21562. + "requested", __func__);
  21563. + break;
  21564. + case VC_SUSPEND_IN_PROGRESS:
  21565. + vchiq_log_info(vchiq_susp_log_level, "%s: suspend already in "
  21566. + "progress", __func__);
  21567. + break;
  21568. +
  21569. + default:
  21570. + /* We don't expect to be in other states, so log but continue
  21571. + * anyway */
  21572. + vchiq_log_error(vchiq_susp_log_level,
  21573. + "%s unexpected suspend state %s", __func__,
  21574. + suspend_state_names[arm_state->vc_suspend_state +
  21575. + VC_SUSPEND_NUM_OFFSET]);
  21576. + /* fall through */
  21577. + case VC_SUSPEND_REJECTED:
  21578. + case VC_SUSPEND_FAILED:
  21579. + /* Ensure any idle state actions have been run */
  21580. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21581. + /* fall through */
  21582. + case VC_SUSPEND_IDLE:
  21583. + vchiq_log_info(vchiq_susp_log_level,
  21584. + "%s: suspending", __func__);
  21585. + set_suspend_state(arm_state, VC_SUSPEND_REQUESTED);
  21586. + /* kick the slot handler thread to initiate suspend */
  21587. + request_poll(state, NULL, 0);
  21588. + break;
  21589. + }
  21590. +
  21591. +out:
  21592. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  21593. + return status;
  21594. +}
  21595. +
  21596. +void
  21597. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state)
  21598. +{
  21599. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21600. + int susp = 0;
  21601. +
  21602. + if (!arm_state)
  21603. + goto out;
  21604. +
  21605. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21606. +
  21607. + write_lock_bh(&arm_state->susp_res_lock);
  21608. + if (arm_state->vc_suspend_state == VC_SUSPEND_REQUESTED &&
  21609. + arm_state->vc_resume_state == VC_RESUME_RESUMED) {
  21610. + set_suspend_state(arm_state, VC_SUSPEND_IN_PROGRESS);
  21611. + susp = 1;
  21612. + }
  21613. + write_unlock_bh(&arm_state->susp_res_lock);
  21614. +
  21615. + if (susp)
  21616. + vchiq_platform_suspend(state);
  21617. +
  21618. +out:
  21619. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21620. + return;
  21621. +}
  21622. +
  21623. +
  21624. +static void
  21625. +output_timeout_error(VCHIQ_STATE_T *state)
  21626. +{
  21627. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21628. + char service_err[50] = "";
  21629. + int vc_use_count = arm_state->videocore_use_count;
  21630. + int active_services = state->unused_service;
  21631. + int i;
  21632. +
  21633. + if (!arm_state->videocore_use_count) {
  21634. + snprintf(service_err, 50, " Videocore usecount is 0");
  21635. + goto output_msg;
  21636. + }
  21637. + for (i = 0; i < active_services; i++) {
  21638. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  21639. + if (service_ptr && service_ptr->service_use_count &&
  21640. + (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE)) {
  21641. + snprintf(service_err, 50, " %c%c%c%c(%d) service has "
  21642. + "use count %d%s", VCHIQ_FOURCC_AS_4CHARS(
  21643. + service_ptr->base.fourcc),
  21644. + service_ptr->client_id,
  21645. + service_ptr->service_use_count,
  21646. + service_ptr->service_use_count ==
  21647. + vc_use_count ? "" : " (+ more)");
  21648. + break;
  21649. + }
  21650. + }
  21651. +
  21652. +output_msg:
  21653. + vchiq_log_error(vchiq_susp_log_level,
  21654. + "timed out waiting for vc suspend (%d).%s",
  21655. + arm_state->autosuspend_override, service_err);
  21656. +
  21657. +}
  21658. +
  21659. +/* Try to get videocore into suspended state, regardless of autosuspend state.
  21660. +** We don't actually force suspend, since videocore may get into a bad state
  21661. +** if we force suspend at a bad time. Instead, we wait for autosuspend to
  21662. +** determine a good point to suspend. If this doesn't happen within 100ms we
  21663. +** report failure.
  21664. +**
  21665. +** Returns VCHIQ_SUCCESS if videocore suspended successfully, VCHIQ_RETRY if
  21666. +** videocore failed to suspend in time or VCHIQ_ERROR if interrupted.
  21667. +*/
  21668. +VCHIQ_STATUS_T
  21669. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state)
  21670. +{
  21671. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21672. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  21673. + long rc = 0;
  21674. + int repeat = -1;
  21675. +
  21676. + if (!arm_state)
  21677. + goto out;
  21678. +
  21679. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21680. +
  21681. + write_lock_bh(&arm_state->susp_res_lock);
  21682. +
  21683. + status = block_resume(arm_state);
  21684. + if (status != VCHIQ_SUCCESS)
  21685. + goto unlock;
  21686. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21687. + /* Already suspended - just block resume and exit */
  21688. + vchiq_log_info(vchiq_susp_log_level, "%s already suspended",
  21689. + __func__);
  21690. + status = VCHIQ_SUCCESS;
  21691. + goto unlock;
  21692. + } else if (arm_state->vc_suspend_state <= VC_SUSPEND_IDLE) {
  21693. + /* initiate suspend immediately in the case that we're waiting
  21694. + * for the timeout */
  21695. + stop_suspend_timer(arm_state);
  21696. + if (!vchiq_videocore_wanted(state)) {
  21697. + vchiq_log_info(vchiq_susp_log_level, "%s videocore "
  21698. + "idle, initiating suspend", __func__);
  21699. + status = vchiq_arm_vcsuspend(state);
  21700. + } else if (arm_state->autosuspend_override <
  21701. + FORCE_SUSPEND_FAIL_MAX) {
  21702. + vchiq_log_info(vchiq_susp_log_level, "%s letting "
  21703. + "videocore go idle", __func__);
  21704. + status = VCHIQ_SUCCESS;
  21705. + } else {
  21706. + vchiq_log_warning(vchiq_susp_log_level, "%s failed too "
  21707. + "many times - attempting suspend", __func__);
  21708. + status = vchiq_arm_vcsuspend(state);
  21709. + }
  21710. + } else {
  21711. + vchiq_log_info(vchiq_susp_log_level, "%s videocore suspend "
  21712. + "in progress - wait for completion", __func__);
  21713. + status = VCHIQ_SUCCESS;
  21714. + }
  21715. +
  21716. + /* Wait for suspend to happen due to system idle (not forced..) */
  21717. + if (status != VCHIQ_SUCCESS)
  21718. + goto unblock_resume;
  21719. +
  21720. + do {
  21721. + write_unlock_bh(&arm_state->susp_res_lock);
  21722. +
  21723. + rc = wait_for_completion_interruptible_timeout(
  21724. + &arm_state->vc_suspend_complete,
  21725. + msecs_to_jiffies(FORCE_SUSPEND_TIMEOUT_MS));
  21726. +
  21727. + write_lock_bh(&arm_state->susp_res_lock);
  21728. + if (rc < 0) {
  21729. + vchiq_log_warning(vchiq_susp_log_level, "%s "
  21730. + "interrupted waiting for suspend", __func__);
  21731. + status = VCHIQ_ERROR;
  21732. + goto unblock_resume;
  21733. + } else if (rc == 0) {
  21734. + if (arm_state->vc_suspend_state > VC_SUSPEND_IDLE) {
  21735. + /* Repeat timeout once if in progress */
  21736. + if (repeat < 0) {
  21737. + repeat = 1;
  21738. + continue;
  21739. + }
  21740. + }
  21741. + arm_state->autosuspend_override++;
  21742. + output_timeout_error(state);
  21743. +
  21744. + status = VCHIQ_RETRY;
  21745. + goto unblock_resume;
  21746. + }
  21747. + } while (0 < (repeat--));
  21748. +
  21749. + /* Check and report state in case we need to abort ARM suspend */
  21750. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED) {
  21751. + status = VCHIQ_RETRY;
  21752. + vchiq_log_error(vchiq_susp_log_level,
  21753. + "%s videocore suspend failed (state %s)", __func__,
  21754. + suspend_state_names[arm_state->vc_suspend_state +
  21755. + VC_SUSPEND_NUM_OFFSET]);
  21756. + /* Reset the state only if it's still in an error state.
  21757. + * Something could have already initiated another suspend. */
  21758. + if (arm_state->vc_suspend_state < VC_SUSPEND_IDLE)
  21759. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21760. +
  21761. + goto unblock_resume;
  21762. + }
  21763. +
  21764. + /* successfully suspended - unlock and exit */
  21765. + goto unlock;
  21766. +
  21767. +unblock_resume:
  21768. + /* all error states need to unblock resume before exit */
  21769. + unblock_resume(arm_state);
  21770. +
  21771. +unlock:
  21772. + write_unlock_bh(&arm_state->susp_res_lock);
  21773. +
  21774. +out:
  21775. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, status);
  21776. + return status;
  21777. +}
  21778. +
  21779. +void
  21780. +vchiq_check_suspend(VCHIQ_STATE_T *state)
  21781. +{
  21782. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21783. +
  21784. + if (!arm_state)
  21785. + goto out;
  21786. +
  21787. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21788. +
  21789. + write_lock_bh(&arm_state->susp_res_lock);
  21790. + if (arm_state->vc_suspend_state != VC_SUSPEND_SUSPENDED &&
  21791. + arm_state->first_connect &&
  21792. + !vchiq_videocore_wanted(state)) {
  21793. + vchiq_arm_vcsuspend(state);
  21794. + }
  21795. + write_unlock_bh(&arm_state->susp_res_lock);
  21796. +
  21797. +out:
  21798. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21799. + return;
  21800. +}
  21801. +
  21802. +
  21803. +int
  21804. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state)
  21805. +{
  21806. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21807. + int resume = 0;
  21808. + int ret = -1;
  21809. +
  21810. + if (!arm_state)
  21811. + goto out;
  21812. +
  21813. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21814. +
  21815. + write_lock_bh(&arm_state->susp_res_lock);
  21816. + unblock_resume(arm_state);
  21817. + resume = vchiq_check_resume(state);
  21818. + write_unlock_bh(&arm_state->susp_res_lock);
  21819. +
  21820. + if (resume) {
  21821. + if (wait_for_completion_interruptible(
  21822. + &arm_state->vc_resume_complete) < 0) {
  21823. + vchiq_log_error(vchiq_susp_log_level,
  21824. + "%s interrupted", __func__);
  21825. + /* failed, cannot accurately derive suspend
  21826. + * state, so exit early. */
  21827. + goto out;
  21828. + }
  21829. + }
  21830. +
  21831. + read_lock_bh(&arm_state->susp_res_lock);
  21832. + if (arm_state->vc_suspend_state == VC_SUSPEND_SUSPENDED) {
  21833. + vchiq_log_info(vchiq_susp_log_level,
  21834. + "%s: Videocore remains suspended", __func__);
  21835. + } else {
  21836. + vchiq_log_info(vchiq_susp_log_level,
  21837. + "%s: Videocore resumed", __func__);
  21838. + ret = 0;
  21839. + }
  21840. + read_unlock_bh(&arm_state->susp_res_lock);
  21841. +out:
  21842. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  21843. + return ret;
  21844. +}
  21845. +
  21846. +/* This function should be called with the write lock held */
  21847. +int
  21848. +vchiq_check_resume(VCHIQ_STATE_T *state)
  21849. +{
  21850. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21851. + int resume = 0;
  21852. +
  21853. + if (!arm_state)
  21854. + goto out;
  21855. +
  21856. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21857. +
  21858. + if (need_resume(state)) {
  21859. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  21860. + request_poll(state, NULL, 0);
  21861. + resume = 1;
  21862. + }
  21863. +
  21864. +out:
  21865. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21866. + return resume;
  21867. +}
  21868. +
  21869. +void
  21870. +vchiq_platform_check_resume(VCHIQ_STATE_T *state)
  21871. +{
  21872. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21873. + int res = 0;
  21874. +
  21875. + if (!arm_state)
  21876. + goto out;
  21877. +
  21878. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21879. +
  21880. + write_lock_bh(&arm_state->susp_res_lock);
  21881. + if (arm_state->wake_address == 0) {
  21882. + vchiq_log_info(vchiq_susp_log_level,
  21883. + "%s: already awake", __func__);
  21884. + goto unlock;
  21885. + }
  21886. + if (arm_state->vc_resume_state == VC_RESUME_IN_PROGRESS) {
  21887. + vchiq_log_info(vchiq_susp_log_level,
  21888. + "%s: already resuming", __func__);
  21889. + goto unlock;
  21890. + }
  21891. +
  21892. + if (arm_state->vc_resume_state == VC_RESUME_REQUESTED) {
  21893. + set_resume_state(arm_state, VC_RESUME_IN_PROGRESS);
  21894. + res = 1;
  21895. + } else
  21896. + vchiq_log_trace(vchiq_susp_log_level,
  21897. + "%s: not resuming (resume state %s)", __func__,
  21898. + resume_state_names[arm_state->vc_resume_state +
  21899. + VC_RESUME_NUM_OFFSET]);
  21900. +
  21901. +unlock:
  21902. + write_unlock_bh(&arm_state->susp_res_lock);
  21903. +
  21904. + if (res)
  21905. + vchiq_platform_resume(state);
  21906. +
  21907. +out:
  21908. + vchiq_log_trace(vchiq_susp_log_level, "%s exit", __func__);
  21909. + return;
  21910. +
  21911. +}
  21912. +
  21913. +
  21914. +
  21915. +VCHIQ_STATUS_T
  21916. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  21917. + enum USE_TYPE_E use_type)
  21918. +{
  21919. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  21920. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  21921. + char entity[16];
  21922. + int *entity_uc;
  21923. + int local_uc, local_entity_uc;
  21924. +
  21925. + if (!arm_state)
  21926. + goto out;
  21927. +
  21928. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  21929. +
  21930. + if (use_type == USE_TYPE_VCHIQ) {
  21931. + sprintf(entity, "VCHIQ: ");
  21932. + entity_uc = &arm_state->peer_use_count;
  21933. + } else if (service) {
  21934. + sprintf(entity, "%c%c%c%c:%03d",
  21935. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  21936. + service->client_id);
  21937. + entity_uc = &service->service_use_count;
  21938. + } else {
  21939. + vchiq_log_error(vchiq_susp_log_level, "%s null service "
  21940. + "ptr", __func__);
  21941. + ret = VCHIQ_ERROR;
  21942. + goto out;
  21943. + }
  21944. +
  21945. + write_lock_bh(&arm_state->susp_res_lock);
  21946. + while (arm_state->resume_blocked) {
  21947. + /* If we call 'use' while force suspend is waiting for suspend,
  21948. + * then we're about to block the thread which the force is
  21949. + * waiting to complete, so we're bound to just time out. In this
  21950. + * case, set the suspend state such that the wait will be
  21951. + * canceled, so we can complete as quickly as possible. */
  21952. + if (arm_state->resume_blocked && arm_state->vc_suspend_state ==
  21953. + VC_SUSPEND_IDLE) {
  21954. + set_suspend_state(arm_state, VC_SUSPEND_FORCE_CANCELED);
  21955. + break;
  21956. + }
  21957. + /* If suspend is already in progress then we need to block */
  21958. + if (!try_wait_for_completion(&arm_state->resume_blocker)) {
  21959. + /* Indicate that there are threads waiting on the resume
  21960. + * blocker. These need to be allowed to complete before
  21961. + * a _second_ call to force suspend can complete,
  21962. + * otherwise low priority threads might never actually
  21963. + * continue */
  21964. + arm_state->blocked_count++;
  21965. + write_unlock_bh(&arm_state->susp_res_lock);
  21966. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21967. + "blocked - waiting...", __func__, entity);
  21968. + if (wait_for_completion_killable(
  21969. + &arm_state->resume_blocker) != 0) {
  21970. + vchiq_log_error(vchiq_susp_log_level, "%s %s "
  21971. + "wait for resume blocker interrupted",
  21972. + __func__, entity);
  21973. + ret = VCHIQ_ERROR;
  21974. + write_lock_bh(&arm_state->susp_res_lock);
  21975. + arm_state->blocked_count--;
  21976. + write_unlock_bh(&arm_state->susp_res_lock);
  21977. + goto out;
  21978. + }
  21979. + vchiq_log_info(vchiq_susp_log_level, "%s %s resume "
  21980. + "unblocked", __func__, entity);
  21981. + write_lock_bh(&arm_state->susp_res_lock);
  21982. + if (--arm_state->blocked_count == 0)
  21983. + complete_all(&arm_state->blocked_blocker);
  21984. + }
  21985. + }
  21986. +
  21987. + stop_suspend_timer(arm_state);
  21988. +
  21989. + local_uc = ++arm_state->videocore_use_count;
  21990. + local_entity_uc = ++(*entity_uc);
  21991. +
  21992. + /* If there's a pending request which hasn't yet been serviced then
  21993. + * just clear it. If we're past VC_SUSPEND_REQUESTED state then
  21994. + * vc_resume_complete will block until we either resume or fail to
  21995. + * suspend */
  21996. + if (arm_state->vc_suspend_state <= VC_SUSPEND_REQUESTED)
  21997. + set_suspend_state(arm_state, VC_SUSPEND_IDLE);
  21998. +
  21999. + if ((use_type != USE_TYPE_SERVICE_NO_RESUME) && need_resume(state)) {
  22000. + set_resume_state(arm_state, VC_RESUME_REQUESTED);
  22001. + vchiq_log_info(vchiq_susp_log_level,
  22002. + "%s %s count %d, state count %d",
  22003. + __func__, entity, local_entity_uc, local_uc);
  22004. + request_poll(state, NULL, 0);
  22005. + } else
  22006. + vchiq_log_trace(vchiq_susp_log_level,
  22007. + "%s %s count %d, state count %d",
  22008. + __func__, entity, *entity_uc, local_uc);
  22009. +
  22010. +
  22011. + write_unlock_bh(&arm_state->susp_res_lock);
  22012. +
  22013. + /* Completion is in a done state when we're not suspended, so this won't
  22014. + * block for the non-suspended case. */
  22015. + if (!try_wait_for_completion(&arm_state->vc_resume_complete)) {
  22016. + vchiq_log_info(vchiq_susp_log_level, "%s %s wait for resume",
  22017. + __func__, entity);
  22018. + if (wait_for_completion_killable(
  22019. + &arm_state->vc_resume_complete) != 0) {
  22020. + vchiq_log_error(vchiq_susp_log_level, "%s %s wait for "
  22021. + "resume interrupted", __func__, entity);
  22022. + ret = VCHIQ_ERROR;
  22023. + goto out;
  22024. + }
  22025. + vchiq_log_info(vchiq_susp_log_level, "%s %s resumed", __func__,
  22026. + entity);
  22027. + }
  22028. +
  22029. + if (ret == VCHIQ_SUCCESS) {
  22030. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  22031. + long ack_cnt = atomic_xchg(&arm_state->ka_use_ack_count, 0);
  22032. + while (ack_cnt && (status == VCHIQ_SUCCESS)) {
  22033. + /* Send the use notify to videocore */
  22034. + status = vchiq_send_remote_use_active(state);
  22035. + if (status == VCHIQ_SUCCESS)
  22036. + ack_cnt--;
  22037. + else
  22038. + atomic_add(ack_cnt,
  22039. + &arm_state->ka_use_ack_count);
  22040. + }
  22041. + }
  22042. +
  22043. +out:
  22044. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22045. + return ret;
  22046. +}
  22047. +
  22048. +VCHIQ_STATUS_T
  22049. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service)
  22050. +{
  22051. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22052. + VCHIQ_STATUS_T ret = VCHIQ_SUCCESS;
  22053. + char entity[16];
  22054. + int *entity_uc;
  22055. + int local_uc, local_entity_uc;
  22056. +
  22057. + if (!arm_state)
  22058. + goto out;
  22059. +
  22060. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22061. +
  22062. + if (service) {
  22063. + sprintf(entity, "%c%c%c%c:%03d",
  22064. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22065. + service->client_id);
  22066. + entity_uc = &service->service_use_count;
  22067. + } else {
  22068. + sprintf(entity, "PEER: ");
  22069. + entity_uc = &arm_state->peer_use_count;
  22070. + }
  22071. +
  22072. + write_lock_bh(&arm_state->susp_res_lock);
  22073. + if (!arm_state->videocore_use_count || !(*entity_uc)) {
  22074. + /* Don't use BUG_ON - don't allow user thread to crash kernel */
  22075. + WARN_ON(!arm_state->videocore_use_count);
  22076. + WARN_ON(!(*entity_uc));
  22077. + ret = VCHIQ_ERROR;
  22078. + goto unlock;
  22079. + }
  22080. + local_uc = --arm_state->videocore_use_count;
  22081. + local_entity_uc = --(*entity_uc);
  22082. +
  22083. + if (!vchiq_videocore_wanted(state)) {
  22084. + if (vchiq_platform_use_suspend_timer() &&
  22085. + !arm_state->resume_blocked) {
  22086. + /* Only use the timer if we're not trying to force
  22087. + * suspend (=> resume_blocked) */
  22088. + start_suspend_timer(arm_state);
  22089. + } else {
  22090. + vchiq_log_info(vchiq_susp_log_level,
  22091. + "%s %s count %d, state count %d - suspending",
  22092. + __func__, entity, *entity_uc,
  22093. + arm_state->videocore_use_count);
  22094. + vchiq_arm_vcsuspend(state);
  22095. + }
  22096. + } else
  22097. + vchiq_log_trace(vchiq_susp_log_level,
  22098. + "%s %s count %d, state count %d",
  22099. + __func__, entity, *entity_uc,
  22100. + arm_state->videocore_use_count);
  22101. +
  22102. +unlock:
  22103. + write_unlock_bh(&arm_state->susp_res_lock);
  22104. +
  22105. +out:
  22106. + vchiq_log_trace(vchiq_susp_log_level, "%s exit %d", __func__, ret);
  22107. + return ret;
  22108. +}
  22109. +
  22110. +void
  22111. +vchiq_on_remote_use(VCHIQ_STATE_T *state)
  22112. +{
  22113. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22114. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22115. + atomic_inc(&arm_state->ka_use_count);
  22116. + complete(&arm_state->ka_evt);
  22117. +}
  22118. +
  22119. +void
  22120. +vchiq_on_remote_release(VCHIQ_STATE_T *state)
  22121. +{
  22122. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22123. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22124. + atomic_inc(&arm_state->ka_release_count);
  22125. + complete(&arm_state->ka_evt);
  22126. +}
  22127. +
  22128. +VCHIQ_STATUS_T
  22129. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service)
  22130. +{
  22131. + return vchiq_use_internal(service->state, service, USE_TYPE_SERVICE);
  22132. +}
  22133. +
  22134. +VCHIQ_STATUS_T
  22135. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service)
  22136. +{
  22137. + return vchiq_release_internal(service->state, service);
  22138. +}
  22139. +
  22140. +static void suspend_timer_callback(unsigned long context)
  22141. +{
  22142. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *)context;
  22143. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22144. + if (!arm_state)
  22145. + goto out;
  22146. + vchiq_log_info(vchiq_susp_log_level,
  22147. + "%s - suspend timer expired - check suspend", __func__);
  22148. + vchiq_check_suspend(state);
  22149. +out:
  22150. + return;
  22151. +}
  22152. +
  22153. +VCHIQ_STATUS_T
  22154. +vchiq_use_service_no_resume(VCHIQ_SERVICE_HANDLE_T handle)
  22155. +{
  22156. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22157. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22158. + if (service) {
  22159. + ret = vchiq_use_internal(service->state, service,
  22160. + USE_TYPE_SERVICE_NO_RESUME);
  22161. + unlock_service(service);
  22162. + }
  22163. + return ret;
  22164. +}
  22165. +
  22166. +VCHIQ_STATUS_T
  22167. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle)
  22168. +{
  22169. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22170. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22171. + if (service) {
  22172. + ret = vchiq_use_internal(service->state, service,
  22173. + USE_TYPE_SERVICE);
  22174. + unlock_service(service);
  22175. + }
  22176. + return ret;
  22177. +}
  22178. +
  22179. +VCHIQ_STATUS_T
  22180. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle)
  22181. +{
  22182. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22183. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  22184. + if (service) {
  22185. + ret = vchiq_release_internal(service->state, service);
  22186. + unlock_service(service);
  22187. + }
  22188. + return ret;
  22189. +}
  22190. +
  22191. +void
  22192. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state)
  22193. +{
  22194. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22195. + int i, j = 0;
  22196. + /* Only dump 64 services */
  22197. + static const int local_max_services = 64;
  22198. + /* If there's more than 64 services, only dump ones with
  22199. + * non-zero counts */
  22200. + int only_nonzero = 0;
  22201. + static const char *nz = "<-- preventing suspend";
  22202. +
  22203. + enum vc_suspend_status vc_suspend_state;
  22204. + enum vc_resume_status vc_resume_state;
  22205. + int peer_count;
  22206. + int vc_use_count;
  22207. + int active_services;
  22208. + struct service_data_struct {
  22209. + int fourcc;
  22210. + int clientid;
  22211. + int use_count;
  22212. + } service_data[local_max_services];
  22213. +
  22214. + if (!arm_state)
  22215. + return;
  22216. +
  22217. + read_lock_bh(&arm_state->susp_res_lock);
  22218. + vc_suspend_state = arm_state->vc_suspend_state;
  22219. + vc_resume_state = arm_state->vc_resume_state;
  22220. + peer_count = arm_state->peer_use_count;
  22221. + vc_use_count = arm_state->videocore_use_count;
  22222. + active_services = state->unused_service;
  22223. + if (active_services > local_max_services)
  22224. + only_nonzero = 1;
  22225. +
  22226. + for (i = 0; (i < active_services) && (j < local_max_services); i++) {
  22227. + VCHIQ_SERVICE_T *service_ptr = state->services[i];
  22228. + if (!service_ptr)
  22229. + continue;
  22230. +
  22231. + if (only_nonzero && !service_ptr->service_use_count)
  22232. + continue;
  22233. +
  22234. + if (service_ptr->srvstate != VCHIQ_SRVSTATE_FREE) {
  22235. + service_data[j].fourcc = service_ptr->base.fourcc;
  22236. + service_data[j].clientid = service_ptr->client_id;
  22237. + service_data[j++].use_count = service_ptr->
  22238. + service_use_count;
  22239. + }
  22240. + }
  22241. +
  22242. + read_unlock_bh(&arm_state->susp_res_lock);
  22243. +
  22244. + vchiq_log_warning(vchiq_susp_log_level,
  22245. + "-- Videcore suspend state: %s --",
  22246. + suspend_state_names[vc_suspend_state + VC_SUSPEND_NUM_OFFSET]);
  22247. + vchiq_log_warning(vchiq_susp_log_level,
  22248. + "-- Videcore resume state: %s --",
  22249. + resume_state_names[vc_resume_state + VC_RESUME_NUM_OFFSET]);
  22250. +
  22251. + if (only_nonzero)
  22252. + vchiq_log_warning(vchiq_susp_log_level, "Too many active "
  22253. + "services (%d). Only dumping up to first %d services "
  22254. + "with non-zero use-count", active_services,
  22255. + local_max_services);
  22256. +
  22257. + for (i = 0; i < j; i++) {
  22258. + vchiq_log_warning(vchiq_susp_log_level,
  22259. + "----- %c%c%c%c:%d service count %d %s",
  22260. + VCHIQ_FOURCC_AS_4CHARS(service_data[i].fourcc),
  22261. + service_data[i].clientid,
  22262. + service_data[i].use_count,
  22263. + service_data[i].use_count ? nz : "");
  22264. + }
  22265. + vchiq_log_warning(vchiq_susp_log_level,
  22266. + "----- VCHIQ use count count %d", peer_count);
  22267. + vchiq_log_warning(vchiq_susp_log_level,
  22268. + "--- Overall vchiq instance use count %d", vc_use_count);
  22269. +
  22270. + vchiq_dump_platform_use_state(state);
  22271. +}
  22272. +
  22273. +VCHIQ_STATUS_T
  22274. +vchiq_check_service(VCHIQ_SERVICE_T *service)
  22275. +{
  22276. + VCHIQ_ARM_STATE_T *arm_state;
  22277. + VCHIQ_STATUS_T ret = VCHIQ_ERROR;
  22278. +
  22279. + if (!service || !service->state)
  22280. + goto out;
  22281. +
  22282. + vchiq_log_trace(vchiq_susp_log_level, "%s", __func__);
  22283. +
  22284. + arm_state = vchiq_platform_get_arm_state(service->state);
  22285. +
  22286. + read_lock_bh(&arm_state->susp_res_lock);
  22287. + if (service->service_use_count)
  22288. + ret = VCHIQ_SUCCESS;
  22289. + read_unlock_bh(&arm_state->susp_res_lock);
  22290. +
  22291. + if (ret == VCHIQ_ERROR) {
  22292. + vchiq_log_error(vchiq_susp_log_level,
  22293. + "%s ERROR - %c%c%c%c:%d service count %d, "
  22294. + "state count %d, videocore suspend state %s", __func__,
  22295. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  22296. + service->client_id, service->service_use_count,
  22297. + arm_state->videocore_use_count,
  22298. + suspend_state_names[arm_state->vc_suspend_state +
  22299. + VC_SUSPEND_NUM_OFFSET]);
  22300. + vchiq_dump_service_use_state(service->state);
  22301. + }
  22302. +out:
  22303. + return ret;
  22304. +}
  22305. +
  22306. +/* stub functions */
  22307. +void vchiq_on_remote_use_active(VCHIQ_STATE_T *state)
  22308. +{
  22309. + (void)state;
  22310. +}
  22311. +
  22312. +void vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  22313. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate)
  22314. +{
  22315. + VCHIQ_ARM_STATE_T *arm_state = vchiq_platform_get_arm_state(state);
  22316. + vchiq_log_info(vchiq_susp_log_level, "%d: %s->%s", state->id,
  22317. + get_conn_state_name(oldstate), get_conn_state_name(newstate));
  22318. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTED) {
  22319. + write_lock_bh(&arm_state->susp_res_lock);
  22320. + if (!arm_state->first_connect) {
  22321. + char threadname[10];
  22322. + arm_state->first_connect = 1;
  22323. + write_unlock_bh(&arm_state->susp_res_lock);
  22324. + snprintf(threadname, sizeof(threadname), "VCHIQka-%d",
  22325. + state->id);
  22326. + arm_state->ka_thread = kthread_create(
  22327. + &vchiq_keepalive_thread_func,
  22328. + (void *)state,
  22329. + threadname);
  22330. + if (arm_state->ka_thread == NULL) {
  22331. + vchiq_log_error(vchiq_susp_log_level,
  22332. + "vchiq: FATAL: couldn't create thread %s",
  22333. + threadname);
  22334. + } else {
  22335. + wake_up_process(arm_state->ka_thread);
  22336. + }
  22337. + } else
  22338. + write_unlock_bh(&arm_state->susp_res_lock);
  22339. + }
  22340. +}
  22341. +
  22342. +
  22343. +/****************************************************************************
  22344. +*
  22345. +* vchiq_init - called when the module is loaded.
  22346. +*
  22347. +***************************************************************************/
  22348. +
  22349. +static int __init
  22350. +vchiq_init(void)
  22351. +{
  22352. + int err;
  22353. + void *ptr_err;
  22354. +
  22355. + /* create proc entries */
  22356. + err = vchiq_proc_init();
  22357. + if (err != 0)
  22358. + goto failed_proc_init;
  22359. +
  22360. + err = alloc_chrdev_region(&vchiq_devid, VCHIQ_MINOR, 1, DEVICE_NAME);
  22361. + if (err != 0) {
  22362. + vchiq_log_error(vchiq_arm_log_level,
  22363. + "Unable to allocate device number");
  22364. + goto failed_alloc_chrdev;
  22365. + }
  22366. + cdev_init(&vchiq_cdev, &vchiq_fops);
  22367. + vchiq_cdev.owner = THIS_MODULE;
  22368. + err = cdev_add(&vchiq_cdev, vchiq_devid, 1);
  22369. + if (err != 0) {
  22370. + vchiq_log_error(vchiq_arm_log_level,
  22371. + "Unable to register device");
  22372. + goto failed_cdev_add;
  22373. + }
  22374. +
  22375. + /* create sysfs entries */
  22376. + vchiq_class = class_create(THIS_MODULE, DEVICE_NAME);
  22377. + ptr_err = vchiq_class;
  22378. + if (IS_ERR(ptr_err))
  22379. + goto failed_class_create;
  22380. +
  22381. + vchiq_dev = device_create(vchiq_class, NULL,
  22382. + vchiq_devid, NULL, "vchiq");
  22383. + ptr_err = vchiq_dev;
  22384. + if (IS_ERR(ptr_err))
  22385. + goto failed_device_create;
  22386. +
  22387. + err = vchiq_platform_init(&g_state);
  22388. + if (err != 0)
  22389. + goto failed_platform_init;
  22390. +
  22391. + vchiq_log_info(vchiq_arm_log_level,
  22392. + "vchiq: initialised - version %d (min %d), device %d.%d",
  22393. + VCHIQ_VERSION, VCHIQ_VERSION_MIN,
  22394. + MAJOR(vchiq_devid), MINOR(vchiq_devid));
  22395. +
  22396. + return 0;
  22397. +
  22398. +failed_platform_init:
  22399. + device_destroy(vchiq_class, vchiq_devid);
  22400. +failed_device_create:
  22401. + class_destroy(vchiq_class);
  22402. +failed_class_create:
  22403. + cdev_del(&vchiq_cdev);
  22404. + err = PTR_ERR(ptr_err);
  22405. +failed_cdev_add:
  22406. + unregister_chrdev_region(vchiq_devid, 1);
  22407. +failed_alloc_chrdev:
  22408. + vchiq_proc_deinit();
  22409. +failed_proc_init:
  22410. + vchiq_log_warning(vchiq_arm_log_level, "could not load vchiq");
  22411. + return err;
  22412. +}
  22413. +
  22414. +static int vchiq_instance_get_use_count(VCHIQ_INSTANCE_T instance)
  22415. +{
  22416. + VCHIQ_SERVICE_T *service;
  22417. + int use_count = 0, i;
  22418. + i = 0;
  22419. + while ((service = next_service_by_instance(instance->state,
  22420. + instance, &i)) != NULL) {
  22421. + use_count += service->service_use_count;
  22422. + unlock_service(service);
  22423. + }
  22424. + return use_count;
  22425. +}
  22426. +
  22427. +/* read the per-process use-count */
  22428. +static int proc_read_use_count(char *page, char **start,
  22429. + off_t off, int count,
  22430. + int *eof, void *data)
  22431. +{
  22432. + VCHIQ_INSTANCE_T instance = data;
  22433. + int len, use_count;
  22434. +
  22435. + use_count = vchiq_instance_get_use_count(instance);
  22436. + len = snprintf(page+off, count, "%d\n", use_count);
  22437. +
  22438. + return len;
  22439. +}
  22440. +
  22441. +/* add an instance (process) to the proc entries */
  22442. +static int vchiq_proc_add_instance(VCHIQ_INSTANCE_T instance)
  22443. +{
  22444. +#if 1
  22445. + return 0;
  22446. +#else
  22447. + char pidstr[32];
  22448. + struct proc_dir_entry *top, *use_count;
  22449. + struct proc_dir_entry *clients = vchiq_clients_top();
  22450. + int pid = instance->pid;
  22451. +
  22452. + snprintf(pidstr, sizeof(pidstr), "%d", pid);
  22453. + top = proc_mkdir(pidstr, clients);
  22454. + if (!top)
  22455. + goto fail_top;
  22456. +
  22457. + use_count = create_proc_read_entry("use_count",
  22458. + 0444, top,
  22459. + proc_read_use_count,
  22460. + instance);
  22461. + if (!use_count)
  22462. + goto fail_use_count;
  22463. +
  22464. + instance->proc_entry = top;
  22465. +
  22466. + return 0;
  22467. +
  22468. +fail_use_count:
  22469. + remove_proc_entry(top->name, clients);
  22470. +fail_top:
  22471. + return -ENOMEM;
  22472. +#endif
  22473. +}
  22474. +
  22475. +static void vchiq_proc_remove_instance(VCHIQ_INSTANCE_T instance)
  22476. +{
  22477. +#if 0
  22478. + struct proc_dir_entry *clients = vchiq_clients_top();
  22479. + remove_proc_entry("use_count", instance->proc_entry);
  22480. + remove_proc_entry(instance->proc_entry->name, clients);
  22481. +#endif
  22482. +}
  22483. +
  22484. +/****************************************************************************
  22485. +*
  22486. +* vchiq_exit - called when the module is unloaded.
  22487. +*
  22488. +***************************************************************************/
  22489. +
  22490. +static void __exit
  22491. +vchiq_exit(void)
  22492. +{
  22493. + vchiq_platform_exit(&g_state);
  22494. + device_destroy(vchiq_class, vchiq_devid);
  22495. + class_destroy(vchiq_class);
  22496. + cdev_del(&vchiq_cdev);
  22497. + unregister_chrdev_region(vchiq_devid, 1);
  22498. +}
  22499. +
  22500. +module_init(vchiq_init);
  22501. +module_exit(vchiq_exit);
  22502. +MODULE_LICENSE("GPL");
  22503. +MODULE_AUTHOR("Broadcom Corporation");
  22504. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h
  22505. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 1970-01-01 01:00:00.000000000 +0100
  22506. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_arm.h 2014-06-11 21:03:34.000000000 +0200
  22507. @@ -0,0 +1,212 @@
  22508. +/**
  22509. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22510. + *
  22511. + * Redistribution and use in source and binary forms, with or without
  22512. + * modification, are permitted provided that the following conditions
  22513. + * are met:
  22514. + * 1. Redistributions of source code must retain the above copyright
  22515. + * notice, this list of conditions, and the following disclaimer,
  22516. + * without modification.
  22517. + * 2. Redistributions in binary form must reproduce the above copyright
  22518. + * notice, this list of conditions and the following disclaimer in the
  22519. + * documentation and/or other materials provided with the distribution.
  22520. + * 3. The names of the above-listed copyright holders may not be used
  22521. + * to endorse or promote products derived from this software without
  22522. + * specific prior written permission.
  22523. + *
  22524. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22525. + * GNU General Public License ("GPL") version 2, as published by the Free
  22526. + * Software Foundation.
  22527. + *
  22528. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22529. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22530. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22531. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22532. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22533. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22534. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22535. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22536. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22537. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22538. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22539. + */
  22540. +
  22541. +#ifndef VCHIQ_ARM_H
  22542. +#define VCHIQ_ARM_H
  22543. +
  22544. +#include <linux/mutex.h>
  22545. +#include <linux/semaphore.h>
  22546. +#include <linux/atomic.h>
  22547. +#include "vchiq_core.h"
  22548. +
  22549. +
  22550. +enum vc_suspend_status {
  22551. + VC_SUSPEND_FORCE_CANCELED = -3, /* Force suspend canceled, too busy */
  22552. + VC_SUSPEND_REJECTED = -2, /* Videocore rejected suspend request */
  22553. + VC_SUSPEND_FAILED = -1, /* Videocore suspend failed */
  22554. + VC_SUSPEND_IDLE = 0, /* VC active, no suspend actions */
  22555. + VC_SUSPEND_REQUESTED, /* User has requested suspend */
  22556. + VC_SUSPEND_IN_PROGRESS, /* Slot handler has recvd suspend request */
  22557. + VC_SUSPEND_SUSPENDED /* Videocore suspend succeeded */
  22558. +};
  22559. +
  22560. +enum vc_resume_status {
  22561. + VC_RESUME_FAILED = -1, /* Videocore resume failed */
  22562. + VC_RESUME_IDLE = 0, /* VC suspended, no resume actions */
  22563. + VC_RESUME_REQUESTED, /* User has requested resume */
  22564. + VC_RESUME_IN_PROGRESS, /* Slot handler has received resume request */
  22565. + VC_RESUME_RESUMED /* Videocore resumed successfully (active) */
  22566. +};
  22567. +
  22568. +
  22569. +enum USE_TYPE_E {
  22570. + USE_TYPE_SERVICE,
  22571. + USE_TYPE_SERVICE_NO_RESUME,
  22572. + USE_TYPE_VCHIQ
  22573. +};
  22574. +
  22575. +
  22576. +
  22577. +typedef struct vchiq_arm_state_struct {
  22578. + /* Keepalive-related data */
  22579. + struct task_struct *ka_thread;
  22580. + struct completion ka_evt;
  22581. + atomic_t ka_use_count;
  22582. + atomic_t ka_use_ack_count;
  22583. + atomic_t ka_release_count;
  22584. +
  22585. + struct completion vc_suspend_complete;
  22586. + struct completion vc_resume_complete;
  22587. +
  22588. + rwlock_t susp_res_lock;
  22589. + enum vc_suspend_status vc_suspend_state;
  22590. + enum vc_resume_status vc_resume_state;
  22591. +
  22592. + unsigned int wake_address;
  22593. +
  22594. + struct timer_list suspend_timer;
  22595. + int suspend_timer_timeout;
  22596. + int suspend_timer_running;
  22597. +
  22598. + /* Global use count for videocore.
  22599. + ** This is equal to the sum of the use counts for all services. When
  22600. + ** this hits zero the videocore suspend procedure will be initiated.
  22601. + */
  22602. + int videocore_use_count;
  22603. +
  22604. + /* Use count to track requests from videocore peer.
  22605. + ** This use count is not associated with a service, so needs to be
  22606. + ** tracked separately with the state.
  22607. + */
  22608. + int peer_use_count;
  22609. +
  22610. + /* Flag to indicate whether resume is blocked. This happens when the
  22611. + ** ARM is suspending
  22612. + */
  22613. + struct completion resume_blocker;
  22614. + int resume_blocked;
  22615. + struct completion blocked_blocker;
  22616. + int blocked_count;
  22617. +
  22618. + int autosuspend_override;
  22619. +
  22620. + /* Flag to indicate that the first vchiq connect has made it through.
  22621. + ** This means that both sides should be fully ready, and we should
  22622. + ** be able to suspend after this point.
  22623. + */
  22624. + int first_connect;
  22625. +
  22626. + unsigned long long suspend_start_time;
  22627. + unsigned long long sleep_start_time;
  22628. + unsigned long long resume_start_time;
  22629. + unsigned long long last_wake_time;
  22630. +
  22631. +} VCHIQ_ARM_STATE_T;
  22632. +
  22633. +extern int vchiq_arm_log_level;
  22634. +extern int vchiq_susp_log_level;
  22635. +
  22636. +extern int __init
  22637. +vchiq_platform_init(VCHIQ_STATE_T *state);
  22638. +
  22639. +extern void __exit
  22640. +vchiq_platform_exit(VCHIQ_STATE_T *state);
  22641. +
  22642. +extern VCHIQ_STATE_T *
  22643. +vchiq_get_state(void);
  22644. +
  22645. +extern VCHIQ_STATUS_T
  22646. +vchiq_arm_vcsuspend(VCHIQ_STATE_T *state);
  22647. +
  22648. +extern VCHIQ_STATUS_T
  22649. +vchiq_arm_force_suspend(VCHIQ_STATE_T *state);
  22650. +
  22651. +extern int
  22652. +vchiq_arm_allow_resume(VCHIQ_STATE_T *state);
  22653. +
  22654. +extern VCHIQ_STATUS_T
  22655. +vchiq_arm_vcresume(VCHIQ_STATE_T *state);
  22656. +
  22657. +extern VCHIQ_STATUS_T
  22658. +vchiq_arm_init_state(VCHIQ_STATE_T *state, VCHIQ_ARM_STATE_T *arm_state);
  22659. +
  22660. +extern int
  22661. +vchiq_check_resume(VCHIQ_STATE_T *state);
  22662. +
  22663. +extern void
  22664. +vchiq_check_suspend(VCHIQ_STATE_T *state);
  22665. +
  22666. +extern VCHIQ_STATUS_T
  22667. +vchiq_use_service(VCHIQ_SERVICE_HANDLE_T handle);
  22668. +
  22669. +extern VCHIQ_STATUS_T
  22670. +vchiq_release_service(VCHIQ_SERVICE_HANDLE_T handle);
  22671. +
  22672. +extern VCHIQ_STATUS_T
  22673. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  22674. +
  22675. +extern VCHIQ_STATUS_T
  22676. +vchiq_platform_suspend(VCHIQ_STATE_T *state);
  22677. +
  22678. +extern int
  22679. +vchiq_platform_videocore_wanted(VCHIQ_STATE_T *state);
  22680. +
  22681. +extern int
  22682. +vchiq_platform_use_suspend_timer(void);
  22683. +
  22684. +extern void
  22685. +vchiq_dump_platform_use_state(VCHIQ_STATE_T *state);
  22686. +
  22687. +extern void
  22688. +vchiq_dump_service_use_state(VCHIQ_STATE_T *state);
  22689. +
  22690. +extern VCHIQ_ARM_STATE_T*
  22691. +vchiq_platform_get_arm_state(VCHIQ_STATE_T *state);
  22692. +
  22693. +extern int
  22694. +vchiq_videocore_wanted(VCHIQ_STATE_T *state);
  22695. +
  22696. +extern VCHIQ_STATUS_T
  22697. +vchiq_use_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  22698. + enum USE_TYPE_E use_type);
  22699. +extern VCHIQ_STATUS_T
  22700. +vchiq_release_internal(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service);
  22701. +
  22702. +void
  22703. +set_suspend_state(VCHIQ_ARM_STATE_T *arm_state,
  22704. + enum vc_suspend_status new_state);
  22705. +
  22706. +void
  22707. +set_resume_state(VCHIQ_ARM_STATE_T *arm_state,
  22708. + enum vc_resume_status new_state);
  22709. +
  22710. +void
  22711. +start_suspend_timer(VCHIQ_ARM_STATE_T *arm_state);
  22712. +
  22713. +extern int vchiq_proc_init(void);
  22714. +extern void vchiq_proc_deinit(void);
  22715. +extern struct proc_dir_entry *vchiq_proc_top(void);
  22716. +extern struct proc_dir_entry *vchiq_clients_top(void);
  22717. +
  22718. +
  22719. +#endif /* VCHIQ_ARM_H */
  22720. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h
  22721. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 1970-01-01 01:00:00.000000000 +0100
  22722. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_build_info.h 2014-06-11 21:03:34.000000000 +0200
  22723. @@ -0,0 +1,37 @@
  22724. +/**
  22725. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22726. + *
  22727. + * Redistribution and use in source and binary forms, with or without
  22728. + * modification, are permitted provided that the following conditions
  22729. + * are met:
  22730. + * 1. Redistributions of source code must retain the above copyright
  22731. + * notice, this list of conditions, and the following disclaimer,
  22732. + * without modification.
  22733. + * 2. Redistributions in binary form must reproduce the above copyright
  22734. + * notice, this list of conditions and the following disclaimer in the
  22735. + * documentation and/or other materials provided with the distribution.
  22736. + * 3. The names of the above-listed copyright holders may not be used
  22737. + * to endorse or promote products derived from this software without
  22738. + * specific prior written permission.
  22739. + *
  22740. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22741. + * GNU General Public License ("GPL") version 2, as published by the Free
  22742. + * Software Foundation.
  22743. + *
  22744. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22745. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22746. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22747. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22748. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22749. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22750. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22751. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22752. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22753. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22754. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22755. + */
  22756. +
  22757. +const char *vchiq_get_build_hostname(void);
  22758. +const char *vchiq_get_build_version(void);
  22759. +const char *vchiq_get_build_time(void);
  22760. +const char *vchiq_get_build_date(void);
  22761. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h
  22762. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 1970-01-01 01:00:00.000000000 +0100
  22763. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_cfg.h 2014-06-11 21:03:34.000000000 +0200
  22764. @@ -0,0 +1,60 @@
  22765. +/**
  22766. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22767. + *
  22768. + * Redistribution and use in source and binary forms, with or without
  22769. + * modification, are permitted provided that the following conditions
  22770. + * are met:
  22771. + * 1. Redistributions of source code must retain the above copyright
  22772. + * notice, this list of conditions, and the following disclaimer,
  22773. + * without modification.
  22774. + * 2. Redistributions in binary form must reproduce the above copyright
  22775. + * notice, this list of conditions and the following disclaimer in the
  22776. + * documentation and/or other materials provided with the distribution.
  22777. + * 3. The names of the above-listed copyright holders may not be used
  22778. + * to endorse or promote products derived from this software without
  22779. + * specific prior written permission.
  22780. + *
  22781. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22782. + * GNU General Public License ("GPL") version 2, as published by the Free
  22783. + * Software Foundation.
  22784. + *
  22785. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22786. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22787. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22788. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22789. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22790. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22791. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22792. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22793. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22794. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22795. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22796. + */
  22797. +
  22798. +#ifndef VCHIQ_CFG_H
  22799. +#define VCHIQ_CFG_H
  22800. +
  22801. +#define VCHIQ_MAGIC VCHIQ_MAKE_FOURCC('V', 'C', 'H', 'I')
  22802. +/* The version of VCHIQ - change with any non-trivial change */
  22803. +#define VCHIQ_VERSION 6
  22804. +/* The minimum compatible version - update to match VCHIQ_VERSION with any
  22805. +** incompatible change */
  22806. +#define VCHIQ_VERSION_MIN 3
  22807. +
  22808. +#define VCHIQ_MAX_STATES 1
  22809. +#define VCHIQ_MAX_SERVICES 4096
  22810. +#define VCHIQ_MAX_SLOTS 128
  22811. +#define VCHIQ_MAX_SLOTS_PER_SIDE 64
  22812. +
  22813. +#define VCHIQ_NUM_CURRENT_BULKS 32
  22814. +#define VCHIQ_NUM_SERVICE_BULKS 4
  22815. +
  22816. +#ifndef VCHIQ_ENABLE_DEBUG
  22817. +#define VCHIQ_ENABLE_DEBUG 1
  22818. +#endif
  22819. +
  22820. +#ifndef VCHIQ_ENABLE_STATS
  22821. +#define VCHIQ_ENABLE_STATS 1
  22822. +#endif
  22823. +
  22824. +#endif /* VCHIQ_CFG_H */
  22825. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c
  22826. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 1970-01-01 01:00:00.000000000 +0100
  22827. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.c 2014-06-11 21:03:34.000000000 +0200
  22828. @@ -0,0 +1,120 @@
  22829. +/**
  22830. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22831. + *
  22832. + * Redistribution and use in source and binary forms, with or without
  22833. + * modification, are permitted provided that the following conditions
  22834. + * are met:
  22835. + * 1. Redistributions of source code must retain the above copyright
  22836. + * notice, this list of conditions, and the following disclaimer,
  22837. + * without modification.
  22838. + * 2. Redistributions in binary form must reproduce the above copyright
  22839. + * notice, this list of conditions and the following disclaimer in the
  22840. + * documentation and/or other materials provided with the distribution.
  22841. + * 3. The names of the above-listed copyright holders may not be used
  22842. + * to endorse or promote products derived from this software without
  22843. + * specific prior written permission.
  22844. + *
  22845. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22846. + * GNU General Public License ("GPL") version 2, as published by the Free
  22847. + * Software Foundation.
  22848. + *
  22849. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22850. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22851. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22852. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22853. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22854. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22855. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22856. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22857. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22858. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22859. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22860. + */
  22861. +
  22862. +#include "vchiq_connected.h"
  22863. +#include "vchiq_core.h"
  22864. +#include "vchiq_killable.h"
  22865. +#include <linux/module.h>
  22866. +#include <linux/mutex.h>
  22867. +
  22868. +#define MAX_CALLBACKS 10
  22869. +
  22870. +static int g_connected;
  22871. +static int g_num_deferred_callbacks;
  22872. +static VCHIQ_CONNECTED_CALLBACK_T g_deferred_callback[MAX_CALLBACKS];
  22873. +static int g_once_init;
  22874. +static struct mutex g_connected_mutex;
  22875. +
  22876. +/****************************************************************************
  22877. +*
  22878. +* Function to initialize our lock.
  22879. +*
  22880. +***************************************************************************/
  22881. +
  22882. +static void connected_init(void)
  22883. +{
  22884. + if (!g_once_init) {
  22885. + mutex_init(&g_connected_mutex);
  22886. + g_once_init = 1;
  22887. + }
  22888. +}
  22889. +
  22890. +/****************************************************************************
  22891. +*
  22892. +* This function is used to defer initialization until the vchiq stack is
  22893. +* initialized. If the stack is already initialized, then the callback will
  22894. +* be made immediately, otherwise it will be deferred until
  22895. +* vchiq_call_connected_callbacks is called.
  22896. +*
  22897. +***************************************************************************/
  22898. +
  22899. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback)
  22900. +{
  22901. + connected_init();
  22902. +
  22903. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22904. + return;
  22905. +
  22906. + if (g_connected)
  22907. + /* We're already connected. Call the callback immediately. */
  22908. +
  22909. + callback();
  22910. + else {
  22911. + if (g_num_deferred_callbacks >= MAX_CALLBACKS)
  22912. + vchiq_log_error(vchiq_core_log_level,
  22913. + "There already %d callback registered - "
  22914. + "please increase MAX_CALLBACKS",
  22915. + g_num_deferred_callbacks);
  22916. + else {
  22917. + g_deferred_callback[g_num_deferred_callbacks] =
  22918. + callback;
  22919. + g_num_deferred_callbacks++;
  22920. + }
  22921. + }
  22922. + mutex_unlock(&g_connected_mutex);
  22923. +}
  22924. +
  22925. +/****************************************************************************
  22926. +*
  22927. +* This function is called by the vchiq stack once it has been connected to
  22928. +* the videocore and clients can start to use the stack.
  22929. +*
  22930. +***************************************************************************/
  22931. +
  22932. +void vchiq_call_connected_callbacks(void)
  22933. +{
  22934. + int i;
  22935. +
  22936. + connected_init();
  22937. +
  22938. + if (mutex_lock_interruptible(&g_connected_mutex) != 0)
  22939. + return;
  22940. +
  22941. + for (i = 0; i < g_num_deferred_callbacks; i++)
  22942. + g_deferred_callback[i]();
  22943. +
  22944. + g_num_deferred_callbacks = 0;
  22945. + g_connected = 1;
  22946. + mutex_unlock(&g_connected_mutex);
  22947. +}
  22948. +EXPORT_SYMBOL(vchiq_add_connected_callback);
  22949. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h
  22950. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 1970-01-01 01:00:00.000000000 +0100
  22951. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_connected.h 2014-06-11 21:03:34.000000000 +0200
  22952. @@ -0,0 +1,50 @@
  22953. +/**
  22954. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  22955. + *
  22956. + * Redistribution and use in source and binary forms, with or without
  22957. + * modification, are permitted provided that the following conditions
  22958. + * are met:
  22959. + * 1. Redistributions of source code must retain the above copyright
  22960. + * notice, this list of conditions, and the following disclaimer,
  22961. + * without modification.
  22962. + * 2. Redistributions in binary form must reproduce the above copyright
  22963. + * notice, this list of conditions and the following disclaimer in the
  22964. + * documentation and/or other materials provided with the distribution.
  22965. + * 3. The names of the above-listed copyright holders may not be used
  22966. + * to endorse or promote products derived from this software without
  22967. + * specific prior written permission.
  22968. + *
  22969. + * ALTERNATIVELY, this software may be distributed under the terms of the
  22970. + * GNU General Public License ("GPL") version 2, as published by the Free
  22971. + * Software Foundation.
  22972. + *
  22973. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  22974. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22975. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22976. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22977. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  22978. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22979. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  22980. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  22981. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  22982. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22983. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  22984. + */
  22985. +
  22986. +#ifndef VCHIQ_CONNECTED_H
  22987. +#define VCHIQ_CONNECTED_H
  22988. +
  22989. +/* ---- Include Files ----------------------------------------------------- */
  22990. +
  22991. +/* ---- Constants and Types ---------------------------------------------- */
  22992. +
  22993. +typedef void (*VCHIQ_CONNECTED_CALLBACK_T)(void);
  22994. +
  22995. +/* ---- Variable Externs ------------------------------------------------- */
  22996. +
  22997. +/* ---- Function Prototypes ---------------------------------------------- */
  22998. +
  22999. +void vchiq_add_connected_callback(VCHIQ_CONNECTED_CALLBACK_T callback);
  23000. +void vchiq_call_connected_callbacks(void);
  23001. +
  23002. +#endif /* VCHIQ_CONNECTED_H */
  23003. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c
  23004. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 1970-01-01 01:00:00.000000000 +0100
  23005. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.c 2014-06-11 21:03:34.000000000 +0200
  23006. @@ -0,0 +1,3825 @@
  23007. +/**
  23008. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  23009. + *
  23010. + * Redistribution and use in source and binary forms, with or without
  23011. + * modification, are permitted provided that the following conditions
  23012. + * are met:
  23013. + * 1. Redistributions of source code must retain the above copyright
  23014. + * notice, this list of conditions, and the following disclaimer,
  23015. + * without modification.
  23016. + * 2. Redistributions in binary form must reproduce the above copyright
  23017. + * notice, this list of conditions and the following disclaimer in the
  23018. + * documentation and/or other materials provided with the distribution.
  23019. + * 3. The names of the above-listed copyright holders may not be used
  23020. + * to endorse or promote products derived from this software without
  23021. + * specific prior written permission.
  23022. + *
  23023. + * ALTERNATIVELY, this software may be distributed under the terms of the
  23024. + * GNU General Public License ("GPL") version 2, as published by the Free
  23025. + * Software Foundation.
  23026. + *
  23027. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  23028. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  23029. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23030. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23031. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23032. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  23033. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  23034. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23035. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23036. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23037. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23038. + */
  23039. +
  23040. +#include "vchiq_core.h"
  23041. +#include "vchiq_killable.h"
  23042. +
  23043. +#define VCHIQ_SLOT_HANDLER_STACK 8192
  23044. +
  23045. +#define HANDLE_STATE_SHIFT 12
  23046. +
  23047. +#define SLOT_INFO_FROM_INDEX(state, index) (state->slot_info + (index))
  23048. +#define SLOT_DATA_FROM_INDEX(state, index) (state->slot_data + (index))
  23049. +#define SLOT_INDEX_FROM_DATA(state, data) \
  23050. + (((unsigned int)((char *)data - (char *)state->slot_data)) / \
  23051. + VCHIQ_SLOT_SIZE)
  23052. +#define SLOT_INDEX_FROM_INFO(state, info) \
  23053. + ((unsigned int)(info - state->slot_info))
  23054. +#define SLOT_QUEUE_INDEX_FROM_POS(pos) \
  23055. + ((int)((unsigned int)(pos) / VCHIQ_SLOT_SIZE))
  23056. +
  23057. +
  23058. +#define BULK_INDEX(x) (x & (VCHIQ_NUM_SERVICE_BULKS - 1))
  23059. +
  23060. +
  23061. +struct vchiq_open_payload {
  23062. + int fourcc;
  23063. + int client_id;
  23064. + short version;
  23065. + short version_min;
  23066. +};
  23067. +
  23068. +struct vchiq_openack_payload {
  23069. + short version;
  23070. +};
  23071. +
  23072. +/* we require this for consistency between endpoints */
  23073. +vchiq_static_assert(sizeof(VCHIQ_HEADER_T) == 8);
  23074. +vchiq_static_assert(IS_POW2(sizeof(VCHIQ_HEADER_T)));
  23075. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_CURRENT_BULKS));
  23076. +vchiq_static_assert(IS_POW2(VCHIQ_NUM_SERVICE_BULKS));
  23077. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SERVICES));
  23078. +vchiq_static_assert(VCHIQ_VERSION >= VCHIQ_VERSION_MIN);
  23079. +
  23080. +/* Run time control of log level, based on KERN_XXX level. */
  23081. +int vchiq_core_log_level = VCHIQ_LOG_DEFAULT;
  23082. +int vchiq_core_msg_log_level = VCHIQ_LOG_DEFAULT;
  23083. +int vchiq_sync_log_level = VCHIQ_LOG_DEFAULT;
  23084. +
  23085. +static atomic_t pause_bulks_count = ATOMIC_INIT(0);
  23086. +
  23087. +static DEFINE_SPINLOCK(service_spinlock);
  23088. +DEFINE_SPINLOCK(bulk_waiter_spinlock);
  23089. +DEFINE_SPINLOCK(quota_spinlock);
  23090. +
  23091. +VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  23092. +static unsigned int handle_seq;
  23093. +
  23094. +static const char *const srvstate_names[] = {
  23095. + "FREE",
  23096. + "HIDDEN",
  23097. + "LISTENING",
  23098. + "OPENING",
  23099. + "OPEN",
  23100. + "OPENSYNC",
  23101. + "CLOSESENT",
  23102. + "CLOSERECVD",
  23103. + "CLOSEWAIT",
  23104. + "CLOSED"
  23105. +};
  23106. +
  23107. +static const char *const reason_names[] = {
  23108. + "SERVICE_OPENED",
  23109. + "SERVICE_CLOSED",
  23110. + "MESSAGE_AVAILABLE",
  23111. + "BULK_TRANSMIT_DONE",
  23112. + "BULK_RECEIVE_DONE",
  23113. + "BULK_TRANSMIT_ABORTED",
  23114. + "BULK_RECEIVE_ABORTED"
  23115. +};
  23116. +
  23117. +static const char *const conn_state_names[] = {
  23118. + "DISCONNECTED",
  23119. + "CONNECTING",
  23120. + "CONNECTED",
  23121. + "PAUSING",
  23122. + "PAUSE_SENT",
  23123. + "PAUSED",
  23124. + "RESUMING",
  23125. + "PAUSE_TIMEOUT",
  23126. + "RESUME_TIMEOUT"
  23127. +};
  23128. +
  23129. +
  23130. +static void
  23131. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header);
  23132. +
  23133. +static const char *msg_type_str(unsigned int msg_type)
  23134. +{
  23135. + switch (msg_type) {
  23136. + case VCHIQ_MSG_PADDING: return "PADDING";
  23137. + case VCHIQ_MSG_CONNECT: return "CONNECT";
  23138. + case VCHIQ_MSG_OPEN: return "OPEN";
  23139. + case VCHIQ_MSG_OPENACK: return "OPENACK";
  23140. + case VCHIQ_MSG_CLOSE: return "CLOSE";
  23141. + case VCHIQ_MSG_DATA: return "DATA";
  23142. + case VCHIQ_MSG_BULK_RX: return "BULK_RX";
  23143. + case VCHIQ_MSG_BULK_TX: return "BULK_TX";
  23144. + case VCHIQ_MSG_BULK_RX_DONE: return "BULK_RX_DONE";
  23145. + case VCHIQ_MSG_BULK_TX_DONE: return "BULK_TX_DONE";
  23146. + case VCHIQ_MSG_PAUSE: return "PAUSE";
  23147. + case VCHIQ_MSG_RESUME: return "RESUME";
  23148. + case VCHIQ_MSG_REMOTE_USE: return "REMOTE_USE";
  23149. + case VCHIQ_MSG_REMOTE_RELEASE: return "REMOTE_RELEASE";
  23150. + case VCHIQ_MSG_REMOTE_USE_ACTIVE: return "REMOTE_USE_ACTIVE";
  23151. + }
  23152. + return "???";
  23153. +}
  23154. +
  23155. +static inline void
  23156. +vchiq_set_service_state(VCHIQ_SERVICE_T *service, int newstate)
  23157. +{
  23158. + vchiq_log_info(vchiq_core_log_level, "%d: srv:%d %s->%s",
  23159. + service->state->id, service->localport,
  23160. + srvstate_names[service->srvstate],
  23161. + srvstate_names[newstate]);
  23162. + service->srvstate = newstate;
  23163. +}
  23164. +
  23165. +VCHIQ_SERVICE_T *
  23166. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle)
  23167. +{
  23168. + VCHIQ_SERVICE_T *service;
  23169. +
  23170. + spin_lock(&service_spinlock);
  23171. + service = handle_to_service(handle);
  23172. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23173. + (service->handle == handle)) {
  23174. + BUG_ON(service->ref_count == 0);
  23175. + service->ref_count++;
  23176. + } else
  23177. + service = NULL;
  23178. + spin_unlock(&service_spinlock);
  23179. +
  23180. + if (!service)
  23181. + vchiq_log_info(vchiq_core_log_level,
  23182. + "Invalid service handle 0x%x", handle);
  23183. +
  23184. + return service;
  23185. +}
  23186. +
  23187. +VCHIQ_SERVICE_T *
  23188. +find_service_by_port(VCHIQ_STATE_T *state, int localport)
  23189. +{
  23190. + VCHIQ_SERVICE_T *service = NULL;
  23191. + if ((unsigned int)localport <= VCHIQ_PORT_MAX) {
  23192. + spin_lock(&service_spinlock);
  23193. + service = state->services[localport];
  23194. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE)) {
  23195. + BUG_ON(service->ref_count == 0);
  23196. + service->ref_count++;
  23197. + } else
  23198. + service = NULL;
  23199. + spin_unlock(&service_spinlock);
  23200. + }
  23201. +
  23202. + if (!service)
  23203. + vchiq_log_info(vchiq_core_log_level,
  23204. + "Invalid port %d", localport);
  23205. +
  23206. + return service;
  23207. +}
  23208. +
  23209. +VCHIQ_SERVICE_T *
  23210. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  23211. + VCHIQ_SERVICE_HANDLE_T handle) {
  23212. + VCHIQ_SERVICE_T *service;
  23213. +
  23214. + spin_lock(&service_spinlock);
  23215. + service = handle_to_service(handle);
  23216. + if (service && (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23217. + (service->handle == handle) &&
  23218. + (service->instance == instance)) {
  23219. + BUG_ON(service->ref_count == 0);
  23220. + service->ref_count++;
  23221. + } else
  23222. + service = NULL;
  23223. + spin_unlock(&service_spinlock);
  23224. +
  23225. + if (!service)
  23226. + vchiq_log_info(vchiq_core_log_level,
  23227. + "Invalid service handle 0x%x", handle);
  23228. +
  23229. + return service;
  23230. +}
  23231. +
  23232. +VCHIQ_SERVICE_T *
  23233. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  23234. + int *pidx)
  23235. +{
  23236. + VCHIQ_SERVICE_T *service = NULL;
  23237. + int idx = *pidx;
  23238. +
  23239. + spin_lock(&service_spinlock);
  23240. + while (idx < state->unused_service) {
  23241. + VCHIQ_SERVICE_T *srv = state->services[idx++];
  23242. + if (srv && (srv->srvstate != VCHIQ_SRVSTATE_FREE) &&
  23243. + (srv->instance == instance)) {
  23244. + service = srv;
  23245. + BUG_ON(service->ref_count == 0);
  23246. + service->ref_count++;
  23247. + break;
  23248. + }
  23249. + }
  23250. + spin_unlock(&service_spinlock);
  23251. +
  23252. + *pidx = idx;
  23253. +
  23254. + return service;
  23255. +}
  23256. +
  23257. +void
  23258. +lock_service(VCHIQ_SERVICE_T *service)
  23259. +{
  23260. + spin_lock(&service_spinlock);
  23261. + BUG_ON(!service || (service->ref_count == 0));
  23262. + if (service)
  23263. + service->ref_count++;
  23264. + spin_unlock(&service_spinlock);
  23265. +}
  23266. +
  23267. +void
  23268. +unlock_service(VCHIQ_SERVICE_T *service)
  23269. +{
  23270. + VCHIQ_STATE_T *state = service->state;
  23271. + spin_lock(&service_spinlock);
  23272. + BUG_ON(!service || (service->ref_count == 0));
  23273. + if (service && service->ref_count) {
  23274. + service->ref_count--;
  23275. + if (!service->ref_count) {
  23276. + BUG_ON(service->srvstate != VCHIQ_SRVSTATE_FREE);
  23277. + state->services[service->localport] = NULL;
  23278. + } else
  23279. + service = NULL;
  23280. + }
  23281. + spin_unlock(&service_spinlock);
  23282. +
  23283. + if (service && service->userdata_term)
  23284. + service->userdata_term(service->base.userdata);
  23285. +
  23286. + kfree(service);
  23287. +}
  23288. +
  23289. +int
  23290. +vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T handle)
  23291. +{
  23292. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  23293. + int id;
  23294. +
  23295. + id = service ? service->client_id : 0;
  23296. + if (service)
  23297. + unlock_service(service);
  23298. +
  23299. + return id;
  23300. +}
  23301. +
  23302. +void *
  23303. +vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T handle)
  23304. +{
  23305. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23306. +
  23307. + return service ? service->base.userdata : NULL;
  23308. +}
  23309. +
  23310. +int
  23311. +vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T handle)
  23312. +{
  23313. + VCHIQ_SERVICE_T *service = handle_to_service(handle);
  23314. +
  23315. + return service ? service->base.fourcc : 0;
  23316. +}
  23317. +
  23318. +static void
  23319. +mark_service_closing_internal(VCHIQ_SERVICE_T *service, int sh_thread)
  23320. +{
  23321. + VCHIQ_STATE_T *state = service->state;
  23322. + VCHIQ_SERVICE_QUOTA_T *service_quota;
  23323. +
  23324. + service->closing = 1;
  23325. +
  23326. + /* Synchronise with other threads. */
  23327. + mutex_lock(&state->recycle_mutex);
  23328. + mutex_unlock(&state->recycle_mutex);
  23329. + if (!sh_thread || (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT)) {
  23330. + /* If we're pausing then the slot_mutex is held until resume
  23331. + * by the slot handler. Therefore don't try to acquire this
  23332. + * mutex if we're the slot handler and in the pause sent state.
  23333. + * We don't need to in this case anyway. */
  23334. + mutex_lock(&state->slot_mutex);
  23335. + mutex_unlock(&state->slot_mutex);
  23336. + }
  23337. +
  23338. + /* Unblock any sending thread. */
  23339. + service_quota = &state->service_quotas[service->localport];
  23340. + up(&service_quota->quota_event);
  23341. +}
  23342. +
  23343. +static void
  23344. +mark_service_closing(VCHIQ_SERVICE_T *service)
  23345. +{
  23346. + mark_service_closing_internal(service, 0);
  23347. +}
  23348. +
  23349. +static inline VCHIQ_STATUS_T
  23350. +make_service_callback(VCHIQ_SERVICE_T *service, VCHIQ_REASON_T reason,
  23351. + VCHIQ_HEADER_T *header, void *bulk_userdata)
  23352. +{
  23353. + VCHIQ_STATUS_T status;
  23354. + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, %x)",
  23355. + service->state->id, service->localport, reason_names[reason],
  23356. + (unsigned int)header, (unsigned int)bulk_userdata);
  23357. + status = service->base.callback(reason, header, service->handle,
  23358. + bulk_userdata);
  23359. + if (status == VCHIQ_ERROR) {
  23360. + vchiq_log_warning(vchiq_core_log_level,
  23361. + "%d: ignoring ERROR from callback to service %x",
  23362. + service->state->id, service->handle);
  23363. + status = VCHIQ_SUCCESS;
  23364. + }
  23365. + return status;
  23366. +}
  23367. +
  23368. +inline void
  23369. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate)
  23370. +{
  23371. + VCHIQ_CONNSTATE_T oldstate = state->conn_state;
  23372. + vchiq_log_info(vchiq_core_log_level, "%d: %s->%s", state->id,
  23373. + conn_state_names[oldstate],
  23374. + conn_state_names[newstate]);
  23375. + state->conn_state = newstate;
  23376. + vchiq_platform_conn_state_changed(state, oldstate, newstate);
  23377. +}
  23378. +
  23379. +static inline void
  23380. +remote_event_create(REMOTE_EVENT_T *event)
  23381. +{
  23382. + event->armed = 0;
  23383. + /* Don't clear the 'fired' flag because it may already have been set
  23384. + ** by the other side. */
  23385. + sema_init(event->event, 0);
  23386. +}
  23387. +
  23388. +static inline void
  23389. +remote_event_destroy(REMOTE_EVENT_T *event)
  23390. +{
  23391. + (void)event;
  23392. +}
  23393. +
  23394. +static inline int
  23395. +remote_event_wait(REMOTE_EVENT_T *event)
  23396. +{
  23397. + if (!event->fired) {
  23398. + event->armed = 1;
  23399. + dsb();
  23400. + if (!event->fired) {
  23401. + if (down_interruptible(event->event) != 0) {
  23402. + event->armed = 0;
  23403. + return 0;
  23404. + }
  23405. + }
  23406. + event->armed = 0;
  23407. + wmb();
  23408. + }
  23409. +
  23410. + event->fired = 0;
  23411. + return 1;
  23412. +}
  23413. +
  23414. +static inline void
  23415. +remote_event_signal_local(REMOTE_EVENT_T *event)
  23416. +{
  23417. + event->armed = 0;
  23418. + up(event->event);
  23419. +}
  23420. +
  23421. +static inline void
  23422. +remote_event_poll(REMOTE_EVENT_T *event)
  23423. +{
  23424. + if (event->fired && event->armed)
  23425. + remote_event_signal_local(event);
  23426. +}
  23427. +
  23428. +void
  23429. +remote_event_pollall(VCHIQ_STATE_T *state)
  23430. +{
  23431. + remote_event_poll(&state->local->sync_trigger);
  23432. + remote_event_poll(&state->local->sync_release);
  23433. + remote_event_poll(&state->local->trigger);
  23434. + remote_event_poll(&state->local->recycle);
  23435. +}
  23436. +
  23437. +/* Round up message sizes so that any space at the end of a slot is always big
  23438. +** enough for a header. This relies on header size being a power of two, which
  23439. +** has been verified earlier by a static assertion. */
  23440. +
  23441. +static inline unsigned int
  23442. +calc_stride(unsigned int size)
  23443. +{
  23444. + /* Allow room for the header */
  23445. + size += sizeof(VCHIQ_HEADER_T);
  23446. +
  23447. + /* Round up */
  23448. + return (size + sizeof(VCHIQ_HEADER_T) - 1) & ~(sizeof(VCHIQ_HEADER_T)
  23449. + - 1);
  23450. +}
  23451. +
  23452. +/* Called by the slot handler thread */
  23453. +static VCHIQ_SERVICE_T *
  23454. +get_listening_service(VCHIQ_STATE_T *state, int fourcc)
  23455. +{
  23456. + int i;
  23457. +
  23458. + WARN_ON(fourcc == VCHIQ_FOURCC_INVALID);
  23459. +
  23460. + for (i = 0; i < state->unused_service; i++) {
  23461. + VCHIQ_SERVICE_T *service = state->services[i];
  23462. + if (service &&
  23463. + (service->public_fourcc == fourcc) &&
  23464. + ((service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  23465. + ((service->srvstate == VCHIQ_SRVSTATE_OPEN) &&
  23466. + (service->remoteport == VCHIQ_PORT_FREE)))) {
  23467. + lock_service(service);
  23468. + return service;
  23469. + }
  23470. + }
  23471. +
  23472. + return NULL;
  23473. +}
  23474. +
  23475. +/* Called by the slot handler thread */
  23476. +static VCHIQ_SERVICE_T *
  23477. +get_connected_service(VCHIQ_STATE_T *state, unsigned int port)
  23478. +{
  23479. + int i;
  23480. + for (i = 0; i < state->unused_service; i++) {
  23481. + VCHIQ_SERVICE_T *service = state->services[i];
  23482. + if (service && (service->srvstate == VCHIQ_SRVSTATE_OPEN)
  23483. + && (service->remoteport == port)) {
  23484. + lock_service(service);
  23485. + return service;
  23486. + }
  23487. + }
  23488. + return NULL;
  23489. +}
  23490. +
  23491. +inline void
  23492. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type)
  23493. +{
  23494. + uint32_t value;
  23495. +
  23496. + if (service) {
  23497. + do {
  23498. + value = atomic_read(&service->poll_flags);
  23499. + } while (atomic_cmpxchg(&service->poll_flags, value,
  23500. + value | (1 << poll_type)) != value);
  23501. +
  23502. + do {
  23503. + value = atomic_read(&state->poll_services[
  23504. + service->localport>>5]);
  23505. + } while (atomic_cmpxchg(
  23506. + &state->poll_services[service->localport>>5],
  23507. + value, value | (1 << (service->localport & 0x1f)))
  23508. + != value);
  23509. + }
  23510. +
  23511. + state->poll_needed = 1;
  23512. + wmb();
  23513. +
  23514. + /* ... and ensure the slot handler runs. */
  23515. + remote_event_signal_local(&state->local->trigger);
  23516. +}
  23517. +
  23518. +/* Called from queue_message, by the slot handler and application threads,
  23519. +** with slot_mutex held */
  23520. +static VCHIQ_HEADER_T *
  23521. +reserve_space(VCHIQ_STATE_T *state, int space, int is_blocking)
  23522. +{
  23523. + VCHIQ_SHARED_STATE_T *local = state->local;
  23524. + int tx_pos = state->local_tx_pos;
  23525. + int slot_space = VCHIQ_SLOT_SIZE - (tx_pos & VCHIQ_SLOT_MASK);
  23526. +
  23527. + if (space > slot_space) {
  23528. + VCHIQ_HEADER_T *header;
  23529. + /* Fill the remaining space with padding */
  23530. + WARN_ON(state->tx_data == NULL);
  23531. + header = (VCHIQ_HEADER_T *)
  23532. + (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  23533. + header->msgid = VCHIQ_MSGID_PADDING;
  23534. + header->size = slot_space - sizeof(VCHIQ_HEADER_T);
  23535. +
  23536. + tx_pos += slot_space;
  23537. + }
  23538. +
  23539. + /* If necessary, get the next slot. */
  23540. + if ((tx_pos & VCHIQ_SLOT_MASK) == 0) {
  23541. + int slot_index;
  23542. +
  23543. + /* If there is no free slot... */
  23544. +
  23545. + if (down_trylock(&state->slot_available_event) != 0) {
  23546. + /* ...wait for one. */
  23547. +
  23548. + VCHIQ_STATS_INC(state, slot_stalls);
  23549. +
  23550. + /* But first, flush through the last slot. */
  23551. + state->local_tx_pos = tx_pos;
  23552. + local->tx_pos = tx_pos;
  23553. + remote_event_signal(&state->remote->trigger);
  23554. +
  23555. + if (!is_blocking ||
  23556. + (down_interruptible(
  23557. + &state->slot_available_event) != 0))
  23558. + return NULL; /* No space available */
  23559. + }
  23560. +
  23561. + BUG_ON(tx_pos ==
  23562. + (state->slot_queue_available * VCHIQ_SLOT_SIZE));
  23563. +
  23564. + slot_index = local->slot_queue[
  23565. + SLOT_QUEUE_INDEX_FROM_POS(tx_pos) &
  23566. + VCHIQ_SLOT_QUEUE_MASK];
  23567. + state->tx_data =
  23568. + (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  23569. + }
  23570. +
  23571. + state->local_tx_pos = tx_pos + space;
  23572. +
  23573. + return (VCHIQ_HEADER_T *)(state->tx_data + (tx_pos & VCHIQ_SLOT_MASK));
  23574. +}
  23575. +
  23576. +/* Called by the recycle thread. */
  23577. +static void
  23578. +process_free_queue(VCHIQ_STATE_T *state)
  23579. +{
  23580. + VCHIQ_SHARED_STATE_T *local = state->local;
  23581. + BITSET_T service_found[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  23582. + int slot_queue_available;
  23583. +
  23584. + /* Use a read memory barrier to ensure that any state that may have
  23585. + ** been modified by another thread is not masked by stale prefetched
  23586. + ** values. */
  23587. + rmb();
  23588. +
  23589. + /* Find slots which have been freed by the other side, and return them
  23590. + ** to the available queue. */
  23591. + slot_queue_available = state->slot_queue_available;
  23592. +
  23593. + while (slot_queue_available != local->slot_queue_recycle) {
  23594. + unsigned int pos;
  23595. + int slot_index = local->slot_queue[slot_queue_available++ &
  23596. + VCHIQ_SLOT_QUEUE_MASK];
  23597. + char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index);
  23598. + int data_found = 0;
  23599. +
  23600. + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%x %x %x",
  23601. + state->id, slot_index, (unsigned int)data,
  23602. + local->slot_queue_recycle, slot_queue_available);
  23603. +
  23604. + /* Initialise the bitmask for services which have used this
  23605. + ** slot */
  23606. + BITSET_ZERO(service_found);
  23607. +
  23608. + pos = 0;
  23609. +
  23610. + while (pos < VCHIQ_SLOT_SIZE) {
  23611. + VCHIQ_HEADER_T *header =
  23612. + (VCHIQ_HEADER_T *)(data + pos);
  23613. + int msgid = header->msgid;
  23614. + if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) {
  23615. + int port = VCHIQ_MSG_SRCPORT(msgid);
  23616. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  23617. + &state->service_quotas[port];
  23618. + int count;
  23619. + spin_lock(&quota_spinlock);
  23620. + count = service_quota->message_use_count;
  23621. + if (count > 0)
  23622. + service_quota->message_use_count =
  23623. + count - 1;
  23624. + spin_unlock(&quota_spinlock);
  23625. +
  23626. + if (count == service_quota->message_quota)
  23627. + /* Signal the service that it
  23628. + ** has dropped below its quota
  23629. + */
  23630. + up(&service_quota->quota_event);
  23631. + else if (count == 0) {
  23632. + vchiq_log_error(vchiq_core_log_level,
  23633. + "service %d "
  23634. + "message_use_count=%d "
  23635. + "(header %x, msgid %x, "
  23636. + "header->msgid %x, "
  23637. + "header->size %x)",
  23638. + port,
  23639. + service_quota->
  23640. + message_use_count,
  23641. + (unsigned int)header, msgid,
  23642. + header->msgid,
  23643. + header->size);
  23644. + WARN(1, "invalid message use count\n");
  23645. + }
  23646. + if (!BITSET_IS_SET(service_found, port)) {
  23647. + /* Set the found bit for this service */
  23648. + BITSET_SET(service_found, port);
  23649. +
  23650. + spin_lock(&quota_spinlock);
  23651. + count = service_quota->slot_use_count;
  23652. + if (count > 0)
  23653. + service_quota->slot_use_count =
  23654. + count - 1;
  23655. + spin_unlock(&quota_spinlock);
  23656. +
  23657. + if (count > 0) {
  23658. + /* Signal the service in case
  23659. + ** it has dropped below its
  23660. + ** quota */
  23661. + up(&service_quota->quota_event);
  23662. + vchiq_log_trace(
  23663. + vchiq_core_log_level,
  23664. + "%d: pfq:%d %x@%x - "
  23665. + "slot_use->%d",
  23666. + state->id, port,
  23667. + header->size,
  23668. + (unsigned int)header,
  23669. + count - 1);
  23670. + } else {
  23671. + vchiq_log_error(
  23672. + vchiq_core_log_level,
  23673. + "service %d "
  23674. + "slot_use_count"
  23675. + "=%d (header %x"
  23676. + ", msgid %x, "
  23677. + "header->msgid"
  23678. + " %x, header->"
  23679. + "size %x)",
  23680. + port, count,
  23681. + (unsigned int)header,
  23682. + msgid,
  23683. + header->msgid,
  23684. + header->size);
  23685. + WARN(1, "bad slot use count\n");
  23686. + }
  23687. + }
  23688. +
  23689. + data_found = 1;
  23690. + }
  23691. +
  23692. + pos += calc_stride(header->size);
  23693. + if (pos > VCHIQ_SLOT_SIZE) {
  23694. + vchiq_log_error(vchiq_core_log_level,
  23695. + "pfq - pos %x: header %x, msgid %x, "
  23696. + "header->msgid %x, header->size %x",
  23697. + pos, (unsigned int)header, msgid,
  23698. + header->msgid, header->size);
  23699. + WARN(1, "invalid slot position\n");
  23700. + }
  23701. + }
  23702. +
  23703. + if (data_found) {
  23704. + int count;
  23705. + spin_lock(&quota_spinlock);
  23706. + count = state->data_use_count;
  23707. + if (count > 0)
  23708. + state->data_use_count =
  23709. + count - 1;
  23710. + spin_unlock(&quota_spinlock);
  23711. + if (count == state->data_quota)
  23712. + up(&state->data_quota_event);
  23713. + }
  23714. +
  23715. + state->slot_queue_available = slot_queue_available;
  23716. + up(&state->slot_available_event);
  23717. + }
  23718. +}
  23719. +
  23720. +/* Called by the slot handler and application threads */
  23721. +static VCHIQ_STATUS_T
  23722. +queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23723. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23724. + int count, int size, int is_blocking)
  23725. +{
  23726. + VCHIQ_SHARED_STATE_T *local;
  23727. + VCHIQ_SERVICE_QUOTA_T *service_quota = NULL;
  23728. + VCHIQ_HEADER_T *header;
  23729. + int type = VCHIQ_MSG_TYPE(msgid);
  23730. +
  23731. + unsigned int stride;
  23732. +
  23733. + local = state->local;
  23734. +
  23735. + stride = calc_stride(size);
  23736. +
  23737. + WARN_ON(!(stride <= VCHIQ_SLOT_SIZE));
  23738. +
  23739. + if ((type != VCHIQ_MSG_RESUME) &&
  23740. + (mutex_lock_interruptible(&state->slot_mutex) != 0))
  23741. + return VCHIQ_RETRY;
  23742. +
  23743. + if (type == VCHIQ_MSG_DATA) {
  23744. + int tx_end_index;
  23745. +
  23746. + BUG_ON(!service);
  23747. +
  23748. + if (service->closing) {
  23749. + /* The service has been closed */
  23750. + mutex_unlock(&state->slot_mutex);
  23751. + return VCHIQ_ERROR;
  23752. + }
  23753. +
  23754. + service_quota = &state->service_quotas[service->localport];
  23755. +
  23756. + spin_lock(&quota_spinlock);
  23757. +
  23758. + /* Ensure this service doesn't use more than its quota of
  23759. + ** messages or slots */
  23760. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23761. + state->local_tx_pos + stride - 1);
  23762. +
  23763. + /* Ensure data messages don't use more than their quota of
  23764. + ** slots */
  23765. + while ((tx_end_index != state->previous_data_index) &&
  23766. + (state->data_use_count == state->data_quota)) {
  23767. + VCHIQ_STATS_INC(state, data_stalls);
  23768. + spin_unlock(&quota_spinlock);
  23769. + mutex_unlock(&state->slot_mutex);
  23770. +
  23771. + if (down_interruptible(&state->data_quota_event)
  23772. + != 0)
  23773. + return VCHIQ_RETRY;
  23774. +
  23775. + mutex_lock(&state->slot_mutex);
  23776. + spin_lock(&quota_spinlock);
  23777. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23778. + state->local_tx_pos + stride - 1);
  23779. + if ((tx_end_index == state->previous_data_index) ||
  23780. + (state->data_use_count < state->data_quota)) {
  23781. + /* Pass the signal on to other waiters */
  23782. + up(&state->data_quota_event);
  23783. + break;
  23784. + }
  23785. + }
  23786. +
  23787. + while ((service_quota->message_use_count ==
  23788. + service_quota->message_quota) ||
  23789. + ((tx_end_index != service_quota->previous_tx_index) &&
  23790. + (service_quota->slot_use_count ==
  23791. + service_quota->slot_quota))) {
  23792. + spin_unlock(&quota_spinlock);
  23793. + vchiq_log_trace(vchiq_core_log_level,
  23794. + "%d: qm:%d %s,%x - quota stall "
  23795. + "(msg %d, slot %d)",
  23796. + state->id, service->localport,
  23797. + msg_type_str(type), size,
  23798. + service_quota->message_use_count,
  23799. + service_quota->slot_use_count);
  23800. + VCHIQ_SERVICE_STATS_INC(service, quota_stalls);
  23801. + mutex_unlock(&state->slot_mutex);
  23802. + if (down_interruptible(&service_quota->quota_event)
  23803. + != 0)
  23804. + return VCHIQ_RETRY;
  23805. + if (service->closing)
  23806. + return VCHIQ_ERROR;
  23807. + if (mutex_lock_interruptible(&state->slot_mutex) != 0)
  23808. + return VCHIQ_RETRY;
  23809. + if (service->srvstate != VCHIQ_SRVSTATE_OPEN) {
  23810. + /* The service has been closed */
  23811. + mutex_unlock(&state->slot_mutex);
  23812. + return VCHIQ_ERROR;
  23813. + }
  23814. + spin_lock(&quota_spinlock);
  23815. + tx_end_index = SLOT_QUEUE_INDEX_FROM_POS(
  23816. + state->local_tx_pos + stride - 1);
  23817. + }
  23818. +
  23819. + spin_unlock(&quota_spinlock);
  23820. + }
  23821. +
  23822. + header = reserve_space(state, stride, is_blocking);
  23823. +
  23824. + if (!header) {
  23825. + if (service)
  23826. + VCHIQ_SERVICE_STATS_INC(service, slot_stalls);
  23827. + mutex_unlock(&state->slot_mutex);
  23828. + return VCHIQ_RETRY;
  23829. + }
  23830. +
  23831. + if (type == VCHIQ_MSG_DATA) {
  23832. + int i, pos;
  23833. + int tx_end_index;
  23834. + int slot_use_count;
  23835. +
  23836. + vchiq_log_info(vchiq_core_log_level,
  23837. + "%d: qm %s@%x,%x (%d->%d)",
  23838. + state->id,
  23839. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23840. + (unsigned int)header, size,
  23841. + VCHIQ_MSG_SRCPORT(msgid),
  23842. + VCHIQ_MSG_DSTPORT(msgid));
  23843. +
  23844. + BUG_ON(!service);
  23845. +
  23846. + for (i = 0, pos = 0; i < (unsigned int)count;
  23847. + pos += elements[i++].size)
  23848. + if (elements[i].size) {
  23849. + if (vchiq_copy_from_user
  23850. + (header->data + pos, elements[i].data,
  23851. + (size_t) elements[i].size) !=
  23852. + VCHIQ_SUCCESS) {
  23853. + mutex_unlock(&state->slot_mutex);
  23854. + VCHIQ_SERVICE_STATS_INC(service,
  23855. + error_count);
  23856. + return VCHIQ_ERROR;
  23857. + }
  23858. + if (i == 0) {
  23859. + if (vchiq_core_msg_log_level >=
  23860. + VCHIQ_LOG_INFO)
  23861. + vchiq_log_dump_mem("Sent", 0,
  23862. + header->data + pos,
  23863. + min(64u,
  23864. + elements[0].size));
  23865. + }
  23866. + }
  23867. +
  23868. + spin_lock(&quota_spinlock);
  23869. + service_quota->message_use_count++;
  23870. +
  23871. + tx_end_index =
  23872. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos - 1);
  23873. +
  23874. + /* If this transmission can't fit in the last slot used by any
  23875. + ** service, the data_use_count must be increased. */
  23876. + if (tx_end_index != state->previous_data_index) {
  23877. + state->previous_data_index = tx_end_index;
  23878. + state->data_use_count++;
  23879. + }
  23880. +
  23881. + /* If this isn't the same slot last used by this service,
  23882. + ** the service's slot_use_count must be increased. */
  23883. + if (tx_end_index != service_quota->previous_tx_index) {
  23884. + service_quota->previous_tx_index = tx_end_index;
  23885. + slot_use_count = ++service_quota->slot_use_count;
  23886. + } else {
  23887. + slot_use_count = 0;
  23888. + }
  23889. +
  23890. + spin_unlock(&quota_spinlock);
  23891. +
  23892. + if (slot_use_count)
  23893. + vchiq_log_trace(vchiq_core_log_level,
  23894. + "%d: qm:%d %s,%x - slot_use->%d (hdr %p)",
  23895. + state->id, service->localport,
  23896. + msg_type_str(VCHIQ_MSG_TYPE(msgid)), size,
  23897. + slot_use_count, header);
  23898. +
  23899. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  23900. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  23901. + } else {
  23902. + vchiq_log_info(vchiq_core_log_level,
  23903. + "%d: qm %s@%x,%x (%d->%d)", state->id,
  23904. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23905. + (unsigned int)header, size,
  23906. + VCHIQ_MSG_SRCPORT(msgid),
  23907. + VCHIQ_MSG_DSTPORT(msgid));
  23908. + if (size != 0) {
  23909. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  23910. + memcpy(header->data, elements[0].data,
  23911. + elements[0].size);
  23912. + }
  23913. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  23914. + }
  23915. +
  23916. + header->msgid = msgid;
  23917. + header->size = size;
  23918. +
  23919. + {
  23920. + int svc_fourcc;
  23921. +
  23922. + svc_fourcc = service
  23923. + ? service->base.fourcc
  23924. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  23925. +
  23926. + vchiq_log_info(vchiq_core_msg_log_level,
  23927. + "Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  23928. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23929. + VCHIQ_MSG_TYPE(msgid),
  23930. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  23931. + VCHIQ_MSG_SRCPORT(msgid),
  23932. + VCHIQ_MSG_DSTPORT(msgid),
  23933. + size);
  23934. + }
  23935. +
  23936. + /* Make sure the new header is visible to the peer. */
  23937. + wmb();
  23938. +
  23939. + /* Make the new tx_pos visible to the peer. */
  23940. + local->tx_pos = state->local_tx_pos;
  23941. + wmb();
  23942. +
  23943. + if (service && (type == VCHIQ_MSG_CLOSE))
  23944. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_CLOSESENT);
  23945. +
  23946. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  23947. + mutex_unlock(&state->slot_mutex);
  23948. +
  23949. + remote_event_signal(&state->remote->trigger);
  23950. +
  23951. + return VCHIQ_SUCCESS;
  23952. +}
  23953. +
  23954. +/* Called by the slot handler and application threads */
  23955. +static VCHIQ_STATUS_T
  23956. +queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service,
  23957. + int msgid, const VCHIQ_ELEMENT_T *elements,
  23958. + int count, int size, int is_blocking)
  23959. +{
  23960. + VCHIQ_SHARED_STATE_T *local;
  23961. + VCHIQ_HEADER_T *header;
  23962. +
  23963. + local = state->local;
  23964. +
  23965. + if ((VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_RESUME) &&
  23966. + (mutex_lock_interruptible(&state->sync_mutex) != 0))
  23967. + return VCHIQ_RETRY;
  23968. +
  23969. + remote_event_wait(&local->sync_release);
  23970. +
  23971. + rmb();
  23972. +
  23973. + header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  23974. + local->slot_sync);
  23975. +
  23976. + {
  23977. + int oldmsgid = header->msgid;
  23978. + if (oldmsgid != VCHIQ_MSGID_PADDING)
  23979. + vchiq_log_error(vchiq_core_log_level,
  23980. + "%d: qms - msgid %x, not PADDING",
  23981. + state->id, oldmsgid);
  23982. + }
  23983. +
  23984. + if (service) {
  23985. + int i, pos;
  23986. +
  23987. + vchiq_log_info(vchiq_sync_log_level,
  23988. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  23989. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  23990. + (unsigned int)header, size,
  23991. + VCHIQ_MSG_SRCPORT(msgid),
  23992. + VCHIQ_MSG_DSTPORT(msgid));
  23993. +
  23994. + for (i = 0, pos = 0; i < (unsigned int)count;
  23995. + pos += elements[i++].size)
  23996. + if (elements[i].size) {
  23997. + if (vchiq_copy_from_user
  23998. + (header->data + pos, elements[i].data,
  23999. + (size_t) elements[i].size) !=
  24000. + VCHIQ_SUCCESS) {
  24001. + mutex_unlock(&state->sync_mutex);
  24002. + VCHIQ_SERVICE_STATS_INC(service,
  24003. + error_count);
  24004. + return VCHIQ_ERROR;
  24005. + }
  24006. + if (i == 0) {
  24007. + if (vchiq_sync_log_level >=
  24008. + VCHIQ_LOG_TRACE)
  24009. + vchiq_log_dump_mem("Sent Sync",
  24010. + 0, header->data + pos,
  24011. + min(64u,
  24012. + elements[0].size));
  24013. + }
  24014. + }
  24015. +
  24016. + VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count);
  24017. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size);
  24018. + } else {
  24019. + vchiq_log_info(vchiq_sync_log_level,
  24020. + "%d: qms %s@%x,%x (%d->%d)", state->id,
  24021. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24022. + (unsigned int)header, size,
  24023. + VCHIQ_MSG_SRCPORT(msgid),
  24024. + VCHIQ_MSG_DSTPORT(msgid));
  24025. + if (size != 0) {
  24026. + WARN_ON(!((count == 1) && (size == elements[0].size)));
  24027. + memcpy(header->data, elements[0].data,
  24028. + elements[0].size);
  24029. + }
  24030. + VCHIQ_STATS_INC(state, ctrl_tx_count);
  24031. + }
  24032. +
  24033. + header->size = size;
  24034. + header->msgid = msgid;
  24035. +
  24036. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  24037. + int svc_fourcc;
  24038. +
  24039. + svc_fourcc = service
  24040. + ? service->base.fourcc
  24041. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24042. +
  24043. + vchiq_log_trace(vchiq_sync_log_level,
  24044. + "Sent Sync Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d",
  24045. + msg_type_str(VCHIQ_MSG_TYPE(msgid)),
  24046. + VCHIQ_MSG_TYPE(msgid),
  24047. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24048. + VCHIQ_MSG_SRCPORT(msgid),
  24049. + VCHIQ_MSG_DSTPORT(msgid),
  24050. + size);
  24051. + }
  24052. +
  24053. + /* Make sure the new header is visible to the peer. */
  24054. + wmb();
  24055. +
  24056. + remote_event_signal(&state->remote->sync_trigger);
  24057. +
  24058. + if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE)
  24059. + mutex_unlock(&state->sync_mutex);
  24060. +
  24061. + return VCHIQ_SUCCESS;
  24062. +}
  24063. +
  24064. +static inline void
  24065. +claim_slot(VCHIQ_SLOT_INFO_T *slot)
  24066. +{
  24067. + slot->use_count++;
  24068. +}
  24069. +
  24070. +static void
  24071. +release_slot(VCHIQ_STATE_T *state, VCHIQ_SLOT_INFO_T *slot_info,
  24072. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_T *service)
  24073. +{
  24074. + int release_count;
  24075. +
  24076. + mutex_lock(&state->recycle_mutex);
  24077. +
  24078. + if (header) {
  24079. + int msgid = header->msgid;
  24080. + if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) ||
  24081. + (service && service->closing)) {
  24082. + mutex_unlock(&state->recycle_mutex);
  24083. + return;
  24084. + }
  24085. +
  24086. + /* Rewrite the message header to prevent a double
  24087. + ** release */
  24088. + header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED;
  24089. + }
  24090. +
  24091. + release_count = slot_info->release_count;
  24092. + slot_info->release_count = ++release_count;
  24093. +
  24094. + if (release_count == slot_info->use_count) {
  24095. + int slot_queue_recycle;
  24096. + /* Add to the freed queue */
  24097. +
  24098. + /* A read barrier is necessary here to prevent speculative
  24099. + ** fetches of remote->slot_queue_recycle from overtaking the
  24100. + ** mutex. */
  24101. + rmb();
  24102. +
  24103. + slot_queue_recycle = state->remote->slot_queue_recycle;
  24104. + state->remote->slot_queue[slot_queue_recycle &
  24105. + VCHIQ_SLOT_QUEUE_MASK] =
  24106. + SLOT_INDEX_FROM_INFO(state, slot_info);
  24107. + state->remote->slot_queue_recycle = slot_queue_recycle + 1;
  24108. + vchiq_log_info(vchiq_core_log_level,
  24109. + "%d: release_slot %d - recycle->%x",
  24110. + state->id, SLOT_INDEX_FROM_INFO(state, slot_info),
  24111. + state->remote->slot_queue_recycle);
  24112. +
  24113. + /* A write barrier is necessary, but remote_event_signal
  24114. + ** contains one. */
  24115. + remote_event_signal(&state->remote->recycle);
  24116. + }
  24117. +
  24118. + mutex_unlock(&state->recycle_mutex);
  24119. +}
  24120. +
  24121. +/* Called by the slot handler - don't hold the bulk mutex */
  24122. +static VCHIQ_STATUS_T
  24123. +notify_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue,
  24124. + int retry_poll)
  24125. +{
  24126. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  24127. +
  24128. + vchiq_log_trace(vchiq_core_log_level,
  24129. + "%d: nb:%d %cx - p=%x rn=%x r=%x",
  24130. + service->state->id, service->localport,
  24131. + (queue == &service->bulk_tx) ? 't' : 'r',
  24132. + queue->process, queue->remote_notify, queue->remove);
  24133. +
  24134. + if (service->state->is_master) {
  24135. + while (queue->remote_notify != queue->process) {
  24136. + VCHIQ_BULK_T *bulk =
  24137. + &queue->bulks[BULK_INDEX(queue->remote_notify)];
  24138. + int msgtype = (bulk->dir == VCHIQ_BULK_TRANSMIT) ?
  24139. + VCHIQ_MSG_BULK_RX_DONE : VCHIQ_MSG_BULK_TX_DONE;
  24140. + int msgid = VCHIQ_MAKE_MSG(msgtype, service->localport,
  24141. + service->remoteport);
  24142. + VCHIQ_ELEMENT_T element = { &bulk->actual, 4 };
  24143. + /* Only reply to non-dummy bulk requests */
  24144. + if (bulk->remote_data) {
  24145. + status = queue_message(service->state, NULL,
  24146. + msgid, &element, 1, 4, 0);
  24147. + if (status != VCHIQ_SUCCESS)
  24148. + break;
  24149. + }
  24150. + queue->remote_notify++;
  24151. + }
  24152. + } else {
  24153. + queue->remote_notify = queue->process;
  24154. + }
  24155. +
  24156. + if (status == VCHIQ_SUCCESS) {
  24157. + while (queue->remove != queue->remote_notify) {
  24158. + VCHIQ_BULK_T *bulk =
  24159. + &queue->bulks[BULK_INDEX(queue->remove)];
  24160. +
  24161. + /* Only generate callbacks for non-dummy bulk
  24162. + ** requests, and non-terminated services */
  24163. + if (bulk->data && service->instance) {
  24164. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED) {
  24165. + if (bulk->dir == VCHIQ_BULK_TRANSMIT) {
  24166. + VCHIQ_SERVICE_STATS_INC(service,
  24167. + bulk_tx_count);
  24168. + VCHIQ_SERVICE_STATS_ADD(service,
  24169. + bulk_tx_bytes,
  24170. + bulk->actual);
  24171. + } else {
  24172. + VCHIQ_SERVICE_STATS_INC(service,
  24173. + bulk_rx_count);
  24174. + VCHIQ_SERVICE_STATS_ADD(service,
  24175. + bulk_rx_bytes,
  24176. + bulk->actual);
  24177. + }
  24178. + } else {
  24179. + VCHIQ_SERVICE_STATS_INC(service,
  24180. + bulk_aborted_count);
  24181. + }
  24182. + if (bulk->mode == VCHIQ_BULK_MODE_BLOCKING) {
  24183. + struct bulk_waiter *waiter;
  24184. + spin_lock(&bulk_waiter_spinlock);
  24185. + waiter = bulk->userdata;
  24186. + if (waiter) {
  24187. + waiter->actual = bulk->actual;
  24188. + up(&waiter->event);
  24189. + }
  24190. + spin_unlock(&bulk_waiter_spinlock);
  24191. + } else if (bulk->mode ==
  24192. + VCHIQ_BULK_MODE_CALLBACK) {
  24193. + VCHIQ_REASON_T reason = (bulk->dir ==
  24194. + VCHIQ_BULK_TRANSMIT) ?
  24195. + ((bulk->actual ==
  24196. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24197. + VCHIQ_BULK_TRANSMIT_ABORTED :
  24198. + VCHIQ_BULK_TRANSMIT_DONE) :
  24199. + ((bulk->actual ==
  24200. + VCHIQ_BULK_ACTUAL_ABORTED) ?
  24201. + VCHIQ_BULK_RECEIVE_ABORTED :
  24202. + VCHIQ_BULK_RECEIVE_DONE);
  24203. + status = make_service_callback(service,
  24204. + reason, NULL, bulk->userdata);
  24205. + if (status == VCHIQ_RETRY)
  24206. + break;
  24207. + }
  24208. + }
  24209. +
  24210. + queue->remove++;
  24211. + up(&service->bulk_remove_event);
  24212. + }
  24213. + if (!retry_poll)
  24214. + status = VCHIQ_SUCCESS;
  24215. + }
  24216. +
  24217. + if (status == VCHIQ_RETRY)
  24218. + request_poll(service->state, service,
  24219. + (queue == &service->bulk_tx) ?
  24220. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  24221. +
  24222. + return status;
  24223. +}
  24224. +
  24225. +/* Called by the slot handler thread */
  24226. +static void
  24227. +poll_services(VCHIQ_STATE_T *state)
  24228. +{
  24229. + int group, i;
  24230. +
  24231. + for (group = 0; group < BITSET_SIZE(state->unused_service); group++) {
  24232. + uint32_t flags;
  24233. + flags = atomic_xchg(&state->poll_services[group], 0);
  24234. + for (i = 0; flags; i++) {
  24235. + if (flags & (1 << i)) {
  24236. + VCHIQ_SERVICE_T *service =
  24237. + find_service_by_port(state,
  24238. + (group<<5) + i);
  24239. + uint32_t service_flags;
  24240. + flags &= ~(1 << i);
  24241. + if (!service)
  24242. + continue;
  24243. + service_flags =
  24244. + atomic_xchg(&service->poll_flags, 0);
  24245. + if (service_flags &
  24246. + (1 << VCHIQ_POLL_REMOVE)) {
  24247. + vchiq_log_info(vchiq_core_log_level,
  24248. + "%d: ps - remove %d<->%d",
  24249. + state->id, service->localport,
  24250. + service->remoteport);
  24251. +
  24252. + /* Make it look like a client, because
  24253. + it must be removed and not left in
  24254. + the LISTENING state. */
  24255. + service->public_fourcc =
  24256. + VCHIQ_FOURCC_INVALID;
  24257. +
  24258. + if (vchiq_close_service_internal(
  24259. + service, 0/*!close_recvd*/) !=
  24260. + VCHIQ_SUCCESS)
  24261. + request_poll(state, service,
  24262. + VCHIQ_POLL_REMOVE);
  24263. + } else if (service_flags &
  24264. + (1 << VCHIQ_POLL_TERMINATE)) {
  24265. + vchiq_log_info(vchiq_core_log_level,
  24266. + "%d: ps - terminate %d<->%d",
  24267. + state->id, service->localport,
  24268. + service->remoteport);
  24269. + if (vchiq_close_service_internal(
  24270. + service, 0/*!close_recvd*/) !=
  24271. + VCHIQ_SUCCESS)
  24272. + request_poll(state, service,
  24273. + VCHIQ_POLL_TERMINATE);
  24274. + }
  24275. + if (service_flags & (1 << VCHIQ_POLL_TXNOTIFY))
  24276. + notify_bulks(service,
  24277. + &service->bulk_tx,
  24278. + 1/*retry_poll*/);
  24279. + if (service_flags & (1 << VCHIQ_POLL_RXNOTIFY))
  24280. + notify_bulks(service,
  24281. + &service->bulk_rx,
  24282. + 1/*retry_poll*/);
  24283. + unlock_service(service);
  24284. + }
  24285. + }
  24286. + }
  24287. +}
  24288. +
  24289. +/* Called by the slot handler or application threads, holding the bulk mutex. */
  24290. +static int
  24291. +resolve_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24292. +{
  24293. + VCHIQ_STATE_T *state = service->state;
  24294. + int resolved = 0;
  24295. + int rc;
  24296. +
  24297. + while ((queue->process != queue->local_insert) &&
  24298. + (queue->process != queue->remote_insert)) {
  24299. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24300. +
  24301. + vchiq_log_trace(vchiq_core_log_level,
  24302. + "%d: rb:%d %cx - li=%x ri=%x p=%x",
  24303. + state->id, service->localport,
  24304. + (queue == &service->bulk_tx) ? 't' : 'r',
  24305. + queue->local_insert, queue->remote_insert,
  24306. + queue->process);
  24307. +
  24308. + WARN_ON(!((int)(queue->local_insert - queue->process) > 0));
  24309. + WARN_ON(!((int)(queue->remote_insert - queue->process) > 0));
  24310. +
  24311. + rc = mutex_lock_interruptible(&state->bulk_transfer_mutex);
  24312. + if (rc != 0)
  24313. + break;
  24314. +
  24315. + vchiq_transfer_bulk(bulk);
  24316. + mutex_unlock(&state->bulk_transfer_mutex);
  24317. +
  24318. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24319. + const char *header = (queue == &service->bulk_tx) ?
  24320. + "Send Bulk to" : "Recv Bulk from";
  24321. + if (bulk->actual != VCHIQ_BULK_ACTUAL_ABORTED)
  24322. + vchiq_log_info(vchiq_core_msg_log_level,
  24323. + "%s %c%c%c%c d:%d len:%d %x<->%x",
  24324. + header,
  24325. + VCHIQ_FOURCC_AS_4CHARS(
  24326. + service->base.fourcc),
  24327. + service->remoteport,
  24328. + bulk->size,
  24329. + (unsigned int)bulk->data,
  24330. + (unsigned int)bulk->remote_data);
  24331. + else
  24332. + vchiq_log_info(vchiq_core_msg_log_level,
  24333. + "%s %c%c%c%c d:%d ABORTED - tx len:%d,"
  24334. + " rx len:%d %x<->%x",
  24335. + header,
  24336. + VCHIQ_FOURCC_AS_4CHARS(
  24337. + service->base.fourcc),
  24338. + service->remoteport,
  24339. + bulk->size,
  24340. + bulk->remote_size,
  24341. + (unsigned int)bulk->data,
  24342. + (unsigned int)bulk->remote_data);
  24343. + }
  24344. +
  24345. + vchiq_complete_bulk(bulk);
  24346. + queue->process++;
  24347. + resolved++;
  24348. + }
  24349. + return resolved;
  24350. +}
  24351. +
  24352. +/* Called with the bulk_mutex held */
  24353. +static void
  24354. +abort_outstanding_bulks(VCHIQ_SERVICE_T *service, VCHIQ_BULK_QUEUE_T *queue)
  24355. +{
  24356. + int is_tx = (queue == &service->bulk_tx);
  24357. + vchiq_log_trace(vchiq_core_log_level,
  24358. + "%d: aob:%d %cx - li=%x ri=%x p=%x",
  24359. + service->state->id, service->localport, is_tx ? 't' : 'r',
  24360. + queue->local_insert, queue->remote_insert, queue->process);
  24361. +
  24362. + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0));
  24363. + WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0));
  24364. +
  24365. + while ((queue->process != queue->local_insert) ||
  24366. + (queue->process != queue->remote_insert)) {
  24367. + VCHIQ_BULK_T *bulk = &queue->bulks[BULK_INDEX(queue->process)];
  24368. +
  24369. + if (queue->process == queue->remote_insert) {
  24370. + /* fabricate a matching dummy bulk */
  24371. + bulk->remote_data = NULL;
  24372. + bulk->remote_size = 0;
  24373. + queue->remote_insert++;
  24374. + }
  24375. +
  24376. + if (queue->process != queue->local_insert) {
  24377. + vchiq_complete_bulk(bulk);
  24378. +
  24379. + vchiq_log_info(vchiq_core_msg_log_level,
  24380. + "%s %c%c%c%c d:%d ABORTED - tx len:%d, "
  24381. + "rx len:%d",
  24382. + is_tx ? "Send Bulk to" : "Recv Bulk from",
  24383. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24384. + service->remoteport,
  24385. + bulk->size,
  24386. + bulk->remote_size);
  24387. + } else {
  24388. + /* fabricate a matching dummy bulk */
  24389. + bulk->data = NULL;
  24390. + bulk->size = 0;
  24391. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  24392. + bulk->dir = is_tx ? VCHIQ_BULK_TRANSMIT :
  24393. + VCHIQ_BULK_RECEIVE;
  24394. + queue->local_insert++;
  24395. + }
  24396. +
  24397. + queue->process++;
  24398. + }
  24399. +}
  24400. +
  24401. +/* Called from the slot handler thread */
  24402. +static void
  24403. +pause_bulks(VCHIQ_STATE_T *state)
  24404. +{
  24405. + if (unlikely(atomic_inc_return(&pause_bulks_count) != 1)) {
  24406. + WARN_ON_ONCE(1);
  24407. + atomic_set(&pause_bulks_count, 1);
  24408. + return;
  24409. + }
  24410. +
  24411. + /* Block bulk transfers from all services */
  24412. + mutex_lock(&state->bulk_transfer_mutex);
  24413. +}
  24414. +
  24415. +/* Called from the slot handler thread */
  24416. +static void
  24417. +resume_bulks(VCHIQ_STATE_T *state)
  24418. +{
  24419. + int i;
  24420. + if (unlikely(atomic_dec_return(&pause_bulks_count) != 0)) {
  24421. + WARN_ON_ONCE(1);
  24422. + atomic_set(&pause_bulks_count, 0);
  24423. + return;
  24424. + }
  24425. +
  24426. + /* Allow bulk transfers from all services */
  24427. + mutex_unlock(&state->bulk_transfer_mutex);
  24428. +
  24429. + if (state->deferred_bulks == 0)
  24430. + return;
  24431. +
  24432. + /* Deal with any bulks which had to be deferred due to being in
  24433. + * paused state. Don't try to match up to number of deferred bulks
  24434. + * in case we've had something come and close the service in the
  24435. + * interim - just process all bulk queues for all services */
  24436. + vchiq_log_info(vchiq_core_log_level, "%s: processing %d deferred bulks",
  24437. + __func__, state->deferred_bulks);
  24438. +
  24439. + for (i = 0; i < state->unused_service; i++) {
  24440. + VCHIQ_SERVICE_T *service = state->services[i];
  24441. + int resolved_rx = 0;
  24442. + int resolved_tx = 0;
  24443. + if (!service || (service->srvstate != VCHIQ_SRVSTATE_OPEN))
  24444. + continue;
  24445. +
  24446. + mutex_lock(&service->bulk_mutex);
  24447. + resolved_rx = resolve_bulks(service, &service->bulk_rx);
  24448. + resolved_tx = resolve_bulks(service, &service->bulk_tx);
  24449. + mutex_unlock(&service->bulk_mutex);
  24450. + if (resolved_rx)
  24451. + notify_bulks(service, &service->bulk_rx, 1);
  24452. + if (resolved_tx)
  24453. + notify_bulks(service, &service->bulk_tx, 1);
  24454. + }
  24455. + state->deferred_bulks = 0;
  24456. +}
  24457. +
  24458. +static int
  24459. +parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  24460. +{
  24461. + VCHIQ_SERVICE_T *service = NULL;
  24462. + int msgid, size;
  24463. + int type;
  24464. + unsigned int localport, remoteport;
  24465. +
  24466. + msgid = header->msgid;
  24467. + size = header->size;
  24468. + type = VCHIQ_MSG_TYPE(msgid);
  24469. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24470. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24471. + if (size >= sizeof(struct vchiq_open_payload)) {
  24472. + const struct vchiq_open_payload *payload =
  24473. + (struct vchiq_open_payload *)header->data;
  24474. + unsigned int fourcc;
  24475. +
  24476. + fourcc = payload->fourcc;
  24477. + vchiq_log_info(vchiq_core_log_level,
  24478. + "%d: prs OPEN@%x (%d->'%c%c%c%c')",
  24479. + state->id, (unsigned int)header,
  24480. + localport,
  24481. + VCHIQ_FOURCC_AS_4CHARS(fourcc));
  24482. +
  24483. + service = get_listening_service(state, fourcc);
  24484. +
  24485. + if (service) {
  24486. + /* A matching service exists */
  24487. + short version = payload->version;
  24488. + short version_min = payload->version_min;
  24489. + if ((service->version < version_min) ||
  24490. + (version < service->version_min)) {
  24491. + /* Version mismatch */
  24492. + vchiq_loud_error_header();
  24493. + vchiq_loud_error("%d: service %d (%c%c%c%c) "
  24494. + "version mismatch - local (%d, min %d)"
  24495. + " vs. remote (%d, min %d)",
  24496. + state->id, service->localport,
  24497. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  24498. + service->version, service->version_min,
  24499. + version, version_min);
  24500. + vchiq_loud_error_footer();
  24501. + unlock_service(service);
  24502. + service = NULL;
  24503. + goto fail_open;
  24504. + }
  24505. + service->peer_version = version;
  24506. +
  24507. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  24508. + struct vchiq_openack_payload ack_payload = {
  24509. + service->version
  24510. + };
  24511. + VCHIQ_ELEMENT_T body = {
  24512. + &ack_payload,
  24513. + sizeof(ack_payload)
  24514. + };
  24515. +
  24516. + /* Acknowledge the OPEN */
  24517. + if (service->sync) {
  24518. + if (queue_message_sync(state, NULL,
  24519. + VCHIQ_MAKE_MSG(
  24520. + VCHIQ_MSG_OPENACK,
  24521. + service->localport,
  24522. + remoteport),
  24523. + &body, 1, sizeof(ack_payload),
  24524. + 0) == VCHIQ_RETRY)
  24525. + goto bail_not_ready;
  24526. + } else {
  24527. + if (queue_message(state, NULL,
  24528. + VCHIQ_MAKE_MSG(
  24529. + VCHIQ_MSG_OPENACK,
  24530. + service->localport,
  24531. + remoteport),
  24532. + &body, 1, sizeof(ack_payload),
  24533. + 0) == VCHIQ_RETRY)
  24534. + goto bail_not_ready;
  24535. + }
  24536. +
  24537. + /* The service is now open */
  24538. + vchiq_set_service_state(service,
  24539. + service->sync ? VCHIQ_SRVSTATE_OPENSYNC
  24540. + : VCHIQ_SRVSTATE_OPEN);
  24541. + }
  24542. +
  24543. + service->remoteport = remoteport;
  24544. + service->client_id = ((int *)header->data)[1];
  24545. + if (make_service_callback(service, VCHIQ_SERVICE_OPENED,
  24546. + NULL, NULL) == VCHIQ_RETRY) {
  24547. + /* Bail out if not ready */
  24548. + service->remoteport = VCHIQ_PORT_FREE;
  24549. + goto bail_not_ready;
  24550. + }
  24551. +
  24552. + /* Success - the message has been dealt with */
  24553. + unlock_service(service);
  24554. + return 1;
  24555. + }
  24556. + }
  24557. +
  24558. +fail_open:
  24559. + /* No available service, or an invalid request - send a CLOSE */
  24560. + if (queue_message(state, NULL,
  24561. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CLOSE, 0, VCHIQ_MSG_SRCPORT(msgid)),
  24562. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  24563. + goto bail_not_ready;
  24564. +
  24565. + return 1;
  24566. +
  24567. +bail_not_ready:
  24568. + if (service)
  24569. + unlock_service(service);
  24570. +
  24571. + return 0;
  24572. +}
  24573. +
  24574. +/* Called by the slot handler thread */
  24575. +static void
  24576. +parse_rx_slots(VCHIQ_STATE_T *state)
  24577. +{
  24578. + VCHIQ_SHARED_STATE_T *remote = state->remote;
  24579. + VCHIQ_SERVICE_T *service = NULL;
  24580. + int tx_pos;
  24581. + DEBUG_INITIALISE(state->local)
  24582. +
  24583. + tx_pos = remote->tx_pos;
  24584. +
  24585. + while (state->rx_pos != tx_pos) {
  24586. + VCHIQ_HEADER_T *header;
  24587. + int msgid, size;
  24588. + int type;
  24589. + unsigned int localport, remoteport;
  24590. +
  24591. + DEBUG_TRACE(PARSE_LINE);
  24592. + if (!state->rx_data) {
  24593. + int rx_index;
  24594. + WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0));
  24595. + rx_index = remote->slot_queue[
  24596. + SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) &
  24597. + VCHIQ_SLOT_QUEUE_MASK];
  24598. + state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state,
  24599. + rx_index);
  24600. + state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index);
  24601. +
  24602. + /* Initialise use_count to one, and increment
  24603. + ** release_count at the end of the slot to avoid
  24604. + ** releasing the slot prematurely. */
  24605. + state->rx_info->use_count = 1;
  24606. + state->rx_info->release_count = 0;
  24607. + }
  24608. +
  24609. + header = (VCHIQ_HEADER_T *)(state->rx_data +
  24610. + (state->rx_pos & VCHIQ_SLOT_MASK));
  24611. + DEBUG_VALUE(PARSE_HEADER, (int)header);
  24612. + msgid = header->msgid;
  24613. + DEBUG_VALUE(PARSE_MSGID, msgid);
  24614. + size = header->size;
  24615. + type = VCHIQ_MSG_TYPE(msgid);
  24616. + localport = VCHIQ_MSG_DSTPORT(msgid);
  24617. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  24618. +
  24619. + if (type != VCHIQ_MSG_DATA)
  24620. + VCHIQ_STATS_INC(state, ctrl_rx_count);
  24621. +
  24622. + switch (type) {
  24623. + case VCHIQ_MSG_OPENACK:
  24624. + case VCHIQ_MSG_CLOSE:
  24625. + case VCHIQ_MSG_DATA:
  24626. + case VCHIQ_MSG_BULK_RX:
  24627. + case VCHIQ_MSG_BULK_TX:
  24628. + case VCHIQ_MSG_BULK_RX_DONE:
  24629. + case VCHIQ_MSG_BULK_TX_DONE:
  24630. + service = find_service_by_port(state, localport);
  24631. + if ((!service || service->remoteport != remoteport) &&
  24632. + (localport == 0) &&
  24633. + (type == VCHIQ_MSG_CLOSE)) {
  24634. + /* This could be a CLOSE from a client which
  24635. + hadn't yet received the OPENACK - look for
  24636. + the connected service */
  24637. + if (service)
  24638. + unlock_service(service);
  24639. + service = get_connected_service(state,
  24640. + remoteport);
  24641. + if (service)
  24642. + vchiq_log_warning(vchiq_core_log_level,
  24643. + "%d: prs %s@%x (%d->%d) - "
  24644. + "found connected service %d",
  24645. + state->id, msg_type_str(type),
  24646. + (unsigned int)header,
  24647. + remoteport, localport,
  24648. + service->localport);
  24649. + }
  24650. +
  24651. + if (!service) {
  24652. + vchiq_log_error(vchiq_core_log_level,
  24653. + "%d: prs %s@%x (%d->%d) - "
  24654. + "invalid/closed service %d",
  24655. + state->id, msg_type_str(type),
  24656. + (unsigned int)header,
  24657. + remoteport, localport, localport);
  24658. + goto skip_message;
  24659. + }
  24660. + break;
  24661. + default:
  24662. + break;
  24663. + }
  24664. +
  24665. + if (vchiq_core_msg_log_level >= VCHIQ_LOG_INFO) {
  24666. + int svc_fourcc;
  24667. +
  24668. + svc_fourcc = service
  24669. + ? service->base.fourcc
  24670. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  24671. + vchiq_log_info(vchiq_core_msg_log_level,
  24672. + "Rcvd Msg %s(%u) from %c%c%c%c s:%d d:%d "
  24673. + "len:%d",
  24674. + msg_type_str(type), type,
  24675. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  24676. + remoteport, localport, size);
  24677. + if (size > 0)
  24678. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  24679. + min(64, size));
  24680. + }
  24681. +
  24682. + if (((unsigned int)header & VCHIQ_SLOT_MASK) + calc_stride(size)
  24683. + > VCHIQ_SLOT_SIZE) {
  24684. + vchiq_log_error(vchiq_core_log_level,
  24685. + "header %x (msgid %x) - size %x too big for "
  24686. + "slot",
  24687. + (unsigned int)header, (unsigned int)msgid,
  24688. + (unsigned int)size);
  24689. + WARN(1, "oversized for slot\n");
  24690. + }
  24691. +
  24692. + switch (type) {
  24693. + case VCHIQ_MSG_OPEN:
  24694. + WARN_ON(!(VCHIQ_MSG_DSTPORT(msgid) == 0));
  24695. + if (!parse_open(state, header))
  24696. + goto bail_not_ready;
  24697. + break;
  24698. + case VCHIQ_MSG_OPENACK:
  24699. + if (size >= sizeof(struct vchiq_openack_payload)) {
  24700. + const struct vchiq_openack_payload *payload =
  24701. + (struct vchiq_openack_payload *)
  24702. + header->data;
  24703. + service->peer_version = payload->version;
  24704. + }
  24705. + vchiq_log_info(vchiq_core_log_level,
  24706. + "%d: prs OPENACK@%x,%x (%d->%d) v:%d",
  24707. + state->id, (unsigned int)header, size,
  24708. + remoteport, localport, service->peer_version);
  24709. + if (service->srvstate ==
  24710. + VCHIQ_SRVSTATE_OPENING) {
  24711. + service->remoteport = remoteport;
  24712. + vchiq_set_service_state(service,
  24713. + VCHIQ_SRVSTATE_OPEN);
  24714. + up(&service->remove_event);
  24715. + } else
  24716. + vchiq_log_error(vchiq_core_log_level,
  24717. + "OPENACK received in state %s",
  24718. + srvstate_names[service->srvstate]);
  24719. + break;
  24720. + case VCHIQ_MSG_CLOSE:
  24721. + WARN_ON(size != 0); /* There should be no data */
  24722. +
  24723. + vchiq_log_info(vchiq_core_log_level,
  24724. + "%d: prs CLOSE@%x (%d->%d)",
  24725. + state->id, (unsigned int)header,
  24726. + remoteport, localport);
  24727. +
  24728. + mark_service_closing_internal(service, 1);
  24729. +
  24730. + if (vchiq_close_service_internal(service,
  24731. + 1/*close_recvd*/) == VCHIQ_RETRY)
  24732. + goto bail_not_ready;
  24733. +
  24734. + vchiq_log_info(vchiq_core_log_level,
  24735. + "Close Service %c%c%c%c s:%u d:%d",
  24736. + VCHIQ_FOURCC_AS_4CHARS(service->base.fourcc),
  24737. + service->localport,
  24738. + service->remoteport);
  24739. + break;
  24740. + case VCHIQ_MSG_DATA:
  24741. + vchiq_log_trace(vchiq_core_log_level,
  24742. + "%d: prs DATA@%x,%x (%d->%d)",
  24743. + state->id, (unsigned int)header, size,
  24744. + remoteport, localport);
  24745. +
  24746. + if ((service->remoteport == remoteport)
  24747. + && (service->srvstate ==
  24748. + VCHIQ_SRVSTATE_OPEN)) {
  24749. + header->msgid = msgid | VCHIQ_MSGID_CLAIMED;
  24750. + claim_slot(state->rx_info);
  24751. + DEBUG_TRACE(PARSE_LINE);
  24752. + if (make_service_callback(service,
  24753. + VCHIQ_MESSAGE_AVAILABLE, header,
  24754. + NULL) == VCHIQ_RETRY) {
  24755. + DEBUG_TRACE(PARSE_LINE);
  24756. + goto bail_not_ready;
  24757. + }
  24758. + VCHIQ_SERVICE_STATS_INC(service, ctrl_rx_count);
  24759. + VCHIQ_SERVICE_STATS_ADD(service, ctrl_rx_bytes,
  24760. + size);
  24761. + } else {
  24762. + VCHIQ_STATS_INC(state, error_count);
  24763. + }
  24764. + break;
  24765. + case VCHIQ_MSG_CONNECT:
  24766. + vchiq_log_info(vchiq_core_log_level,
  24767. + "%d: prs CONNECT@%x",
  24768. + state->id, (unsigned int)header);
  24769. + up(&state->connect);
  24770. + break;
  24771. + case VCHIQ_MSG_BULK_RX:
  24772. + case VCHIQ_MSG_BULK_TX: {
  24773. + VCHIQ_BULK_QUEUE_T *queue;
  24774. + WARN_ON(!state->is_master);
  24775. + queue = (type == VCHIQ_MSG_BULK_RX) ?
  24776. + &service->bulk_tx : &service->bulk_rx;
  24777. + if ((service->remoteport == remoteport)
  24778. + && (service->srvstate ==
  24779. + VCHIQ_SRVSTATE_OPEN)) {
  24780. + VCHIQ_BULK_T *bulk;
  24781. + int resolved = 0;
  24782. +
  24783. + DEBUG_TRACE(PARSE_LINE);
  24784. + if (mutex_lock_interruptible(
  24785. + &service->bulk_mutex) != 0) {
  24786. + DEBUG_TRACE(PARSE_LINE);
  24787. + goto bail_not_ready;
  24788. + }
  24789. +
  24790. + WARN_ON(!(queue->remote_insert < queue->remove +
  24791. + VCHIQ_NUM_SERVICE_BULKS));
  24792. + bulk = &queue->bulks[
  24793. + BULK_INDEX(queue->remote_insert)];
  24794. + bulk->remote_data =
  24795. + (void *)((int *)header->data)[0];
  24796. + bulk->remote_size = ((int *)header->data)[1];
  24797. + wmb();
  24798. +
  24799. + vchiq_log_info(vchiq_core_log_level,
  24800. + "%d: prs %s@%x (%d->%d) %x@%x",
  24801. + state->id, msg_type_str(type),
  24802. + (unsigned int)header,
  24803. + remoteport, localport,
  24804. + bulk->remote_size,
  24805. + (unsigned int)bulk->remote_data);
  24806. +
  24807. + queue->remote_insert++;
  24808. +
  24809. + if (atomic_read(&pause_bulks_count)) {
  24810. + state->deferred_bulks++;
  24811. + vchiq_log_info(vchiq_core_log_level,
  24812. + "%s: deferring bulk (%d)",
  24813. + __func__,
  24814. + state->deferred_bulks);
  24815. + if (state->conn_state !=
  24816. + VCHIQ_CONNSTATE_PAUSE_SENT)
  24817. + vchiq_log_error(
  24818. + vchiq_core_log_level,
  24819. + "%s: bulks paused in "
  24820. + "unexpected state %s",
  24821. + __func__,
  24822. + conn_state_names[
  24823. + state->conn_state]);
  24824. + } else if (state->conn_state ==
  24825. + VCHIQ_CONNSTATE_CONNECTED) {
  24826. + DEBUG_TRACE(PARSE_LINE);
  24827. + resolved = resolve_bulks(service,
  24828. + queue);
  24829. + }
  24830. +
  24831. + mutex_unlock(&service->bulk_mutex);
  24832. + if (resolved)
  24833. + notify_bulks(service, queue,
  24834. + 1/*retry_poll*/);
  24835. + }
  24836. + } break;
  24837. + case VCHIQ_MSG_BULK_RX_DONE:
  24838. + case VCHIQ_MSG_BULK_TX_DONE:
  24839. + WARN_ON(state->is_master);
  24840. + if ((service->remoteport == remoteport)
  24841. + && (service->srvstate !=
  24842. + VCHIQ_SRVSTATE_FREE)) {
  24843. + VCHIQ_BULK_QUEUE_T *queue;
  24844. + VCHIQ_BULK_T *bulk;
  24845. +
  24846. + queue = (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24847. + &service->bulk_rx : &service->bulk_tx;
  24848. +
  24849. + DEBUG_TRACE(PARSE_LINE);
  24850. + if (mutex_lock_interruptible(
  24851. + &service->bulk_mutex) != 0) {
  24852. + DEBUG_TRACE(PARSE_LINE);
  24853. + goto bail_not_ready;
  24854. + }
  24855. + if ((int)(queue->remote_insert -
  24856. + queue->local_insert) >= 0) {
  24857. + vchiq_log_error(vchiq_core_log_level,
  24858. + "%d: prs %s@%x (%d->%d) "
  24859. + "unexpected (ri=%d,li=%d)",
  24860. + state->id, msg_type_str(type),
  24861. + (unsigned int)header,
  24862. + remoteport, localport,
  24863. + queue->remote_insert,
  24864. + queue->local_insert);
  24865. + mutex_unlock(&service->bulk_mutex);
  24866. + break;
  24867. + }
  24868. +
  24869. + BUG_ON(queue->process == queue->local_insert);
  24870. + BUG_ON(queue->process != queue->remote_insert);
  24871. +
  24872. + bulk = &queue->bulks[
  24873. + BULK_INDEX(queue->remote_insert)];
  24874. + bulk->actual = *(int *)header->data;
  24875. + queue->remote_insert++;
  24876. +
  24877. + vchiq_log_info(vchiq_core_log_level,
  24878. + "%d: prs %s@%x (%d->%d) %x@%x",
  24879. + state->id, msg_type_str(type),
  24880. + (unsigned int)header,
  24881. + remoteport, localport,
  24882. + bulk->actual, (unsigned int)bulk->data);
  24883. +
  24884. + vchiq_log_trace(vchiq_core_log_level,
  24885. + "%d: prs:%d %cx li=%x ri=%x p=%x",
  24886. + state->id, localport,
  24887. + (type == VCHIQ_MSG_BULK_RX_DONE) ?
  24888. + 'r' : 't',
  24889. + queue->local_insert,
  24890. + queue->remote_insert, queue->process);
  24891. +
  24892. + DEBUG_TRACE(PARSE_LINE);
  24893. + WARN_ON(queue->process == queue->local_insert);
  24894. + vchiq_complete_bulk(bulk);
  24895. + queue->process++;
  24896. + mutex_unlock(&service->bulk_mutex);
  24897. + DEBUG_TRACE(PARSE_LINE);
  24898. + notify_bulks(service, queue, 1/*retry_poll*/);
  24899. + DEBUG_TRACE(PARSE_LINE);
  24900. + }
  24901. + break;
  24902. + case VCHIQ_MSG_PADDING:
  24903. + vchiq_log_trace(vchiq_core_log_level,
  24904. + "%d: prs PADDING@%x,%x",
  24905. + state->id, (unsigned int)header, size);
  24906. + break;
  24907. + case VCHIQ_MSG_PAUSE:
  24908. + /* If initiated, signal the application thread */
  24909. + vchiq_log_trace(vchiq_core_log_level,
  24910. + "%d: prs PAUSE@%x,%x",
  24911. + state->id, (unsigned int)header, size);
  24912. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  24913. + vchiq_log_error(vchiq_core_log_level,
  24914. + "%d: PAUSE received in state PAUSED",
  24915. + state->id);
  24916. + break;
  24917. + }
  24918. + if (state->conn_state != VCHIQ_CONNSTATE_PAUSE_SENT) {
  24919. + /* Send a PAUSE in response */
  24920. + if (queue_message(state, NULL,
  24921. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  24922. + NULL, 0, 0, 0) == VCHIQ_RETRY)
  24923. + goto bail_not_ready;
  24924. + if (state->is_master)
  24925. + pause_bulks(state);
  24926. + }
  24927. + /* At this point slot_mutex is held */
  24928. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSED);
  24929. + vchiq_platform_paused(state);
  24930. + break;
  24931. + case VCHIQ_MSG_RESUME:
  24932. + vchiq_log_trace(vchiq_core_log_level,
  24933. + "%d: prs RESUME@%x,%x",
  24934. + state->id, (unsigned int)header, size);
  24935. + /* Release the slot mutex */
  24936. + mutex_unlock(&state->slot_mutex);
  24937. + if (state->is_master)
  24938. + resume_bulks(state);
  24939. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  24940. + vchiq_platform_resumed(state);
  24941. + break;
  24942. +
  24943. + case VCHIQ_MSG_REMOTE_USE:
  24944. + vchiq_on_remote_use(state);
  24945. + break;
  24946. + case VCHIQ_MSG_REMOTE_RELEASE:
  24947. + vchiq_on_remote_release(state);
  24948. + break;
  24949. + case VCHIQ_MSG_REMOTE_USE_ACTIVE:
  24950. + vchiq_on_remote_use_active(state);
  24951. + break;
  24952. +
  24953. + default:
  24954. + vchiq_log_error(vchiq_core_log_level,
  24955. + "%d: prs invalid msgid %x@%x,%x",
  24956. + state->id, msgid, (unsigned int)header, size);
  24957. + WARN(1, "invalid message\n");
  24958. + break;
  24959. + }
  24960. +
  24961. +skip_message:
  24962. + if (service) {
  24963. + unlock_service(service);
  24964. + service = NULL;
  24965. + }
  24966. +
  24967. + state->rx_pos += calc_stride(size);
  24968. +
  24969. + DEBUG_TRACE(PARSE_LINE);
  24970. + /* Perform some housekeeping when the end of the slot is
  24971. + ** reached. */
  24972. + if ((state->rx_pos & VCHIQ_SLOT_MASK) == 0) {
  24973. + /* Remove the extra reference count. */
  24974. + release_slot(state, state->rx_info, NULL, NULL);
  24975. + state->rx_data = NULL;
  24976. + }
  24977. + }
  24978. +
  24979. +bail_not_ready:
  24980. + if (service)
  24981. + unlock_service(service);
  24982. +}
  24983. +
  24984. +/* Called by the slot handler thread */
  24985. +static int
  24986. +slot_handler_func(void *v)
  24987. +{
  24988. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  24989. + VCHIQ_SHARED_STATE_T *local = state->local;
  24990. + DEBUG_INITIALISE(local)
  24991. +
  24992. + while (1) {
  24993. + DEBUG_COUNT(SLOT_HANDLER_COUNT);
  24994. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  24995. + remote_event_wait(&local->trigger);
  24996. +
  24997. + rmb();
  24998. +
  24999. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25000. + if (state->poll_needed) {
  25001. + /* Check if we need to suspend - may change our
  25002. + * conn_state */
  25003. + vchiq_platform_check_suspend(state);
  25004. +
  25005. + state->poll_needed = 0;
  25006. +
  25007. + /* Handle service polling and other rare conditions here
  25008. + ** out of the mainline code */
  25009. + switch (state->conn_state) {
  25010. + case VCHIQ_CONNSTATE_CONNECTED:
  25011. + /* Poll the services as requested */
  25012. + poll_services(state);
  25013. + break;
  25014. +
  25015. + case VCHIQ_CONNSTATE_PAUSING:
  25016. + if (state->is_master)
  25017. + pause_bulks(state);
  25018. + if (queue_message(state, NULL,
  25019. + VCHIQ_MAKE_MSG(VCHIQ_MSG_PAUSE, 0, 0),
  25020. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25021. + vchiq_set_conn_state(state,
  25022. + VCHIQ_CONNSTATE_PAUSE_SENT);
  25023. + } else {
  25024. + if (state->is_master)
  25025. + resume_bulks(state);
  25026. + /* Retry later */
  25027. + state->poll_needed = 1;
  25028. + }
  25029. + break;
  25030. +
  25031. + case VCHIQ_CONNSTATE_PAUSED:
  25032. + vchiq_platform_resume(state);
  25033. + break;
  25034. +
  25035. + case VCHIQ_CONNSTATE_RESUMING:
  25036. + if (queue_message(state, NULL,
  25037. + VCHIQ_MAKE_MSG(VCHIQ_MSG_RESUME, 0, 0),
  25038. + NULL, 0, 0, 0) != VCHIQ_RETRY) {
  25039. + if (state->is_master)
  25040. + resume_bulks(state);
  25041. + vchiq_set_conn_state(state,
  25042. + VCHIQ_CONNSTATE_CONNECTED);
  25043. + vchiq_platform_resumed(state);
  25044. + } else {
  25045. + /* This should really be impossible,
  25046. + ** since the PAUSE should have flushed
  25047. + ** through outstanding messages. */
  25048. + vchiq_log_error(vchiq_core_log_level,
  25049. + "Failed to send RESUME "
  25050. + "message");
  25051. + BUG();
  25052. + }
  25053. + break;
  25054. +
  25055. + case VCHIQ_CONNSTATE_PAUSE_TIMEOUT:
  25056. + case VCHIQ_CONNSTATE_RESUME_TIMEOUT:
  25057. + vchiq_platform_handle_timeout(state);
  25058. + break;
  25059. + default:
  25060. + break;
  25061. + }
  25062. +
  25063. +
  25064. + }
  25065. +
  25066. + DEBUG_TRACE(SLOT_HANDLER_LINE);
  25067. + parse_rx_slots(state);
  25068. + }
  25069. + return 0;
  25070. +}
  25071. +
  25072. +
  25073. +/* Called by the recycle thread */
  25074. +static int
  25075. +recycle_func(void *v)
  25076. +{
  25077. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25078. + VCHIQ_SHARED_STATE_T *local = state->local;
  25079. +
  25080. + while (1) {
  25081. + remote_event_wait(&local->recycle);
  25082. +
  25083. + process_free_queue(state);
  25084. + }
  25085. + return 0;
  25086. +}
  25087. +
  25088. +
  25089. +/* Called by the sync thread */
  25090. +static int
  25091. +sync_func(void *v)
  25092. +{
  25093. + VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v;
  25094. + VCHIQ_SHARED_STATE_T *local = state->local;
  25095. + VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state,
  25096. + state->remote->slot_sync);
  25097. +
  25098. + while (1) {
  25099. + VCHIQ_SERVICE_T *service;
  25100. + int msgid, size;
  25101. + int type;
  25102. + unsigned int localport, remoteport;
  25103. +
  25104. + remote_event_wait(&local->sync_trigger);
  25105. +
  25106. + rmb();
  25107. +
  25108. + msgid = header->msgid;
  25109. + size = header->size;
  25110. + type = VCHIQ_MSG_TYPE(msgid);
  25111. + localport = VCHIQ_MSG_DSTPORT(msgid);
  25112. + remoteport = VCHIQ_MSG_SRCPORT(msgid);
  25113. +
  25114. + service = find_service_by_port(state, localport);
  25115. +
  25116. + if (!service) {
  25117. + vchiq_log_error(vchiq_sync_log_level,
  25118. + "%d: sf %s@%x (%d->%d) - "
  25119. + "invalid/closed service %d",
  25120. + state->id, msg_type_str(type),
  25121. + (unsigned int)header,
  25122. + remoteport, localport, localport);
  25123. + release_message_sync(state, header);
  25124. + continue;
  25125. + }
  25126. +
  25127. + if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) {
  25128. + int svc_fourcc;
  25129. +
  25130. + svc_fourcc = service
  25131. + ? service->base.fourcc
  25132. + : VCHIQ_MAKE_FOURCC('?', '?', '?', '?');
  25133. + vchiq_log_trace(vchiq_sync_log_level,
  25134. + "Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d",
  25135. + msg_type_str(type),
  25136. + VCHIQ_FOURCC_AS_4CHARS(svc_fourcc),
  25137. + remoteport, localport, size);
  25138. + if (size > 0)
  25139. + vchiq_log_dump_mem("Rcvd", 0, header->data,
  25140. + min(64, size));
  25141. + }
  25142. +
  25143. + switch (type) {
  25144. + case VCHIQ_MSG_OPENACK:
  25145. + if (size >= sizeof(struct vchiq_openack_payload)) {
  25146. + const struct vchiq_openack_payload *payload =
  25147. + (struct vchiq_openack_payload *)
  25148. + header->data;
  25149. + service->peer_version = payload->version;
  25150. + }
  25151. + vchiq_log_info(vchiq_sync_log_level,
  25152. + "%d: sf OPENACK@%x,%x (%d->%d) v:%d",
  25153. + state->id, (unsigned int)header, size,
  25154. + remoteport, localport, service->peer_version);
  25155. + if (service->srvstate == VCHIQ_SRVSTATE_OPENING) {
  25156. + service->remoteport = remoteport;
  25157. + vchiq_set_service_state(service,
  25158. + VCHIQ_SRVSTATE_OPENSYNC);
  25159. + up(&service->remove_event);
  25160. + }
  25161. + release_message_sync(state, header);
  25162. + break;
  25163. +
  25164. + case VCHIQ_MSG_DATA:
  25165. + vchiq_log_trace(vchiq_sync_log_level,
  25166. + "%d: sf DATA@%x,%x (%d->%d)",
  25167. + state->id, (unsigned int)header, size,
  25168. + remoteport, localport);
  25169. +
  25170. + if ((service->remoteport == remoteport) &&
  25171. + (service->srvstate ==
  25172. + VCHIQ_SRVSTATE_OPENSYNC)) {
  25173. + if (make_service_callback(service,
  25174. + VCHIQ_MESSAGE_AVAILABLE, header,
  25175. + NULL) == VCHIQ_RETRY)
  25176. + vchiq_log_error(vchiq_sync_log_level,
  25177. + "synchronous callback to "
  25178. + "service %d returns "
  25179. + "VCHIQ_RETRY",
  25180. + localport);
  25181. + }
  25182. + break;
  25183. +
  25184. + default:
  25185. + vchiq_log_error(vchiq_sync_log_level,
  25186. + "%d: sf unexpected msgid %x@%x,%x",
  25187. + state->id, msgid, (unsigned int)header, size);
  25188. + release_message_sync(state, header);
  25189. + break;
  25190. + }
  25191. +
  25192. + unlock_service(service);
  25193. + }
  25194. +
  25195. + return 0;
  25196. +}
  25197. +
  25198. +
  25199. +static void
  25200. +init_bulk_queue(VCHIQ_BULK_QUEUE_T *queue)
  25201. +{
  25202. + queue->local_insert = 0;
  25203. + queue->remote_insert = 0;
  25204. + queue->process = 0;
  25205. + queue->remote_notify = 0;
  25206. + queue->remove = 0;
  25207. +}
  25208. +
  25209. +
  25210. +inline const char *
  25211. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state)
  25212. +{
  25213. + return conn_state_names[conn_state];
  25214. +}
  25215. +
  25216. +
  25217. +VCHIQ_SLOT_ZERO_T *
  25218. +vchiq_init_slots(void *mem_base, int mem_size)
  25219. +{
  25220. + int mem_align = (VCHIQ_SLOT_SIZE - (int)mem_base) & VCHIQ_SLOT_MASK;
  25221. + VCHIQ_SLOT_ZERO_T *slot_zero =
  25222. + (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align);
  25223. + int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE;
  25224. + int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS;
  25225. +
  25226. + /* Ensure there is enough memory to run an absolutely minimum system */
  25227. + num_slots -= first_data_slot;
  25228. +
  25229. + if (num_slots < 4) {
  25230. + vchiq_log_error(vchiq_core_log_level,
  25231. + "vchiq_init_slots - insufficient memory %x bytes",
  25232. + mem_size);
  25233. + return NULL;
  25234. + }
  25235. +
  25236. + memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T));
  25237. +
  25238. + slot_zero->magic = VCHIQ_MAGIC;
  25239. + slot_zero->version = VCHIQ_VERSION;
  25240. + slot_zero->version_min = VCHIQ_VERSION_MIN;
  25241. + slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T);
  25242. + slot_zero->slot_size = VCHIQ_SLOT_SIZE;
  25243. + slot_zero->max_slots = VCHIQ_MAX_SLOTS;
  25244. + slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE;
  25245. +
  25246. + slot_zero->master.slot_sync = first_data_slot;
  25247. + slot_zero->master.slot_first = first_data_slot + 1;
  25248. + slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1;
  25249. + slot_zero->slave.slot_sync = first_data_slot + (num_slots/2);
  25250. + slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1;
  25251. + slot_zero->slave.slot_last = first_data_slot + num_slots - 1;
  25252. +
  25253. + return slot_zero;
  25254. +}
  25255. +
  25256. +VCHIQ_STATUS_T
  25257. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  25258. + int is_master)
  25259. +{
  25260. + VCHIQ_SHARED_STATE_T *local;
  25261. + VCHIQ_SHARED_STATE_T *remote;
  25262. + VCHIQ_STATUS_T status;
  25263. + char threadname[10];
  25264. + static int id;
  25265. + int i;
  25266. +
  25267. + vchiq_log_warning(vchiq_core_log_level,
  25268. + "%s: slot_zero = 0x%08lx, is_master = %d",
  25269. + __func__, (unsigned long)slot_zero, is_master);
  25270. +
  25271. + /* Check the input configuration */
  25272. +
  25273. + if (slot_zero->magic != VCHIQ_MAGIC) {
  25274. + vchiq_loud_error_header();
  25275. + vchiq_loud_error("Invalid VCHIQ magic value found.");
  25276. + vchiq_loud_error("slot_zero=%x: magic=%x (expected %x)",
  25277. + (unsigned int)slot_zero, slot_zero->magic, VCHIQ_MAGIC);
  25278. + vchiq_loud_error_footer();
  25279. + return VCHIQ_ERROR;
  25280. + }
  25281. +
  25282. + if (slot_zero->version < VCHIQ_VERSION_MIN) {
  25283. + vchiq_loud_error_header();
  25284. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25285. + vchiq_loud_error("slot_zero=%x: VideoCore version=%d "
  25286. + "(minimum %d)",
  25287. + (unsigned int)slot_zero, slot_zero->version,
  25288. + VCHIQ_VERSION_MIN);
  25289. + vchiq_loud_error("Restart with a newer VideoCore image.");
  25290. + vchiq_loud_error_footer();
  25291. + return VCHIQ_ERROR;
  25292. + }
  25293. +
  25294. + if (VCHIQ_VERSION < slot_zero->version_min) {
  25295. + vchiq_loud_error_header();
  25296. + vchiq_loud_error("Incompatible VCHIQ versions found.");
  25297. + vchiq_loud_error("slot_zero=%x: version=%d (VideoCore "
  25298. + "minimum %d)",
  25299. + (unsigned int)slot_zero, VCHIQ_VERSION,
  25300. + slot_zero->version_min);
  25301. + vchiq_loud_error("Restart with a newer kernel.");
  25302. + vchiq_loud_error_footer();
  25303. + return VCHIQ_ERROR;
  25304. + }
  25305. +
  25306. + if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) ||
  25307. + (slot_zero->slot_size != VCHIQ_SLOT_SIZE) ||
  25308. + (slot_zero->max_slots != VCHIQ_MAX_SLOTS) ||
  25309. + (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) {
  25310. + vchiq_loud_error_header();
  25311. + if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T))
  25312. + vchiq_loud_error("slot_zero=%x: slot_zero_size=%x "
  25313. + "(expected %x)",
  25314. + (unsigned int)slot_zero,
  25315. + slot_zero->slot_zero_size,
  25316. + sizeof(VCHIQ_SLOT_ZERO_T));
  25317. + if (slot_zero->slot_size != VCHIQ_SLOT_SIZE)
  25318. + vchiq_loud_error("slot_zero=%x: slot_size=%d "
  25319. + "(expected %d",
  25320. + (unsigned int)slot_zero, slot_zero->slot_size,
  25321. + VCHIQ_SLOT_SIZE);
  25322. + if (slot_zero->max_slots != VCHIQ_MAX_SLOTS)
  25323. + vchiq_loud_error("slot_zero=%x: max_slots=%d "
  25324. + "(expected %d)",
  25325. + (unsigned int)slot_zero, slot_zero->max_slots,
  25326. + VCHIQ_MAX_SLOTS);
  25327. + if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)
  25328. + vchiq_loud_error("slot_zero=%x: max_slots_per_side=%d "
  25329. + "(expected %d)",
  25330. + (unsigned int)slot_zero,
  25331. + slot_zero->max_slots_per_side,
  25332. + VCHIQ_MAX_SLOTS_PER_SIDE);
  25333. + vchiq_loud_error_footer();
  25334. + return VCHIQ_ERROR;
  25335. + }
  25336. +
  25337. + if (is_master) {
  25338. + local = &slot_zero->master;
  25339. + remote = &slot_zero->slave;
  25340. + } else {
  25341. + local = &slot_zero->slave;
  25342. + remote = &slot_zero->master;
  25343. + }
  25344. +
  25345. + if (local->initialised) {
  25346. + vchiq_loud_error_header();
  25347. + if (remote->initialised)
  25348. + vchiq_loud_error("local state has already been "
  25349. + "initialised");
  25350. + else
  25351. + vchiq_loud_error("master/slave mismatch - two %ss",
  25352. + is_master ? "master" : "slave");
  25353. + vchiq_loud_error_footer();
  25354. + return VCHIQ_ERROR;
  25355. + }
  25356. +
  25357. + memset(state, 0, sizeof(VCHIQ_STATE_T));
  25358. +
  25359. + state->id = id++;
  25360. + state->is_master = is_master;
  25361. +
  25362. + /*
  25363. + initialize shared state pointers
  25364. + */
  25365. +
  25366. + state->local = local;
  25367. + state->remote = remote;
  25368. + state->slot_data = (VCHIQ_SLOT_T *)slot_zero;
  25369. +
  25370. + /*
  25371. + initialize events and mutexes
  25372. + */
  25373. +
  25374. + sema_init(&state->connect, 0);
  25375. + mutex_init(&state->mutex);
  25376. + sema_init(&state->trigger_event, 0);
  25377. + sema_init(&state->recycle_event, 0);
  25378. + sema_init(&state->sync_trigger_event, 0);
  25379. + sema_init(&state->sync_release_event, 0);
  25380. +
  25381. + mutex_init(&state->slot_mutex);
  25382. + mutex_init(&state->recycle_mutex);
  25383. + mutex_init(&state->sync_mutex);
  25384. + mutex_init(&state->bulk_transfer_mutex);
  25385. +
  25386. + sema_init(&state->slot_available_event, 0);
  25387. + sema_init(&state->slot_remove_event, 0);
  25388. + sema_init(&state->data_quota_event, 0);
  25389. +
  25390. + state->slot_queue_available = 0;
  25391. +
  25392. + for (i = 0; i < VCHIQ_MAX_SERVICES; i++) {
  25393. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25394. + &state->service_quotas[i];
  25395. + sema_init(&service_quota->quota_event, 0);
  25396. + }
  25397. +
  25398. + for (i = local->slot_first; i <= local->slot_last; i++) {
  25399. + local->slot_queue[state->slot_queue_available++] = i;
  25400. + up(&state->slot_available_event);
  25401. + }
  25402. +
  25403. + state->default_slot_quota = state->slot_queue_available/2;
  25404. + state->default_message_quota =
  25405. + min((unsigned short)(state->default_slot_quota * 256),
  25406. + (unsigned short)~0);
  25407. +
  25408. + state->previous_data_index = -1;
  25409. + state->data_use_count = 0;
  25410. + state->data_quota = state->slot_queue_available - 1;
  25411. +
  25412. + local->trigger.event = &state->trigger_event;
  25413. + remote_event_create(&local->trigger);
  25414. + local->tx_pos = 0;
  25415. +
  25416. + local->recycle.event = &state->recycle_event;
  25417. + remote_event_create(&local->recycle);
  25418. + local->slot_queue_recycle = state->slot_queue_available;
  25419. +
  25420. + local->sync_trigger.event = &state->sync_trigger_event;
  25421. + remote_event_create(&local->sync_trigger);
  25422. +
  25423. + local->sync_release.event = &state->sync_release_event;
  25424. + remote_event_create(&local->sync_release);
  25425. +
  25426. + /* At start-of-day, the slot is empty and available */
  25427. + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid
  25428. + = VCHIQ_MSGID_PADDING;
  25429. + remote_event_signal_local(&local->sync_release);
  25430. +
  25431. + local->debug[DEBUG_ENTRIES] = DEBUG_MAX;
  25432. +
  25433. + status = vchiq_platform_init_state(state);
  25434. +
  25435. + /*
  25436. + bring up slot handler thread
  25437. + */
  25438. + snprintf(threadname, sizeof(threadname), "VCHIQ-%d", state->id);
  25439. + state->slot_handler_thread = kthread_create(&slot_handler_func,
  25440. + (void *)state,
  25441. + threadname);
  25442. +
  25443. + if (state->slot_handler_thread == NULL) {
  25444. + vchiq_loud_error_header();
  25445. + vchiq_loud_error("couldn't create thread %s", threadname);
  25446. + vchiq_loud_error_footer();
  25447. + return VCHIQ_ERROR;
  25448. + }
  25449. + set_user_nice(state->slot_handler_thread, -19);
  25450. + wake_up_process(state->slot_handler_thread);
  25451. +
  25452. + snprintf(threadname, sizeof(threadname), "VCHIQr-%d", state->id);
  25453. + state->recycle_thread = kthread_create(&recycle_func,
  25454. + (void *)state,
  25455. + threadname);
  25456. + if (state->recycle_thread == NULL) {
  25457. + vchiq_loud_error_header();
  25458. + vchiq_loud_error("couldn't create thread %s", threadname);
  25459. + vchiq_loud_error_footer();
  25460. + return VCHIQ_ERROR;
  25461. + }
  25462. + set_user_nice(state->recycle_thread, -19);
  25463. + wake_up_process(state->recycle_thread);
  25464. +
  25465. + snprintf(threadname, sizeof(threadname), "VCHIQs-%d", state->id);
  25466. + state->sync_thread = kthread_create(&sync_func,
  25467. + (void *)state,
  25468. + threadname);
  25469. + if (state->sync_thread == NULL) {
  25470. + vchiq_loud_error_header();
  25471. + vchiq_loud_error("couldn't create thread %s", threadname);
  25472. + vchiq_loud_error_footer();
  25473. + return VCHIQ_ERROR;
  25474. + }
  25475. + set_user_nice(state->sync_thread, -20);
  25476. + wake_up_process(state->sync_thread);
  25477. +
  25478. + BUG_ON(state->id >= VCHIQ_MAX_STATES);
  25479. + vchiq_states[state->id] = state;
  25480. +
  25481. + /* Indicate readiness to the other side */
  25482. + local->initialised = 1;
  25483. +
  25484. + return status;
  25485. +}
  25486. +
  25487. +/* Called from application thread when a client or server service is created. */
  25488. +VCHIQ_SERVICE_T *
  25489. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  25490. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  25491. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term)
  25492. +{
  25493. + VCHIQ_SERVICE_T *service;
  25494. +
  25495. + service = kmalloc(sizeof(VCHIQ_SERVICE_T), GFP_KERNEL);
  25496. + if (service) {
  25497. + service->base.fourcc = params->fourcc;
  25498. + service->base.callback = params->callback;
  25499. + service->base.userdata = params->userdata;
  25500. + service->handle = VCHIQ_SERVICE_HANDLE_INVALID;
  25501. + service->ref_count = 1;
  25502. + service->srvstate = VCHIQ_SRVSTATE_FREE;
  25503. + service->userdata_term = userdata_term;
  25504. + service->localport = VCHIQ_PORT_FREE;
  25505. + service->remoteport = VCHIQ_PORT_FREE;
  25506. +
  25507. + service->public_fourcc = (srvstate == VCHIQ_SRVSTATE_OPENING) ?
  25508. + VCHIQ_FOURCC_INVALID : params->fourcc;
  25509. + service->client_id = 0;
  25510. + service->auto_close = 1;
  25511. + service->sync = 0;
  25512. + service->closing = 0;
  25513. + atomic_set(&service->poll_flags, 0);
  25514. + service->version = params->version;
  25515. + service->version_min = params->version_min;
  25516. + service->state = state;
  25517. + service->instance = instance;
  25518. + service->service_use_count = 0;
  25519. + init_bulk_queue(&service->bulk_tx);
  25520. + init_bulk_queue(&service->bulk_rx);
  25521. + sema_init(&service->remove_event, 0);
  25522. + sema_init(&service->bulk_remove_event, 0);
  25523. + mutex_init(&service->bulk_mutex);
  25524. + memset(&service->stats, 0, sizeof(service->stats));
  25525. + } else {
  25526. + vchiq_log_error(vchiq_core_log_level,
  25527. + "Out of memory");
  25528. + }
  25529. +
  25530. + if (service) {
  25531. + VCHIQ_SERVICE_T **pservice = NULL;
  25532. + int i;
  25533. +
  25534. + /* Although it is perfectly possible to use service_spinlock
  25535. + ** to protect the creation of services, it is overkill as it
  25536. + ** disables interrupts while the array is searched.
  25537. + ** The only danger is of another thread trying to create a
  25538. + ** service - service deletion is safe.
  25539. + ** Therefore it is preferable to use state->mutex which,
  25540. + ** although slower to claim, doesn't block interrupts while
  25541. + ** it is held.
  25542. + */
  25543. +
  25544. + mutex_lock(&state->mutex);
  25545. +
  25546. + /* Prepare to use a previously unused service */
  25547. + if (state->unused_service < VCHIQ_MAX_SERVICES)
  25548. + pservice = &state->services[state->unused_service];
  25549. +
  25550. + if (srvstate == VCHIQ_SRVSTATE_OPENING) {
  25551. + for (i = 0; i < state->unused_service; i++) {
  25552. + VCHIQ_SERVICE_T *srv = state->services[i];
  25553. + if (!srv) {
  25554. + pservice = &state->services[i];
  25555. + break;
  25556. + }
  25557. + }
  25558. + } else {
  25559. + for (i = (state->unused_service - 1); i >= 0; i--) {
  25560. + VCHIQ_SERVICE_T *srv = state->services[i];
  25561. + if (!srv)
  25562. + pservice = &state->services[i];
  25563. + else if ((srv->public_fourcc == params->fourcc)
  25564. + && ((srv->instance != instance) ||
  25565. + (srv->base.callback !=
  25566. + params->callback))) {
  25567. + /* There is another server using this
  25568. + ** fourcc which doesn't match. */
  25569. + pservice = NULL;
  25570. + break;
  25571. + }
  25572. + }
  25573. + }
  25574. +
  25575. + if (pservice) {
  25576. + service->localport = (pservice - state->services);
  25577. + if (!handle_seq)
  25578. + handle_seq = VCHIQ_MAX_STATES *
  25579. + VCHIQ_MAX_SERVICES;
  25580. + service->handle = handle_seq |
  25581. + (state->id * VCHIQ_MAX_SERVICES) |
  25582. + service->localport;
  25583. + handle_seq += VCHIQ_MAX_STATES * VCHIQ_MAX_SERVICES;
  25584. + *pservice = service;
  25585. + if (pservice == &state->services[state->unused_service])
  25586. + state->unused_service++;
  25587. + }
  25588. +
  25589. + mutex_unlock(&state->mutex);
  25590. +
  25591. + if (!pservice) {
  25592. + kfree(service);
  25593. + service = NULL;
  25594. + }
  25595. + }
  25596. +
  25597. + if (service) {
  25598. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  25599. + &state->service_quotas[service->localport];
  25600. + service_quota->slot_quota = state->default_slot_quota;
  25601. + service_quota->message_quota = state->default_message_quota;
  25602. + if (service_quota->slot_use_count == 0)
  25603. + service_quota->previous_tx_index =
  25604. + SLOT_QUEUE_INDEX_FROM_POS(state->local_tx_pos)
  25605. + - 1;
  25606. +
  25607. + /* Bring this service online */
  25608. + vchiq_set_service_state(service, srvstate);
  25609. +
  25610. + vchiq_log_info(vchiq_core_msg_log_level,
  25611. + "%s Service %c%c%c%c SrcPort:%d",
  25612. + (srvstate == VCHIQ_SRVSTATE_OPENING)
  25613. + ? "Open" : "Add",
  25614. + VCHIQ_FOURCC_AS_4CHARS(params->fourcc),
  25615. + service->localport);
  25616. + }
  25617. +
  25618. + /* Don't unlock the service - leave it with a ref_count of 1. */
  25619. +
  25620. + return service;
  25621. +}
  25622. +
  25623. +VCHIQ_STATUS_T
  25624. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id)
  25625. +{
  25626. + struct vchiq_open_payload payload = {
  25627. + service->base.fourcc,
  25628. + client_id,
  25629. + service->version,
  25630. + service->version_min
  25631. + };
  25632. + VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) };
  25633. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25634. +
  25635. + service->client_id = client_id;
  25636. + vchiq_use_service_internal(service);
  25637. + status = queue_message(service->state, NULL,
  25638. + VCHIQ_MAKE_MSG(VCHIQ_MSG_OPEN, service->localport, 0),
  25639. + &body, 1, sizeof(payload), 1);
  25640. + if (status == VCHIQ_SUCCESS) {
  25641. + if (down_interruptible(&service->remove_event) != 0) {
  25642. + status = VCHIQ_RETRY;
  25643. + vchiq_release_service_internal(service);
  25644. + } else if ((service->srvstate != VCHIQ_SRVSTATE_OPEN) &&
  25645. + (service->srvstate != VCHIQ_SRVSTATE_OPENSYNC)) {
  25646. + if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT)
  25647. + vchiq_log_error(vchiq_core_log_level,
  25648. + "%d: osi - srvstate = %s (ref %d)",
  25649. + service->state->id,
  25650. + srvstate_names[service->srvstate],
  25651. + service->ref_count);
  25652. + status = VCHIQ_ERROR;
  25653. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  25654. + vchiq_release_service_internal(service);
  25655. + }
  25656. + }
  25657. + return status;
  25658. +}
  25659. +
  25660. +static void
  25661. +release_service_messages(VCHIQ_SERVICE_T *service)
  25662. +{
  25663. + VCHIQ_STATE_T *state = service->state;
  25664. + int slot_last = state->remote->slot_last;
  25665. + int i;
  25666. +
  25667. + /* Release any claimed messages */
  25668. + for (i = state->remote->slot_first; i <= slot_last; i++) {
  25669. + VCHIQ_SLOT_INFO_T *slot_info =
  25670. + SLOT_INFO_FROM_INDEX(state, i);
  25671. + if (slot_info->release_count != slot_info->use_count) {
  25672. + char *data =
  25673. + (char *)SLOT_DATA_FROM_INDEX(state, i);
  25674. + unsigned int pos, end;
  25675. +
  25676. + end = VCHIQ_SLOT_SIZE;
  25677. + if (data == state->rx_data)
  25678. + /* This buffer is still being read from - stop
  25679. + ** at the current read position */
  25680. + end = state->rx_pos & VCHIQ_SLOT_MASK;
  25681. +
  25682. + pos = 0;
  25683. +
  25684. + while (pos < end) {
  25685. + VCHIQ_HEADER_T *header =
  25686. + (VCHIQ_HEADER_T *)(data + pos);
  25687. + int msgid = header->msgid;
  25688. + int port = VCHIQ_MSG_DSTPORT(msgid);
  25689. + if ((port == service->localport) &&
  25690. + (msgid & VCHIQ_MSGID_CLAIMED)) {
  25691. + vchiq_log_info(vchiq_core_log_level,
  25692. + " fsi - hdr %x",
  25693. + (unsigned int)header);
  25694. + release_slot(state, slot_info, header,
  25695. + NULL);
  25696. + }
  25697. + pos += calc_stride(header->size);
  25698. + if (pos > VCHIQ_SLOT_SIZE) {
  25699. + vchiq_log_error(vchiq_core_log_level,
  25700. + "fsi - pos %x: header %x, "
  25701. + "msgid %x, header->msgid %x, "
  25702. + "header->size %x",
  25703. + pos, (unsigned int)header,
  25704. + msgid, header->msgid,
  25705. + header->size);
  25706. + WARN(1, "invalid slot position\n");
  25707. + }
  25708. + }
  25709. + }
  25710. + }
  25711. +}
  25712. +
  25713. +static int
  25714. +do_abort_bulks(VCHIQ_SERVICE_T *service)
  25715. +{
  25716. + VCHIQ_STATUS_T status;
  25717. +
  25718. + /* Abort any outstanding bulk transfers */
  25719. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0)
  25720. + return 0;
  25721. + abort_outstanding_bulks(service, &service->bulk_tx);
  25722. + abort_outstanding_bulks(service, &service->bulk_rx);
  25723. + mutex_unlock(&service->bulk_mutex);
  25724. +
  25725. + status = notify_bulks(service, &service->bulk_tx, 0/*!retry_poll*/);
  25726. + if (status == VCHIQ_SUCCESS)
  25727. + status = notify_bulks(service, &service->bulk_rx,
  25728. + 0/*!retry_poll*/);
  25729. + return (status == VCHIQ_SUCCESS);
  25730. +}
  25731. +
  25732. +static VCHIQ_STATUS_T
  25733. +close_service_complete(VCHIQ_SERVICE_T *service, int failstate)
  25734. +{
  25735. + VCHIQ_STATUS_T status;
  25736. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25737. + int newstate;
  25738. +
  25739. + switch (service->srvstate) {
  25740. + case VCHIQ_SRVSTATE_OPEN:
  25741. + case VCHIQ_SRVSTATE_CLOSESENT:
  25742. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25743. + if (is_server) {
  25744. + if (service->auto_close) {
  25745. + service->client_id = 0;
  25746. + service->remoteport = VCHIQ_PORT_FREE;
  25747. + newstate = VCHIQ_SRVSTATE_LISTENING;
  25748. + } else
  25749. + newstate = VCHIQ_SRVSTATE_CLOSEWAIT;
  25750. + } else
  25751. + newstate = VCHIQ_SRVSTATE_CLOSED;
  25752. + vchiq_set_service_state(service, newstate);
  25753. + break;
  25754. + case VCHIQ_SRVSTATE_LISTENING:
  25755. + break;
  25756. + default:
  25757. + vchiq_log_error(vchiq_core_log_level,
  25758. + "close_service_complete(%x) called in state %s",
  25759. + service->handle, srvstate_names[service->srvstate]);
  25760. + WARN(1, "close_service_complete in unexpected state\n");
  25761. + return VCHIQ_ERROR;
  25762. + }
  25763. +
  25764. + status = make_service_callback(service,
  25765. + VCHIQ_SERVICE_CLOSED, NULL, NULL);
  25766. +
  25767. + if (status != VCHIQ_RETRY) {
  25768. + int uc = service->service_use_count;
  25769. + int i;
  25770. + /* Complete the close process */
  25771. + for (i = 0; i < uc; i++)
  25772. + /* cater for cases where close is forced and the
  25773. + ** client may not close all it's handles */
  25774. + vchiq_release_service_internal(service);
  25775. +
  25776. + service->client_id = 0;
  25777. + service->remoteport = VCHIQ_PORT_FREE;
  25778. +
  25779. + if (service->srvstate == VCHIQ_SRVSTATE_CLOSED)
  25780. + vchiq_free_service_internal(service);
  25781. + else if (service->srvstate != VCHIQ_SRVSTATE_CLOSEWAIT) {
  25782. + if (is_server)
  25783. + service->closing = 0;
  25784. +
  25785. + up(&service->remove_event);
  25786. + }
  25787. + } else
  25788. + vchiq_set_service_state(service, failstate);
  25789. +
  25790. + return status;
  25791. +}
  25792. +
  25793. +/* Called by the slot handler */
  25794. +VCHIQ_STATUS_T
  25795. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd)
  25796. +{
  25797. + VCHIQ_STATE_T *state = service->state;
  25798. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  25799. + int is_server = (service->public_fourcc != VCHIQ_FOURCC_INVALID);
  25800. +
  25801. + vchiq_log_info(vchiq_core_log_level, "%d: csi:%d,%d (%s)",
  25802. + service->state->id, service->localport, close_recvd,
  25803. + srvstate_names[service->srvstate]);
  25804. +
  25805. + switch (service->srvstate) {
  25806. + case VCHIQ_SRVSTATE_CLOSED:
  25807. + case VCHIQ_SRVSTATE_HIDDEN:
  25808. + case VCHIQ_SRVSTATE_LISTENING:
  25809. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25810. + if (close_recvd)
  25811. + vchiq_log_error(vchiq_core_log_level,
  25812. + "vchiq_close_service_internal(1) called "
  25813. + "in state %s",
  25814. + srvstate_names[service->srvstate]);
  25815. + else if (is_server) {
  25816. + if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) {
  25817. + status = VCHIQ_ERROR;
  25818. + } else {
  25819. + service->client_id = 0;
  25820. + service->remoteport = VCHIQ_PORT_FREE;
  25821. + if (service->srvstate ==
  25822. + VCHIQ_SRVSTATE_CLOSEWAIT)
  25823. + vchiq_set_service_state(service,
  25824. + VCHIQ_SRVSTATE_LISTENING);
  25825. + }
  25826. + up(&service->remove_event);
  25827. + } else
  25828. + vchiq_free_service_internal(service);
  25829. + break;
  25830. + case VCHIQ_SRVSTATE_OPENING:
  25831. + if (close_recvd) {
  25832. + /* The open was rejected - tell the user */
  25833. + vchiq_set_service_state(service,
  25834. + VCHIQ_SRVSTATE_CLOSEWAIT);
  25835. + up(&service->remove_event);
  25836. + } else {
  25837. + /* Shutdown mid-open - let the other side know */
  25838. + status = queue_message(state, service,
  25839. + VCHIQ_MAKE_MSG
  25840. + (VCHIQ_MSG_CLOSE,
  25841. + service->localport,
  25842. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25843. + NULL, 0, 0, 0);
  25844. + }
  25845. + break;
  25846. +
  25847. + case VCHIQ_SRVSTATE_OPENSYNC:
  25848. + mutex_lock(&state->sync_mutex);
  25849. + /* Drop through */
  25850. +
  25851. + case VCHIQ_SRVSTATE_OPEN:
  25852. + if (state->is_master || close_recvd) {
  25853. + if (!do_abort_bulks(service))
  25854. + status = VCHIQ_RETRY;
  25855. + }
  25856. +
  25857. + release_service_messages(service);
  25858. +
  25859. + if (status == VCHIQ_SUCCESS)
  25860. + status = queue_message(state, service,
  25861. + VCHIQ_MAKE_MSG
  25862. + (VCHIQ_MSG_CLOSE,
  25863. + service->localport,
  25864. + VCHIQ_MSG_DSTPORT(service->remoteport)),
  25865. + NULL, 0, 0, 0);
  25866. +
  25867. + if (status == VCHIQ_SUCCESS) {
  25868. + if (!close_recvd)
  25869. + break;
  25870. + } else if (service->srvstate == VCHIQ_SRVSTATE_OPENSYNC) {
  25871. + mutex_unlock(&state->sync_mutex);
  25872. + break;
  25873. + } else
  25874. + break;
  25875. +
  25876. + status = close_service_complete(service,
  25877. + VCHIQ_SRVSTATE_CLOSERECVD);
  25878. + break;
  25879. +
  25880. + case VCHIQ_SRVSTATE_CLOSESENT:
  25881. + if (!close_recvd)
  25882. + /* This happens when a process is killed mid-close */
  25883. + break;
  25884. +
  25885. + if (!state->is_master) {
  25886. + if (!do_abort_bulks(service)) {
  25887. + status = VCHIQ_RETRY;
  25888. + break;
  25889. + }
  25890. + }
  25891. +
  25892. + if (status == VCHIQ_SUCCESS)
  25893. + status = close_service_complete(service,
  25894. + VCHIQ_SRVSTATE_CLOSERECVD);
  25895. + break;
  25896. +
  25897. + case VCHIQ_SRVSTATE_CLOSERECVD:
  25898. + if (!close_recvd && is_server)
  25899. + /* Force into LISTENING mode */
  25900. + vchiq_set_service_state(service,
  25901. + VCHIQ_SRVSTATE_LISTENING);
  25902. + status = close_service_complete(service,
  25903. + VCHIQ_SRVSTATE_CLOSERECVD);
  25904. + break;
  25905. +
  25906. + default:
  25907. + vchiq_log_error(vchiq_core_log_level,
  25908. + "vchiq_close_service_internal(%d) called in state %s",
  25909. + close_recvd, srvstate_names[service->srvstate]);
  25910. + break;
  25911. + }
  25912. +
  25913. + return status;
  25914. +}
  25915. +
  25916. +/* Called from the application process upon process death */
  25917. +void
  25918. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service)
  25919. +{
  25920. + VCHIQ_STATE_T *state = service->state;
  25921. +
  25922. + vchiq_log_info(vchiq_core_log_level, "%d: tsi - (%d<->%d)",
  25923. + state->id, service->localport, service->remoteport);
  25924. +
  25925. + mark_service_closing(service);
  25926. +
  25927. + /* Mark the service for removal by the slot handler */
  25928. + request_poll(state, service, VCHIQ_POLL_REMOVE);
  25929. +}
  25930. +
  25931. +/* Called from the slot handler */
  25932. +void
  25933. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service)
  25934. +{
  25935. + VCHIQ_STATE_T *state = service->state;
  25936. +
  25937. + vchiq_log_info(vchiq_core_log_level, "%d: fsi - (%d)",
  25938. + state->id, service->localport);
  25939. +
  25940. + switch (service->srvstate) {
  25941. + case VCHIQ_SRVSTATE_OPENING:
  25942. + case VCHIQ_SRVSTATE_CLOSED:
  25943. + case VCHIQ_SRVSTATE_HIDDEN:
  25944. + case VCHIQ_SRVSTATE_LISTENING:
  25945. + case VCHIQ_SRVSTATE_CLOSEWAIT:
  25946. + break;
  25947. + default:
  25948. + vchiq_log_error(vchiq_core_log_level,
  25949. + "%d: fsi - (%d) in state %s",
  25950. + state->id, service->localport,
  25951. + srvstate_names[service->srvstate]);
  25952. + return;
  25953. + }
  25954. +
  25955. + vchiq_set_service_state(service, VCHIQ_SRVSTATE_FREE);
  25956. +
  25957. + up(&service->remove_event);
  25958. +
  25959. + /* Release the initial lock */
  25960. + unlock_service(service);
  25961. +}
  25962. +
  25963. +VCHIQ_STATUS_T
  25964. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  25965. +{
  25966. + VCHIQ_SERVICE_T *service;
  25967. + int i;
  25968. +
  25969. + /* Find all services registered to this client and enable them. */
  25970. + i = 0;
  25971. + while ((service = next_service_by_instance(state, instance,
  25972. + &i)) != NULL) {
  25973. + if (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)
  25974. + vchiq_set_service_state(service,
  25975. + VCHIQ_SRVSTATE_LISTENING);
  25976. + unlock_service(service);
  25977. + }
  25978. +
  25979. + if (state->conn_state == VCHIQ_CONNSTATE_DISCONNECTED) {
  25980. + if (queue_message(state, NULL,
  25981. + VCHIQ_MAKE_MSG(VCHIQ_MSG_CONNECT, 0, 0), NULL, 0,
  25982. + 0, 1) == VCHIQ_RETRY)
  25983. + return VCHIQ_RETRY;
  25984. +
  25985. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTING);
  25986. + }
  25987. +
  25988. + if (state->conn_state == VCHIQ_CONNSTATE_CONNECTING) {
  25989. + if (down_interruptible(&state->connect) != 0)
  25990. + return VCHIQ_RETRY;
  25991. +
  25992. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_CONNECTED);
  25993. + up(&state->connect);
  25994. + }
  25995. +
  25996. + return VCHIQ_SUCCESS;
  25997. +}
  25998. +
  25999. +VCHIQ_STATUS_T
  26000. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance)
  26001. +{
  26002. + VCHIQ_SERVICE_T *service;
  26003. + int i;
  26004. +
  26005. + /* Find all services registered to this client and enable them. */
  26006. + i = 0;
  26007. + while ((service = next_service_by_instance(state, instance,
  26008. + &i)) != NULL) {
  26009. + (void)vchiq_remove_service(service->handle);
  26010. + unlock_service(service);
  26011. + }
  26012. +
  26013. + return VCHIQ_SUCCESS;
  26014. +}
  26015. +
  26016. +VCHIQ_STATUS_T
  26017. +vchiq_pause_internal(VCHIQ_STATE_T *state)
  26018. +{
  26019. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26020. +
  26021. + switch (state->conn_state) {
  26022. + case VCHIQ_CONNSTATE_CONNECTED:
  26023. + /* Request a pause */
  26024. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_PAUSING);
  26025. + request_poll(state, NULL, 0);
  26026. + break;
  26027. + default:
  26028. + vchiq_log_error(vchiq_core_log_level,
  26029. + "vchiq_pause_internal in state %s\n",
  26030. + conn_state_names[state->conn_state]);
  26031. + status = VCHIQ_ERROR;
  26032. + VCHIQ_STATS_INC(state, error_count);
  26033. + break;
  26034. + }
  26035. +
  26036. + return status;
  26037. +}
  26038. +
  26039. +VCHIQ_STATUS_T
  26040. +vchiq_resume_internal(VCHIQ_STATE_T *state)
  26041. +{
  26042. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26043. +
  26044. + if (state->conn_state == VCHIQ_CONNSTATE_PAUSED) {
  26045. + vchiq_set_conn_state(state, VCHIQ_CONNSTATE_RESUMING);
  26046. + request_poll(state, NULL, 0);
  26047. + } else {
  26048. + status = VCHIQ_ERROR;
  26049. + VCHIQ_STATS_INC(state, error_count);
  26050. + }
  26051. +
  26052. + return status;
  26053. +}
  26054. +
  26055. +VCHIQ_STATUS_T
  26056. +vchiq_close_service(VCHIQ_SERVICE_HANDLE_T handle)
  26057. +{
  26058. + /* Unregister the service */
  26059. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26060. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26061. +
  26062. + if (!service)
  26063. + return VCHIQ_ERROR;
  26064. +
  26065. + vchiq_log_info(vchiq_core_log_level,
  26066. + "%d: close_service:%d",
  26067. + service->state->id, service->localport);
  26068. +
  26069. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26070. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26071. + (service->srvstate == VCHIQ_SRVSTATE_HIDDEN)) {
  26072. + unlock_service(service);
  26073. + return VCHIQ_ERROR;
  26074. + }
  26075. +
  26076. + mark_service_closing(service);
  26077. +
  26078. + if (current == service->state->slot_handler_thread) {
  26079. + status = vchiq_close_service_internal(service,
  26080. + 0/*!close_recvd*/);
  26081. + BUG_ON(status == VCHIQ_RETRY);
  26082. + } else {
  26083. + /* Mark the service for termination by the slot handler */
  26084. + request_poll(service->state, service, VCHIQ_POLL_TERMINATE);
  26085. + }
  26086. +
  26087. + while (1) {
  26088. + if (down_interruptible(&service->remove_event) != 0) {
  26089. + status = VCHIQ_RETRY;
  26090. + break;
  26091. + }
  26092. +
  26093. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26094. + (service->srvstate == VCHIQ_SRVSTATE_LISTENING) ||
  26095. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26096. + break;
  26097. +
  26098. + vchiq_log_warning(vchiq_core_log_level,
  26099. + "%d: close_service:%d - waiting in state %s",
  26100. + service->state->id, service->localport,
  26101. + srvstate_names[service->srvstate]);
  26102. + }
  26103. +
  26104. + if ((status == VCHIQ_SUCCESS) &&
  26105. + (service->srvstate != VCHIQ_SRVSTATE_FREE) &&
  26106. + (service->srvstate != VCHIQ_SRVSTATE_LISTENING))
  26107. + status = VCHIQ_ERROR;
  26108. +
  26109. + unlock_service(service);
  26110. +
  26111. + return status;
  26112. +}
  26113. +
  26114. +VCHIQ_STATUS_T
  26115. +vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T handle)
  26116. +{
  26117. + /* Unregister the service */
  26118. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26119. + VCHIQ_STATUS_T status = VCHIQ_SUCCESS;
  26120. +
  26121. + if (!service)
  26122. + return VCHIQ_ERROR;
  26123. +
  26124. + vchiq_log_info(vchiq_core_log_level,
  26125. + "%d: remove_service:%d",
  26126. + service->state->id, service->localport);
  26127. +
  26128. + if (service->srvstate == VCHIQ_SRVSTATE_FREE) {
  26129. + unlock_service(service);
  26130. + return VCHIQ_ERROR;
  26131. + }
  26132. +
  26133. + mark_service_closing(service);
  26134. +
  26135. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26136. + (current == service->state->slot_handler_thread)) {
  26137. + /* Make it look like a client, because it must be removed and
  26138. + not left in the LISTENING state. */
  26139. + service->public_fourcc = VCHIQ_FOURCC_INVALID;
  26140. +
  26141. + status = vchiq_close_service_internal(service,
  26142. + 0/*!close_recvd*/);
  26143. + BUG_ON(status == VCHIQ_RETRY);
  26144. + } else {
  26145. + /* Mark the service for removal by the slot handler */
  26146. + request_poll(service->state, service, VCHIQ_POLL_REMOVE);
  26147. + }
  26148. + while (1) {
  26149. + if (down_interruptible(&service->remove_event) != 0) {
  26150. + status = VCHIQ_RETRY;
  26151. + break;
  26152. + }
  26153. +
  26154. + if ((service->srvstate == VCHIQ_SRVSTATE_FREE) ||
  26155. + (service->srvstate == VCHIQ_SRVSTATE_OPEN))
  26156. + break;
  26157. +
  26158. + vchiq_log_warning(vchiq_core_log_level,
  26159. + "%d: remove_service:%d - waiting in state %s",
  26160. + service->state->id, service->localport,
  26161. + srvstate_names[service->srvstate]);
  26162. + }
  26163. +
  26164. + if ((status == VCHIQ_SUCCESS) &&
  26165. + (service->srvstate != VCHIQ_SRVSTATE_FREE))
  26166. + status = VCHIQ_ERROR;
  26167. +
  26168. + unlock_service(service);
  26169. +
  26170. + return status;
  26171. +}
  26172. +
  26173. +
  26174. +/* This function may be called by kernel threads or user threads.
  26175. + * User threads may receive VCHIQ_RETRY to indicate that a signal has been
  26176. + * received and the call should be retried after being returned to user
  26177. + * context.
  26178. + * When called in blocking mode, the userdata field points to a bulk_waiter
  26179. + * structure.
  26180. + */
  26181. +VCHIQ_STATUS_T
  26182. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  26183. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  26184. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir)
  26185. +{
  26186. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26187. + VCHIQ_BULK_QUEUE_T *queue;
  26188. + VCHIQ_BULK_T *bulk;
  26189. + VCHIQ_STATE_T *state;
  26190. + struct bulk_waiter *bulk_waiter = NULL;
  26191. + const char dir_char = (dir == VCHIQ_BULK_TRANSMIT) ? 't' : 'r';
  26192. + const int dir_msgtype = (dir == VCHIQ_BULK_TRANSMIT) ?
  26193. + VCHIQ_MSG_BULK_TX : VCHIQ_MSG_BULK_RX;
  26194. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26195. +
  26196. + if (!service ||
  26197. + (service->srvstate != VCHIQ_SRVSTATE_OPEN) ||
  26198. + ((memhandle == VCHI_MEM_HANDLE_INVALID) && (offset == NULL)) ||
  26199. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26200. + goto error_exit;
  26201. +
  26202. + switch (mode) {
  26203. + case VCHIQ_BULK_MODE_NOCALLBACK:
  26204. + case VCHIQ_BULK_MODE_CALLBACK:
  26205. + break;
  26206. + case VCHIQ_BULK_MODE_BLOCKING:
  26207. + bulk_waiter = (struct bulk_waiter *)userdata;
  26208. + sema_init(&bulk_waiter->event, 0);
  26209. + bulk_waiter->actual = 0;
  26210. + bulk_waiter->bulk = NULL;
  26211. + break;
  26212. + case VCHIQ_BULK_MODE_WAITING:
  26213. + bulk_waiter = (struct bulk_waiter *)userdata;
  26214. + bulk = bulk_waiter->bulk;
  26215. + goto waiting;
  26216. + default:
  26217. + goto error_exit;
  26218. + }
  26219. +
  26220. + state = service->state;
  26221. +
  26222. + queue = (dir == VCHIQ_BULK_TRANSMIT) ?
  26223. + &service->bulk_tx : &service->bulk_rx;
  26224. +
  26225. + if (mutex_lock_interruptible(&service->bulk_mutex) != 0) {
  26226. + status = VCHIQ_RETRY;
  26227. + goto error_exit;
  26228. + }
  26229. +
  26230. + if (queue->local_insert == queue->remove + VCHIQ_NUM_SERVICE_BULKS) {
  26231. + VCHIQ_SERVICE_STATS_INC(service, bulk_stalls);
  26232. + do {
  26233. + mutex_unlock(&service->bulk_mutex);
  26234. + if (down_interruptible(&service->bulk_remove_event)
  26235. + != 0) {
  26236. + status = VCHIQ_RETRY;
  26237. + goto error_exit;
  26238. + }
  26239. + if (mutex_lock_interruptible(&service->bulk_mutex)
  26240. + != 0) {
  26241. + status = VCHIQ_RETRY;
  26242. + goto error_exit;
  26243. + }
  26244. + } while (queue->local_insert == queue->remove +
  26245. + VCHIQ_NUM_SERVICE_BULKS);
  26246. + }
  26247. +
  26248. + bulk = &queue->bulks[BULK_INDEX(queue->local_insert)];
  26249. +
  26250. + bulk->mode = mode;
  26251. + bulk->dir = dir;
  26252. + bulk->userdata = userdata;
  26253. + bulk->size = size;
  26254. + bulk->actual = VCHIQ_BULK_ACTUAL_ABORTED;
  26255. +
  26256. + if (vchiq_prepare_bulk_data(bulk, memhandle, offset, size, dir) !=
  26257. + VCHIQ_SUCCESS)
  26258. + goto unlock_error_exit;
  26259. +
  26260. + wmb();
  26261. +
  26262. + vchiq_log_info(vchiq_core_log_level,
  26263. + "%d: bt (%d->%d) %cx %x@%x %x",
  26264. + state->id,
  26265. + service->localport, service->remoteport, dir_char,
  26266. + size, (unsigned int)bulk->data, (unsigned int)userdata);
  26267. +
  26268. + if (state->is_master) {
  26269. + queue->local_insert++;
  26270. + if (resolve_bulks(service, queue))
  26271. + request_poll(state, service,
  26272. + (dir == VCHIQ_BULK_TRANSMIT) ?
  26273. + VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY);
  26274. + } else {
  26275. + int payload[2] = { (int)bulk->data, bulk->size };
  26276. + VCHIQ_ELEMENT_T element = { payload, sizeof(payload) };
  26277. +
  26278. + status = queue_message(state, NULL,
  26279. + VCHIQ_MAKE_MSG(dir_msgtype,
  26280. + service->localport, service->remoteport),
  26281. + &element, 1, sizeof(payload), 1);
  26282. + if (status != VCHIQ_SUCCESS) {
  26283. + vchiq_complete_bulk(bulk);
  26284. + goto unlock_error_exit;
  26285. + }
  26286. + queue->local_insert++;
  26287. + }
  26288. +
  26289. + mutex_unlock(&service->bulk_mutex);
  26290. +
  26291. + vchiq_log_trace(vchiq_core_log_level,
  26292. + "%d: bt:%d %cx li=%x ri=%x p=%x",
  26293. + state->id,
  26294. + service->localport, dir_char,
  26295. + queue->local_insert, queue->remote_insert, queue->process);
  26296. +
  26297. +waiting:
  26298. + unlock_service(service);
  26299. +
  26300. + status = VCHIQ_SUCCESS;
  26301. +
  26302. + if (bulk_waiter) {
  26303. + bulk_waiter->bulk = bulk;
  26304. + if (down_interruptible(&bulk_waiter->event) != 0)
  26305. + status = VCHIQ_RETRY;
  26306. + else if (bulk_waiter->actual == VCHIQ_BULK_ACTUAL_ABORTED)
  26307. + status = VCHIQ_ERROR;
  26308. + }
  26309. +
  26310. + return status;
  26311. +
  26312. +unlock_error_exit:
  26313. + mutex_unlock(&service->bulk_mutex);
  26314. +
  26315. +error_exit:
  26316. + if (service)
  26317. + unlock_service(service);
  26318. + return status;
  26319. +}
  26320. +
  26321. +VCHIQ_STATUS_T
  26322. +vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T handle,
  26323. + const VCHIQ_ELEMENT_T *elements, unsigned int count)
  26324. +{
  26325. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26326. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26327. +
  26328. + unsigned int size = 0;
  26329. + unsigned int i;
  26330. +
  26331. + if (!service ||
  26332. + (vchiq_check_service(service) != VCHIQ_SUCCESS))
  26333. + goto error_exit;
  26334. +
  26335. + for (i = 0; i < (unsigned int)count; i++) {
  26336. + if (elements[i].size) {
  26337. + if (elements[i].data == NULL) {
  26338. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26339. + goto error_exit;
  26340. + }
  26341. + size += elements[i].size;
  26342. + }
  26343. + }
  26344. +
  26345. + if (size > VCHIQ_MAX_MSG_SIZE) {
  26346. + VCHIQ_SERVICE_STATS_INC(service, error_count);
  26347. + goto error_exit;
  26348. + }
  26349. +
  26350. + switch (service->srvstate) {
  26351. + case VCHIQ_SRVSTATE_OPEN:
  26352. + status = queue_message(service->state, service,
  26353. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26354. + service->localport,
  26355. + service->remoteport),
  26356. + elements, count, size, 1);
  26357. + break;
  26358. + case VCHIQ_SRVSTATE_OPENSYNC:
  26359. + status = queue_message_sync(service->state, service,
  26360. + VCHIQ_MAKE_MSG(VCHIQ_MSG_DATA,
  26361. + service->localport,
  26362. + service->remoteport),
  26363. + elements, count, size, 1);
  26364. + break;
  26365. + default:
  26366. + status = VCHIQ_ERROR;
  26367. + break;
  26368. + }
  26369. +
  26370. +error_exit:
  26371. + if (service)
  26372. + unlock_service(service);
  26373. +
  26374. + return status;
  26375. +}
  26376. +
  26377. +void
  26378. +vchiq_release_message(VCHIQ_SERVICE_HANDLE_T handle, VCHIQ_HEADER_T *header)
  26379. +{
  26380. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26381. + VCHIQ_SHARED_STATE_T *remote;
  26382. + VCHIQ_STATE_T *state;
  26383. + int slot_index;
  26384. +
  26385. + if (!service)
  26386. + return;
  26387. +
  26388. + state = service->state;
  26389. + remote = state->remote;
  26390. +
  26391. + slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header);
  26392. +
  26393. + if ((slot_index >= remote->slot_first) &&
  26394. + (slot_index <= remote->slot_last)) {
  26395. + int msgid = header->msgid;
  26396. + if (msgid & VCHIQ_MSGID_CLAIMED) {
  26397. + VCHIQ_SLOT_INFO_T *slot_info =
  26398. + SLOT_INFO_FROM_INDEX(state, slot_index);
  26399. +
  26400. + release_slot(state, slot_info, header, service);
  26401. + }
  26402. + } else if (slot_index == remote->slot_sync)
  26403. + release_message_sync(state, header);
  26404. +
  26405. + unlock_service(service);
  26406. +}
  26407. +
  26408. +static void
  26409. +release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header)
  26410. +{
  26411. + header->msgid = VCHIQ_MSGID_PADDING;
  26412. + wmb();
  26413. + remote_event_signal(&state->remote->sync_release);
  26414. +}
  26415. +
  26416. +VCHIQ_STATUS_T
  26417. +vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, short *peer_version)
  26418. +{
  26419. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26420. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26421. +
  26422. + if (!service ||
  26423. + (vchiq_check_service(service) != VCHIQ_SUCCESS) ||
  26424. + !peer_version)
  26425. + goto exit;
  26426. + *peer_version = service->peer_version;
  26427. + status = VCHIQ_SUCCESS;
  26428. +
  26429. +exit:
  26430. + if (service)
  26431. + unlock_service(service);
  26432. + return status;
  26433. +}
  26434. +
  26435. +VCHIQ_STATUS_T
  26436. +vchiq_get_config(VCHIQ_INSTANCE_T instance,
  26437. + int config_size, VCHIQ_CONFIG_T *pconfig)
  26438. +{
  26439. + VCHIQ_CONFIG_T config;
  26440. +
  26441. + (void)instance;
  26442. +
  26443. + config.max_msg_size = VCHIQ_MAX_MSG_SIZE;
  26444. + config.bulk_threshold = VCHIQ_MAX_MSG_SIZE;
  26445. + config.max_outstanding_bulks = VCHIQ_NUM_SERVICE_BULKS;
  26446. + config.max_services = VCHIQ_MAX_SERVICES;
  26447. + config.version = VCHIQ_VERSION;
  26448. + config.version_min = VCHIQ_VERSION_MIN;
  26449. +
  26450. + if (config_size > sizeof(VCHIQ_CONFIG_T))
  26451. + return VCHIQ_ERROR;
  26452. +
  26453. + memcpy(pconfig, &config,
  26454. + min(config_size, (int)(sizeof(VCHIQ_CONFIG_T))));
  26455. +
  26456. + return VCHIQ_SUCCESS;
  26457. +}
  26458. +
  26459. +VCHIQ_STATUS_T
  26460. +vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T handle,
  26461. + VCHIQ_SERVICE_OPTION_T option, int value)
  26462. +{
  26463. + VCHIQ_SERVICE_T *service = find_service_by_handle(handle);
  26464. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  26465. +
  26466. + if (service) {
  26467. + switch (option) {
  26468. + case VCHIQ_SERVICE_OPTION_AUTOCLOSE:
  26469. + service->auto_close = value;
  26470. + status = VCHIQ_SUCCESS;
  26471. + break;
  26472. +
  26473. + case VCHIQ_SERVICE_OPTION_SLOT_QUOTA: {
  26474. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26475. + &service->state->service_quotas[
  26476. + service->localport];
  26477. + if (value == 0)
  26478. + value = service->state->default_slot_quota;
  26479. + if ((value >= service_quota->slot_use_count) &&
  26480. + (value < (unsigned short)~0)) {
  26481. + service_quota->slot_quota = value;
  26482. + if ((value >= service_quota->slot_use_count) &&
  26483. + (service_quota->message_quota >=
  26484. + service_quota->message_use_count)) {
  26485. + /* Signal the service that it may have
  26486. + ** dropped below its quota */
  26487. + up(&service_quota->quota_event);
  26488. + }
  26489. + status = VCHIQ_SUCCESS;
  26490. + }
  26491. + } break;
  26492. +
  26493. + case VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA: {
  26494. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26495. + &service->state->service_quotas[
  26496. + service->localport];
  26497. + if (value == 0)
  26498. + value = service->state->default_message_quota;
  26499. + if ((value >= service_quota->message_use_count) &&
  26500. + (value < (unsigned short)~0)) {
  26501. + service_quota->message_quota = value;
  26502. + if ((value >=
  26503. + service_quota->message_use_count) &&
  26504. + (service_quota->slot_quota >=
  26505. + service_quota->slot_use_count))
  26506. + /* Signal the service that it may have
  26507. + ** dropped below its quota */
  26508. + up(&service_quota->quota_event);
  26509. + status = VCHIQ_SUCCESS;
  26510. + }
  26511. + } break;
  26512. +
  26513. + case VCHIQ_SERVICE_OPTION_SYNCHRONOUS:
  26514. + if ((service->srvstate == VCHIQ_SRVSTATE_HIDDEN) ||
  26515. + (service->srvstate ==
  26516. + VCHIQ_SRVSTATE_LISTENING)) {
  26517. + service->sync = value;
  26518. + status = VCHIQ_SUCCESS;
  26519. + }
  26520. + break;
  26521. +
  26522. + default:
  26523. + break;
  26524. + }
  26525. + unlock_service(service);
  26526. + }
  26527. +
  26528. + return status;
  26529. +}
  26530. +
  26531. +void
  26532. +vchiq_dump_shared_state(void *dump_context, VCHIQ_STATE_T *state,
  26533. + VCHIQ_SHARED_STATE_T *shared, const char *label)
  26534. +{
  26535. + static const char *const debug_names[] = {
  26536. + "<entries>",
  26537. + "SLOT_HANDLER_COUNT",
  26538. + "SLOT_HANDLER_LINE",
  26539. + "PARSE_LINE",
  26540. + "PARSE_HEADER",
  26541. + "PARSE_MSGID",
  26542. + "AWAIT_COMPLETION_LINE",
  26543. + "DEQUEUE_MESSAGE_LINE",
  26544. + "SERVICE_CALLBACK_LINE",
  26545. + "MSG_QUEUE_FULL_COUNT",
  26546. + "COMPLETION_QUEUE_FULL_COUNT"
  26547. + };
  26548. + int i;
  26549. +
  26550. + char buf[80];
  26551. + int len;
  26552. + len = snprintf(buf, sizeof(buf),
  26553. + " %s: slots %d-%d tx_pos=%x recycle=%x",
  26554. + label, shared->slot_first, shared->slot_last,
  26555. + shared->tx_pos, shared->slot_queue_recycle);
  26556. + vchiq_dump(dump_context, buf, len + 1);
  26557. +
  26558. + len = snprintf(buf, sizeof(buf),
  26559. + " Slots claimed:");
  26560. + vchiq_dump(dump_context, buf, len + 1);
  26561. +
  26562. + for (i = shared->slot_first; i <= shared->slot_last; i++) {
  26563. + VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i);
  26564. + if (slot_info.use_count != slot_info.release_count) {
  26565. + len = snprintf(buf, sizeof(buf),
  26566. + " %d: %d/%d", i, slot_info.use_count,
  26567. + slot_info.release_count);
  26568. + vchiq_dump(dump_context, buf, len + 1);
  26569. + }
  26570. + }
  26571. +
  26572. + for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) {
  26573. + len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)",
  26574. + debug_names[i], shared->debug[i], shared->debug[i]);
  26575. + vchiq_dump(dump_context, buf, len + 1);
  26576. + }
  26577. +}
  26578. +
  26579. +void
  26580. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state)
  26581. +{
  26582. + char buf[80];
  26583. + int len;
  26584. + int i;
  26585. +
  26586. + len = snprintf(buf, sizeof(buf), "State %d: %s", state->id,
  26587. + conn_state_names[state->conn_state]);
  26588. + vchiq_dump(dump_context, buf, len + 1);
  26589. +
  26590. + len = snprintf(buf, sizeof(buf),
  26591. + " tx_pos=%x(@%x), rx_pos=%x(@%x)",
  26592. + state->local->tx_pos,
  26593. + (uint32_t)state->tx_data +
  26594. + (state->local_tx_pos & VCHIQ_SLOT_MASK),
  26595. + state->rx_pos,
  26596. + (uint32_t)state->rx_data +
  26597. + (state->rx_pos & VCHIQ_SLOT_MASK));
  26598. + vchiq_dump(dump_context, buf, len + 1);
  26599. +
  26600. + len = snprintf(buf, sizeof(buf),
  26601. + " Version: %d (min %d)",
  26602. + VCHIQ_VERSION, VCHIQ_VERSION_MIN);
  26603. + vchiq_dump(dump_context, buf, len + 1);
  26604. +
  26605. + if (VCHIQ_ENABLE_STATS) {
  26606. + len = snprintf(buf, sizeof(buf),
  26607. + " Stats: ctrl_tx_count=%d, ctrl_rx_count=%d, "
  26608. + "error_count=%d",
  26609. + state->stats.ctrl_tx_count, state->stats.ctrl_rx_count,
  26610. + state->stats.error_count);
  26611. + vchiq_dump(dump_context, buf, len + 1);
  26612. + }
  26613. +
  26614. + len = snprintf(buf, sizeof(buf),
  26615. + " Slots: %d available (%d data), %d recyclable, %d stalls "
  26616. + "(%d data)",
  26617. + ((state->slot_queue_available * VCHIQ_SLOT_SIZE) -
  26618. + state->local_tx_pos) / VCHIQ_SLOT_SIZE,
  26619. + state->data_quota - state->data_use_count,
  26620. + state->local->slot_queue_recycle - state->slot_queue_available,
  26621. + state->stats.slot_stalls, state->stats.data_stalls);
  26622. + vchiq_dump(dump_context, buf, len + 1);
  26623. +
  26624. + vchiq_dump_platform_state(dump_context);
  26625. +
  26626. + vchiq_dump_shared_state(dump_context, state, state->local, "Local");
  26627. + vchiq_dump_shared_state(dump_context, state, state->remote, "Remote");
  26628. +
  26629. + vchiq_dump_platform_instances(dump_context);
  26630. +
  26631. + for (i = 0; i < state->unused_service; i++) {
  26632. + VCHIQ_SERVICE_T *service = find_service_by_port(state, i);
  26633. +
  26634. + if (service) {
  26635. + vchiq_dump_service_state(dump_context, service);
  26636. + unlock_service(service);
  26637. + }
  26638. + }
  26639. +}
  26640. +
  26641. +void
  26642. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service)
  26643. +{
  26644. + char buf[80];
  26645. + int len;
  26646. +
  26647. + len = snprintf(buf, sizeof(buf), "Service %d: %s (ref %u)",
  26648. + service->localport, srvstate_names[service->srvstate],
  26649. + service->ref_count - 1); /*Don't include the lock just taken*/
  26650. +
  26651. + if (service->srvstate != VCHIQ_SRVSTATE_FREE) {
  26652. + char remoteport[30];
  26653. + VCHIQ_SERVICE_QUOTA_T *service_quota =
  26654. + &service->state->service_quotas[service->localport];
  26655. + int fourcc = service->base.fourcc;
  26656. + int tx_pending, rx_pending;
  26657. + if (service->remoteport != VCHIQ_PORT_FREE) {
  26658. + int len2 = snprintf(remoteport, sizeof(remoteport),
  26659. + "%d", service->remoteport);
  26660. + if (service->public_fourcc != VCHIQ_FOURCC_INVALID)
  26661. + snprintf(remoteport + len2,
  26662. + sizeof(remoteport) - len2,
  26663. + " (client %x)", service->client_id);
  26664. + } else
  26665. + strcpy(remoteport, "n/a");
  26666. +
  26667. + len += snprintf(buf + len, sizeof(buf) - len,
  26668. + " '%c%c%c%c' remote %s (msg use %d/%d, slot use %d/%d)",
  26669. + VCHIQ_FOURCC_AS_4CHARS(fourcc),
  26670. + remoteport,
  26671. + service_quota->message_use_count,
  26672. + service_quota->message_quota,
  26673. + service_quota->slot_use_count,
  26674. + service_quota->slot_quota);
  26675. +
  26676. + vchiq_dump(dump_context, buf, len + 1);
  26677. +
  26678. + tx_pending = service->bulk_tx.local_insert -
  26679. + service->bulk_tx.remote_insert;
  26680. +
  26681. + rx_pending = service->bulk_rx.local_insert -
  26682. + service->bulk_rx.remote_insert;
  26683. +
  26684. + len = snprintf(buf, sizeof(buf),
  26685. + " Bulk: tx_pending=%d (size %d),"
  26686. + " rx_pending=%d (size %d)",
  26687. + tx_pending,
  26688. + tx_pending ? service->bulk_tx.bulks[
  26689. + BULK_INDEX(service->bulk_tx.remove)].size : 0,
  26690. + rx_pending,
  26691. + rx_pending ? service->bulk_rx.bulks[
  26692. + BULK_INDEX(service->bulk_rx.remove)].size : 0);
  26693. +
  26694. + if (VCHIQ_ENABLE_STATS) {
  26695. + vchiq_dump(dump_context, buf, len + 1);
  26696. +
  26697. + len = snprintf(buf, sizeof(buf),
  26698. + " Ctrl: tx_count=%d, tx_bytes=%llu, "
  26699. + "rx_count=%d, rx_bytes=%llu",
  26700. + service->stats.ctrl_tx_count,
  26701. + service->stats.ctrl_tx_bytes,
  26702. + service->stats.ctrl_rx_count,
  26703. + service->stats.ctrl_rx_bytes);
  26704. + vchiq_dump(dump_context, buf, len + 1);
  26705. +
  26706. + len = snprintf(buf, sizeof(buf),
  26707. + " Bulk: tx_count=%d, tx_bytes=%llu, "
  26708. + "rx_count=%d, rx_bytes=%llu",
  26709. + service->stats.bulk_tx_count,
  26710. + service->stats.bulk_tx_bytes,
  26711. + service->stats.bulk_rx_count,
  26712. + service->stats.bulk_rx_bytes);
  26713. + vchiq_dump(dump_context, buf, len + 1);
  26714. +
  26715. + len = snprintf(buf, sizeof(buf),
  26716. + " %d quota stalls, %d slot stalls, "
  26717. + "%d bulk stalls, %d aborted, %d errors",
  26718. + service->stats.quota_stalls,
  26719. + service->stats.slot_stalls,
  26720. + service->stats.bulk_stalls,
  26721. + service->stats.bulk_aborted_count,
  26722. + service->stats.error_count);
  26723. + }
  26724. + }
  26725. +
  26726. + vchiq_dump(dump_context, buf, len + 1);
  26727. +
  26728. + if (service->srvstate != VCHIQ_SRVSTATE_FREE)
  26729. + vchiq_dump_platform_service_state(dump_context, service);
  26730. +}
  26731. +
  26732. +
  26733. +void
  26734. +vchiq_loud_error_header(void)
  26735. +{
  26736. + vchiq_log_error(vchiq_core_log_level,
  26737. + "============================================================"
  26738. + "================");
  26739. + vchiq_log_error(vchiq_core_log_level,
  26740. + "============================================================"
  26741. + "================");
  26742. + vchiq_log_error(vchiq_core_log_level, "=====");
  26743. +}
  26744. +
  26745. +void
  26746. +vchiq_loud_error_footer(void)
  26747. +{
  26748. + vchiq_log_error(vchiq_core_log_level, "=====");
  26749. + vchiq_log_error(vchiq_core_log_level,
  26750. + "============================================================"
  26751. + "================");
  26752. + vchiq_log_error(vchiq_core_log_level,
  26753. + "============================================================"
  26754. + "================");
  26755. +}
  26756. +
  26757. +
  26758. +VCHIQ_STATUS_T vchiq_send_remote_use(VCHIQ_STATE_T *state)
  26759. +{
  26760. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26761. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26762. + status = queue_message(state, NULL,
  26763. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE, 0, 0),
  26764. + NULL, 0, 0, 0);
  26765. + return status;
  26766. +}
  26767. +
  26768. +VCHIQ_STATUS_T vchiq_send_remote_release(VCHIQ_STATE_T *state)
  26769. +{
  26770. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26771. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26772. + status = queue_message(state, NULL,
  26773. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_RELEASE, 0, 0),
  26774. + NULL, 0, 0, 0);
  26775. + return status;
  26776. +}
  26777. +
  26778. +VCHIQ_STATUS_T vchiq_send_remote_use_active(VCHIQ_STATE_T *state)
  26779. +{
  26780. + VCHIQ_STATUS_T status = VCHIQ_RETRY;
  26781. + if (state->conn_state != VCHIQ_CONNSTATE_DISCONNECTED)
  26782. + status = queue_message(state, NULL,
  26783. + VCHIQ_MAKE_MSG(VCHIQ_MSG_REMOTE_USE_ACTIVE, 0, 0),
  26784. + NULL, 0, 0, 0);
  26785. + return status;
  26786. +}
  26787. +
  26788. +void vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  26789. + size_t numBytes)
  26790. +{
  26791. + const uint8_t *mem = (const uint8_t *)voidMem;
  26792. + size_t offset;
  26793. + char lineBuf[100];
  26794. + char *s;
  26795. +
  26796. + while (numBytes > 0) {
  26797. + s = lineBuf;
  26798. +
  26799. + for (offset = 0; offset < 16; offset++) {
  26800. + if (offset < numBytes)
  26801. + s += snprintf(s, 4, "%02x ", mem[offset]);
  26802. + else
  26803. + s += snprintf(s, 4, " ");
  26804. + }
  26805. +
  26806. + for (offset = 0; offset < 16; offset++) {
  26807. + if (offset < numBytes) {
  26808. + uint8_t ch = mem[offset];
  26809. +
  26810. + if ((ch < ' ') || (ch > '~'))
  26811. + ch = '.';
  26812. + *s++ = (char)ch;
  26813. + }
  26814. + }
  26815. + *s++ = '\0';
  26816. +
  26817. + if ((label != NULL) && (*label != '\0'))
  26818. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26819. + "%s: %08x: %s", label, addr, lineBuf);
  26820. + else
  26821. + vchiq_log_trace(VCHIQ_LOG_TRACE,
  26822. + "%08x: %s", addr, lineBuf);
  26823. +
  26824. + addr += 16;
  26825. + mem += 16;
  26826. + if (numBytes > 16)
  26827. + numBytes -= 16;
  26828. + else
  26829. + numBytes = 0;
  26830. + }
  26831. +}
  26832. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h
  26833. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 1970-01-01 01:00:00.000000000 +0100
  26834. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_core.h 2014-06-11 21:03:34.000000000 +0200
  26835. @@ -0,0 +1,706 @@
  26836. +/**
  26837. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  26838. + *
  26839. + * Redistribution and use in source and binary forms, with or without
  26840. + * modification, are permitted provided that the following conditions
  26841. + * are met:
  26842. + * 1. Redistributions of source code must retain the above copyright
  26843. + * notice, this list of conditions, and the following disclaimer,
  26844. + * without modification.
  26845. + * 2. Redistributions in binary form must reproduce the above copyright
  26846. + * notice, this list of conditions and the following disclaimer in the
  26847. + * documentation and/or other materials provided with the distribution.
  26848. + * 3. The names of the above-listed copyright holders may not be used
  26849. + * to endorse or promote products derived from this software without
  26850. + * specific prior written permission.
  26851. + *
  26852. + * ALTERNATIVELY, this software may be distributed under the terms of the
  26853. + * GNU General Public License ("GPL") version 2, as published by the Free
  26854. + * Software Foundation.
  26855. + *
  26856. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  26857. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26858. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  26859. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  26860. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  26861. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26862. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26863. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26864. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  26865. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  26866. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26867. + */
  26868. +
  26869. +#ifndef VCHIQ_CORE_H
  26870. +#define VCHIQ_CORE_H
  26871. +
  26872. +#include <linux/mutex.h>
  26873. +#include <linux/semaphore.h>
  26874. +#include <linux/kthread.h>
  26875. +
  26876. +#include "vchiq_cfg.h"
  26877. +
  26878. +#include "vchiq.h"
  26879. +
  26880. +/* Run time control of log level, based on KERN_XXX level. */
  26881. +#define VCHIQ_LOG_DEFAULT 4
  26882. +#define VCHIQ_LOG_ERROR 3
  26883. +#define VCHIQ_LOG_WARNING 4
  26884. +#define VCHIQ_LOG_INFO 6
  26885. +#define VCHIQ_LOG_TRACE 7
  26886. +
  26887. +#define VCHIQ_LOG_PREFIX KERN_INFO "vchiq: "
  26888. +
  26889. +#ifndef vchiq_log_error
  26890. +#define vchiq_log_error(cat, fmt, ...) \
  26891. + do { if (cat >= VCHIQ_LOG_ERROR) \
  26892. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26893. +#endif
  26894. +#ifndef vchiq_log_warning
  26895. +#define vchiq_log_warning(cat, fmt, ...) \
  26896. + do { if (cat >= VCHIQ_LOG_WARNING) \
  26897. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26898. +#endif
  26899. +#ifndef vchiq_log_info
  26900. +#define vchiq_log_info(cat, fmt, ...) \
  26901. + do { if (cat >= VCHIQ_LOG_INFO) \
  26902. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26903. +#endif
  26904. +#ifndef vchiq_log_trace
  26905. +#define vchiq_log_trace(cat, fmt, ...) \
  26906. + do { if (cat >= VCHIQ_LOG_TRACE) \
  26907. + printk(VCHIQ_LOG_PREFIX fmt "\n", ##__VA_ARGS__); } while (0)
  26908. +#endif
  26909. +
  26910. +#define vchiq_loud_error(...) \
  26911. + vchiq_log_error(vchiq_core_log_level, "===== " __VA_ARGS__)
  26912. +
  26913. +#ifndef vchiq_static_assert
  26914. +#define vchiq_static_assert(cond) __attribute__((unused)) \
  26915. + extern int vchiq_static_assert[(cond) ? 1 : -1]
  26916. +#endif
  26917. +
  26918. +#define IS_POW2(x) (x && ((x & (x - 1)) == 0))
  26919. +
  26920. +/* Ensure that the slot size and maximum number of slots are powers of 2 */
  26921. +vchiq_static_assert(IS_POW2(VCHIQ_SLOT_SIZE));
  26922. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS));
  26923. +vchiq_static_assert(IS_POW2(VCHIQ_MAX_SLOTS_PER_SIDE));
  26924. +
  26925. +#define VCHIQ_SLOT_MASK (VCHIQ_SLOT_SIZE - 1)
  26926. +#define VCHIQ_SLOT_QUEUE_MASK (VCHIQ_MAX_SLOTS_PER_SIDE - 1)
  26927. +#define VCHIQ_SLOT_ZERO_SLOTS ((sizeof(VCHIQ_SLOT_ZERO_T) + \
  26928. + VCHIQ_SLOT_SIZE - 1) / VCHIQ_SLOT_SIZE)
  26929. +
  26930. +#define VCHIQ_MSG_PADDING 0 /* - */
  26931. +#define VCHIQ_MSG_CONNECT 1 /* - */
  26932. +#define VCHIQ_MSG_OPEN 2 /* + (srcport, -), fourcc, client_id */
  26933. +#define VCHIQ_MSG_OPENACK 3 /* + (srcport, dstport) */
  26934. +#define VCHIQ_MSG_CLOSE 4 /* + (srcport, dstport) */
  26935. +#define VCHIQ_MSG_DATA 5 /* + (srcport, dstport) */
  26936. +#define VCHIQ_MSG_BULK_RX 6 /* + (srcport, dstport), data, size */
  26937. +#define VCHIQ_MSG_BULK_TX 7 /* + (srcport, dstport), data, size */
  26938. +#define VCHIQ_MSG_BULK_RX_DONE 8 /* + (srcport, dstport), actual */
  26939. +#define VCHIQ_MSG_BULK_TX_DONE 9 /* + (srcport, dstport), actual */
  26940. +#define VCHIQ_MSG_PAUSE 10 /* - */
  26941. +#define VCHIQ_MSG_RESUME 11 /* - */
  26942. +#define VCHIQ_MSG_REMOTE_USE 12 /* - */
  26943. +#define VCHIQ_MSG_REMOTE_RELEASE 13 /* - */
  26944. +#define VCHIQ_MSG_REMOTE_USE_ACTIVE 14 /* - */
  26945. +
  26946. +#define VCHIQ_PORT_MAX (VCHIQ_MAX_SERVICES - 1)
  26947. +#define VCHIQ_PORT_FREE 0x1000
  26948. +#define VCHIQ_PORT_IS_VALID(port) (port < VCHIQ_PORT_FREE)
  26949. +#define VCHIQ_MAKE_MSG(type, srcport, dstport) \
  26950. + ((type<<24) | (srcport<<12) | (dstport<<0))
  26951. +#define VCHIQ_MSG_TYPE(msgid) ((unsigned int)msgid >> 24)
  26952. +#define VCHIQ_MSG_SRCPORT(msgid) \
  26953. + (unsigned short)(((unsigned int)msgid >> 12) & 0xfff)
  26954. +#define VCHIQ_MSG_DSTPORT(msgid) \
  26955. + ((unsigned short)msgid & 0xfff)
  26956. +
  26957. +#define VCHIQ_FOURCC_AS_4CHARS(fourcc) \
  26958. + ((fourcc) >> 24) & 0xff, \
  26959. + ((fourcc) >> 16) & 0xff, \
  26960. + ((fourcc) >> 8) & 0xff, \
  26961. + (fourcc) & 0xff
  26962. +
  26963. +/* Ensure the fields are wide enough */
  26964. +vchiq_static_assert(VCHIQ_MSG_SRCPORT(VCHIQ_MAKE_MSG(0, 0, VCHIQ_PORT_MAX))
  26965. + == 0);
  26966. +vchiq_static_assert(VCHIQ_MSG_TYPE(VCHIQ_MAKE_MSG(0, VCHIQ_PORT_MAX, 0)) == 0);
  26967. +vchiq_static_assert((unsigned int)VCHIQ_PORT_MAX <
  26968. + (unsigned int)VCHIQ_PORT_FREE);
  26969. +
  26970. +#define VCHIQ_MSGID_PADDING VCHIQ_MAKE_MSG(VCHIQ_MSG_PADDING, 0, 0)
  26971. +#define VCHIQ_MSGID_CLAIMED 0x40000000
  26972. +
  26973. +#define VCHIQ_FOURCC_INVALID 0x00000000
  26974. +#define VCHIQ_FOURCC_IS_LEGAL(fourcc) (fourcc != VCHIQ_FOURCC_INVALID)
  26975. +
  26976. +#define VCHIQ_BULK_ACTUAL_ABORTED -1
  26977. +
  26978. +typedef uint32_t BITSET_T;
  26979. +
  26980. +vchiq_static_assert((sizeof(BITSET_T) * 8) == 32);
  26981. +
  26982. +#define BITSET_SIZE(b) ((b + 31) >> 5)
  26983. +#define BITSET_WORD(b) (b >> 5)
  26984. +#define BITSET_BIT(b) (1 << (b & 31))
  26985. +#define BITSET_ZERO(bs) memset(bs, 0, sizeof(bs))
  26986. +#define BITSET_IS_SET(bs, b) (bs[BITSET_WORD(b)] & BITSET_BIT(b))
  26987. +#define BITSET_SET(bs, b) (bs[BITSET_WORD(b)] |= BITSET_BIT(b))
  26988. +#define BITSET_CLR(bs, b) (bs[BITSET_WORD(b)] &= ~BITSET_BIT(b))
  26989. +
  26990. +#if VCHIQ_ENABLE_STATS
  26991. +#define VCHIQ_STATS_INC(state, stat) (state->stats. stat++)
  26992. +#define VCHIQ_SERVICE_STATS_INC(service, stat) (service->stats. stat++)
  26993. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) \
  26994. + (service->stats. stat += addend)
  26995. +#else
  26996. +#define VCHIQ_STATS_INC(state, stat) ((void)0)
  26997. +#define VCHIQ_SERVICE_STATS_INC(service, stat) ((void)0)
  26998. +#define VCHIQ_SERVICE_STATS_ADD(service, stat, addend) ((void)0)
  26999. +#endif
  27000. +
  27001. +enum {
  27002. + DEBUG_ENTRIES,
  27003. +#if VCHIQ_ENABLE_DEBUG
  27004. + DEBUG_SLOT_HANDLER_COUNT,
  27005. + DEBUG_SLOT_HANDLER_LINE,
  27006. + DEBUG_PARSE_LINE,
  27007. + DEBUG_PARSE_HEADER,
  27008. + DEBUG_PARSE_MSGID,
  27009. + DEBUG_AWAIT_COMPLETION_LINE,
  27010. + DEBUG_DEQUEUE_MESSAGE_LINE,
  27011. + DEBUG_SERVICE_CALLBACK_LINE,
  27012. + DEBUG_MSG_QUEUE_FULL_COUNT,
  27013. + DEBUG_COMPLETION_QUEUE_FULL_COUNT,
  27014. +#endif
  27015. + DEBUG_MAX
  27016. +};
  27017. +
  27018. +#if VCHIQ_ENABLE_DEBUG
  27019. +
  27020. +#define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug;
  27021. +#define DEBUG_TRACE(d) \
  27022. + do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(); } while (0)
  27023. +#define DEBUG_VALUE(d, v) \
  27024. + do { debug_ptr[DEBUG_ ## d] = (v); dsb(); } while (0)
  27025. +#define DEBUG_COUNT(d) \
  27026. + do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0)
  27027. +
  27028. +#else /* VCHIQ_ENABLE_DEBUG */
  27029. +
  27030. +#define DEBUG_INITIALISE(local)
  27031. +#define DEBUG_TRACE(d)
  27032. +#define DEBUG_VALUE(d, v)
  27033. +#define DEBUG_COUNT(d)
  27034. +
  27035. +#endif /* VCHIQ_ENABLE_DEBUG */
  27036. +
  27037. +typedef enum {
  27038. + VCHIQ_CONNSTATE_DISCONNECTED,
  27039. + VCHIQ_CONNSTATE_CONNECTING,
  27040. + VCHIQ_CONNSTATE_CONNECTED,
  27041. + VCHIQ_CONNSTATE_PAUSING,
  27042. + VCHIQ_CONNSTATE_PAUSE_SENT,
  27043. + VCHIQ_CONNSTATE_PAUSED,
  27044. + VCHIQ_CONNSTATE_RESUMING,
  27045. + VCHIQ_CONNSTATE_PAUSE_TIMEOUT,
  27046. + VCHIQ_CONNSTATE_RESUME_TIMEOUT
  27047. +} VCHIQ_CONNSTATE_T;
  27048. +
  27049. +enum {
  27050. + VCHIQ_SRVSTATE_FREE,
  27051. + VCHIQ_SRVSTATE_HIDDEN,
  27052. + VCHIQ_SRVSTATE_LISTENING,
  27053. + VCHIQ_SRVSTATE_OPENING,
  27054. + VCHIQ_SRVSTATE_OPEN,
  27055. + VCHIQ_SRVSTATE_OPENSYNC,
  27056. + VCHIQ_SRVSTATE_CLOSESENT,
  27057. + VCHIQ_SRVSTATE_CLOSERECVD,
  27058. + VCHIQ_SRVSTATE_CLOSEWAIT,
  27059. + VCHIQ_SRVSTATE_CLOSED
  27060. +};
  27061. +
  27062. +enum {
  27063. + VCHIQ_POLL_TERMINATE,
  27064. + VCHIQ_POLL_REMOVE,
  27065. + VCHIQ_POLL_TXNOTIFY,
  27066. + VCHIQ_POLL_RXNOTIFY,
  27067. + VCHIQ_POLL_COUNT
  27068. +};
  27069. +
  27070. +typedef enum {
  27071. + VCHIQ_BULK_TRANSMIT,
  27072. + VCHIQ_BULK_RECEIVE
  27073. +} VCHIQ_BULK_DIR_T;
  27074. +
  27075. +typedef void (*VCHIQ_USERDATA_TERM_T)(void *userdata);
  27076. +
  27077. +typedef struct vchiq_bulk_struct {
  27078. + short mode;
  27079. + short dir;
  27080. + void *userdata;
  27081. + VCHI_MEM_HANDLE_T handle;
  27082. + void *data;
  27083. + int size;
  27084. + void *remote_data;
  27085. + int remote_size;
  27086. + int actual;
  27087. +} VCHIQ_BULK_T;
  27088. +
  27089. +typedef struct vchiq_bulk_queue_struct {
  27090. + int local_insert; /* Where to insert the next local bulk */
  27091. + int remote_insert; /* Where to insert the next remote bulk (master) */
  27092. + int process; /* Bulk to transfer next */
  27093. + int remote_notify; /* Bulk to notify the remote client of next (mstr) */
  27094. + int remove; /* Bulk to notify the local client of, and remove,
  27095. + ** next */
  27096. + VCHIQ_BULK_T bulks[VCHIQ_NUM_SERVICE_BULKS];
  27097. +} VCHIQ_BULK_QUEUE_T;
  27098. +
  27099. +typedef struct remote_event_struct {
  27100. + int armed;
  27101. + int fired;
  27102. + struct semaphore *event;
  27103. +} REMOTE_EVENT_T;
  27104. +
  27105. +typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T;
  27106. +
  27107. +typedef struct vchiq_state_struct VCHIQ_STATE_T;
  27108. +
  27109. +typedef struct vchiq_slot_struct {
  27110. + char data[VCHIQ_SLOT_SIZE];
  27111. +} VCHIQ_SLOT_T;
  27112. +
  27113. +typedef struct vchiq_slot_info_struct {
  27114. + /* Use two counters rather than one to avoid the need for a mutex. */
  27115. + short use_count;
  27116. + short release_count;
  27117. +} VCHIQ_SLOT_INFO_T;
  27118. +
  27119. +typedef struct vchiq_service_struct {
  27120. + VCHIQ_SERVICE_BASE_T base;
  27121. + VCHIQ_SERVICE_HANDLE_T handle;
  27122. + unsigned int ref_count;
  27123. + int srvstate;
  27124. + VCHIQ_USERDATA_TERM_T userdata_term;
  27125. + unsigned int localport;
  27126. + unsigned int remoteport;
  27127. + int public_fourcc;
  27128. + int client_id;
  27129. + char auto_close;
  27130. + char sync;
  27131. + char closing;
  27132. + atomic_t poll_flags;
  27133. + short version;
  27134. + short version_min;
  27135. + short peer_version;
  27136. +
  27137. + VCHIQ_STATE_T *state;
  27138. + VCHIQ_INSTANCE_T instance;
  27139. +
  27140. + int service_use_count;
  27141. +
  27142. + VCHIQ_BULK_QUEUE_T bulk_tx;
  27143. + VCHIQ_BULK_QUEUE_T bulk_rx;
  27144. +
  27145. + struct semaphore remove_event;
  27146. + struct semaphore bulk_remove_event;
  27147. + struct mutex bulk_mutex;
  27148. +
  27149. + struct service_stats_struct {
  27150. + int quota_stalls;
  27151. + int slot_stalls;
  27152. + int bulk_stalls;
  27153. + int error_count;
  27154. + int ctrl_tx_count;
  27155. + int ctrl_rx_count;
  27156. + int bulk_tx_count;
  27157. + int bulk_rx_count;
  27158. + int bulk_aborted_count;
  27159. + uint64_t ctrl_tx_bytes;
  27160. + uint64_t ctrl_rx_bytes;
  27161. + uint64_t bulk_tx_bytes;
  27162. + uint64_t bulk_rx_bytes;
  27163. + } stats;
  27164. +} VCHIQ_SERVICE_T;
  27165. +
  27166. +/* The quota information is outside VCHIQ_SERVICE_T so that it can be
  27167. + statically allocated, since for accounting reasons a service's slot
  27168. + usage is carried over between users of the same port number.
  27169. + */
  27170. +typedef struct vchiq_service_quota_struct {
  27171. + unsigned short slot_quota;
  27172. + unsigned short slot_use_count;
  27173. + unsigned short message_quota;
  27174. + unsigned short message_use_count;
  27175. + struct semaphore quota_event;
  27176. + int previous_tx_index;
  27177. +} VCHIQ_SERVICE_QUOTA_T;
  27178. +
  27179. +typedef struct vchiq_shared_state_struct {
  27180. +
  27181. + /* A non-zero value here indicates that the content is valid. */
  27182. + int initialised;
  27183. +
  27184. + /* The first and last (inclusive) slots allocated to the owner. */
  27185. + int slot_first;
  27186. + int slot_last;
  27187. +
  27188. + /* The slot allocated to synchronous messages from the owner. */
  27189. + int slot_sync;
  27190. +
  27191. + /* Signalling this event indicates that owner's slot handler thread
  27192. + ** should run. */
  27193. + REMOTE_EVENT_T trigger;
  27194. +
  27195. + /* Indicates the byte position within the stream where the next message
  27196. + ** will be written. The least significant bits are an index into the
  27197. + ** slot. The next bits are the index of the slot in slot_queue. */
  27198. + int tx_pos;
  27199. +
  27200. + /* This event should be signalled when a slot is recycled. */
  27201. + REMOTE_EVENT_T recycle;
  27202. +
  27203. + /* The slot_queue index where the next recycled slot will be written. */
  27204. + int slot_queue_recycle;
  27205. +
  27206. + /* This event should be signalled when a synchronous message is sent. */
  27207. + REMOTE_EVENT_T sync_trigger;
  27208. +
  27209. + /* This event should be signalled when a synchronous message has been
  27210. + ** released. */
  27211. + REMOTE_EVENT_T sync_release;
  27212. +
  27213. + /* A circular buffer of slot indexes. */
  27214. + int slot_queue[VCHIQ_MAX_SLOTS_PER_SIDE];
  27215. +
  27216. + /* Debugging state */
  27217. + int debug[DEBUG_MAX];
  27218. +} VCHIQ_SHARED_STATE_T;
  27219. +
  27220. +typedef struct vchiq_slot_zero_struct {
  27221. + int magic;
  27222. + short version;
  27223. + short version_min;
  27224. + int slot_zero_size;
  27225. + int slot_size;
  27226. + int max_slots;
  27227. + int max_slots_per_side;
  27228. + int platform_data[2];
  27229. + VCHIQ_SHARED_STATE_T master;
  27230. + VCHIQ_SHARED_STATE_T slave;
  27231. + VCHIQ_SLOT_INFO_T slots[VCHIQ_MAX_SLOTS];
  27232. +} VCHIQ_SLOT_ZERO_T;
  27233. +
  27234. +struct vchiq_state_struct {
  27235. + int id;
  27236. + int initialised;
  27237. + VCHIQ_CONNSTATE_T conn_state;
  27238. + int is_master;
  27239. +
  27240. + VCHIQ_SHARED_STATE_T *local;
  27241. + VCHIQ_SHARED_STATE_T *remote;
  27242. + VCHIQ_SLOT_T *slot_data;
  27243. +
  27244. + unsigned short default_slot_quota;
  27245. + unsigned short default_message_quota;
  27246. +
  27247. + /* Event indicating connect message received */
  27248. + struct semaphore connect;
  27249. +
  27250. + /* Mutex protecting services */
  27251. + struct mutex mutex;
  27252. + VCHIQ_INSTANCE_T *instance;
  27253. +
  27254. + /* Processes incoming messages */
  27255. + struct task_struct *slot_handler_thread;
  27256. +
  27257. + /* Processes recycled slots */
  27258. + struct task_struct *recycle_thread;
  27259. +
  27260. + /* Processes synchronous messages */
  27261. + struct task_struct *sync_thread;
  27262. +
  27263. + /* Local implementation of the trigger remote event */
  27264. + struct semaphore trigger_event;
  27265. +
  27266. + /* Local implementation of the recycle remote event */
  27267. + struct semaphore recycle_event;
  27268. +
  27269. + /* Local implementation of the sync trigger remote event */
  27270. + struct semaphore sync_trigger_event;
  27271. +
  27272. + /* Local implementation of the sync release remote event */
  27273. + struct semaphore sync_release_event;
  27274. +
  27275. + char *tx_data;
  27276. + char *rx_data;
  27277. + VCHIQ_SLOT_INFO_T *rx_info;
  27278. +
  27279. + struct mutex slot_mutex;
  27280. +
  27281. + struct mutex recycle_mutex;
  27282. +
  27283. + struct mutex sync_mutex;
  27284. +
  27285. + struct mutex bulk_transfer_mutex;
  27286. +
  27287. + /* Indicates the byte position within the stream from where the next
  27288. + ** message will be read. The least significant bits are an index into
  27289. + ** the slot.The next bits are the index of the slot in
  27290. + ** remote->slot_queue. */
  27291. + int rx_pos;
  27292. +
  27293. + /* A cached copy of local->tx_pos. Only write to local->tx_pos, and read
  27294. + from remote->tx_pos. */
  27295. + int local_tx_pos;
  27296. +
  27297. + /* The slot_queue index of the slot to become available next. */
  27298. + int slot_queue_available;
  27299. +
  27300. + /* A flag to indicate if any poll has been requested */
  27301. + int poll_needed;
  27302. +
  27303. + /* Ths index of the previous slot used for data messages. */
  27304. + int previous_data_index;
  27305. +
  27306. + /* The number of slots occupied by data messages. */
  27307. + unsigned short data_use_count;
  27308. +
  27309. + /* The maximum number of slots to be occupied by data messages. */
  27310. + unsigned short data_quota;
  27311. +
  27312. + /* An array of bit sets indicating which services must be polled. */
  27313. + atomic_t poll_services[BITSET_SIZE(VCHIQ_MAX_SERVICES)];
  27314. +
  27315. + /* The number of the first unused service */
  27316. + int unused_service;
  27317. +
  27318. + /* Signalled when a free slot becomes available. */
  27319. + struct semaphore slot_available_event;
  27320. +
  27321. + struct semaphore slot_remove_event;
  27322. +
  27323. + /* Signalled when a free data slot becomes available. */
  27324. + struct semaphore data_quota_event;
  27325. +
  27326. + /* Incremented when there are bulk transfers which cannot be processed
  27327. + * whilst paused and must be processed on resume */
  27328. + int deferred_bulks;
  27329. +
  27330. + struct state_stats_struct {
  27331. + int slot_stalls;
  27332. + int data_stalls;
  27333. + int ctrl_tx_count;
  27334. + int ctrl_rx_count;
  27335. + int error_count;
  27336. + } stats;
  27337. +
  27338. + VCHIQ_SERVICE_T * services[VCHIQ_MAX_SERVICES];
  27339. + VCHIQ_SERVICE_QUOTA_T service_quotas[VCHIQ_MAX_SERVICES];
  27340. + VCHIQ_SLOT_INFO_T slot_info[VCHIQ_MAX_SLOTS];
  27341. +
  27342. + VCHIQ_PLATFORM_STATE_T platform_state;
  27343. +};
  27344. +
  27345. +struct bulk_waiter {
  27346. + VCHIQ_BULK_T *bulk;
  27347. + struct semaphore event;
  27348. + int actual;
  27349. +};
  27350. +
  27351. +extern spinlock_t bulk_waiter_spinlock;
  27352. +
  27353. +extern int vchiq_core_log_level;
  27354. +extern int vchiq_core_msg_log_level;
  27355. +extern int vchiq_sync_log_level;
  27356. +
  27357. +extern VCHIQ_STATE_T *vchiq_states[VCHIQ_MAX_STATES];
  27358. +
  27359. +extern const char *
  27360. +get_conn_state_name(VCHIQ_CONNSTATE_T conn_state);
  27361. +
  27362. +extern VCHIQ_SLOT_ZERO_T *
  27363. +vchiq_init_slots(void *mem_base, int mem_size);
  27364. +
  27365. +extern VCHIQ_STATUS_T
  27366. +vchiq_init_state(VCHIQ_STATE_T *state, VCHIQ_SLOT_ZERO_T *slot_zero,
  27367. + int is_master);
  27368. +
  27369. +extern VCHIQ_STATUS_T
  27370. +vchiq_connect_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27371. +
  27372. +extern VCHIQ_SERVICE_T *
  27373. +vchiq_add_service_internal(VCHIQ_STATE_T *state,
  27374. + const VCHIQ_SERVICE_PARAMS_T *params, int srvstate,
  27375. + VCHIQ_INSTANCE_T instance, VCHIQ_USERDATA_TERM_T userdata_term);
  27376. +
  27377. +extern VCHIQ_STATUS_T
  27378. +vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id);
  27379. +
  27380. +extern VCHIQ_STATUS_T
  27381. +vchiq_close_service_internal(VCHIQ_SERVICE_T *service, int close_recvd);
  27382. +
  27383. +extern void
  27384. +vchiq_terminate_service_internal(VCHIQ_SERVICE_T *service);
  27385. +
  27386. +extern void
  27387. +vchiq_free_service_internal(VCHIQ_SERVICE_T *service);
  27388. +
  27389. +extern VCHIQ_STATUS_T
  27390. +vchiq_shutdown_internal(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance);
  27391. +
  27392. +extern VCHIQ_STATUS_T
  27393. +vchiq_pause_internal(VCHIQ_STATE_T *state);
  27394. +
  27395. +extern VCHIQ_STATUS_T
  27396. +vchiq_resume_internal(VCHIQ_STATE_T *state);
  27397. +
  27398. +extern void
  27399. +remote_event_pollall(VCHIQ_STATE_T *state);
  27400. +
  27401. +extern VCHIQ_STATUS_T
  27402. +vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle,
  27403. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, void *userdata,
  27404. + VCHIQ_BULK_MODE_T mode, VCHIQ_BULK_DIR_T dir);
  27405. +
  27406. +extern void
  27407. +vchiq_dump_state(void *dump_context, VCHIQ_STATE_T *state);
  27408. +
  27409. +extern void
  27410. +vchiq_dump_service_state(void *dump_context, VCHIQ_SERVICE_T *service);
  27411. +
  27412. +extern void
  27413. +vchiq_loud_error_header(void);
  27414. +
  27415. +extern void
  27416. +vchiq_loud_error_footer(void);
  27417. +
  27418. +extern void
  27419. +request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T *service, int poll_type);
  27420. +
  27421. +static inline VCHIQ_SERVICE_T *
  27422. +handle_to_service(VCHIQ_SERVICE_HANDLE_T handle)
  27423. +{
  27424. + VCHIQ_STATE_T *state = vchiq_states[(handle / VCHIQ_MAX_SERVICES) &
  27425. + (VCHIQ_MAX_STATES - 1)];
  27426. + if (!state)
  27427. + return NULL;
  27428. +
  27429. + return state->services[handle & (VCHIQ_MAX_SERVICES - 1)];
  27430. +}
  27431. +
  27432. +extern VCHIQ_SERVICE_T *
  27433. +find_service_by_handle(VCHIQ_SERVICE_HANDLE_T handle);
  27434. +
  27435. +extern VCHIQ_SERVICE_T *
  27436. +find_service_by_port(VCHIQ_STATE_T *state, int localport);
  27437. +
  27438. +extern VCHIQ_SERVICE_T *
  27439. +find_service_for_instance(VCHIQ_INSTANCE_T instance,
  27440. + VCHIQ_SERVICE_HANDLE_T handle);
  27441. +
  27442. +extern VCHIQ_SERVICE_T *
  27443. +next_service_by_instance(VCHIQ_STATE_T *state, VCHIQ_INSTANCE_T instance,
  27444. + int *pidx);
  27445. +
  27446. +extern void
  27447. +lock_service(VCHIQ_SERVICE_T *service);
  27448. +
  27449. +extern void
  27450. +unlock_service(VCHIQ_SERVICE_T *service);
  27451. +
  27452. +/* The following functions are called from vchiq_core, and external
  27453. +** implementations must be provided. */
  27454. +
  27455. +extern VCHIQ_STATUS_T
  27456. +vchiq_prepare_bulk_data(VCHIQ_BULK_T *bulk,
  27457. + VCHI_MEM_HANDLE_T memhandle, void *offset, int size, int dir);
  27458. +
  27459. +extern void
  27460. +vchiq_transfer_bulk(VCHIQ_BULK_T *bulk);
  27461. +
  27462. +extern void
  27463. +vchiq_complete_bulk(VCHIQ_BULK_T *bulk);
  27464. +
  27465. +extern VCHIQ_STATUS_T
  27466. +vchiq_copy_from_user(void *dst, const void *src, int size);
  27467. +
  27468. +extern void
  27469. +remote_event_signal(REMOTE_EVENT_T *event);
  27470. +
  27471. +void
  27472. +vchiq_platform_check_suspend(VCHIQ_STATE_T *state);
  27473. +
  27474. +extern void
  27475. +vchiq_platform_paused(VCHIQ_STATE_T *state);
  27476. +
  27477. +extern VCHIQ_STATUS_T
  27478. +vchiq_platform_resume(VCHIQ_STATE_T *state);
  27479. +
  27480. +extern void
  27481. +vchiq_platform_resumed(VCHIQ_STATE_T *state);
  27482. +
  27483. +extern void
  27484. +vchiq_dump(void *dump_context, const char *str, int len);
  27485. +
  27486. +extern void
  27487. +vchiq_dump_platform_state(void *dump_context);
  27488. +
  27489. +extern void
  27490. +vchiq_dump_platform_instances(void *dump_context);
  27491. +
  27492. +extern void
  27493. +vchiq_dump_platform_service_state(void *dump_context,
  27494. + VCHIQ_SERVICE_T *service);
  27495. +
  27496. +extern VCHIQ_STATUS_T
  27497. +vchiq_use_service_internal(VCHIQ_SERVICE_T *service);
  27498. +
  27499. +extern VCHIQ_STATUS_T
  27500. +vchiq_release_service_internal(VCHIQ_SERVICE_T *service);
  27501. +
  27502. +extern void
  27503. +vchiq_on_remote_use(VCHIQ_STATE_T *state);
  27504. +
  27505. +extern void
  27506. +vchiq_on_remote_release(VCHIQ_STATE_T *state);
  27507. +
  27508. +extern VCHIQ_STATUS_T
  27509. +vchiq_platform_init_state(VCHIQ_STATE_T *state);
  27510. +
  27511. +extern VCHIQ_STATUS_T
  27512. +vchiq_check_service(VCHIQ_SERVICE_T *service);
  27513. +
  27514. +extern void
  27515. +vchiq_on_remote_use_active(VCHIQ_STATE_T *state);
  27516. +
  27517. +extern VCHIQ_STATUS_T
  27518. +vchiq_send_remote_use(VCHIQ_STATE_T *state);
  27519. +
  27520. +extern VCHIQ_STATUS_T
  27521. +vchiq_send_remote_release(VCHIQ_STATE_T *state);
  27522. +
  27523. +extern VCHIQ_STATUS_T
  27524. +vchiq_send_remote_use_active(VCHIQ_STATE_T *state);
  27525. +
  27526. +extern void
  27527. +vchiq_platform_conn_state_changed(VCHIQ_STATE_T *state,
  27528. + VCHIQ_CONNSTATE_T oldstate, VCHIQ_CONNSTATE_T newstate);
  27529. +
  27530. +extern void
  27531. +vchiq_platform_handle_timeout(VCHIQ_STATE_T *state);
  27532. +
  27533. +extern void
  27534. +vchiq_set_conn_state(VCHIQ_STATE_T *state, VCHIQ_CONNSTATE_T newstate);
  27535. +
  27536. +
  27537. +extern void
  27538. +vchiq_log_dump_mem(const char *label, uint32_t addr, const void *voidMem,
  27539. + size_t numBytes);
  27540. +
  27541. +#endif
  27542. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion
  27543. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 1970-01-01 01:00:00.000000000 +0100
  27544. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_genversion 2014-06-11 21:03:34.000000000 +0200
  27545. @@ -0,0 +1,87 @@
  27546. +#!/usr/bin/perl -w
  27547. +
  27548. +use strict;
  27549. +
  27550. +#
  27551. +# Generate a version from available information
  27552. +#
  27553. +
  27554. +my $prefix = shift @ARGV;
  27555. +my $root = shift @ARGV;
  27556. +
  27557. +
  27558. +if ( not defined $root ) {
  27559. + die "usage: $0 prefix root-dir\n";
  27560. +}
  27561. +
  27562. +if ( ! -d $root ) {
  27563. + die "root directory $root not found\n";
  27564. +}
  27565. +
  27566. +my $version = "unknown";
  27567. +my $tainted = "";
  27568. +
  27569. +if ( -d "$root/.git" ) {
  27570. + # attempt to work out git version. only do so
  27571. + # on a linux build host, as cygwin builds are
  27572. + # already slow enough
  27573. +
  27574. + if ( -f "/usr/bin/git" || -f "/usr/local/bin/git" ) {
  27575. + if (not open(F, "git --git-dir $root/.git rev-parse --verify HEAD|")) {
  27576. + $version = "no git version";
  27577. + }
  27578. + else {
  27579. + $version = <F>;
  27580. + $version =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27581. + $version =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27582. + }
  27583. +
  27584. + if (open(G, "git --git-dir $root/.git status --porcelain|")) {
  27585. + $tainted = <G>;
  27586. + $tainted =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27587. + $tainted =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27588. + if (length $tainted) {
  27589. + $version = join ' ', $version, "(tainted)";
  27590. + }
  27591. + else {
  27592. + $version = join ' ', $version, "(clean)";
  27593. + }
  27594. + }
  27595. + }
  27596. +}
  27597. +
  27598. +my $hostname = `hostname`;
  27599. +$hostname =~ s/[ \r\n]*$//; # chomp may not be enough (cygwin).
  27600. +$hostname =~ s/^[ \r\n]*//; # chomp may not be enough (cygwin).
  27601. +
  27602. +
  27603. +print STDERR "Version $version\n";
  27604. +print <<EOF;
  27605. +#include "${prefix}_build_info.h"
  27606. +#include <linux/broadcom/vc_debug_sym.h>
  27607. +
  27608. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_hostname, "$hostname" );
  27609. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_version, "$version" );
  27610. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_time, __TIME__ );
  27611. +VC_DEBUG_DECLARE_STRING_VAR( ${prefix}_build_date, __DATE__ );
  27612. +
  27613. +const char *vchiq_get_build_hostname( void )
  27614. +{
  27615. + return vchiq_build_hostname;
  27616. +}
  27617. +
  27618. +const char *vchiq_get_build_version( void )
  27619. +{
  27620. + return vchiq_build_version;
  27621. +}
  27622. +
  27623. +const char *vchiq_get_build_date( void )
  27624. +{
  27625. + return vchiq_build_date;
  27626. +}
  27627. +
  27628. +const char *vchiq_get_build_time( void )
  27629. +{
  27630. + return vchiq_build_time;
  27631. +}
  27632. +EOF
  27633. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h
  27634. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 1970-01-01 01:00:00.000000000 +0100
  27635. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq.h 2014-06-11 21:03:34.000000000 +0200
  27636. @@ -0,0 +1,40 @@
  27637. +/**
  27638. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27639. + *
  27640. + * Redistribution and use in source and binary forms, with or without
  27641. + * modification, are permitted provided that the following conditions
  27642. + * are met:
  27643. + * 1. Redistributions of source code must retain the above copyright
  27644. + * notice, this list of conditions, and the following disclaimer,
  27645. + * without modification.
  27646. + * 2. Redistributions in binary form must reproduce the above copyright
  27647. + * notice, this list of conditions and the following disclaimer in the
  27648. + * documentation and/or other materials provided with the distribution.
  27649. + * 3. The names of the above-listed copyright holders may not be used
  27650. + * to endorse or promote products derived from this software without
  27651. + * specific prior written permission.
  27652. + *
  27653. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27654. + * GNU General Public License ("GPL") version 2, as published by the Free
  27655. + * Software Foundation.
  27656. + *
  27657. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27658. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27659. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27660. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27661. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27662. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27663. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27664. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27665. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27666. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27667. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27668. + */
  27669. +
  27670. +#ifndef VCHIQ_VCHIQ_H
  27671. +#define VCHIQ_VCHIQ_H
  27672. +
  27673. +#include "vchiq_if.h"
  27674. +#include "vchiq_util.h"
  27675. +
  27676. +#endif
  27677. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h
  27678. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 1970-01-01 01:00:00.000000000 +0100
  27679. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_if.h 2014-06-11 21:03:34.000000000 +0200
  27680. @@ -0,0 +1,188 @@
  27681. +/**
  27682. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27683. + *
  27684. + * Redistribution and use in source and binary forms, with or without
  27685. + * modification, are permitted provided that the following conditions
  27686. + * are met:
  27687. + * 1. Redistributions of source code must retain the above copyright
  27688. + * notice, this list of conditions, and the following disclaimer,
  27689. + * without modification.
  27690. + * 2. Redistributions in binary form must reproduce the above copyright
  27691. + * notice, this list of conditions and the following disclaimer in the
  27692. + * documentation and/or other materials provided with the distribution.
  27693. + * 3. The names of the above-listed copyright holders may not be used
  27694. + * to endorse or promote products derived from this software without
  27695. + * specific prior written permission.
  27696. + *
  27697. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27698. + * GNU General Public License ("GPL") version 2, as published by the Free
  27699. + * Software Foundation.
  27700. + *
  27701. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27702. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27703. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27704. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27705. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27706. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27707. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27708. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27709. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27710. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27711. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27712. + */
  27713. +
  27714. +#ifndef VCHIQ_IF_H
  27715. +#define VCHIQ_IF_H
  27716. +
  27717. +#include "interface/vchi/vchi_mh.h"
  27718. +
  27719. +#define VCHIQ_SERVICE_HANDLE_INVALID 0
  27720. +
  27721. +#define VCHIQ_SLOT_SIZE 4096
  27722. +#define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
  27723. +#define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
  27724. +
  27725. +#define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
  27726. + (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
  27727. +#define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
  27728. +#define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service)
  27729. +
  27730. +typedef enum {
  27731. + VCHIQ_SERVICE_OPENED, /* service, -, - */
  27732. + VCHIQ_SERVICE_CLOSED, /* service, -, - */
  27733. + VCHIQ_MESSAGE_AVAILABLE, /* service, header, - */
  27734. + VCHIQ_BULK_TRANSMIT_DONE, /* service, -, bulk_userdata */
  27735. + VCHIQ_BULK_RECEIVE_DONE, /* service, -, bulk_userdata */
  27736. + VCHIQ_BULK_TRANSMIT_ABORTED, /* service, -, bulk_userdata */
  27737. + VCHIQ_BULK_RECEIVE_ABORTED /* service, -, bulk_userdata */
  27738. +} VCHIQ_REASON_T;
  27739. +
  27740. +typedef enum {
  27741. + VCHIQ_ERROR = -1,
  27742. + VCHIQ_SUCCESS = 0,
  27743. + VCHIQ_RETRY = 1
  27744. +} VCHIQ_STATUS_T;
  27745. +
  27746. +typedef enum {
  27747. + VCHIQ_BULK_MODE_CALLBACK,
  27748. + VCHIQ_BULK_MODE_BLOCKING,
  27749. + VCHIQ_BULK_MODE_NOCALLBACK,
  27750. + VCHIQ_BULK_MODE_WAITING /* Reserved for internal use */
  27751. +} VCHIQ_BULK_MODE_T;
  27752. +
  27753. +typedef enum {
  27754. + VCHIQ_SERVICE_OPTION_AUTOCLOSE,
  27755. + VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
  27756. + VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
  27757. + VCHIQ_SERVICE_OPTION_SYNCHRONOUS
  27758. +} VCHIQ_SERVICE_OPTION_T;
  27759. +
  27760. +typedef struct vchiq_header_struct {
  27761. + /* The message identifier - opaque to applications. */
  27762. + int msgid;
  27763. +
  27764. + /* Size of message data. */
  27765. + unsigned int size;
  27766. +
  27767. + char data[0]; /* message */
  27768. +} VCHIQ_HEADER_T;
  27769. +
  27770. +typedef struct {
  27771. + const void *data;
  27772. + unsigned int size;
  27773. +} VCHIQ_ELEMENT_T;
  27774. +
  27775. +typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
  27776. +
  27777. +typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
  27778. + VCHIQ_SERVICE_HANDLE_T, void *);
  27779. +
  27780. +typedef struct vchiq_service_base_struct {
  27781. + int fourcc;
  27782. + VCHIQ_CALLBACK_T callback;
  27783. + void *userdata;
  27784. +} VCHIQ_SERVICE_BASE_T;
  27785. +
  27786. +typedef struct vchiq_service_params_struct {
  27787. + int fourcc;
  27788. + VCHIQ_CALLBACK_T callback;
  27789. + void *userdata;
  27790. + short version; /* Increment for non-trivial changes */
  27791. + short version_min; /* Update for incompatible changes */
  27792. +} VCHIQ_SERVICE_PARAMS_T;
  27793. +
  27794. +typedef struct vchiq_config_struct {
  27795. + unsigned int max_msg_size;
  27796. + unsigned int bulk_threshold; /* The message size above which it
  27797. + is better to use a bulk transfer
  27798. + (<= max_msg_size) */
  27799. + unsigned int max_outstanding_bulks;
  27800. + unsigned int max_services;
  27801. + short version; /* The version of VCHIQ */
  27802. + short version_min; /* The minimum compatible version of VCHIQ */
  27803. +} VCHIQ_CONFIG_T;
  27804. +
  27805. +typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
  27806. +typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
  27807. +
  27808. +extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
  27809. +extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
  27810. +extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
  27811. +extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
  27812. + const VCHIQ_SERVICE_PARAMS_T *params,
  27813. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27814. +extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
  27815. + const VCHIQ_SERVICE_PARAMS_T *params,
  27816. + VCHIQ_SERVICE_HANDLE_T *pservice);
  27817. +extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
  27818. +extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
  27819. +extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
  27820. +extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
  27821. + VCHIQ_SERVICE_HANDLE_T service);
  27822. +extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
  27823. +
  27824. +extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
  27825. + const VCHIQ_ELEMENT_T *elements, unsigned int count);
  27826. +extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
  27827. + VCHIQ_HEADER_T *header);
  27828. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27829. + const void *data, unsigned int size, void *userdata);
  27830. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27831. + void *data, unsigned int size, void *userdata);
  27832. +extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
  27833. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27834. + const void *offset, unsigned int size, void *userdata);
  27835. +extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
  27836. + VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
  27837. + void *offset, unsigned int size, void *userdata);
  27838. +extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
  27839. + const void *data, unsigned int size, void *userdata,
  27840. + VCHIQ_BULK_MODE_T mode);
  27841. +extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
  27842. + void *data, unsigned int size, void *userdata,
  27843. + VCHIQ_BULK_MODE_T mode);
  27844. +extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
  27845. + VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
  27846. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27847. +extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
  27848. + VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
  27849. + void *userdata, VCHIQ_BULK_MODE_T mode);
  27850. +extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
  27851. +extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
  27852. +extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
  27853. +extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
  27854. + int config_size, VCHIQ_CONFIG_T *pconfig);
  27855. +extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
  27856. + VCHIQ_SERVICE_OPTION_T option, int value);
  27857. +
  27858. +extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
  27859. + VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
  27860. +extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
  27861. +
  27862. +extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
  27863. + void *ptr, size_t num_bytes);
  27864. +
  27865. +extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
  27866. + short *peer_version);
  27867. +
  27868. +#endif /* VCHIQ_IF_H */
  27869. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h
  27870. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 1970-01-01 01:00:00.000000000 +0100
  27871. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_ioctl.h 2014-06-11 21:03:34.000000000 +0200
  27872. @@ -0,0 +1,129 @@
  27873. +/**
  27874. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  27875. + *
  27876. + * Redistribution and use in source and binary forms, with or without
  27877. + * modification, are permitted provided that the following conditions
  27878. + * are met:
  27879. + * 1. Redistributions of source code must retain the above copyright
  27880. + * notice, this list of conditions, and the following disclaimer,
  27881. + * without modification.
  27882. + * 2. Redistributions in binary form must reproduce the above copyright
  27883. + * notice, this list of conditions and the following disclaimer in the
  27884. + * documentation and/or other materials provided with the distribution.
  27885. + * 3. The names of the above-listed copyright holders may not be used
  27886. + * to endorse or promote products derived from this software without
  27887. + * specific prior written permission.
  27888. + *
  27889. + * ALTERNATIVELY, this software may be distributed under the terms of the
  27890. + * GNU General Public License ("GPL") version 2, as published by the Free
  27891. + * Software Foundation.
  27892. + *
  27893. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  27894. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  27895. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  27896. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  27897. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27898. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  27899. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  27900. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27901. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27902. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27903. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27904. + */
  27905. +
  27906. +#ifndef VCHIQ_IOCTLS_H
  27907. +#define VCHIQ_IOCTLS_H
  27908. +
  27909. +#include <linux/ioctl.h>
  27910. +#include "vchiq_if.h"
  27911. +
  27912. +#define VCHIQ_IOC_MAGIC 0xc4
  27913. +#define VCHIQ_INVALID_HANDLE (~0)
  27914. +
  27915. +typedef struct {
  27916. + VCHIQ_SERVICE_PARAMS_T params;
  27917. + int is_open;
  27918. + int is_vchi;
  27919. + unsigned int handle; /* OUT */
  27920. +} VCHIQ_CREATE_SERVICE_T;
  27921. +
  27922. +typedef struct {
  27923. + unsigned int handle;
  27924. + unsigned int count;
  27925. + const VCHIQ_ELEMENT_T *elements;
  27926. +} VCHIQ_QUEUE_MESSAGE_T;
  27927. +
  27928. +typedef struct {
  27929. + unsigned int handle;
  27930. + void *data;
  27931. + unsigned int size;
  27932. + void *userdata;
  27933. + VCHIQ_BULK_MODE_T mode;
  27934. +} VCHIQ_QUEUE_BULK_TRANSFER_T;
  27935. +
  27936. +typedef struct {
  27937. + VCHIQ_REASON_T reason;
  27938. + VCHIQ_HEADER_T *header;
  27939. + void *service_userdata;
  27940. + void *bulk_userdata;
  27941. +} VCHIQ_COMPLETION_DATA_T;
  27942. +
  27943. +typedef struct {
  27944. + unsigned int count;
  27945. + VCHIQ_COMPLETION_DATA_T *buf;
  27946. + unsigned int msgbufsize;
  27947. + unsigned int msgbufcount; /* IN/OUT */
  27948. + void **msgbufs;
  27949. +} VCHIQ_AWAIT_COMPLETION_T;
  27950. +
  27951. +typedef struct {
  27952. + unsigned int handle;
  27953. + int blocking;
  27954. + unsigned int bufsize;
  27955. + void *buf;
  27956. +} VCHIQ_DEQUEUE_MESSAGE_T;
  27957. +
  27958. +typedef struct {
  27959. + unsigned int config_size;
  27960. + VCHIQ_CONFIG_T *pconfig;
  27961. +} VCHIQ_GET_CONFIG_T;
  27962. +
  27963. +typedef struct {
  27964. + unsigned int handle;
  27965. + VCHIQ_SERVICE_OPTION_T option;
  27966. + int value;
  27967. +} VCHIQ_SET_SERVICE_OPTION_T;
  27968. +
  27969. +typedef struct {
  27970. + void *virt_addr;
  27971. + size_t num_bytes;
  27972. +} VCHIQ_DUMP_MEM_T;
  27973. +
  27974. +#define VCHIQ_IOC_CONNECT _IO(VCHIQ_IOC_MAGIC, 0)
  27975. +#define VCHIQ_IOC_SHUTDOWN _IO(VCHIQ_IOC_MAGIC, 1)
  27976. +#define VCHIQ_IOC_CREATE_SERVICE \
  27977. + _IOWR(VCHIQ_IOC_MAGIC, 2, VCHIQ_CREATE_SERVICE_T)
  27978. +#define VCHIQ_IOC_REMOVE_SERVICE _IO(VCHIQ_IOC_MAGIC, 3)
  27979. +#define VCHIQ_IOC_QUEUE_MESSAGE \
  27980. + _IOW(VCHIQ_IOC_MAGIC, 4, VCHIQ_QUEUE_MESSAGE_T)
  27981. +#define VCHIQ_IOC_QUEUE_BULK_TRANSMIT \
  27982. + _IOWR(VCHIQ_IOC_MAGIC, 5, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27983. +#define VCHIQ_IOC_QUEUE_BULK_RECEIVE \
  27984. + _IOWR(VCHIQ_IOC_MAGIC, 6, VCHIQ_QUEUE_BULK_TRANSFER_T)
  27985. +#define VCHIQ_IOC_AWAIT_COMPLETION \
  27986. + _IOWR(VCHIQ_IOC_MAGIC, 7, VCHIQ_AWAIT_COMPLETION_T)
  27987. +#define VCHIQ_IOC_DEQUEUE_MESSAGE \
  27988. + _IOWR(VCHIQ_IOC_MAGIC, 8, VCHIQ_DEQUEUE_MESSAGE_T)
  27989. +#define VCHIQ_IOC_GET_CLIENT_ID _IO(VCHIQ_IOC_MAGIC, 9)
  27990. +#define VCHIQ_IOC_GET_CONFIG \
  27991. + _IOWR(VCHIQ_IOC_MAGIC, 10, VCHIQ_GET_CONFIG_T)
  27992. +#define VCHIQ_IOC_CLOSE_SERVICE _IO(VCHIQ_IOC_MAGIC, 11)
  27993. +#define VCHIQ_IOC_USE_SERVICE _IO(VCHIQ_IOC_MAGIC, 12)
  27994. +#define VCHIQ_IOC_RELEASE_SERVICE _IO(VCHIQ_IOC_MAGIC, 13)
  27995. +#define VCHIQ_IOC_SET_SERVICE_OPTION \
  27996. + _IOW(VCHIQ_IOC_MAGIC, 14, VCHIQ_SET_SERVICE_OPTION_T)
  27997. +#define VCHIQ_IOC_DUMP_PHYS_MEM \
  27998. + _IOW(VCHIQ_IOC_MAGIC, 15, VCHIQ_DUMP_MEM_T)
  27999. +#define VCHIQ_IOC_MAX 15
  28000. +
  28001. +#endif
  28002. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c
  28003. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 1970-01-01 01:00:00.000000000 +0100
  28004. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_kern_lib.c 2014-06-11 21:03:34.000000000 +0200
  28005. @@ -0,0 +1,457 @@
  28006. +/**
  28007. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28008. + *
  28009. + * Redistribution and use in source and binary forms, with or without
  28010. + * modification, are permitted provided that the following conditions
  28011. + * are met:
  28012. + * 1. Redistributions of source code must retain the above copyright
  28013. + * notice, this list of conditions, and the following disclaimer,
  28014. + * without modification.
  28015. + * 2. Redistributions in binary form must reproduce the above copyright
  28016. + * notice, this list of conditions and the following disclaimer in the
  28017. + * documentation and/or other materials provided with the distribution.
  28018. + * 3. The names of the above-listed copyright holders may not be used
  28019. + * to endorse or promote products derived from this software without
  28020. + * specific prior written permission.
  28021. + *
  28022. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28023. + * GNU General Public License ("GPL") version 2, as published by the Free
  28024. + * Software Foundation.
  28025. + *
  28026. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28027. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28028. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28029. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28030. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28031. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28032. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28033. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28034. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28035. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28036. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28037. + */
  28038. +
  28039. +/* ---- Include Files ---------------------------------------------------- */
  28040. +
  28041. +#include <linux/kernel.h>
  28042. +#include <linux/module.h>
  28043. +#include <linux/mutex.h>
  28044. +
  28045. +#include "vchiq_core.h"
  28046. +#include "vchiq_arm.h"
  28047. +#include "vchiq_killable.h"
  28048. +
  28049. +/* ---- Public Variables ------------------------------------------------- */
  28050. +
  28051. +/* ---- Private Constants and Types -------------------------------------- */
  28052. +
  28053. +struct bulk_waiter_node {
  28054. + struct bulk_waiter bulk_waiter;
  28055. + int pid;
  28056. + struct list_head list;
  28057. +};
  28058. +
  28059. +struct vchiq_instance_struct {
  28060. + VCHIQ_STATE_T *state;
  28061. +
  28062. + int connected;
  28063. +
  28064. + struct list_head bulk_waiter_list;
  28065. + struct mutex bulk_waiter_list_mutex;
  28066. +};
  28067. +
  28068. +static VCHIQ_STATUS_T
  28069. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28070. + unsigned int size, VCHIQ_BULK_DIR_T dir);
  28071. +
  28072. +/****************************************************************************
  28073. +*
  28074. +* vchiq_initialise
  28075. +*
  28076. +***************************************************************************/
  28077. +#define VCHIQ_INIT_RETRIES 10
  28078. +VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *instanceOut)
  28079. +{
  28080. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28081. + VCHIQ_STATE_T *state;
  28082. + VCHIQ_INSTANCE_T instance = NULL;
  28083. + int i;
  28084. +
  28085. + vchiq_log_trace(vchiq_core_log_level, "%s called", __func__);
  28086. +
  28087. + /* VideoCore may not be ready due to boot up timing.
  28088. + It may never be ready if kernel and firmware are mismatched, so don't block forever. */
  28089. + for (i=0; i<VCHIQ_INIT_RETRIES; i++) {
  28090. + state = vchiq_get_state();
  28091. + if (state)
  28092. + break;
  28093. + udelay(500);
  28094. + }
  28095. + if (i==VCHIQ_INIT_RETRIES) {
  28096. + vchiq_log_error(vchiq_core_log_level,
  28097. + "%s: videocore not initialized\n", __func__);
  28098. + goto failed;
  28099. + } else if (i>0) {
  28100. + vchiq_log_warning(vchiq_core_log_level,
  28101. + "%s: videocore initialized after %d retries\n", __func__, i);
  28102. + }
  28103. +
  28104. + instance = kzalloc(sizeof(*instance), GFP_KERNEL);
  28105. + if (!instance) {
  28106. + vchiq_log_error(vchiq_core_log_level,
  28107. + "%s: error allocating vchiq instance\n", __func__);
  28108. + goto failed;
  28109. + }
  28110. +
  28111. + instance->connected = 0;
  28112. + instance->state = state;
  28113. + mutex_init(&instance->bulk_waiter_list_mutex);
  28114. + INIT_LIST_HEAD(&instance->bulk_waiter_list);
  28115. +
  28116. + *instanceOut = instance;
  28117. +
  28118. + status = VCHIQ_SUCCESS;
  28119. +
  28120. +failed:
  28121. + vchiq_log_trace(vchiq_core_log_level,
  28122. + "%s(%p): returning %d", __func__, instance, status);
  28123. +
  28124. + return status;
  28125. +}
  28126. +EXPORT_SYMBOL(vchiq_initialise);
  28127. +
  28128. +/****************************************************************************
  28129. +*
  28130. +* vchiq_shutdown
  28131. +*
  28132. +***************************************************************************/
  28133. +
  28134. +VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance)
  28135. +{
  28136. + VCHIQ_STATUS_T status;
  28137. + VCHIQ_STATE_T *state = instance->state;
  28138. +
  28139. + vchiq_log_trace(vchiq_core_log_level,
  28140. + "%s(%p) called", __func__, instance);
  28141. +
  28142. + if (mutex_lock_interruptible(&state->mutex) != 0)
  28143. + return VCHIQ_RETRY;
  28144. +
  28145. + /* Remove all services */
  28146. + status = vchiq_shutdown_internal(state, instance);
  28147. +
  28148. + mutex_unlock(&state->mutex);
  28149. +
  28150. + vchiq_log_trace(vchiq_core_log_level,
  28151. + "%s(%p): returning %d", __func__, instance, status);
  28152. +
  28153. + if (status == VCHIQ_SUCCESS) {
  28154. + struct list_head *pos, *next;
  28155. + list_for_each_safe(pos, next,
  28156. + &instance->bulk_waiter_list) {
  28157. + struct bulk_waiter_node *waiter;
  28158. + waiter = list_entry(pos,
  28159. + struct bulk_waiter_node,
  28160. + list);
  28161. + list_del(pos);
  28162. + vchiq_log_info(vchiq_arm_log_level,
  28163. + "bulk_waiter - cleaned up %x "
  28164. + "for pid %d",
  28165. + (unsigned int)waiter, waiter->pid);
  28166. + kfree(waiter);
  28167. + }
  28168. + kfree(instance);
  28169. + }
  28170. +
  28171. + return status;
  28172. +}
  28173. +EXPORT_SYMBOL(vchiq_shutdown);
  28174. +
  28175. +/****************************************************************************
  28176. +*
  28177. +* vchiq_is_connected
  28178. +*
  28179. +***************************************************************************/
  28180. +
  28181. +int vchiq_is_connected(VCHIQ_INSTANCE_T instance)
  28182. +{
  28183. + return instance->connected;
  28184. +}
  28185. +
  28186. +/****************************************************************************
  28187. +*
  28188. +* vchiq_connect
  28189. +*
  28190. +***************************************************************************/
  28191. +
  28192. +VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance)
  28193. +{
  28194. + VCHIQ_STATUS_T status;
  28195. + VCHIQ_STATE_T *state = instance->state;
  28196. +
  28197. + vchiq_log_trace(vchiq_core_log_level,
  28198. + "%s(%p) called", __func__, instance);
  28199. +
  28200. + if (mutex_lock_interruptible(&state->mutex) != 0) {
  28201. + vchiq_log_trace(vchiq_core_log_level,
  28202. + "%s: call to mutex_lock failed", __func__);
  28203. + status = VCHIQ_RETRY;
  28204. + goto failed;
  28205. + }
  28206. + status = vchiq_connect_internal(state, instance);
  28207. +
  28208. + if (status == VCHIQ_SUCCESS)
  28209. + instance->connected = 1;
  28210. +
  28211. + mutex_unlock(&state->mutex);
  28212. +
  28213. +failed:
  28214. + vchiq_log_trace(vchiq_core_log_level,
  28215. + "%s(%p): returning %d", __func__, instance, status);
  28216. +
  28217. + return status;
  28218. +}
  28219. +EXPORT_SYMBOL(vchiq_connect);
  28220. +
  28221. +/****************************************************************************
  28222. +*
  28223. +* vchiq_add_service
  28224. +*
  28225. +***************************************************************************/
  28226. +
  28227. +VCHIQ_STATUS_T vchiq_add_service(
  28228. + VCHIQ_INSTANCE_T instance,
  28229. + const VCHIQ_SERVICE_PARAMS_T *params,
  28230. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28231. +{
  28232. + VCHIQ_STATUS_T status;
  28233. + VCHIQ_STATE_T *state = instance->state;
  28234. + VCHIQ_SERVICE_T *service = NULL;
  28235. + int srvstate;
  28236. +
  28237. + vchiq_log_trace(vchiq_core_log_level,
  28238. + "%s(%p) called", __func__, instance);
  28239. +
  28240. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28241. +
  28242. + srvstate = vchiq_is_connected(instance)
  28243. + ? VCHIQ_SRVSTATE_LISTENING
  28244. + : VCHIQ_SRVSTATE_HIDDEN;
  28245. +
  28246. + service = vchiq_add_service_internal(
  28247. + state,
  28248. + params,
  28249. + srvstate,
  28250. + instance,
  28251. + NULL);
  28252. +
  28253. + if (service) {
  28254. + *phandle = service->handle;
  28255. + status = VCHIQ_SUCCESS;
  28256. + } else
  28257. + status = VCHIQ_ERROR;
  28258. +
  28259. + vchiq_log_trace(vchiq_core_log_level,
  28260. + "%s(%p): returning %d", __func__, instance, status);
  28261. +
  28262. + return status;
  28263. +}
  28264. +EXPORT_SYMBOL(vchiq_add_service);
  28265. +
  28266. +/****************************************************************************
  28267. +*
  28268. +* vchiq_open_service
  28269. +*
  28270. +***************************************************************************/
  28271. +
  28272. +VCHIQ_STATUS_T vchiq_open_service(
  28273. + VCHIQ_INSTANCE_T instance,
  28274. + const VCHIQ_SERVICE_PARAMS_T *params,
  28275. + VCHIQ_SERVICE_HANDLE_T *phandle)
  28276. +{
  28277. + VCHIQ_STATUS_T status = VCHIQ_ERROR;
  28278. + VCHIQ_STATE_T *state = instance->state;
  28279. + VCHIQ_SERVICE_T *service = NULL;
  28280. +
  28281. + vchiq_log_trace(vchiq_core_log_level,
  28282. + "%s(%p) called", __func__, instance);
  28283. +
  28284. + *phandle = VCHIQ_SERVICE_HANDLE_INVALID;
  28285. +
  28286. + if (!vchiq_is_connected(instance))
  28287. + goto failed;
  28288. +
  28289. + service = vchiq_add_service_internal(state,
  28290. + params,
  28291. + VCHIQ_SRVSTATE_OPENING,
  28292. + instance,
  28293. + NULL);
  28294. +
  28295. + if (service) {
  28296. + status = vchiq_open_service_internal(service, current->pid);
  28297. + if (status == VCHIQ_SUCCESS)
  28298. + *phandle = service->handle;
  28299. + else
  28300. + vchiq_remove_service(service->handle);
  28301. + }
  28302. +
  28303. +failed:
  28304. + vchiq_log_trace(vchiq_core_log_level,
  28305. + "%s(%p): returning %d", __func__, instance, status);
  28306. +
  28307. + return status;
  28308. +}
  28309. +EXPORT_SYMBOL(vchiq_open_service);
  28310. +
  28311. +VCHIQ_STATUS_T
  28312. +vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle,
  28313. + const void *data, unsigned int size, void *userdata)
  28314. +{
  28315. + return vchiq_bulk_transfer(handle,
  28316. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28317. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_TRANSMIT);
  28318. +}
  28319. +EXPORT_SYMBOL(vchiq_queue_bulk_transmit);
  28320. +
  28321. +VCHIQ_STATUS_T
  28322. +vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28323. + unsigned int size, void *userdata)
  28324. +{
  28325. + return vchiq_bulk_transfer(handle,
  28326. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28327. + VCHIQ_BULK_MODE_CALLBACK, VCHIQ_BULK_RECEIVE);
  28328. +}
  28329. +EXPORT_SYMBOL(vchiq_queue_bulk_receive);
  28330. +
  28331. +VCHIQ_STATUS_T
  28332. +vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T handle, const void *data,
  28333. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28334. +{
  28335. + VCHIQ_STATUS_T status;
  28336. +
  28337. + switch (mode) {
  28338. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28339. + case VCHIQ_BULK_MODE_CALLBACK:
  28340. + status = vchiq_bulk_transfer(handle,
  28341. + VCHI_MEM_HANDLE_INVALID, (void *)data, size, userdata,
  28342. + mode, VCHIQ_BULK_TRANSMIT);
  28343. + break;
  28344. + case VCHIQ_BULK_MODE_BLOCKING:
  28345. + status = vchiq_blocking_bulk_transfer(handle,
  28346. + (void *)data, size, VCHIQ_BULK_TRANSMIT);
  28347. + break;
  28348. + default:
  28349. + return VCHIQ_ERROR;
  28350. + }
  28351. +
  28352. + return status;
  28353. +}
  28354. +EXPORT_SYMBOL(vchiq_bulk_transmit);
  28355. +
  28356. +VCHIQ_STATUS_T
  28357. +vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28358. + unsigned int size, void *userdata, VCHIQ_BULK_MODE_T mode)
  28359. +{
  28360. + VCHIQ_STATUS_T status;
  28361. +
  28362. + switch (mode) {
  28363. + case VCHIQ_BULK_MODE_NOCALLBACK:
  28364. + case VCHIQ_BULK_MODE_CALLBACK:
  28365. + status = vchiq_bulk_transfer(handle,
  28366. + VCHI_MEM_HANDLE_INVALID, data, size, userdata,
  28367. + mode, VCHIQ_BULK_RECEIVE);
  28368. + break;
  28369. + case VCHIQ_BULK_MODE_BLOCKING:
  28370. + status = vchiq_blocking_bulk_transfer(handle,
  28371. + (void *)data, size, VCHIQ_BULK_RECEIVE);
  28372. + break;
  28373. + default:
  28374. + return VCHIQ_ERROR;
  28375. + }
  28376. +
  28377. + return status;
  28378. +}
  28379. +EXPORT_SYMBOL(vchiq_bulk_receive);
  28380. +
  28381. +static VCHIQ_STATUS_T
  28382. +vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T handle, void *data,
  28383. + unsigned int size, VCHIQ_BULK_DIR_T dir)
  28384. +{
  28385. + VCHIQ_INSTANCE_T instance;
  28386. + VCHIQ_SERVICE_T *service;
  28387. + VCHIQ_STATUS_T status;
  28388. + struct bulk_waiter_node *waiter = NULL;
  28389. + struct list_head *pos;
  28390. +
  28391. + service = find_service_by_handle(handle);
  28392. + if (!service)
  28393. + return VCHIQ_ERROR;
  28394. +
  28395. + instance = service->instance;
  28396. +
  28397. + unlock_service(service);
  28398. +
  28399. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28400. + list_for_each(pos, &instance->bulk_waiter_list) {
  28401. + if (list_entry(pos, struct bulk_waiter_node,
  28402. + list)->pid == current->pid) {
  28403. + waiter = list_entry(pos,
  28404. + struct bulk_waiter_node,
  28405. + list);
  28406. + list_del(pos);
  28407. + break;
  28408. + }
  28409. + }
  28410. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28411. +
  28412. + if (waiter) {
  28413. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28414. + if (bulk) {
  28415. + /* This thread has an outstanding bulk transfer. */
  28416. + if ((bulk->data != data) ||
  28417. + (bulk->size != size)) {
  28418. + /* This is not a retry of the previous one.
  28419. + ** Cancel the signal when the transfer
  28420. + ** completes. */
  28421. + spin_lock(&bulk_waiter_spinlock);
  28422. + bulk->userdata = NULL;
  28423. + spin_unlock(&bulk_waiter_spinlock);
  28424. + }
  28425. + }
  28426. + }
  28427. +
  28428. + if (!waiter) {
  28429. + waiter = kzalloc(sizeof(struct bulk_waiter_node), GFP_KERNEL);
  28430. + if (!waiter) {
  28431. + vchiq_log_error(vchiq_core_log_level,
  28432. + "%s - out of memory", __func__);
  28433. + return VCHIQ_ERROR;
  28434. + }
  28435. + }
  28436. +
  28437. + status = vchiq_bulk_transfer(handle, VCHI_MEM_HANDLE_INVALID,
  28438. + data, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING,
  28439. + dir);
  28440. + if ((status != VCHIQ_RETRY) || fatal_signal_pending(current) ||
  28441. + !waiter->bulk_waiter.bulk) {
  28442. + VCHIQ_BULK_T *bulk = waiter->bulk_waiter.bulk;
  28443. + if (bulk) {
  28444. + /* Cancel the signal when the transfer
  28445. + ** completes. */
  28446. + spin_lock(&bulk_waiter_spinlock);
  28447. + bulk->userdata = NULL;
  28448. + spin_unlock(&bulk_waiter_spinlock);
  28449. + }
  28450. + kfree(waiter);
  28451. + } else {
  28452. + waiter->pid = current->pid;
  28453. + mutex_lock(&instance->bulk_waiter_list_mutex);
  28454. + list_add(&waiter->list, &instance->bulk_waiter_list);
  28455. + mutex_unlock(&instance->bulk_waiter_list_mutex);
  28456. + vchiq_log_info(vchiq_arm_log_level,
  28457. + "saved bulk_waiter %x for pid %d",
  28458. + (unsigned int)waiter, current->pid);
  28459. + }
  28460. +
  28461. + return status;
  28462. +}
  28463. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h
  28464. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 1970-01-01 01:00:00.000000000 +0100
  28465. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_killable.h 2014-06-11 21:03:34.000000000 +0200
  28466. @@ -0,0 +1,69 @@
  28467. +/**
  28468. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28469. + *
  28470. + * Redistribution and use in source and binary forms, with or without
  28471. + * modification, are permitted provided that the following conditions
  28472. + * are met:
  28473. + * 1. Redistributions of source code must retain the above copyright
  28474. + * notice, this list of conditions, and the following disclaimer,
  28475. + * without modification.
  28476. + * 2. Redistributions in binary form must reproduce the above copyright
  28477. + * notice, this list of conditions and the following disclaimer in the
  28478. + * documentation and/or other materials provided with the distribution.
  28479. + * 3. The names of the above-listed copyright holders may not be used
  28480. + * to endorse or promote products derived from this software without
  28481. + * specific prior written permission.
  28482. + *
  28483. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28484. + * GNU General Public License ("GPL") version 2, as published by the Free
  28485. + * Software Foundation.
  28486. + *
  28487. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28488. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28489. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28490. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28491. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28492. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28493. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28494. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28495. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28496. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28497. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28498. + */
  28499. +
  28500. +#ifndef VCHIQ_KILLABLE_H
  28501. +#define VCHIQ_KILLABLE_H
  28502. +
  28503. +#include <linux/mutex.h>
  28504. +#include <linux/semaphore.h>
  28505. +
  28506. +#define SHUTDOWN_SIGS (sigmask(SIGKILL) | sigmask(SIGINT) | sigmask(SIGQUIT))
  28507. +
  28508. +static inline int __must_check down_interruptible_killable(struct semaphore *sem)
  28509. +{
  28510. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  28511. + int ret;
  28512. + sigset_t blocked, oldset;
  28513. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  28514. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  28515. + ret = down_interruptible(sem);
  28516. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  28517. + return ret;
  28518. +}
  28519. +#define down_interruptible down_interruptible_killable
  28520. +
  28521. +
  28522. +static inline int __must_check mutex_lock_interruptible_killable(struct mutex *lock)
  28523. +{
  28524. + /* Allow interception of killable signals only. We don't want to be interrupted by harmless signals like SIGALRM */
  28525. + int ret;
  28526. + sigset_t blocked, oldset;
  28527. + siginitsetinv(&blocked, SHUTDOWN_SIGS);
  28528. + sigprocmask(SIG_SETMASK, &blocked, &oldset);
  28529. + ret = mutex_lock_interruptible(lock);
  28530. + sigprocmask(SIG_SETMASK, &oldset, NULL);
  28531. + return ret;
  28532. +}
  28533. +#define mutex_lock_interruptible mutex_lock_interruptible_killable
  28534. +
  28535. +#endif
  28536. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h
  28537. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 1970-01-01 01:00:00.000000000 +0100
  28538. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_memdrv.h 2014-06-11 21:03:34.000000000 +0200
  28539. @@ -0,0 +1,71 @@
  28540. +/**
  28541. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28542. + *
  28543. + * Redistribution and use in source and binary forms, with or without
  28544. + * modification, are permitted provided that the following conditions
  28545. + * are met:
  28546. + * 1. Redistributions of source code must retain the above copyright
  28547. + * notice, this list of conditions, and the following disclaimer,
  28548. + * without modification.
  28549. + * 2. Redistributions in binary form must reproduce the above copyright
  28550. + * notice, this list of conditions and the following disclaimer in the
  28551. + * documentation and/or other materials provided with the distribution.
  28552. + * 3. The names of the above-listed copyright holders may not be used
  28553. + * to endorse or promote products derived from this software without
  28554. + * specific prior written permission.
  28555. + *
  28556. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28557. + * GNU General Public License ("GPL") version 2, as published by the Free
  28558. + * Software Foundation.
  28559. + *
  28560. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28561. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28562. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28563. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28564. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28565. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28566. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28567. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28568. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28569. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28570. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28571. + */
  28572. +
  28573. +#ifndef VCHIQ_MEMDRV_H
  28574. +#define VCHIQ_MEMDRV_H
  28575. +
  28576. +/* ---- Include Files ----------------------------------------------------- */
  28577. +
  28578. +#include <linux/kernel.h>
  28579. +#include "vchiq_if.h"
  28580. +
  28581. +/* ---- Constants and Types ---------------------------------------------- */
  28582. +
  28583. +typedef struct {
  28584. + void *armSharedMemVirt;
  28585. + dma_addr_t armSharedMemPhys;
  28586. + size_t armSharedMemSize;
  28587. +
  28588. + void *vcSharedMemVirt;
  28589. + dma_addr_t vcSharedMemPhys;
  28590. + size_t vcSharedMemSize;
  28591. +} VCHIQ_SHARED_MEM_INFO_T;
  28592. +
  28593. +/* ---- Variable Externs ------------------------------------------------- */
  28594. +
  28595. +/* ---- Function Prototypes ---------------------------------------------- */
  28596. +
  28597. +void vchiq_get_shared_mem_info(VCHIQ_SHARED_MEM_INFO_T *info);
  28598. +
  28599. +VCHIQ_STATUS_T vchiq_memdrv_initialise(void);
  28600. +
  28601. +VCHIQ_STATUS_T vchiq_userdrv_create_instance(
  28602. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28603. +
  28604. +VCHIQ_STATUS_T vchiq_userdrv_suspend(
  28605. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28606. +
  28607. +VCHIQ_STATUS_T vchiq_userdrv_resume(
  28608. + const VCHIQ_PLATFORM_DATA_T * platform_data);
  28609. +
  28610. +#endif
  28611. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h
  28612. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 1970-01-01 01:00:00.000000000 +0100
  28613. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_pagelist.h 2014-06-11 21:03:34.000000000 +0200
  28614. @@ -0,0 +1,58 @@
  28615. +/**
  28616. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28617. + *
  28618. + * Redistribution and use in source and binary forms, with or without
  28619. + * modification, are permitted provided that the following conditions
  28620. + * are met:
  28621. + * 1. Redistributions of source code must retain the above copyright
  28622. + * notice, this list of conditions, and the following disclaimer,
  28623. + * without modification.
  28624. + * 2. Redistributions in binary form must reproduce the above copyright
  28625. + * notice, this list of conditions and the following disclaimer in the
  28626. + * documentation and/or other materials provided with the distribution.
  28627. + * 3. The names of the above-listed copyright holders may not be used
  28628. + * to endorse or promote products derived from this software without
  28629. + * specific prior written permission.
  28630. + *
  28631. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28632. + * GNU General Public License ("GPL") version 2, as published by the Free
  28633. + * Software Foundation.
  28634. + *
  28635. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28636. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28637. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28638. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28639. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28640. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28641. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28642. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28643. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28644. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28645. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28646. + */
  28647. +
  28648. +#ifndef VCHIQ_PAGELIST_H
  28649. +#define VCHIQ_PAGELIST_H
  28650. +
  28651. +#ifndef PAGE_SIZE
  28652. +#define PAGE_SIZE 4096
  28653. +#endif
  28654. +#define CACHE_LINE_SIZE 32
  28655. +#define PAGELIST_WRITE 0
  28656. +#define PAGELIST_READ 1
  28657. +#define PAGELIST_READ_WITH_FRAGMENTS 2
  28658. +
  28659. +typedef struct pagelist_struct {
  28660. + unsigned long length;
  28661. + unsigned short type;
  28662. + unsigned short offset;
  28663. + unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of following
  28664. + pages at consecutive addresses. */
  28665. +} PAGELIST_T;
  28666. +
  28667. +typedef struct fragments_struct {
  28668. + char headbuf[CACHE_LINE_SIZE];
  28669. + char tailbuf[CACHE_LINE_SIZE];
  28670. +} FRAGMENTS_T;
  28671. +
  28672. +#endif /* VCHIQ_PAGELIST_H */
  28673. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c
  28674. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 1970-01-01 01:00:00.000000000 +0100
  28675. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_proc.c 2014-06-11 21:03:34.000000000 +0200
  28676. @@ -0,0 +1,253 @@
  28677. +/**
  28678. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28679. + *
  28680. + * Redistribution and use in source and binary forms, with or without
  28681. + * modification, are permitted provided that the following conditions
  28682. + * are met:
  28683. + * 1. Redistributions of source code must retain the above copyright
  28684. + * notice, this list of conditions, and the following disclaimer,
  28685. + * without modification.
  28686. + * 2. Redistributions in binary form must reproduce the above copyright
  28687. + * notice, this list of conditions and the following disclaimer in the
  28688. + * documentation and/or other materials provided with the distribution.
  28689. + * 3. The names of the above-listed copyright holders may not be used
  28690. + * to endorse or promote products derived from this software without
  28691. + * specific prior written permission.
  28692. + *
  28693. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28694. + * GNU General Public License ("GPL") version 2, as published by the Free
  28695. + * Software Foundation.
  28696. + *
  28697. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28698. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28699. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28700. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28701. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28702. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28703. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28704. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28705. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28706. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28707. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28708. + */
  28709. +
  28710. +
  28711. +#include <linux/proc_fs.h>
  28712. +#include "vchiq_core.h"
  28713. +#include "vchiq_arm.h"
  28714. +
  28715. +#if 1
  28716. +
  28717. +int vchiq_proc_init(void)
  28718. +{
  28719. + return 0;
  28720. +}
  28721. +
  28722. +void vchiq_proc_deinit(void)
  28723. +{
  28724. +}
  28725. +
  28726. +#else
  28727. +
  28728. +struct vchiq_proc_info {
  28729. + /* Global 'vc' proc entry used by all instances */
  28730. + struct proc_dir_entry *vc_cfg_dir;
  28731. +
  28732. + /* one entry per client process */
  28733. + struct proc_dir_entry *clients;
  28734. +
  28735. + /* log categories */
  28736. + struct proc_dir_entry *log_categories;
  28737. +};
  28738. +
  28739. +static struct vchiq_proc_info proc_info;
  28740. +
  28741. +struct proc_dir_entry *vchiq_proc_top(void)
  28742. +{
  28743. + BUG_ON(proc_info.vc_cfg_dir == NULL);
  28744. + return proc_info.vc_cfg_dir;
  28745. +}
  28746. +
  28747. +/****************************************************************************
  28748. +*
  28749. +* log category entries
  28750. +*
  28751. +***************************************************************************/
  28752. +#define PROC_WRITE_BUF_SIZE 256
  28753. +
  28754. +#define VCHIQ_LOG_ERROR_STR "error"
  28755. +#define VCHIQ_LOG_WARNING_STR "warning"
  28756. +#define VCHIQ_LOG_INFO_STR "info"
  28757. +#define VCHIQ_LOG_TRACE_STR "trace"
  28758. +
  28759. +static int log_cfg_read(char *buffer,
  28760. + char **start,
  28761. + off_t off,
  28762. + int count,
  28763. + int *eof,
  28764. + void *data)
  28765. +{
  28766. + int len = 0;
  28767. + char *log_value = NULL;
  28768. +
  28769. + switch (*((int *)data)) {
  28770. + case VCHIQ_LOG_ERROR:
  28771. + log_value = VCHIQ_LOG_ERROR_STR;
  28772. + break;
  28773. + case VCHIQ_LOG_WARNING:
  28774. + log_value = VCHIQ_LOG_WARNING_STR;
  28775. + break;
  28776. + case VCHIQ_LOG_INFO:
  28777. + log_value = VCHIQ_LOG_INFO_STR;
  28778. + break;
  28779. + case VCHIQ_LOG_TRACE:
  28780. + log_value = VCHIQ_LOG_TRACE_STR;
  28781. + break;
  28782. + default:
  28783. + break;
  28784. + }
  28785. +
  28786. + len += sprintf(buffer + len,
  28787. + "%s\n",
  28788. + log_value ? log_value : "(null)");
  28789. +
  28790. + return len;
  28791. +}
  28792. +
  28793. +
  28794. +static int log_cfg_write(struct file *file,
  28795. + const char __user *buffer,
  28796. + unsigned long count,
  28797. + void *data)
  28798. +{
  28799. + int *log_module = data;
  28800. + char kbuf[PROC_WRITE_BUF_SIZE + 1];
  28801. +
  28802. + (void)file;
  28803. +
  28804. + memset(kbuf, 0, PROC_WRITE_BUF_SIZE + 1);
  28805. + if (count >= PROC_WRITE_BUF_SIZE)
  28806. + count = PROC_WRITE_BUF_SIZE;
  28807. +
  28808. + if (copy_from_user(kbuf,
  28809. + buffer,
  28810. + count) != 0)
  28811. + return -EFAULT;
  28812. + kbuf[count - 1] = 0;
  28813. +
  28814. + if (strncmp("error", kbuf, strlen("error")) == 0)
  28815. + *log_module = VCHIQ_LOG_ERROR;
  28816. + else if (strncmp("warning", kbuf, strlen("warning")) == 0)
  28817. + *log_module = VCHIQ_LOG_WARNING;
  28818. + else if (strncmp("info", kbuf, strlen("info")) == 0)
  28819. + *log_module = VCHIQ_LOG_INFO;
  28820. + else if (strncmp("trace", kbuf, strlen("trace")) == 0)
  28821. + *log_module = VCHIQ_LOG_TRACE;
  28822. + else
  28823. + *log_module = VCHIQ_LOG_DEFAULT;
  28824. +
  28825. + return count;
  28826. +}
  28827. +
  28828. +/* Log category proc entries */
  28829. +struct vchiq_proc_log_entry {
  28830. + const char *name;
  28831. + int *plevel;
  28832. + struct proc_dir_entry *dir;
  28833. +};
  28834. +
  28835. +static struct vchiq_proc_log_entry vchiq_proc_log_entries[] = {
  28836. + { "core", &vchiq_core_log_level },
  28837. + { "msg", &vchiq_core_msg_log_level },
  28838. + { "sync", &vchiq_sync_log_level },
  28839. + { "susp", &vchiq_susp_log_level },
  28840. + { "arm", &vchiq_arm_log_level },
  28841. +};
  28842. +static int n_log_entries =
  28843. + sizeof(vchiq_proc_log_entries)/sizeof(vchiq_proc_log_entries[0]);
  28844. +
  28845. +/* create an entry under /proc/vc/log for each log category */
  28846. +static int vchiq_proc_create_log_entries(struct proc_dir_entry *top)
  28847. +{
  28848. + struct proc_dir_entry *dir;
  28849. + size_t i;
  28850. + int ret = 0;
  28851. + dir = proc_mkdir("log", proc_info.vc_cfg_dir);
  28852. + if (!dir)
  28853. + return -ENOMEM;
  28854. + proc_info.log_categories = dir;
  28855. +
  28856. + for (i = 0; i < n_log_entries; i++) {
  28857. + dir = create_proc_entry(vchiq_proc_log_entries[i].name,
  28858. + 0644,
  28859. + proc_info.log_categories);
  28860. + if (!dir) {
  28861. + ret = -ENOMEM;
  28862. + break;
  28863. + }
  28864. +
  28865. + dir->read_proc = &log_cfg_read;
  28866. + dir->write_proc = &log_cfg_write;
  28867. + dir->data = (void *)vchiq_proc_log_entries[i].plevel;
  28868. +
  28869. + vchiq_proc_log_entries[i].dir = dir;
  28870. + }
  28871. + return ret;
  28872. +}
  28873. +
  28874. +
  28875. +int vchiq_proc_init(void)
  28876. +{
  28877. + BUG_ON(proc_info.vc_cfg_dir != NULL);
  28878. +
  28879. + proc_info.vc_cfg_dir = proc_mkdir("vc", NULL);
  28880. + if (proc_info.vc_cfg_dir == NULL)
  28881. + goto fail;
  28882. +
  28883. + proc_info.clients = proc_mkdir("clients",
  28884. + proc_info.vc_cfg_dir);
  28885. + if (!proc_info.clients)
  28886. + goto fail;
  28887. +
  28888. + if (vchiq_proc_create_log_entries(proc_info.vc_cfg_dir) != 0)
  28889. + goto fail;
  28890. +
  28891. + return 0;
  28892. +
  28893. +fail:
  28894. + vchiq_proc_deinit();
  28895. + vchiq_log_error(vchiq_arm_log_level,
  28896. + "%s: failed to create proc directory",
  28897. + __func__);
  28898. +
  28899. + return -ENOMEM;
  28900. +}
  28901. +
  28902. +/* remove all the proc entries */
  28903. +void vchiq_proc_deinit(void)
  28904. +{
  28905. + /* log category entries */
  28906. + if (proc_info.log_categories) {
  28907. + size_t i;
  28908. + for (i = 0; i < n_log_entries; i++)
  28909. + if (vchiq_proc_log_entries[i].dir)
  28910. + remove_proc_entry(
  28911. + vchiq_proc_log_entries[i].name,
  28912. + proc_info.log_categories);
  28913. +
  28914. + remove_proc_entry(proc_info.log_categories->name,
  28915. + proc_info.vc_cfg_dir);
  28916. + }
  28917. + if (proc_info.clients)
  28918. + remove_proc_entry(proc_info.clients->name,
  28919. + proc_info.vc_cfg_dir);
  28920. + if (proc_info.vc_cfg_dir)
  28921. + remove_proc_entry(proc_info.vc_cfg_dir->name, NULL);
  28922. +}
  28923. +
  28924. +struct proc_dir_entry *vchiq_clients_top(void)
  28925. +{
  28926. + return proc_info.clients;
  28927. +}
  28928. +
  28929. +#endif
  28930. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c
  28931. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 1970-01-01 01:00:00.000000000 +0100
  28932. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_shim.c 2014-06-11 21:03:34.000000000 +0200
  28933. @@ -0,0 +1,828 @@
  28934. +/**
  28935. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  28936. + *
  28937. + * Redistribution and use in source and binary forms, with or without
  28938. + * modification, are permitted provided that the following conditions
  28939. + * are met:
  28940. + * 1. Redistributions of source code must retain the above copyright
  28941. + * notice, this list of conditions, and the following disclaimer,
  28942. + * without modification.
  28943. + * 2. Redistributions in binary form must reproduce the above copyright
  28944. + * notice, this list of conditions and the following disclaimer in the
  28945. + * documentation and/or other materials provided with the distribution.
  28946. + * 3. The names of the above-listed copyright holders may not be used
  28947. + * to endorse or promote products derived from this software without
  28948. + * specific prior written permission.
  28949. + *
  28950. + * ALTERNATIVELY, this software may be distributed under the terms of the
  28951. + * GNU General Public License ("GPL") version 2, as published by the Free
  28952. + * Software Foundation.
  28953. + *
  28954. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  28955. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  28956. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  28957. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  28958. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  28959. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  28960. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  28961. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  28962. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28963. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28964. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28965. + */
  28966. +#include <linux/module.h>
  28967. +#include <linux/types.h>
  28968. +
  28969. +#include "interface/vchi/vchi.h"
  28970. +#include "vchiq.h"
  28971. +#include "vchiq_core.h"
  28972. +
  28973. +#include "vchiq_util.h"
  28974. +
  28975. +#include <stddef.h>
  28976. +
  28977. +#define vchiq_status_to_vchi(status) ((int32_t)status)
  28978. +
  28979. +typedef struct {
  28980. + VCHIQ_SERVICE_HANDLE_T handle;
  28981. +
  28982. + VCHIU_QUEUE_T queue;
  28983. +
  28984. + VCHI_CALLBACK_T callback;
  28985. + void *callback_param;
  28986. +} SHIM_SERVICE_T;
  28987. +
  28988. +/* ----------------------------------------------------------------------
  28989. + * return pointer to the mphi message driver function table
  28990. + * -------------------------------------------------------------------- */
  28991. +const VCHI_MESSAGE_DRIVER_T *
  28992. +vchi_mphi_message_driver_func_table(void)
  28993. +{
  28994. + return NULL;
  28995. +}
  28996. +
  28997. +/* ----------------------------------------------------------------------
  28998. + * return a pointer to the 'single' connection driver fops
  28999. + * -------------------------------------------------------------------- */
  29000. +const VCHI_CONNECTION_API_T *
  29001. +single_get_func_table(void)
  29002. +{
  29003. + return NULL;
  29004. +}
  29005. +
  29006. +VCHI_CONNECTION_T *vchi_create_connection(
  29007. + const VCHI_CONNECTION_API_T *function_table,
  29008. + const VCHI_MESSAGE_DRIVER_T *low_level)
  29009. +{
  29010. + (void)function_table;
  29011. + (void)low_level;
  29012. + return NULL;
  29013. +}
  29014. +
  29015. +/***********************************************************
  29016. + * Name: vchi_msg_peek
  29017. + *
  29018. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29019. + * void **data,
  29020. + * uint32_t *msg_size,
  29021. +
  29022. +
  29023. + * VCHI_FLAGS_T flags
  29024. + *
  29025. + * Description: Routine to return a pointer to the current message (to allow in
  29026. + * place processing). The message can be removed using
  29027. + * vchi_msg_remove when you're finished
  29028. + *
  29029. + * Returns: int32_t - success == 0
  29030. + *
  29031. + ***********************************************************/
  29032. +int32_t vchi_msg_peek(VCHI_SERVICE_HANDLE_T handle,
  29033. + void **data,
  29034. + uint32_t *msg_size,
  29035. + VCHI_FLAGS_T flags)
  29036. +{
  29037. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29038. + VCHIQ_HEADER_T *header;
  29039. +
  29040. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29041. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29042. +
  29043. + if (flags == VCHI_FLAGS_NONE)
  29044. + if (vchiu_queue_is_empty(&service->queue))
  29045. + return -1;
  29046. +
  29047. + header = vchiu_queue_peek(&service->queue);
  29048. +
  29049. + *data = header->data;
  29050. + *msg_size = header->size;
  29051. +
  29052. + return 0;
  29053. +}
  29054. +EXPORT_SYMBOL(vchi_msg_peek);
  29055. +
  29056. +/***********************************************************
  29057. + * Name: vchi_msg_remove
  29058. + *
  29059. + * Arguments: const VCHI_SERVICE_HANDLE_T handle,
  29060. + *
  29061. + * Description: Routine to remove a message (after it has been read with
  29062. + * vchi_msg_peek)
  29063. + *
  29064. + * Returns: int32_t - success == 0
  29065. + *
  29066. + ***********************************************************/
  29067. +int32_t vchi_msg_remove(VCHI_SERVICE_HANDLE_T handle)
  29068. +{
  29069. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29070. + VCHIQ_HEADER_T *header;
  29071. +
  29072. + header = vchiu_queue_pop(&service->queue);
  29073. +
  29074. + vchiq_release_message(service->handle, header);
  29075. +
  29076. + return 0;
  29077. +}
  29078. +EXPORT_SYMBOL(vchi_msg_remove);
  29079. +
  29080. +/***********************************************************
  29081. + * Name: vchi_msg_queue
  29082. + *
  29083. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29084. + * const void *data,
  29085. + * uint32_t data_size,
  29086. + * VCHI_FLAGS_T flags,
  29087. + * void *msg_handle,
  29088. + *
  29089. + * Description: Thin wrapper to queue a message onto a connection
  29090. + *
  29091. + * Returns: int32_t - success == 0
  29092. + *
  29093. + ***********************************************************/
  29094. +int32_t vchi_msg_queue(VCHI_SERVICE_HANDLE_T handle,
  29095. + const void *data,
  29096. + uint32_t data_size,
  29097. + VCHI_FLAGS_T flags,
  29098. + void *msg_handle)
  29099. +{
  29100. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29101. + VCHIQ_ELEMENT_T element = {data, data_size};
  29102. + VCHIQ_STATUS_T status;
  29103. +
  29104. + (void)msg_handle;
  29105. +
  29106. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29107. +
  29108. + status = vchiq_queue_message(service->handle, &element, 1);
  29109. +
  29110. + /* vchiq_queue_message() may return VCHIQ_RETRY, so we need to
  29111. + ** implement a retry mechanism since this function is supposed
  29112. + ** to block until queued
  29113. + */
  29114. + while (status == VCHIQ_RETRY) {
  29115. + msleep(1);
  29116. + status = vchiq_queue_message(service->handle, &element, 1);
  29117. + }
  29118. +
  29119. + return vchiq_status_to_vchi(status);
  29120. +}
  29121. +EXPORT_SYMBOL(vchi_msg_queue);
  29122. +
  29123. +/***********************************************************
  29124. + * Name: vchi_bulk_queue_receive
  29125. + *
  29126. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29127. + * void *data_dst,
  29128. + * const uint32_t data_size,
  29129. + * VCHI_FLAGS_T flags
  29130. + * void *bulk_handle
  29131. + *
  29132. + * Description: Routine to setup a rcv buffer
  29133. + *
  29134. + * Returns: int32_t - success == 0
  29135. + *
  29136. + ***********************************************************/
  29137. +int32_t vchi_bulk_queue_receive(VCHI_SERVICE_HANDLE_T handle,
  29138. + void *data_dst,
  29139. + uint32_t data_size,
  29140. + VCHI_FLAGS_T flags,
  29141. + void *bulk_handle)
  29142. +{
  29143. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29144. + VCHIQ_BULK_MODE_T mode;
  29145. + VCHIQ_STATUS_T status;
  29146. +
  29147. + switch ((int)flags) {
  29148. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29149. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29150. + WARN_ON(!service->callback);
  29151. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29152. + break;
  29153. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29154. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29155. + break;
  29156. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29157. + case VCHI_FLAGS_NONE:
  29158. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29159. + break;
  29160. + default:
  29161. + WARN(1, "unsupported message\n");
  29162. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29163. + }
  29164. +
  29165. + status = vchiq_bulk_receive(service->handle, data_dst, data_size,
  29166. + bulk_handle, mode);
  29167. +
  29168. + /* vchiq_bulk_receive() may return VCHIQ_RETRY, so we need to
  29169. + ** implement a retry mechanism since this function is supposed
  29170. + ** to block until queued
  29171. + */
  29172. + while (status == VCHIQ_RETRY) {
  29173. + msleep(1);
  29174. + status = vchiq_bulk_receive(service->handle, data_dst,
  29175. + data_size, bulk_handle, mode);
  29176. + }
  29177. +
  29178. + return vchiq_status_to_vchi(status);
  29179. +}
  29180. +EXPORT_SYMBOL(vchi_bulk_queue_receive);
  29181. +
  29182. +/***********************************************************
  29183. + * Name: vchi_bulk_queue_transmit
  29184. + *
  29185. + * Arguments: VCHI_BULK_HANDLE_T handle,
  29186. + * const void *data_src,
  29187. + * uint32_t data_size,
  29188. + * VCHI_FLAGS_T flags,
  29189. + * void *bulk_handle
  29190. + *
  29191. + * Description: Routine to transmit some data
  29192. + *
  29193. + * Returns: int32_t - success == 0
  29194. + *
  29195. + ***********************************************************/
  29196. +int32_t vchi_bulk_queue_transmit(VCHI_SERVICE_HANDLE_T handle,
  29197. + const void *data_src,
  29198. + uint32_t data_size,
  29199. + VCHI_FLAGS_T flags,
  29200. + void *bulk_handle)
  29201. +{
  29202. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29203. + VCHIQ_BULK_MODE_T mode;
  29204. + VCHIQ_STATUS_T status;
  29205. +
  29206. + switch ((int)flags) {
  29207. + case VCHI_FLAGS_CALLBACK_WHEN_OP_COMPLETE
  29208. + | VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29209. + WARN_ON(!service->callback);
  29210. + mode = VCHIQ_BULK_MODE_CALLBACK;
  29211. + break;
  29212. + case VCHI_FLAGS_BLOCK_UNTIL_DATA_READ:
  29213. + case VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE:
  29214. + mode = VCHIQ_BULK_MODE_BLOCKING;
  29215. + break;
  29216. + case VCHI_FLAGS_BLOCK_UNTIL_QUEUED:
  29217. + case VCHI_FLAGS_NONE:
  29218. + mode = VCHIQ_BULK_MODE_NOCALLBACK;
  29219. + break;
  29220. + default:
  29221. + WARN(1, "unsupported message\n");
  29222. + return vchiq_status_to_vchi(VCHIQ_ERROR);
  29223. + }
  29224. +
  29225. + status = vchiq_bulk_transmit(service->handle, data_src, data_size,
  29226. + bulk_handle, mode);
  29227. +
  29228. + /* vchiq_bulk_transmit() may return VCHIQ_RETRY, so we need to
  29229. + ** implement a retry mechanism since this function is supposed
  29230. + ** to block until queued
  29231. + */
  29232. + while (status == VCHIQ_RETRY) {
  29233. + msleep(1);
  29234. + status = vchiq_bulk_transmit(service->handle, data_src,
  29235. + data_size, bulk_handle, mode);
  29236. + }
  29237. +
  29238. + return vchiq_status_to_vchi(status);
  29239. +}
  29240. +EXPORT_SYMBOL(vchi_bulk_queue_transmit);
  29241. +
  29242. +/***********************************************************
  29243. + * Name: vchi_msg_dequeue
  29244. + *
  29245. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29246. + * void *data,
  29247. + * uint32_t max_data_size_to_read,
  29248. + * uint32_t *actual_msg_size
  29249. + * VCHI_FLAGS_T flags
  29250. + *
  29251. + * Description: Routine to dequeue a message into the supplied buffer
  29252. + *
  29253. + * Returns: int32_t - success == 0
  29254. + *
  29255. + ***********************************************************/
  29256. +int32_t vchi_msg_dequeue(VCHI_SERVICE_HANDLE_T handle,
  29257. + void *data,
  29258. + uint32_t max_data_size_to_read,
  29259. + uint32_t *actual_msg_size,
  29260. + VCHI_FLAGS_T flags)
  29261. +{
  29262. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29263. + VCHIQ_HEADER_T *header;
  29264. +
  29265. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29266. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29267. +
  29268. + if (flags == VCHI_FLAGS_NONE)
  29269. + if (vchiu_queue_is_empty(&service->queue))
  29270. + return -1;
  29271. +
  29272. + header = vchiu_queue_pop(&service->queue);
  29273. +
  29274. + memcpy(data, header->data, header->size < max_data_size_to_read ?
  29275. + header->size : max_data_size_to_read);
  29276. +
  29277. + *actual_msg_size = header->size;
  29278. +
  29279. + vchiq_release_message(service->handle, header);
  29280. +
  29281. + return 0;
  29282. +}
  29283. +EXPORT_SYMBOL(vchi_msg_dequeue);
  29284. +
  29285. +/***********************************************************
  29286. + * Name: vchi_msg_queuev
  29287. + *
  29288. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29289. + * VCHI_MSG_VECTOR_T *vector,
  29290. + * uint32_t count,
  29291. + * VCHI_FLAGS_T flags,
  29292. + * void *msg_handle
  29293. + *
  29294. + * Description: Thin wrapper to queue a message onto a connection
  29295. + *
  29296. + * Returns: int32_t - success == 0
  29297. + *
  29298. + ***********************************************************/
  29299. +
  29300. +vchiq_static_assert(sizeof(VCHI_MSG_VECTOR_T) == sizeof(VCHIQ_ELEMENT_T));
  29301. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_base) ==
  29302. + offsetof(VCHIQ_ELEMENT_T, data));
  29303. +vchiq_static_assert(offsetof(VCHI_MSG_VECTOR_T, vec_len) ==
  29304. + offsetof(VCHIQ_ELEMENT_T, size));
  29305. +
  29306. +int32_t vchi_msg_queuev(VCHI_SERVICE_HANDLE_T handle,
  29307. + VCHI_MSG_VECTOR_T *vector,
  29308. + uint32_t count,
  29309. + VCHI_FLAGS_T flags,
  29310. + void *msg_handle)
  29311. +{
  29312. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29313. +
  29314. + (void)msg_handle;
  29315. +
  29316. + WARN_ON(flags != VCHI_FLAGS_BLOCK_UNTIL_QUEUED);
  29317. +
  29318. + return vchiq_status_to_vchi(vchiq_queue_message(service->handle,
  29319. + (const VCHIQ_ELEMENT_T *)vector, count));
  29320. +}
  29321. +EXPORT_SYMBOL(vchi_msg_queuev);
  29322. +
  29323. +/***********************************************************
  29324. + * Name: vchi_held_msg_release
  29325. + *
  29326. + * Arguments: VCHI_HELD_MSG_T *message
  29327. + *
  29328. + * Description: Routine to release a held message (after it has been read with
  29329. + * vchi_msg_hold)
  29330. + *
  29331. + * Returns: int32_t - success == 0
  29332. + *
  29333. + ***********************************************************/
  29334. +int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message)
  29335. +{
  29336. + vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service,
  29337. + (VCHIQ_HEADER_T *)message->message);
  29338. +
  29339. + return 0;
  29340. +}
  29341. +EXPORT_SYMBOL(vchi_held_msg_release);
  29342. +
  29343. +/***********************************************************
  29344. + * Name: vchi_msg_hold
  29345. + *
  29346. + * Arguments: VCHI_SERVICE_HANDLE_T handle,
  29347. + * void **data,
  29348. + * uint32_t *msg_size,
  29349. + * VCHI_FLAGS_T flags,
  29350. + * VCHI_HELD_MSG_T *message_handle
  29351. + *
  29352. + * Description: Routine to return a pointer to the current message (to allow
  29353. + * in place processing). The message is dequeued - don't forget
  29354. + * to release the message using vchi_held_msg_release when you're
  29355. + * finished.
  29356. + *
  29357. + * Returns: int32_t - success == 0
  29358. + *
  29359. + ***********************************************************/
  29360. +int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle,
  29361. + void **data,
  29362. + uint32_t *msg_size,
  29363. + VCHI_FLAGS_T flags,
  29364. + VCHI_HELD_MSG_T *message_handle)
  29365. +{
  29366. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29367. + VCHIQ_HEADER_T *header;
  29368. +
  29369. + WARN_ON((flags != VCHI_FLAGS_NONE) &&
  29370. + (flags != VCHI_FLAGS_BLOCK_UNTIL_OP_COMPLETE));
  29371. +
  29372. + if (flags == VCHI_FLAGS_NONE)
  29373. + if (vchiu_queue_is_empty(&service->queue))
  29374. + return -1;
  29375. +
  29376. + header = vchiu_queue_pop(&service->queue);
  29377. +
  29378. + *data = header->data;
  29379. + *msg_size = header->size;
  29380. +
  29381. + message_handle->service =
  29382. + (struct opaque_vchi_service_t *)service->handle;
  29383. + message_handle->message = header;
  29384. +
  29385. + return 0;
  29386. +}
  29387. +EXPORT_SYMBOL(vchi_msg_hold);
  29388. +
  29389. +/***********************************************************
  29390. + * Name: vchi_initialise
  29391. + *
  29392. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29393. + * VCHI_CONNECTION_T **connections
  29394. + * const uint32_t num_connections
  29395. + *
  29396. + * Description: Initialises the hardware but does not transmit anything
  29397. + * When run as a Host App this will be called twice hence the need
  29398. + * to malloc the state information
  29399. + *
  29400. + * Returns: 0 if successful, failure otherwise
  29401. + *
  29402. + ***********************************************************/
  29403. +
  29404. +int32_t vchi_initialise(VCHI_INSTANCE_T *instance_handle)
  29405. +{
  29406. + VCHIQ_INSTANCE_T instance;
  29407. + VCHIQ_STATUS_T status;
  29408. +
  29409. + status = vchiq_initialise(&instance);
  29410. +
  29411. + *instance_handle = (VCHI_INSTANCE_T)instance;
  29412. +
  29413. + return vchiq_status_to_vchi(status);
  29414. +}
  29415. +EXPORT_SYMBOL(vchi_initialise);
  29416. +
  29417. +/***********************************************************
  29418. + * Name: vchi_connect
  29419. + *
  29420. + * Arguments: VCHI_CONNECTION_T **connections
  29421. + * const uint32_t num_connections
  29422. + * VCHI_INSTANCE_T instance_handle)
  29423. + *
  29424. + * Description: Starts the command service on each connection,
  29425. + * causing INIT messages to be pinged back and forth
  29426. + *
  29427. + * Returns: 0 if successful, failure otherwise
  29428. + *
  29429. + ***********************************************************/
  29430. +int32_t vchi_connect(VCHI_CONNECTION_T **connections,
  29431. + const uint32_t num_connections,
  29432. + VCHI_INSTANCE_T instance_handle)
  29433. +{
  29434. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29435. +
  29436. + (void)connections;
  29437. + (void)num_connections;
  29438. +
  29439. + return vchiq_connect(instance);
  29440. +}
  29441. +EXPORT_SYMBOL(vchi_connect);
  29442. +
  29443. +
  29444. +/***********************************************************
  29445. + * Name: vchi_disconnect
  29446. + *
  29447. + * Arguments: VCHI_INSTANCE_T instance_handle
  29448. + *
  29449. + * Description: Stops the command service on each connection,
  29450. + * causing DE-INIT messages to be pinged back and forth
  29451. + *
  29452. + * Returns: 0 if successful, failure otherwise
  29453. + *
  29454. + ***********************************************************/
  29455. +int32_t vchi_disconnect(VCHI_INSTANCE_T instance_handle)
  29456. +{
  29457. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29458. + return vchiq_status_to_vchi(vchiq_shutdown(instance));
  29459. +}
  29460. +EXPORT_SYMBOL(vchi_disconnect);
  29461. +
  29462. +
  29463. +/***********************************************************
  29464. + * Name: vchi_service_open
  29465. + * Name: vchi_service_create
  29466. + *
  29467. + * Arguments: VCHI_INSTANCE_T *instance_handle
  29468. + * SERVICE_CREATION_T *setup,
  29469. + * VCHI_SERVICE_HANDLE_T *handle
  29470. + *
  29471. + * Description: Routine to open a service
  29472. + *
  29473. + * Returns: int32_t - success == 0
  29474. + *
  29475. + ***********************************************************/
  29476. +
  29477. +static VCHIQ_STATUS_T shim_callback(VCHIQ_REASON_T reason,
  29478. + VCHIQ_HEADER_T *header, VCHIQ_SERVICE_HANDLE_T handle, void *bulk_user)
  29479. +{
  29480. + SHIM_SERVICE_T *service =
  29481. + (SHIM_SERVICE_T *)VCHIQ_GET_SERVICE_USERDATA(handle);
  29482. +
  29483. + if (!service->callback)
  29484. + goto release;
  29485. +
  29486. + switch (reason) {
  29487. + case VCHIQ_MESSAGE_AVAILABLE:
  29488. + vchiu_queue_push(&service->queue, header);
  29489. +
  29490. + service->callback(service->callback_param,
  29491. + VCHI_CALLBACK_MSG_AVAILABLE, NULL);
  29492. +
  29493. + goto done;
  29494. + break;
  29495. +
  29496. + case VCHIQ_BULK_TRANSMIT_DONE:
  29497. + service->callback(service->callback_param,
  29498. + VCHI_CALLBACK_BULK_SENT, bulk_user);
  29499. + break;
  29500. +
  29501. + case VCHIQ_BULK_RECEIVE_DONE:
  29502. + service->callback(service->callback_param,
  29503. + VCHI_CALLBACK_BULK_RECEIVED, bulk_user);
  29504. + break;
  29505. +
  29506. + case VCHIQ_SERVICE_CLOSED:
  29507. + service->callback(service->callback_param,
  29508. + VCHI_CALLBACK_SERVICE_CLOSED, NULL);
  29509. + break;
  29510. +
  29511. + case VCHIQ_SERVICE_OPENED:
  29512. + /* No equivalent VCHI reason */
  29513. + break;
  29514. +
  29515. + case VCHIQ_BULK_TRANSMIT_ABORTED:
  29516. + service->callback(service->callback_param,
  29517. + VCHI_CALLBACK_BULK_TRANSMIT_ABORTED,
  29518. + bulk_user);
  29519. + break;
  29520. +
  29521. + case VCHIQ_BULK_RECEIVE_ABORTED:
  29522. + service->callback(service->callback_param,
  29523. + VCHI_CALLBACK_BULK_RECEIVE_ABORTED,
  29524. + bulk_user);
  29525. + break;
  29526. +
  29527. + default:
  29528. + WARN(1, "not supported\n");
  29529. + break;
  29530. + }
  29531. +
  29532. +release:
  29533. + vchiq_release_message(service->handle, header);
  29534. +done:
  29535. + return VCHIQ_SUCCESS;
  29536. +}
  29537. +
  29538. +static SHIM_SERVICE_T *service_alloc(VCHIQ_INSTANCE_T instance,
  29539. + SERVICE_CREATION_T *setup)
  29540. +{
  29541. + SHIM_SERVICE_T *service = kzalloc(sizeof(SHIM_SERVICE_T), GFP_KERNEL);
  29542. +
  29543. + (void)instance;
  29544. +
  29545. + if (service) {
  29546. + if (vchiu_queue_init(&service->queue, 64)) {
  29547. + service->callback = setup->callback;
  29548. + service->callback_param = setup->callback_param;
  29549. + } else {
  29550. + kfree(service);
  29551. + service = NULL;
  29552. + }
  29553. + }
  29554. +
  29555. + return service;
  29556. +}
  29557. +
  29558. +static void service_free(SHIM_SERVICE_T *service)
  29559. +{
  29560. + if (service) {
  29561. + vchiu_queue_delete(&service->queue);
  29562. + kfree(service);
  29563. + }
  29564. +}
  29565. +
  29566. +int32_t vchi_service_open(VCHI_INSTANCE_T instance_handle,
  29567. + SERVICE_CREATION_T *setup,
  29568. + VCHI_SERVICE_HANDLE_T *handle)
  29569. +{
  29570. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29571. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  29572. + if (service) {
  29573. + VCHIQ_SERVICE_PARAMS_T params;
  29574. + VCHIQ_STATUS_T status;
  29575. +
  29576. + memset(&params, 0, sizeof(params));
  29577. + params.fourcc = setup->service_id;
  29578. + params.callback = shim_callback;
  29579. + params.userdata = service;
  29580. + params.version = setup->version.version;
  29581. + params.version_min = setup->version.version_min;
  29582. +
  29583. + status = vchiq_open_service(instance, &params,
  29584. + &service->handle);
  29585. + if (status != VCHIQ_SUCCESS) {
  29586. + service_free(service);
  29587. + service = NULL;
  29588. + }
  29589. + }
  29590. +
  29591. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  29592. +
  29593. + return (service != NULL) ? 0 : -1;
  29594. +}
  29595. +EXPORT_SYMBOL(vchi_service_open);
  29596. +
  29597. +int32_t vchi_service_create(VCHI_INSTANCE_T instance_handle,
  29598. + SERVICE_CREATION_T *setup,
  29599. + VCHI_SERVICE_HANDLE_T *handle)
  29600. +{
  29601. + VCHIQ_INSTANCE_T instance = (VCHIQ_INSTANCE_T)instance_handle;
  29602. + SHIM_SERVICE_T *service = service_alloc(instance, setup);
  29603. + if (service) {
  29604. + VCHIQ_SERVICE_PARAMS_T params;
  29605. + VCHIQ_STATUS_T status;
  29606. +
  29607. + memset(&params, 0, sizeof(params));
  29608. + params.fourcc = setup->service_id;
  29609. + params.callback = shim_callback;
  29610. + params.userdata = service;
  29611. + params.version = setup->version.version;
  29612. + params.version_min = setup->version.version_min;
  29613. + status = vchiq_add_service(instance, &params, &service->handle);
  29614. +
  29615. + if (status != VCHIQ_SUCCESS) {
  29616. + service_free(service);
  29617. + service = NULL;
  29618. + }
  29619. + }
  29620. +
  29621. + *handle = (VCHI_SERVICE_HANDLE_T)service;
  29622. +
  29623. + return (service != NULL) ? 0 : -1;
  29624. +}
  29625. +EXPORT_SYMBOL(vchi_service_create);
  29626. +
  29627. +int32_t vchi_service_close(const VCHI_SERVICE_HANDLE_T handle)
  29628. +{
  29629. + int32_t ret = -1;
  29630. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29631. + if (service) {
  29632. + VCHIQ_STATUS_T status = vchiq_close_service(service->handle);
  29633. + if (status == VCHIQ_SUCCESS) {
  29634. + service_free(service);
  29635. + service = NULL;
  29636. + }
  29637. +
  29638. + ret = vchiq_status_to_vchi(status);
  29639. + }
  29640. + return ret;
  29641. +}
  29642. +EXPORT_SYMBOL(vchi_service_close);
  29643. +
  29644. +int32_t vchi_service_destroy(const VCHI_SERVICE_HANDLE_T handle)
  29645. +{
  29646. + int32_t ret = -1;
  29647. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29648. + if (service) {
  29649. + VCHIQ_STATUS_T status = vchiq_remove_service(service->handle);
  29650. + if (status == VCHIQ_SUCCESS) {
  29651. + service_free(service);
  29652. + service = NULL;
  29653. + }
  29654. +
  29655. + ret = vchiq_status_to_vchi(status);
  29656. + }
  29657. + return ret;
  29658. +}
  29659. +EXPORT_SYMBOL(vchi_service_destroy);
  29660. +
  29661. +int32_t vchi_get_peer_version( const VCHI_SERVICE_HANDLE_T handle, short *peer_version )
  29662. +{
  29663. + int32_t ret = -1;
  29664. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29665. + if(service)
  29666. + {
  29667. + VCHIQ_STATUS_T status = vchiq_get_peer_version(service->handle, peer_version);
  29668. + ret = vchiq_status_to_vchi( status );
  29669. + }
  29670. + return ret;
  29671. +}
  29672. +EXPORT_SYMBOL(vchi_get_peer_version);
  29673. +
  29674. +/* ----------------------------------------------------------------------
  29675. + * read a uint32_t from buffer.
  29676. + * network format is defined to be little endian
  29677. + * -------------------------------------------------------------------- */
  29678. +uint32_t
  29679. +vchi_readbuf_uint32(const void *_ptr)
  29680. +{
  29681. + const unsigned char *ptr = _ptr;
  29682. + return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
  29683. +}
  29684. +
  29685. +/* ----------------------------------------------------------------------
  29686. + * write a uint32_t to buffer.
  29687. + * network format is defined to be little endian
  29688. + * -------------------------------------------------------------------- */
  29689. +void
  29690. +vchi_writebuf_uint32(void *_ptr, uint32_t value)
  29691. +{
  29692. + unsigned char *ptr = _ptr;
  29693. + ptr[0] = (unsigned char)((value >> 0) & 0xFF);
  29694. + ptr[1] = (unsigned char)((value >> 8) & 0xFF);
  29695. + ptr[2] = (unsigned char)((value >> 16) & 0xFF);
  29696. + ptr[3] = (unsigned char)((value >> 24) & 0xFF);
  29697. +}
  29698. +
  29699. +/* ----------------------------------------------------------------------
  29700. + * read a uint16_t from buffer.
  29701. + * network format is defined to be little endian
  29702. + * -------------------------------------------------------------------- */
  29703. +uint16_t
  29704. +vchi_readbuf_uint16(const void *_ptr)
  29705. +{
  29706. + const unsigned char *ptr = _ptr;
  29707. + return ptr[0] | (ptr[1] << 8);
  29708. +}
  29709. +
  29710. +/* ----------------------------------------------------------------------
  29711. + * write a uint16_t into the buffer.
  29712. + * network format is defined to be little endian
  29713. + * -------------------------------------------------------------------- */
  29714. +void
  29715. +vchi_writebuf_uint16(void *_ptr, uint16_t value)
  29716. +{
  29717. + unsigned char *ptr = _ptr;
  29718. + ptr[0] = (value >> 0) & 0xFF;
  29719. + ptr[1] = (value >> 8) & 0xFF;
  29720. +}
  29721. +
  29722. +/***********************************************************
  29723. + * Name: vchi_service_use
  29724. + *
  29725. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29726. + *
  29727. + * Description: Routine to increment refcount on a service
  29728. + *
  29729. + * Returns: void
  29730. + *
  29731. + ***********************************************************/
  29732. +int32_t vchi_service_use(const VCHI_SERVICE_HANDLE_T handle)
  29733. +{
  29734. + int32_t ret = -1;
  29735. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29736. + if (service)
  29737. + ret = vchiq_status_to_vchi(vchiq_use_service(service->handle));
  29738. + return ret;
  29739. +}
  29740. +EXPORT_SYMBOL(vchi_service_use);
  29741. +
  29742. +/***********************************************************
  29743. + * Name: vchi_service_release
  29744. + *
  29745. + * Arguments: const VCHI_SERVICE_HANDLE_T handle
  29746. + *
  29747. + * Description: Routine to decrement refcount on a service
  29748. + *
  29749. + * Returns: void
  29750. + *
  29751. + ***********************************************************/
  29752. +int32_t vchi_service_release(const VCHI_SERVICE_HANDLE_T handle)
  29753. +{
  29754. + int32_t ret = -1;
  29755. + SHIM_SERVICE_T *service = (SHIM_SERVICE_T *)handle;
  29756. + if (service)
  29757. + ret = vchiq_status_to_vchi(
  29758. + vchiq_release_service(service->handle));
  29759. + return ret;
  29760. +}
  29761. +EXPORT_SYMBOL(vchi_service_release);
  29762. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c
  29763. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 1970-01-01 01:00:00.000000000 +0100
  29764. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.c 2014-06-11 21:03:34.000000000 +0200
  29765. @@ -0,0 +1,152 @@
  29766. +/**
  29767. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29768. + *
  29769. + * Redistribution and use in source and binary forms, with or without
  29770. + * modification, are permitted provided that the following conditions
  29771. + * are met:
  29772. + * 1. Redistributions of source code must retain the above copyright
  29773. + * notice, this list of conditions, and the following disclaimer,
  29774. + * without modification.
  29775. + * 2. Redistributions in binary form must reproduce the above copyright
  29776. + * notice, this list of conditions and the following disclaimer in the
  29777. + * documentation and/or other materials provided with the distribution.
  29778. + * 3. The names of the above-listed copyright holders may not be used
  29779. + * to endorse or promote products derived from this software without
  29780. + * specific prior written permission.
  29781. + *
  29782. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29783. + * GNU General Public License ("GPL") version 2, as published by the Free
  29784. + * Software Foundation.
  29785. + *
  29786. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29787. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29788. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29789. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29790. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29791. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29792. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29793. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29794. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29795. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29796. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29797. + */
  29798. +
  29799. +#include "vchiq_util.h"
  29800. +#include "vchiq_killable.h"
  29801. +
  29802. +static inline int is_pow2(int i)
  29803. +{
  29804. + return i && !(i & (i - 1));
  29805. +}
  29806. +
  29807. +int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size)
  29808. +{
  29809. + WARN_ON(!is_pow2(size));
  29810. +
  29811. + queue->size = size;
  29812. + queue->read = 0;
  29813. + queue->write = 0;
  29814. +
  29815. + sema_init(&queue->pop, 0);
  29816. + sema_init(&queue->push, 0);
  29817. +
  29818. + queue->storage = kzalloc(size * sizeof(VCHIQ_HEADER_T *), GFP_KERNEL);
  29819. + if (queue->storage == NULL) {
  29820. + vchiu_queue_delete(queue);
  29821. + return 0;
  29822. + }
  29823. + return 1;
  29824. +}
  29825. +
  29826. +void vchiu_queue_delete(VCHIU_QUEUE_T *queue)
  29827. +{
  29828. + if (queue->storage != NULL)
  29829. + kfree(queue->storage);
  29830. +}
  29831. +
  29832. +int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue)
  29833. +{
  29834. + return queue->read == queue->write;
  29835. +}
  29836. +
  29837. +int vchiu_queue_is_full(VCHIU_QUEUE_T *queue)
  29838. +{
  29839. + return queue->write == queue->read + queue->size;
  29840. +}
  29841. +
  29842. +void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header)
  29843. +{
  29844. + while (queue->write == queue->read + queue->size) {
  29845. + if (down_interruptible(&queue->pop) != 0) {
  29846. + flush_signals(current);
  29847. + }
  29848. + }
  29849. +
  29850. + /*
  29851. + * Write to queue->storage must be visible after read from
  29852. + * queue->read
  29853. + */
  29854. + smp_mb();
  29855. +
  29856. + queue->storage[queue->write & (queue->size - 1)] = header;
  29857. +
  29858. + /*
  29859. + * Write to queue->storage must be visible before write to
  29860. + * queue->write
  29861. + */
  29862. + smp_wmb();
  29863. +
  29864. + queue->write++;
  29865. +
  29866. + up(&queue->push);
  29867. +}
  29868. +
  29869. +VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue)
  29870. +{
  29871. + while (queue->write == queue->read) {
  29872. + if (down_interruptible(&queue->push) != 0) {
  29873. + flush_signals(current);
  29874. + }
  29875. + }
  29876. +
  29877. + up(&queue->push); // We haven't removed anything from the queue.
  29878. +
  29879. + /*
  29880. + * Read from queue->storage must be visible after read from
  29881. + * queue->write
  29882. + */
  29883. + smp_rmb();
  29884. +
  29885. + return queue->storage[queue->read & (queue->size - 1)];
  29886. +}
  29887. +
  29888. +VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue)
  29889. +{
  29890. + VCHIQ_HEADER_T *header;
  29891. +
  29892. + while (queue->write == queue->read) {
  29893. + if (down_interruptible(&queue->push) != 0) {
  29894. + flush_signals(current);
  29895. + }
  29896. + }
  29897. +
  29898. + /*
  29899. + * Read from queue->storage must be visible after read from
  29900. + * queue->write
  29901. + */
  29902. + smp_rmb();
  29903. +
  29904. + header = queue->storage[queue->read & (queue->size - 1)];
  29905. +
  29906. + /*
  29907. + * Read from queue->storage must be visible before write to
  29908. + * queue->read
  29909. + */
  29910. + smp_mb();
  29911. +
  29912. + queue->read++;
  29913. +
  29914. + up(&queue->pop);
  29915. +
  29916. + return header;
  29917. +}
  29918. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h
  29919. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 1970-01-01 01:00:00.000000000 +0100
  29920. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_util.h 2014-06-11 21:03:34.000000000 +0200
  29921. @@ -0,0 +1,81 @@
  29922. +/**
  29923. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  29924. + *
  29925. + * Redistribution and use in source and binary forms, with or without
  29926. + * modification, are permitted provided that the following conditions
  29927. + * are met:
  29928. + * 1. Redistributions of source code must retain the above copyright
  29929. + * notice, this list of conditions, and the following disclaimer,
  29930. + * without modification.
  29931. + * 2. Redistributions in binary form must reproduce the above copyright
  29932. + * notice, this list of conditions and the following disclaimer in the
  29933. + * documentation and/or other materials provided with the distribution.
  29934. + * 3. The names of the above-listed copyright holders may not be used
  29935. + * to endorse or promote products derived from this software without
  29936. + * specific prior written permission.
  29937. + *
  29938. + * ALTERNATIVELY, this software may be distributed under the terms of the
  29939. + * GNU General Public License ("GPL") version 2, as published by the Free
  29940. + * Software Foundation.
  29941. + *
  29942. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  29943. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  29944. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  29945. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  29946. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  29947. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  29948. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  29949. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  29950. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  29951. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29952. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29953. + */
  29954. +
  29955. +#ifndef VCHIQ_UTIL_H
  29956. +#define VCHIQ_UTIL_H
  29957. +
  29958. +#include <linux/types.h>
  29959. +#include <linux/semaphore.h>
  29960. +#include <linux/mutex.h>
  29961. +#include <linux/bitops.h>
  29962. +#include <linux/kthread.h>
  29963. +#include <linux/wait.h>
  29964. +#include <linux/vmalloc.h>
  29965. +#include <linux/jiffies.h>
  29966. +#include <linux/delay.h>
  29967. +#include <linux/string.h>
  29968. +#include <linux/types.h>
  29969. +#include <linux/interrupt.h>
  29970. +#include <linux/random.h>
  29971. +#include <linux/sched.h>
  29972. +#include <linux/ctype.h>
  29973. +#include <linux/uaccess.h>
  29974. +#include <linux/time.h> /* for time_t */
  29975. +#include <linux/slab.h>
  29976. +#include <linux/vmalloc.h>
  29977. +
  29978. +#include "vchiq_if.h"
  29979. +
  29980. +typedef struct {
  29981. + int size;
  29982. + int read;
  29983. + int write;
  29984. +
  29985. + struct semaphore pop;
  29986. + struct semaphore push;
  29987. +
  29988. + VCHIQ_HEADER_T **storage;
  29989. +} VCHIU_QUEUE_T;
  29990. +
  29991. +extern int vchiu_queue_init(VCHIU_QUEUE_T *queue, int size);
  29992. +extern void vchiu_queue_delete(VCHIU_QUEUE_T *queue);
  29993. +
  29994. +extern int vchiu_queue_is_empty(VCHIU_QUEUE_T *queue);
  29995. +extern int vchiu_queue_is_full(VCHIU_QUEUE_T *queue);
  29996. +
  29997. +extern void vchiu_queue_push(VCHIU_QUEUE_T *queue, VCHIQ_HEADER_T *header);
  29998. +
  29999. +extern VCHIQ_HEADER_T *vchiu_queue_peek(VCHIU_QUEUE_T *queue);
  30000. +extern VCHIQ_HEADER_T *vchiu_queue_pop(VCHIU_QUEUE_T *queue);
  30001. +
  30002. +#endif
  30003. diff -Nur linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c
  30004. --- linux-3.15/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 1970-01-01 01:00:00.000000000 +0100
  30005. +++ linux-rpi/drivers/misc/vc04_services/interface/vchiq_arm/vchiq_version.c 2014-06-11 21:03:34.000000000 +0200
  30006. @@ -0,0 +1,59 @@
  30007. +/**
  30008. + * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  30009. + *
  30010. + * Redistribution and use in source and binary forms, with or without
  30011. + * modification, are permitted provided that the following conditions
  30012. + * are met:
  30013. + * 1. Redistributions of source code must retain the above copyright
  30014. + * notice, this list of conditions, and the following disclaimer,
  30015. + * without modification.
  30016. + * 2. Redistributions in binary form must reproduce the above copyright
  30017. + * notice, this list of conditions and the following disclaimer in the
  30018. + * documentation and/or other materials provided with the distribution.
  30019. + * 3. The names of the above-listed copyright holders may not be used
  30020. + * to endorse or promote products derived from this software without
  30021. + * specific prior written permission.
  30022. + *
  30023. + * ALTERNATIVELY, this software may be distributed under the terms of the
  30024. + * GNU General Public License ("GPL") version 2, as published by the Free
  30025. + * Software Foundation.
  30026. + *
  30027. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  30028. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  30029. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  30030. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  30031. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  30032. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  30033. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30034. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  30035. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  30036. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30037. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30038. + */
  30039. +#include "vchiq_build_info.h"
  30040. +#include <linux/broadcom/vc_debug_sym.h>
  30041. +
  30042. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_hostname, "dc4-arm-01" );
  30043. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_version, "9245b4c35b99b3870e1f7dc598c5692b3c66a6f0 (tainted)" );
  30044. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_time, __TIME__ );
  30045. +VC_DEBUG_DECLARE_STRING_VAR( vchiq_build_date, __DATE__ );
  30046. +
  30047. +const char *vchiq_get_build_hostname( void )
  30048. +{
  30049. + return vchiq_build_hostname;
  30050. +}
  30051. +
  30052. +const char *vchiq_get_build_version( void )
  30053. +{
  30054. + return vchiq_build_version;
  30055. +}
  30056. +
  30057. +const char *vchiq_get_build_date( void )
  30058. +{
  30059. + return vchiq_build_date;
  30060. +}
  30061. +
  30062. +const char *vchiq_get_build_time( void )
  30063. +{
  30064. + return vchiq_build_time;
  30065. +}
  30066. diff -Nur linux-3.15/drivers/misc/vc04_services/Kconfig linux-rpi/drivers/misc/vc04_services/Kconfig
  30067. --- linux-3.15/drivers/misc/vc04_services/Kconfig 1970-01-01 01:00:00.000000000 +0100
  30068. +++ linux-rpi/drivers/misc/vc04_services/Kconfig 2014-06-11 21:03:34.000000000 +0200
  30069. @@ -0,0 +1,9 @@
  30070. +config BCM2708_VCHIQ
  30071. + tristate "Videocore VCHIQ"
  30072. + depends on MACH_BCM2708
  30073. + default y
  30074. + help
  30075. + Kernel to VideoCore communication interface for the
  30076. + BCM2708 family of products.
  30077. + Defaults to Y when the Broadcom Videocore services
  30078. + are included in the build, N otherwise.
  30079. diff -Nur linux-3.15/drivers/misc/vc04_services/Makefile linux-rpi/drivers/misc/vc04_services/Makefile
  30080. --- linux-3.15/drivers/misc/vc04_services/Makefile 1970-01-01 01:00:00.000000000 +0100
  30081. +++ linux-rpi/drivers/misc/vc04_services/Makefile 2014-06-11 21:03:34.000000000 +0200
  30082. @@ -0,0 +1,17 @@
  30083. +ifeq ($(CONFIG_MACH_BCM2708),y)
  30084. +
  30085. +obj-$(CONFIG_BCM2708_VCHIQ) += vchiq.o
  30086. +
  30087. +vchiq-objs := \
  30088. + interface/vchiq_arm/vchiq_core.o \
  30089. + interface/vchiq_arm/vchiq_arm.o \
  30090. + interface/vchiq_arm/vchiq_kern_lib.o \
  30091. + interface/vchiq_arm/vchiq_2835_arm.o \
  30092. + interface/vchiq_arm/vchiq_proc.o \
  30093. + interface/vchiq_arm/vchiq_shim.o \
  30094. + interface/vchiq_arm/vchiq_util.o \
  30095. + interface/vchiq_arm/vchiq_connected.o \
  30096. +
  30097. +ccflags-y += -DVCOS_VERIFY_BKPTS=1 -Idrivers/misc/vc04_services -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000
  30098. +
  30099. +endif
  30100. diff -Nur linux-3.15/drivers/mmc/card/block.c linux-rpi/drivers/mmc/card/block.c
  30101. --- linux-3.15/drivers/mmc/card/block.c 2014-06-08 20:19:54.000000000 +0200
  30102. +++ linux-rpi/drivers/mmc/card/block.c 2014-06-11 21:05:20.000000000 +0200
  30103. @@ -1404,7 +1404,7 @@
  30104. brq->data.blocks = 1;
  30105. }
  30106. - if (brq->data.blocks > 1 || do_rel_wr) {
  30107. + if (brq->data.blocks > 1 || do_rel_wr || card->host->caps2 & MMC_CAP2_FORCE_MULTIBLOCK) {
  30108. /* SPI multiblock writes terminate using a special
  30109. * token, not a STOP_TRANSMISSION request.
  30110. */
  30111. diff -Nur linux-3.15/drivers/mmc/core/sd.c linux-rpi/drivers/mmc/core/sd.c
  30112. --- linux-3.15/drivers/mmc/core/sd.c 2014-06-08 20:19:54.000000000 +0200
  30113. +++ linux-rpi/drivers/mmc/core/sd.c 2014-06-11 21:05:20.000000000 +0200
  30114. @@ -15,6 +15,8 @@
  30115. #include <linux/slab.h>
  30116. #include <linux/stat.h>
  30117. #include <linux/pm_runtime.h>
  30118. +#include <linux/jiffies.h>
  30119. +#include <linux/nmi.h>
  30120. #include <linux/mmc/host.h>
  30121. #include <linux/mmc/card.h>
  30122. @@ -67,6 +69,15 @@
  30123. __res & __mask; \
  30124. })
  30125. +// timeout for tries
  30126. +static const unsigned long retry_timeout_ms= 10*1000;
  30127. +
  30128. +// try at least 10 times, even if timeout is reached
  30129. +static const int retry_min_tries= 10;
  30130. +
  30131. +// delay between tries
  30132. +static const unsigned long retry_delay_ms= 10;
  30133. +
  30134. /*
  30135. * Given the decoded CSD structure, decode the raw CID to our CID structure.
  30136. */
  30137. @@ -219,12 +230,63 @@
  30138. }
  30139. /*
  30140. - * Fetch and process SD Status register.
  30141. + * Fetch and process SD Configuration Register.
  30142. + */
  30143. +static int mmc_read_scr(struct mmc_card *card)
  30144. +{
  30145. + unsigned long timeout_at;
  30146. + int err, tries;
  30147. +
  30148. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30149. + tries= 0;
  30150. +
  30151. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30152. + {
  30153. + unsigned long delay_at;
  30154. + tries++;
  30155. +
  30156. + err = mmc_app_send_scr(card, card->raw_scr);
  30157. + if( !err )
  30158. + break; // success!!!
  30159. +
  30160. + touch_nmi_watchdog(); // we are still alive!
  30161. +
  30162. + // delay
  30163. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30164. + while( time_before( jiffies, delay_at ) )
  30165. + {
  30166. + mdelay( 1 );
  30167. + touch_nmi_watchdog(); // we are still alive!
  30168. + }
  30169. + }
  30170. +
  30171. + if( err)
  30172. + {
  30173. + pr_err("%s: failed to read SD Configuration register (SCR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  30174. + return err;
  30175. + }
  30176. +
  30177. + if( tries > 1 )
  30178. + {
  30179. + pr_info("%s: could read SD Configuration register (SCR) at the %dth attempt\n", mmc_hostname(card->host), tries );
  30180. + }
  30181. +
  30182. + err = mmc_decode_scr(card);
  30183. + if (err)
  30184. + return err;
  30185. +
  30186. + return err;
  30187. +}
  30188. +
  30189. +/*
  30190. + * Fetch and process SD Status Register.
  30191. */
  30192. static int mmc_read_ssr(struct mmc_card *card)
  30193. {
  30194. + unsigned long timeout_at;
  30195. unsigned int au, es, et, eo;
  30196. int err, i;
  30197. + int tries;
  30198. u32 *ssr;
  30199. if (!(card->csd.cmdclass & CCC_APP_SPEC)) {
  30200. @@ -237,14 +299,40 @@
  30201. if (!ssr)
  30202. return -ENOMEM;
  30203. - err = mmc_app_sd_status(card, ssr);
  30204. - if (err) {
  30205. - pr_warning("%s: problem reading SD Status "
  30206. - "register.\n", mmc_hostname(card->host));
  30207. - err = 0;
  30208. + timeout_at= jiffies + msecs_to_jiffies( retry_timeout_ms );
  30209. + tries= 0;
  30210. +
  30211. + while( tries < retry_min_tries || time_before( jiffies, timeout_at ) )
  30212. + {
  30213. + unsigned long delay_at;
  30214. + tries++;
  30215. +
  30216. + err= mmc_app_sd_status(card, ssr);
  30217. + if( !err )
  30218. + break; // sucess!!!
  30219. +
  30220. + touch_nmi_watchdog(); // we are still alive!
  30221. +
  30222. + // delay
  30223. + delay_at= jiffies + msecs_to_jiffies( retry_delay_ms );
  30224. + while( time_before( jiffies, delay_at ) )
  30225. + {
  30226. + mdelay( 1 );
  30227. + touch_nmi_watchdog(); // we are still alive!
  30228. + }
  30229. + }
  30230. +
  30231. + if( err)
  30232. + {
  30233. + pr_err("%s: failed to read SD Status register (SSR) after %d tries during %lu ms, error %d\n", mmc_hostname(card->host), tries, retry_timeout_ms, err );
  30234. goto out;
  30235. }
  30236. + if( tries > 1 )
  30237. + {
  30238. + pr_info("%s: read SD Status register (SSR) after %d attempts\n", mmc_hostname(card->host), tries );
  30239. + }
  30240. +
  30241. for (i = 0; i < 16; i++)
  30242. ssr[i] = be32_to_cpu(ssr[i]);
  30243. @@ -826,14 +914,10 @@
  30244. if (!reinit) {
  30245. /*
  30246. - * Fetch SCR from card.
  30247. + * Fetch and decode SD Configuration register.
  30248. */
  30249. - err = mmc_app_send_scr(card, card->raw_scr);
  30250. - if (err)
  30251. - return err;
  30252. -
  30253. - err = mmc_decode_scr(card);
  30254. - if (err)
  30255. + err = mmc_read_scr(card);
  30256. + if( err )
  30257. return err;
  30258. /*
  30259. diff -Nur linux-3.15/drivers/mmc/host/Kconfig linux-rpi/drivers/mmc/host/Kconfig
  30260. --- linux-3.15/drivers/mmc/host/Kconfig 2014-06-08 20:19:54.000000000 +0200
  30261. +++ linux-rpi/drivers/mmc/host/Kconfig 2014-06-11 21:05:20.000000000 +0200
  30262. @@ -272,6 +272,27 @@
  30263. If you have a controller with this interface, say Y or M here.
  30264. +config MMC_SDHCI_BCM2708
  30265. + tristate "SDHCI support on BCM2708"
  30266. + depends on MMC_SDHCI && MACH_BCM2708
  30267. + select MMC_SDHCI_IO_ACCESSORS
  30268. + help
  30269. + This selects the Secure Digital Host Controller Interface (SDHCI)
  30270. + often referrered to as the eMMC block.
  30271. +
  30272. + If you have a controller with this interface, say Y or M here.
  30273. +
  30274. + If unsure, say N.
  30275. +
  30276. +config MMC_SDHCI_BCM2708_DMA
  30277. + bool "DMA support on BCM2708 Arasan controller"
  30278. + depends on MMC_SDHCI_BCM2708
  30279. + help
  30280. + Enable DMA support on the Arasan SDHCI controller in Broadcom 2708
  30281. + based chips.
  30282. +
  30283. + If unsure, say N.
  30284. +
  30285. config MMC_SDHCI_BCM2835
  30286. tristate "SDHCI platform support for the BCM2835 SD/MMC Controller"
  30287. depends on ARCH_BCM2835
  30288. diff -Nur linux-3.15/drivers/mmc/host/Makefile linux-rpi/drivers/mmc/host/Makefile
  30289. --- linux-3.15/drivers/mmc/host/Makefile 2014-06-08 20:19:54.000000000 +0200
  30290. +++ linux-rpi/drivers/mmc/host/Makefile 2014-06-11 21:05:20.000000000 +0200
  30291. @@ -16,6 +16,7 @@
  30292. obj-$(CONFIG_MMC_SDHCI_S3C) += sdhci-s3c.o
  30293. obj-$(CONFIG_MMC_SDHCI_SIRF) += sdhci-sirf.o
  30294. obj-$(CONFIG_MMC_SDHCI_SPEAR) += sdhci-spear.o
  30295. +obj-$(CONFIG_MMC_SDHCI_BCM2708) += sdhci-bcm2708.o
  30296. obj-$(CONFIG_MMC_WBSD) += wbsd.o
  30297. obj-$(CONFIG_MMC_AU1X) += au1xmmc.o
  30298. obj-$(CONFIG_MMC_OMAP) += omap.o
  30299. diff -Nur linux-3.15/drivers/mmc/host/sdhci-bcm2708.c linux-rpi/drivers/mmc/host/sdhci-bcm2708.c
  30300. --- linux-3.15/drivers/mmc/host/sdhci-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  30301. +++ linux-rpi/drivers/mmc/host/sdhci-bcm2708.c 2014-06-11 21:03:34.000000000 +0200
  30302. @@ -0,0 +1,1410 @@
  30303. +/*
  30304. + * sdhci-bcm2708.c Support for SDHCI device on BCM2708
  30305. + * Copyright (c) 2010 Broadcom
  30306. + *
  30307. + * This program is free software; you can redistribute it and/or modify
  30308. + * it under the terms of the GNU General Public License version 2 as
  30309. + * published by the Free Software Foundation.
  30310. + *
  30311. + * This program is distributed in the hope that it will be useful,
  30312. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30313. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30314. + * GNU General Public License for more details.
  30315. + *
  30316. + * You should have received a copy of the GNU General Public License
  30317. + * along with this program; if not, write to the Free Software
  30318. + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  30319. + */
  30320. +
  30321. +/* Supports:
  30322. + * SDHCI platform device - Arasan SD controller in BCM2708
  30323. + *
  30324. + * Inspired by sdhci-pci.c, by Pierre Ossman
  30325. + */
  30326. +
  30327. +#include <linux/delay.h>
  30328. +#include <linux/highmem.h>
  30329. +#include <linux/platform_device.h>
  30330. +#include <linux/module.h>
  30331. +#include <linux/mmc/mmc.h>
  30332. +#include <linux/mmc/host.h>
  30333. +#include <linux/mmc/sd.h>
  30334. +
  30335. +#include <linux/io.h>
  30336. +#include <linux/dma-mapping.h>
  30337. +#include <mach/dma.h>
  30338. +
  30339. +#include "sdhci.h"
  30340. +
  30341. +/*****************************************************************************\
  30342. + * *
  30343. + * Configuration *
  30344. + * *
  30345. +\*****************************************************************************/
  30346. +
  30347. +#define DRIVER_NAME "bcm2708_sdhci"
  30348. +
  30349. +/* for the time being insist on DMA mode - PIO seems not to work */
  30350. +#ifndef CONFIG_MMC_SDHCI_BCM2708_DMA
  30351. +#warning Non-DMA (PIO) version of this driver currently unavailable
  30352. +#endif
  30353. +#undef CONFIG_MMC_SDHCI_BCM2708_DMA
  30354. +#define CONFIG_MMC_SDHCI_BCM2708_DMA y
  30355. +
  30356. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30357. +/* #define CHECK_DMA_USE */
  30358. +#endif
  30359. +//#define LOG_REGISTERS
  30360. +
  30361. +#define USE_SCHED_TIME
  30362. +#define USE_SPACED_WRITES_2CLK 1 /* space consecutive register writes */
  30363. +#define USE_SOFTWARE_TIMEOUTS 1 /* not hardware timeouts */
  30364. +#define SOFTWARE_ERASE_TIMEOUT_SEC 30
  30365. +
  30366. +#define SDHCI_BCM_DMA_CHAN 4 /* this default is normally overriden */
  30367. +#define SDHCI_BCM_DMA_WAITS 0 /* delays slowing DMA transfers: 0-31 */
  30368. +/* We are worried that SD card DMA use may be blocking the AXI bus for others */
  30369. +
  30370. +/*! TODO: obtain these from the physical address */
  30371. +#define DMA_SDHCI_BASE 0x7e300000 /* EMMC register block on Videocore */
  30372. +#define DMA_SDHCI_BUFFER (DMA_SDHCI_BASE + SDHCI_BUFFER)
  30373. +
  30374. +#define BCM2708_SDHCI_SLEEP_TIMEOUT 1000 /* msecs */
  30375. +
  30376. +/* Mhz clock that the EMMC core is running at. Should match the platform clockman settings */
  30377. +#define BCM2708_EMMC_CLOCK_FREQ 50000000
  30378. +
  30379. +#define REG_EXRDFIFO_EN 0x80
  30380. +#define REG_EXRDFIFO_CFG 0x84
  30381. +
  30382. +int cycle_delay=2;
  30383. +
  30384. +/*****************************************************************************\
  30385. + * *
  30386. + * Debug *
  30387. + * *
  30388. +\*****************************************************************************/
  30389. +
  30390. +
  30391. +
  30392. +#define DBG(f, x...) \
  30393. + pr_debug(DRIVER_NAME " [%s()]: " f, __func__,## x)
  30394. +// printk(KERN_INFO DRIVER_NAME " [%s()]: " f, __func__,## x)//GRAYG
  30395. +
  30396. +
  30397. +/*****************************************************************************\
  30398. + * *
  30399. + * High Precision Time *
  30400. + * *
  30401. +\*****************************************************************************/
  30402. +
  30403. +#ifdef USE_SCHED_TIME
  30404. +
  30405. +#include <mach/frc.h>
  30406. +
  30407. +typedef unsigned long hptime_t;
  30408. +
  30409. +#define FMT_HPT "lu"
  30410. +
  30411. +static inline hptime_t hptime(void)
  30412. +{
  30413. + return frc_clock_ticks32();
  30414. +}
  30415. +
  30416. +#define HPTIME_CLK_NS 1000ul
  30417. +
  30418. +#else
  30419. +
  30420. +typedef unsigned long hptime_t;
  30421. +
  30422. +#define FMT_HPT "lu"
  30423. +
  30424. +static inline hptime_t hptime(void)
  30425. +{
  30426. + return jiffies;
  30427. +}
  30428. +
  30429. +#define HPTIME_CLK_NS (1000000000ul/HZ)
  30430. +
  30431. +#endif
  30432. +
  30433. +static inline unsigned long int since_ns(hptime_t t)
  30434. +{
  30435. + return (unsigned long)((hptime() - t) * HPTIME_CLK_NS);
  30436. +}
  30437. +
  30438. +static bool allow_highspeed = 1;
  30439. +static int emmc_clock_freq = BCM2708_EMMC_CLOCK_FREQ;
  30440. +static bool sync_after_dma = 1;
  30441. +static bool missing_status = 1;
  30442. +static bool spurious_crc_acmd51 = 0;
  30443. +bool enable_llm = 1;
  30444. +bool extra_messages = 0;
  30445. +
  30446. +#if 0
  30447. +static void hptime_test(void)
  30448. +{
  30449. + hptime_t now;
  30450. + hptime_t later;
  30451. +
  30452. + now = hptime();
  30453. + msleep(10);
  30454. + later = hptime();
  30455. +
  30456. + printk(KERN_INFO DRIVER_NAME": 10ms = %"FMT_HPT" clks "
  30457. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30458. + later-now, now, later,
  30459. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30460. +
  30461. + now = hptime();
  30462. + msleep(1000);
  30463. + later = hptime();
  30464. +
  30465. + printk(KERN_INFO DRIVER_NAME": 1s = %"FMT_HPT" clks "
  30466. + "(from %"FMT_HPT" to %"FMT_HPT") = %luns\n",
  30467. + later-now, now, later,
  30468. + (unsigned long)(HPTIME_CLK_NS * (later - now)));
  30469. +}
  30470. +#endif
  30471. +
  30472. +/*****************************************************************************\
  30473. + * *
  30474. + * SDHCI core callbacks *
  30475. + * *
  30476. +\*****************************************************************************/
  30477. +
  30478. +
  30479. +#ifdef CHECK_DMA_USE
  30480. +/*#define CHECK_DMA_REG_USE*/
  30481. +#endif
  30482. +
  30483. +#ifdef CHECK_DMA_REG_USE
  30484. +/* we don't expect anything to be using these registers during a
  30485. + DMA (except the IRQ status) - so check */
  30486. +static void check_dma_reg_use(struct sdhci_host *host, int reg);
  30487. +#else
  30488. +#define check_dma_reg_use(host, reg)
  30489. +#endif
  30490. +
  30491. +
  30492. +static inline u32 sdhci_bcm2708_raw_readl(struct sdhci_host *host, int reg)
  30493. +{
  30494. + return readl(host->ioaddr + reg);
  30495. +}
  30496. +
  30497. +u32 sdhci_bcm2708_readl(struct sdhci_host *host, int reg)
  30498. +{
  30499. + u32 l = sdhci_bcm2708_raw_readl(host, reg);
  30500. +
  30501. +#ifdef LOG_REGISTERS
  30502. + printk(KERN_ERR "%s: readl from 0x%02x, value 0x%08x\n",
  30503. + mmc_hostname(host->mmc), reg, l);
  30504. +#endif
  30505. + check_dma_reg_use(host, reg);
  30506. +
  30507. + return l;
  30508. +}
  30509. +
  30510. +u16 sdhci_bcm2708_readw(struct sdhci_host *host, int reg)
  30511. +{
  30512. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30513. + u32 w = l >> (reg << 3 & 0x18) & 0xffff;
  30514. +
  30515. +#ifdef LOG_REGISTERS
  30516. + printk(KERN_ERR "%s: readw from 0x%02x, value 0x%04x\n",
  30517. + mmc_hostname(host->mmc), reg, w);
  30518. +#endif
  30519. + check_dma_reg_use(host, reg);
  30520. +
  30521. + return (u16)w;
  30522. +}
  30523. +
  30524. +u8 sdhci_bcm2708_readb(struct sdhci_host *host, int reg)
  30525. +{
  30526. + u32 l = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30527. + u32 b = l >> (reg << 3 & 0x18) & 0xff;
  30528. +
  30529. +#ifdef LOG_REGISTERS
  30530. + printk(KERN_ERR "%s: readb from 0x%02x, value 0x%02x\n",
  30531. + mmc_hostname(host->mmc), reg, b);
  30532. +#endif
  30533. + check_dma_reg_use(host, reg);
  30534. +
  30535. + return (u8)b;
  30536. +}
  30537. +
  30538. +
  30539. +static void sdhci_bcm2708_raw_writel(struct sdhci_host *host, u32 val, int reg)
  30540. +{
  30541. + u32 ier;
  30542. +
  30543. +#if USE_SPACED_WRITES_2CLK
  30544. + static bool timeout_disabled = false;
  30545. + unsigned int ns_2clk = 0;
  30546. +
  30547. + /* The Arasan has a bugette whereby it may lose the content of
  30548. + * successive writes to registers that are within two SD-card clock
  30549. + * cycles of each other (a clock domain crossing problem).
  30550. + * It seems, however, that the data register does not have this problem.
  30551. + * (Which is just as well - otherwise we'd have to nobble the DMA engine
  30552. + * too)
  30553. + */
  30554. + if (reg != SDHCI_BUFFER && host->clock != 0) {
  30555. + /* host->clock is the clock freq in Hz */
  30556. + static hptime_t last_write_hpt;
  30557. + hptime_t now = hptime();
  30558. + ns_2clk = cycle_delay*1000000/(host->clock/1000);
  30559. +
  30560. + if (now == last_write_hpt || now == last_write_hpt+1) {
  30561. + /* we can't guarantee any significant time has
  30562. + * passed - we'll have to wait anyway ! */
  30563. + ndelay(ns_2clk);
  30564. + } else
  30565. + {
  30566. + /* we must have waited at least this many ns: */
  30567. + unsigned int ns_wait = HPTIME_CLK_NS *
  30568. + (now - last_write_hpt - 1);
  30569. + if (ns_wait < ns_2clk)
  30570. + ndelay(ns_2clk - ns_wait);
  30571. + }
  30572. + last_write_hpt = now;
  30573. + }
  30574. +#if USE_SOFTWARE_TIMEOUTS
  30575. + /* The Arasan is clocked for timeouts using the SD clock which is too
  30576. + * fast for ERASE commands and causes issues. So we disable timeouts
  30577. + * for ERASE */
  30578. + if (host->cmd != NULL && host->cmd->opcode == MMC_ERASE &&
  30579. + reg == (SDHCI_COMMAND & ~3)) {
  30580. + mod_timer(&host->timer,
  30581. + jiffies + SOFTWARE_ERASE_TIMEOUT_SEC * HZ);
  30582. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30583. + ier &= ~SDHCI_INT_DATA_TIMEOUT;
  30584. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30585. + timeout_disabled = true;
  30586. + ndelay(ns_2clk);
  30587. + } else if (timeout_disabled) {
  30588. + ier = readl(host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30589. + ier |= SDHCI_INT_DATA_TIMEOUT;
  30590. + writel(ier, host->ioaddr + SDHCI_SIGNAL_ENABLE);
  30591. + timeout_disabled = false;
  30592. + ndelay(ns_2clk);
  30593. + }
  30594. +#endif
  30595. + writel(val, host->ioaddr + reg);
  30596. +#else
  30597. + void __iomem * regaddr = host->ioaddr + reg;
  30598. +
  30599. + writel(val, regaddr);
  30600. +
  30601. + if (reg != SDHCI_BUFFER && reg != SDHCI_INT_STATUS && host->clock != 0)
  30602. + {
  30603. + int timeout = 100000;
  30604. + while (val != readl(regaddr) && --timeout > 0)
  30605. + continue;
  30606. +
  30607. + if (timeout <= 0)
  30608. + printk(KERN_ERR "%s: writing 0x%X to reg 0x%X "
  30609. + "always gives 0x%X\n",
  30610. + mmc_hostname(host->mmc),
  30611. + val, reg, readl(regaddr));
  30612. + BUG_ON(timeout <= 0);
  30613. + }
  30614. +#endif
  30615. +}
  30616. +
  30617. +
  30618. +void sdhci_bcm2708_writel(struct sdhci_host *host, u32 val, int reg)
  30619. +{
  30620. +#ifdef LOG_REGISTERS
  30621. + printk(KERN_ERR "%s: writel to 0x%02x, value 0x%08x\n",
  30622. + mmc_hostname(host->mmc), reg, val);
  30623. +#endif
  30624. + check_dma_reg_use(host, reg);
  30625. +
  30626. + sdhci_bcm2708_raw_writel(host, val, reg);
  30627. +}
  30628. +
  30629. +void sdhci_bcm2708_writew(struct sdhci_host *host, u16 val, int reg)
  30630. +{
  30631. + static u32 shadow = 0;
  30632. +
  30633. + u32 p = reg == SDHCI_COMMAND ? shadow :
  30634. + sdhci_bcm2708_raw_readl(host, reg & ~3);
  30635. + u32 s = reg << 3 & 0x18;
  30636. + u32 l = val << s;
  30637. + u32 m = 0xffff << s;
  30638. +
  30639. +#ifdef LOG_REGISTERS
  30640. + printk(KERN_ERR "%s: writew to 0x%02x, value 0x%04x\n",
  30641. + mmc_hostname(host->mmc), reg, val);
  30642. +#endif
  30643. +
  30644. + if (reg == SDHCI_TRANSFER_MODE)
  30645. + shadow = (p & ~m) | l;
  30646. + else {
  30647. + check_dma_reg_use(host, reg);
  30648. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  30649. + }
  30650. +}
  30651. +
  30652. +void sdhci_bcm2708_writeb(struct sdhci_host *host, u8 val, int reg)
  30653. +{
  30654. + u32 p = sdhci_bcm2708_raw_readl(host, reg & ~3);
  30655. + u32 s = reg << 3 & 0x18;
  30656. + u32 l = val << s;
  30657. + u32 m = 0xff << s;
  30658. +
  30659. +#ifdef LOG_REGISTERS
  30660. + printk(KERN_ERR "%s: writeb to 0x%02x, value 0x%02x\n",
  30661. + mmc_hostname(host->mmc), reg, val);
  30662. +#endif
  30663. +
  30664. + check_dma_reg_use(host, reg);
  30665. + sdhci_bcm2708_raw_writel(host, (p & ~m) | l, reg & ~3);
  30666. +}
  30667. +
  30668. +static unsigned int sdhci_bcm2708_get_max_clock(struct sdhci_host *host)
  30669. +{
  30670. + return emmc_clock_freq;
  30671. +}
  30672. +
  30673. +/*****************************************************************************\
  30674. + * *
  30675. + * DMA Operation *
  30676. + * *
  30677. +\*****************************************************************************/
  30678. +
  30679. +struct sdhci_bcm2708_priv {
  30680. + int dma_chan;
  30681. + int dma_irq;
  30682. + void __iomem *dma_chan_base;
  30683. + struct bcm2708_dma_cb *cb_base; /* DMA control blocks */
  30684. + dma_addr_t cb_handle;
  30685. + /* tracking scatter gather progress */
  30686. + unsigned sg_ix; /* scatter gather list index */
  30687. + unsigned sg_done; /* bytes in current sg_ix done */
  30688. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30689. + unsigned char dma_wanted; /* DMA transfer requested */
  30690. + unsigned char dma_waits; /* wait states in DMAs */
  30691. +#ifdef CHECK_DMA_USE
  30692. + unsigned char dmas_pending; /* no of unfinished DMAs */
  30693. + hptime_t when_started;
  30694. + hptime_t when_reset;
  30695. + hptime_t when_stopped;
  30696. +#endif
  30697. +#endif
  30698. + /* signalling the end of a transfer */
  30699. + void (*complete)(struct sdhci_host *);
  30700. +};
  30701. +
  30702. +#define SDHCI_HOST_PRIV(host) \
  30703. + (struct sdhci_bcm2708_priv *)((struct sdhci_host *)(host)+1)
  30704. +
  30705. +
  30706. +
  30707. +#ifdef CHECK_DMA_REG_USE
  30708. +static void check_dma_reg_use(struct sdhci_host *host, int reg)
  30709. +{
  30710. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30711. + if (host_priv->dma_wanted && reg != SDHCI_INT_STATUS) {
  30712. + printk(KERN_INFO"%s: accessing register 0x%x during DMA\n",
  30713. + mmc_hostname(host->mmc), reg);
  30714. + }
  30715. +}
  30716. +#endif
  30717. +
  30718. +
  30719. +
  30720. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  30721. +
  30722. +static void sdhci_clear_set_irqgen(struct sdhci_host *host, u32 clear, u32 set)
  30723. +{
  30724. + u32 ier;
  30725. +
  30726. + ier = sdhci_bcm2708_raw_readl(host, SDHCI_SIGNAL_ENABLE);
  30727. + ier &= ~clear;
  30728. + ier |= set;
  30729. + /* change which requests generate IRQs - makes no difference to
  30730. + the content of SDHCI_INT_STATUS, or the need to acknowledge IRQs */
  30731. + sdhci_bcm2708_raw_writel(host, ier, SDHCI_SIGNAL_ENABLE);
  30732. +}
  30733. +
  30734. +static void sdhci_signal_irqs(struct sdhci_host *host, u32 irqs)
  30735. +{
  30736. + sdhci_clear_set_irqgen(host, 0, irqs);
  30737. +}
  30738. +
  30739. +static void sdhci_unsignal_irqs(struct sdhci_host *host, u32 irqs)
  30740. +{
  30741. + sdhci_clear_set_irqgen(host, irqs, 0);
  30742. +}
  30743. +
  30744. +
  30745. +
  30746. +static void schci_bcm2708_cb_read(struct sdhci_bcm2708_priv *host,
  30747. + int ix,
  30748. + dma_addr_t dma_addr, unsigned len,
  30749. + int /*bool*/ is_last)
  30750. +{
  30751. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30752. + unsigned char dmawaits = host->dma_waits;
  30753. +
  30754. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30755. + BCM2708_DMA_WAITS(dmawaits) |
  30756. + BCM2708_DMA_S_DREQ |
  30757. + BCM2708_DMA_D_WIDTH |
  30758. + BCM2708_DMA_D_INC;
  30759. + cb->src = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30760. + cb->dst = dma_addr;
  30761. + cb->length = len;
  30762. + cb->stride = 0;
  30763. +
  30764. + if (is_last) {
  30765. + cb->info |= BCM2708_DMA_INT_EN |
  30766. + BCM2708_DMA_WAIT_RESP;
  30767. + cb->next = 0;
  30768. + } else
  30769. + cb->next = host->cb_handle +
  30770. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30771. +
  30772. + cb->pad[0] = 0;
  30773. + cb->pad[1] = 0;
  30774. +}
  30775. +
  30776. +static void schci_bcm2708_cb_write(struct sdhci_bcm2708_priv *host,
  30777. + int ix,
  30778. + dma_addr_t dma_addr, unsigned len,
  30779. + int /*bool*/ is_last)
  30780. +{
  30781. + struct bcm2708_dma_cb *cb = &host->cb_base[ix];
  30782. + unsigned char dmawaits = host->dma_waits;
  30783. +
  30784. + /* We can make arbitrarily large writes as long as we specify DREQ to
  30785. + pace the delivery of bytes to the Arasan hardware */
  30786. + cb->info = BCM2708_DMA_PER_MAP(BCM2708_DMA_DREQ_EMMC) |
  30787. + BCM2708_DMA_WAITS(dmawaits) |
  30788. + BCM2708_DMA_D_DREQ |
  30789. + BCM2708_DMA_S_WIDTH |
  30790. + BCM2708_DMA_S_INC;
  30791. + cb->src = dma_addr;
  30792. + cb->dst = DMA_SDHCI_BUFFER; /* DATA register DMA address */
  30793. + cb->length = len;
  30794. + cb->stride = 0;
  30795. +
  30796. + if (is_last) {
  30797. + cb->info |= BCM2708_DMA_INT_EN |
  30798. + BCM2708_DMA_WAIT_RESP;
  30799. + cb->next = 0;
  30800. + } else
  30801. + cb->next = host->cb_handle +
  30802. + (ix+1)*sizeof(struct bcm2708_dma_cb);
  30803. +
  30804. + cb->pad[0] = 0;
  30805. + cb->pad[1] = 0;
  30806. +}
  30807. +
  30808. +
  30809. +static void schci_bcm2708_dma_go(struct sdhci_host *host)
  30810. +{
  30811. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30812. + void __iomem *dma_chan_base = host_priv->dma_chan_base;
  30813. +
  30814. + BUG_ON(host_priv->dma_wanted);
  30815. +#ifdef CHECK_DMA_USE
  30816. + if (host_priv->dma_wanted)
  30817. + printk(KERN_ERR "%s: DMA already in progress - "
  30818. + "now %"FMT_HPT", last started %lu "
  30819. + "reset %lu stopped %lu\n",
  30820. + mmc_hostname(host->mmc),
  30821. + hptime(), since_ns(host_priv->when_started),
  30822. + since_ns(host_priv->when_reset),
  30823. + since_ns(host_priv->when_stopped));
  30824. + else if (host_priv->dmas_pending > 0)
  30825. + printk(KERN_INFO "%s: note - new DMA when %d reset DMAs "
  30826. + "already in progress - "
  30827. + "now %"FMT_HPT", started %lu reset %lu stopped %lu\n",
  30828. + mmc_hostname(host->mmc),
  30829. + host_priv->dmas_pending,
  30830. + hptime(), since_ns(host_priv->when_started),
  30831. + since_ns(host_priv->when_reset),
  30832. + since_ns(host_priv->when_stopped));
  30833. + host_priv->dmas_pending += 1;
  30834. + host_priv->when_started = hptime();
  30835. +#endif
  30836. + host_priv->dma_wanted = 1;
  30837. + DBG("PDMA go - base %p handle %08X\n", dma_chan_base,
  30838. + host_priv->cb_handle);
  30839. + bcm_dma_start(dma_chan_base, host_priv->cb_handle);
  30840. +}
  30841. +
  30842. +
  30843. +static void
  30844. +sdhci_platdma_read(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30845. +{
  30846. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30847. +
  30848. + DBG("PDMA to read %d bytes\n", len);
  30849. + host_priv->sg_done += len;
  30850. + schci_bcm2708_cb_read(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30851. + schci_bcm2708_dma_go(host);
  30852. +}
  30853. +
  30854. +
  30855. +static void
  30856. +sdhci_platdma_write(struct sdhci_host *host, dma_addr_t dma_addr, size_t len)
  30857. +{
  30858. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30859. +
  30860. + DBG("PDMA to write %d bytes\n", len);
  30861. + //BUG_ON(0 != (len & 0x1ff));
  30862. +
  30863. + host_priv->sg_done += len;
  30864. + schci_bcm2708_cb_write(host_priv, 0, dma_addr, len, 1/*TRUE*/);
  30865. + schci_bcm2708_dma_go(host);
  30866. +}
  30867. +
  30868. +/*! space is avaiable to receive into or data is available to write
  30869. + Platform DMA exported function
  30870. +*/
  30871. +void
  30872. +sdhci_bcm2708_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  30873. + void(*completion_callback)(struct sdhci_host *host))
  30874. +{
  30875. + struct mmc_data *data = host->data;
  30876. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30877. + int sg_ix;
  30878. + size_t bytes;
  30879. + dma_addr_t addr;
  30880. +
  30881. + BUG_ON(NULL == data);
  30882. + BUG_ON(0 == data->blksz);
  30883. +
  30884. + host_priv->complete = completion_callback;
  30885. +
  30886. + sg_ix = host_priv->sg_ix;
  30887. + BUG_ON(sg_ix >= data->sg_len);
  30888. +
  30889. + /* we can DMA blocks larger than blksz - it may hang the DMA
  30890. + channel but we are its only user */
  30891. + bytes = sg_dma_len(&data->sg[sg_ix]) - host_priv->sg_done;
  30892. + addr = sg_dma_address(&data->sg[sg_ix]) + host_priv->sg_done;
  30893. +
  30894. + if (bytes > 0) {
  30895. + /* We're going to poll for read/write available state until
  30896. + we finish this DMA
  30897. + */
  30898. +
  30899. + if (data->flags & MMC_DATA_READ) {
  30900. + if (*ref_intmask & SDHCI_INT_DATA_AVAIL) {
  30901. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30902. + SDHCI_INT_SPACE_AVAIL);
  30903. + sdhci_platdma_read(host, addr, bytes);
  30904. + }
  30905. + } else {
  30906. + if (*ref_intmask & SDHCI_INT_SPACE_AVAIL) {
  30907. + sdhci_unsignal_irqs(host, SDHCI_INT_DATA_AVAIL |
  30908. + SDHCI_INT_SPACE_AVAIL);
  30909. + sdhci_platdma_write(host, addr, bytes);
  30910. + }
  30911. + }
  30912. + }
  30913. + /* else:
  30914. + we have run out of bytes that need transferring (e.g. we may be in
  30915. + the middle of the last DMA transfer), or
  30916. + it is also possible that we've been called when another IRQ is
  30917. + signalled, even though we've turned off signalling of our own IRQ */
  30918. +
  30919. + *ref_intmask &= ~SDHCI_INT_DATA_END;
  30920. + /* don't let the main sdhci driver act on this .. we'll deal with it
  30921. + when we respond to the DMA - if one is currently in progress */
  30922. +}
  30923. +
  30924. +/* is it possible to DMA the given mmc_data structure?
  30925. + Platform DMA exported function
  30926. +*/
  30927. +int /*bool*/
  30928. +sdhci_bcm2708_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  30929. +{
  30930. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30931. + int ok = bcm_sg_suitable_for_dma(data->sg, data->sg_len);
  30932. +
  30933. + if (!ok)
  30934. + DBG("Reverting to PIO - bad cache alignment\n");
  30935. +
  30936. + else {
  30937. + host_priv->sg_ix = 0; /* first SG index */
  30938. + host_priv->sg_done = 0; /* no bytes done */
  30939. + }
  30940. +
  30941. + return ok;
  30942. +}
  30943. +
  30944. +#include <mach/arm_control.h> //GRAYG
  30945. +/*! the current SD transacton has been abandonned
  30946. + We need to tidy up if we were in the middle of a DMA
  30947. + Platform DMA exported function
  30948. +*/
  30949. +void
  30950. +sdhci_bcm2708_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  30951. +{
  30952. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  30953. +// unsigned long flags;
  30954. +
  30955. + BUG_ON(NULL == host);
  30956. +
  30957. +// spin_lock_irqsave(&host->lock, flags);
  30958. +
  30959. + if (host_priv->dma_wanted) {
  30960. + if (NULL == data) {
  30961. + printk(KERN_ERR "%s: ongoing DMA reset - no data!\n",
  30962. + mmc_hostname(host->mmc));
  30963. + BUG_ON(NULL == data);
  30964. + } else {
  30965. + struct scatterlist *sg;
  30966. + int sg_len;
  30967. + int sg_todo;
  30968. + int rc;
  30969. + unsigned long cs;
  30970. +
  30971. + sg = data->sg;
  30972. + sg_len = data->sg_len;
  30973. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  30974. +
  30975. + cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  30976. +
  30977. + if (!(BCM2708_DMA_ACTIVE & cs))
  30978. + {
  30979. + if (extra_messages)
  30980. + printk(KERN_INFO "%s: missed completion of "
  30981. + "cmd %d DMA (%d/%d [%d]/[%d]) - "
  30982. + "ignoring it\n",
  30983. + mmc_hostname(host->mmc),
  30984. + host->last_cmdop,
  30985. + host_priv->sg_done, sg_todo,
  30986. + host_priv->sg_ix+1, sg_len);
  30987. + }
  30988. + else
  30989. + printk(KERN_INFO "%s: resetting ongoing cmd %d"
  30990. + "DMA before %d/%d [%d]/[%d] complete\n",
  30991. + mmc_hostname(host->mmc),
  30992. + host->last_cmdop,
  30993. + host_priv->sg_done, sg_todo,
  30994. + host_priv->sg_ix+1, sg_len);
  30995. +#ifdef CHECK_DMA_USE
  30996. + printk(KERN_INFO "%s: now %"FMT_HPT" started %lu "
  30997. + "last reset %lu last stopped %lu\n",
  30998. + mmc_hostname(host->mmc),
  30999. + hptime(), since_ns(host_priv->when_started),
  31000. + since_ns(host_priv->when_reset),
  31001. + since_ns(host_priv->when_stopped));
  31002. + { unsigned long info, debug;
  31003. + void __iomem *base;
  31004. + unsigned long pend0, pend1, pend2;
  31005. +
  31006. + base = host_priv->dma_chan_base;
  31007. + cs = readl(base + BCM2708_DMA_CS);
  31008. + info = readl(base + BCM2708_DMA_INFO);
  31009. + debug = readl(base + BCM2708_DMA_DEBUG);
  31010. + printk(KERN_INFO "%s: DMA%d CS=%08lX TI=%08lX "
  31011. + "DEBUG=%08lX\n",
  31012. + mmc_hostname(host->mmc),
  31013. + host_priv->dma_chan,
  31014. + cs, info, debug);
  31015. + pend0 = readl(__io_address(ARM_IRQ_PEND0));
  31016. + pend1 = readl(__io_address(ARM_IRQ_PEND1));
  31017. + pend2 = readl(__io_address(ARM_IRQ_PEND2));
  31018. +
  31019. + printk(KERN_INFO "%s: PEND0=%08lX "
  31020. + "PEND1=%08lX PEND2=%08lX\n",
  31021. + mmc_hostname(host->mmc),
  31022. + pend0, pend1, pend2);
  31023. +
  31024. + //gintsts = readl(__io_address(GINTSTS));
  31025. + //gintmsk = readl(__io_address(GINTMSK));
  31026. + //printk(KERN_INFO "%s: USB GINTSTS=%08lX"
  31027. + // "GINTMSK=%08lX\n",
  31028. + // mmc_hostname(host->mmc), gintsts, gintmsk);
  31029. + }
  31030. +#endif
  31031. + rc = bcm_dma_abort(host_priv->dma_chan_base);
  31032. + BUG_ON(rc != 0);
  31033. + }
  31034. + host_priv->dma_wanted = 0;
  31035. +#ifdef CHECK_DMA_USE
  31036. + host_priv->when_reset = hptime();
  31037. +#endif
  31038. + }
  31039. +
  31040. +// spin_unlock_irqrestore(&host->lock, flags);
  31041. +}
  31042. +
  31043. +
  31044. +static void sdhci_bcm2708_dma_complete_irq(struct sdhci_host *host,
  31045. + u32 dma_cs)
  31046. +{
  31047. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31048. + struct mmc_data *data;
  31049. + struct scatterlist *sg;
  31050. + int sg_len;
  31051. + int sg_ix;
  31052. + int sg_todo;
  31053. +// unsigned long flags;
  31054. +
  31055. + BUG_ON(NULL == host);
  31056. +
  31057. +// spin_lock_irqsave(&host->lock, flags);
  31058. + data = host->data;
  31059. +
  31060. +#ifdef CHECK_DMA_USE
  31061. + if (host_priv->dmas_pending <= 0)
  31062. + DBG("on completion no DMA in progress - "
  31063. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31064. + hptime(), since_ns(host_priv->when_started),
  31065. + since_ns(host_priv->when_reset),
  31066. + since_ns(host_priv->when_stopped));
  31067. + else if (host_priv->dmas_pending > 1)
  31068. + DBG("still %d DMA in progress after completion - "
  31069. + "now %"FMT_HPT" started %lu reset %lu stopped %lu\n",
  31070. + host_priv->dmas_pending - 1,
  31071. + hptime(), since_ns(host_priv->when_started),
  31072. + since_ns(host_priv->when_reset),
  31073. + since_ns(host_priv->when_stopped));
  31074. + BUG_ON(host_priv->dmas_pending <= 0);
  31075. + host_priv->dmas_pending -= 1;
  31076. + host_priv->when_stopped = hptime();
  31077. +#endif
  31078. + host_priv->dma_wanted = 0;
  31079. +
  31080. + if (NULL == data) {
  31081. + DBG("PDMA unused completion - status 0x%X\n", dma_cs);
  31082. +// spin_unlock_irqrestore(&host->lock, flags);
  31083. + return;
  31084. + }
  31085. + sg = data->sg;
  31086. + sg_len = data->sg_len;
  31087. + sg_todo = sg_dma_len(&sg[host_priv->sg_ix]);
  31088. +
  31089. + DBG("PDMA complete %d/%d [%d]/[%d]..\n",
  31090. + host_priv->sg_done, sg_todo,
  31091. + host_priv->sg_ix+1, sg_len);
  31092. +
  31093. + BUG_ON(host_priv->sg_done > sg_todo);
  31094. +
  31095. + if (host_priv->sg_done >= sg_todo) {
  31096. + host_priv->sg_ix++;
  31097. + host_priv->sg_done = 0;
  31098. + }
  31099. +
  31100. + sg_ix = host_priv->sg_ix;
  31101. + if (sg_ix < sg_len) {
  31102. + u32 irq_mask;
  31103. + /* Set off next DMA if we've got the capacity */
  31104. +
  31105. + if (data->flags & MMC_DATA_READ)
  31106. + irq_mask = SDHCI_INT_DATA_AVAIL;
  31107. + else
  31108. + irq_mask = SDHCI_INT_SPACE_AVAIL;
  31109. +
  31110. + /* We have to use the interrupt status register on the BCM2708
  31111. + rather than the SDHCI_PRESENT_STATE register because latency
  31112. + in the glue logic means that the information retrieved from
  31113. + the latter is not always up-to-date w.r.t the DMA engine -
  31114. + it may not indicate that a read or a write is ready yet */
  31115. + if (sdhci_bcm2708_raw_readl(host, SDHCI_INT_STATUS) &
  31116. + irq_mask) {
  31117. + size_t bytes = sg_dma_len(&sg[sg_ix]) -
  31118. + host_priv->sg_done;
  31119. + dma_addr_t addr = sg_dma_address(&data->sg[sg_ix]) +
  31120. + host_priv->sg_done;
  31121. +
  31122. + /* acknowledge interrupt */
  31123. + sdhci_bcm2708_raw_writel(host, irq_mask,
  31124. + SDHCI_INT_STATUS);
  31125. +
  31126. + BUG_ON(0 == bytes);
  31127. +
  31128. + if (data->flags & MMC_DATA_READ)
  31129. + sdhci_platdma_read(host, addr, bytes);
  31130. + else
  31131. + sdhci_platdma_write(host, addr, bytes);
  31132. + } else {
  31133. + DBG("PDMA - wait avail\n");
  31134. + /* may generate an IRQ if already present */
  31135. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31136. + SDHCI_INT_SPACE_AVAIL);
  31137. + }
  31138. + } else {
  31139. + if (sync_after_dma) {
  31140. + /* On the Arasan controller the stop command (which will be
  31141. + scheduled after this completes) does not seem to work
  31142. + properly if we allow it to be issued when we are
  31143. + transferring data to/from the SD card.
  31144. + We get CRC and DEND errors unless we wait for
  31145. + the SD controller to finish reading/writing to the card. */
  31146. + u32 state_mask;
  31147. + int timeout=3*1000*1000;
  31148. +
  31149. + DBG("PDMA over - sync card\n");
  31150. + if (data->flags & MMC_DATA_READ)
  31151. + state_mask = SDHCI_DOING_READ;
  31152. + else
  31153. + state_mask = SDHCI_DOING_WRITE;
  31154. +
  31155. + while (0 != (sdhci_bcm2708_raw_readl(host, SDHCI_PRESENT_STATE)
  31156. + & state_mask) && --timeout > 0)
  31157. + {
  31158. + udelay(1);
  31159. + continue;
  31160. + }
  31161. + if (timeout <= 0)
  31162. + printk(KERN_ERR"%s: final %s to SD card still "
  31163. + "running\n",
  31164. + mmc_hostname(host->mmc),
  31165. + data->flags & MMC_DATA_READ? "read": "write");
  31166. + }
  31167. + if (host_priv->complete) {
  31168. + (*host_priv->complete)(host);
  31169. + DBG("PDMA %s complete\n",
  31170. + data->flags & MMC_DATA_READ?"read":"write");
  31171. + sdhci_signal_irqs(host, SDHCI_INT_DATA_AVAIL |
  31172. + SDHCI_INT_SPACE_AVAIL);
  31173. + }
  31174. + }
  31175. +// spin_unlock_irqrestore(&host->lock, flags);
  31176. +}
  31177. +
  31178. +static irqreturn_t sdhci_bcm2708_dma_irq(int irq, void *dev_id)
  31179. +{
  31180. + irqreturn_t result = IRQ_NONE;
  31181. + struct sdhci_host *host = dev_id;
  31182. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31183. + u32 dma_cs; /* control and status register */
  31184. +
  31185. + BUG_ON(NULL == dev_id);
  31186. + BUG_ON(NULL == host_priv->dma_chan_base);
  31187. +
  31188. + sdhci_spin_lock(host);
  31189. +
  31190. + dma_cs = readl(host_priv->dma_chan_base + BCM2708_DMA_CS);
  31191. +
  31192. + if (dma_cs & BCM2708_DMA_ERR) {
  31193. + unsigned long debug;
  31194. + debug = readl(host_priv->dma_chan_base +
  31195. + BCM2708_DMA_DEBUG);
  31196. + printk(KERN_ERR "%s: DMA error - CS %lX DEBUG %lX\n",
  31197. + mmc_hostname(host->mmc), (unsigned long)dma_cs,
  31198. + (unsigned long)debug);
  31199. + /* reset error */
  31200. + writel(debug, host_priv->dma_chan_base +
  31201. + BCM2708_DMA_DEBUG);
  31202. + }
  31203. + if (dma_cs & BCM2708_DMA_INT) {
  31204. + /* acknowledge interrupt */
  31205. + writel(BCM2708_DMA_INT,
  31206. + host_priv->dma_chan_base + BCM2708_DMA_CS);
  31207. +
  31208. + dsb(); /* ARM data synchronization (push) operation */
  31209. +
  31210. + if (!host_priv->dma_wanted) {
  31211. + /* ignore this interrupt - it was reset */
  31212. + if (extra_messages)
  31213. + printk(KERN_INFO "%s: DMA IRQ %X ignored - "
  31214. + "results were reset\n",
  31215. + mmc_hostname(host->mmc), dma_cs);
  31216. +#ifdef CHECK_DMA_USE
  31217. + printk(KERN_INFO "%s: now %"FMT_HPT
  31218. + " started %lu reset %lu stopped %lu\n",
  31219. + mmc_hostname(host->mmc), hptime(),
  31220. + since_ns(host_priv->when_started),
  31221. + since_ns(host_priv->when_reset),
  31222. + since_ns(host_priv->when_stopped));
  31223. + host_priv->dmas_pending--;
  31224. +#endif
  31225. + } else
  31226. + sdhci_bcm2708_dma_complete_irq(host, dma_cs);
  31227. +
  31228. + result = IRQ_HANDLED;
  31229. + }
  31230. + sdhci_spin_unlock(host);
  31231. +
  31232. + return result;
  31233. +}
  31234. +#endif /* CONFIG_MMC_SDHCI_BCM2708_DMA */
  31235. +
  31236. +
  31237. +/***************************************************************************** \
  31238. + * *
  31239. + * Device Attributes *
  31240. + * *
  31241. +\*****************************************************************************/
  31242. +
  31243. +
  31244. +/**
  31245. + * Show the DMA-using status
  31246. + */
  31247. +static ssize_t attr_dma_show(struct device *_dev,
  31248. + struct device_attribute *attr, char *buf)
  31249. +{
  31250. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31251. +
  31252. + if (host) {
  31253. + int use_dma = (host->flags & SDHCI_USE_PLATDMA? 1:0);
  31254. + return sprintf(buf, "%d\n", use_dma);
  31255. + } else
  31256. + return -EINVAL;
  31257. +}
  31258. +
  31259. +/**
  31260. + * Set the DMA-using status
  31261. + */
  31262. +static ssize_t attr_dma_store(struct device *_dev,
  31263. + struct device_attribute *attr,
  31264. + const char *buf, size_t count)
  31265. +{
  31266. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31267. +
  31268. + if (host) {
  31269. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31270. + int on = simple_strtol(buf, NULL, 0);
  31271. + if (on) {
  31272. + host->flags |= SDHCI_USE_PLATDMA;
  31273. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31274. + printk(KERN_INFO "%s: DMA enabled\n",
  31275. + mmc_hostname(host->mmc));
  31276. + } else {
  31277. + host->flags &= ~(SDHCI_USE_PLATDMA | SDHCI_REQ_USE_DMA);
  31278. + sdhci_bcm2708_writel(host, 0, REG_EXRDFIFO_EN);
  31279. + printk(KERN_INFO "%s: DMA disabled\n",
  31280. + mmc_hostname(host->mmc));
  31281. + }
  31282. +#endif
  31283. + return count;
  31284. + } else
  31285. + return -EINVAL;
  31286. +}
  31287. +
  31288. +static DEVICE_ATTR(use_dma, S_IRUGO | S_IWUGO, attr_dma_show, attr_dma_store);
  31289. +
  31290. +
  31291. +/**
  31292. + * Show the DMA wait states used
  31293. + */
  31294. +static ssize_t attr_dmawait_show(struct device *_dev,
  31295. + struct device_attribute *attr, char *buf)
  31296. +{
  31297. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31298. +
  31299. + if (host) {
  31300. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31301. + int dmawait = host_priv->dma_waits;
  31302. + return sprintf(buf, "%d\n", dmawait);
  31303. + } else
  31304. + return -EINVAL;
  31305. +}
  31306. +
  31307. +/**
  31308. + * Set the DMA wait state used
  31309. + */
  31310. +static ssize_t attr_dmawait_store(struct device *_dev,
  31311. + struct device_attribute *attr,
  31312. + const char *buf, size_t count)
  31313. +{
  31314. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31315. +
  31316. + if (host) {
  31317. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31318. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31319. + int dma_waits = simple_strtol(buf, NULL, 0);
  31320. + if (dma_waits >= 0 && dma_waits < 32)
  31321. + host_priv->dma_waits = dma_waits;
  31322. + else
  31323. + printk(KERN_ERR "%s: illegal dma_waits value - %d",
  31324. + mmc_hostname(host->mmc), dma_waits);
  31325. +#endif
  31326. + return count;
  31327. + } else
  31328. + return -EINVAL;
  31329. +}
  31330. +
  31331. +static DEVICE_ATTR(dma_wait, S_IRUGO | S_IWUGO,
  31332. + attr_dmawait_show, attr_dmawait_store);
  31333. +
  31334. +
  31335. +/**
  31336. + * Show the DMA-using status
  31337. + */
  31338. +static ssize_t attr_status_show(struct device *_dev,
  31339. + struct device_attribute *attr, char *buf)
  31340. +{
  31341. + struct sdhci_host *host = (struct sdhci_host *)dev_get_drvdata(_dev);
  31342. +
  31343. + if (host) {
  31344. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31345. + return sprintf(buf,
  31346. + "present: yes\n"
  31347. + "power: %s\n"
  31348. + "clock: %u Hz\n"
  31349. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31350. + "dma: %s (%d waits)\n",
  31351. +#else
  31352. + "dma: unconfigured\n",
  31353. +#endif
  31354. + "always on",
  31355. + host->clock
  31356. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31357. + , (host->flags & SDHCI_USE_PLATDMA)? "on": "off"
  31358. + , host_priv->dma_waits
  31359. +#endif
  31360. + );
  31361. + } else
  31362. + return -EINVAL;
  31363. +}
  31364. +
  31365. +static DEVICE_ATTR(status, S_IRUGO, attr_status_show, NULL);
  31366. +
  31367. +/***************************************************************************** \
  31368. + * *
  31369. + * Power Management *
  31370. + * *
  31371. +\*****************************************************************************/
  31372. +
  31373. +
  31374. +#ifdef CONFIG_PM
  31375. +static int sdhci_bcm2708_suspend(struct platform_device *dev, pm_message_t state)
  31376. +{
  31377. + struct sdhci_host *host = (struct sdhci_host *)
  31378. + platform_get_drvdata(dev);
  31379. + int ret = 0;
  31380. +
  31381. + if (host->mmc) {
  31382. + //ret = mmc_suspend_host(host->mmc);
  31383. + }
  31384. +
  31385. + return ret;
  31386. +}
  31387. +
  31388. +static int sdhci_bcm2708_resume(struct platform_device *dev)
  31389. +{
  31390. + struct sdhci_host *host = (struct sdhci_host *)
  31391. + platform_get_drvdata(dev);
  31392. + int ret = 0;
  31393. +
  31394. + if (host->mmc) {
  31395. + //ret = mmc_resume_host(host->mmc);
  31396. + }
  31397. +
  31398. + return ret;
  31399. +}
  31400. +#endif
  31401. +
  31402. +
  31403. +/*****************************************************************************\
  31404. + * *
  31405. + * Device quirk functions. Implemented as local ops because the flags *
  31406. + * field is out of space with newer kernels. This implementation can be *
  31407. + * back ported to older kernels as well. *
  31408. +\****************************************************************************/
  31409. +static unsigned int sdhci_bcm2708_quirk_extra_ints(struct sdhci_host *host)
  31410. +{
  31411. + return 1;
  31412. +}
  31413. +
  31414. +static unsigned int sdhci_bcm2708_quirk_spurious_crc_acmd51(struct sdhci_host *host)
  31415. +{
  31416. + return 1;
  31417. +}
  31418. +
  31419. +static unsigned int sdhci_bcm2708_missing_status(struct sdhci_host *host)
  31420. +{
  31421. + return 1;
  31422. +}
  31423. +
  31424. +/***************************************************************************** \
  31425. + * *
  31426. + * Device ops *
  31427. + * *
  31428. +\*****************************************************************************/
  31429. +
  31430. +static struct sdhci_ops sdhci_bcm2708_ops = {
  31431. +#ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS
  31432. + .read_l = sdhci_bcm2708_readl,
  31433. + .read_w = sdhci_bcm2708_readw,
  31434. + .read_b = sdhci_bcm2708_readb,
  31435. + .write_l = sdhci_bcm2708_writel,
  31436. + .write_w = sdhci_bcm2708_writew,
  31437. + .write_b = sdhci_bcm2708_writeb,
  31438. +#else
  31439. +#error The BCM2708 SDHCI driver needs CONFIG_MMC_SDHCI_IO_ACCESSORS to be set
  31440. +#endif
  31441. + .get_max_clock = sdhci_bcm2708_get_max_clock,
  31442. +
  31443. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31444. + // Platform DMA operations
  31445. + .pdma_able = sdhci_bcm2708_platdma_dmaable,
  31446. + .pdma_avail = sdhci_bcm2708_platdma_avail,
  31447. + .pdma_reset = sdhci_bcm2708_platdma_reset,
  31448. +#endif
  31449. + .extra_ints = sdhci_bcm2708_quirk_extra_ints,
  31450. +};
  31451. +
  31452. +/*****************************************************************************\
  31453. + * *
  31454. + * Device probing/removal *
  31455. + * *
  31456. +\*****************************************************************************/
  31457. +
  31458. +static int sdhci_bcm2708_probe(struct platform_device *pdev)
  31459. +{
  31460. + struct sdhci_host *host;
  31461. + struct resource *iomem;
  31462. + struct sdhci_bcm2708_priv *host_priv;
  31463. + int ret;
  31464. +
  31465. + BUG_ON(pdev == NULL);
  31466. +
  31467. + iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31468. + if (!iomem) {
  31469. + ret = -ENOMEM;
  31470. + goto err;
  31471. + }
  31472. +
  31473. + if (resource_size(iomem) != 0x100)
  31474. + dev_err(&pdev->dev, "Invalid iomem size. You may "
  31475. + "experience problems.\n");
  31476. +
  31477. + if (pdev->dev.parent)
  31478. + host = sdhci_alloc_host(pdev->dev.parent,
  31479. + sizeof(struct sdhci_bcm2708_priv));
  31480. + else
  31481. + host = sdhci_alloc_host(&pdev->dev,
  31482. + sizeof(struct sdhci_bcm2708_priv));
  31483. +
  31484. + if (IS_ERR(host)) {
  31485. + ret = PTR_ERR(host);
  31486. + goto err;
  31487. + }
  31488. + if (missing_status) {
  31489. + sdhci_bcm2708_ops.missing_status = sdhci_bcm2708_missing_status;
  31490. + }
  31491. +
  31492. + if( spurious_crc_acmd51 ) {
  31493. + sdhci_bcm2708_ops.spurious_crc_acmd51 = sdhci_bcm2708_quirk_spurious_crc_acmd51;
  31494. + }
  31495. +
  31496. +
  31497. + printk("sdhci: %s low-latency mode\n",enable_llm?"Enable":"Disable");
  31498. +
  31499. + host->hw_name = "BCM2708_Arasan";
  31500. + host->ops = &sdhci_bcm2708_ops;
  31501. + host->irq = platform_get_irq(pdev, 0);
  31502. + host->second_irq = 0;
  31503. +
  31504. + host->quirks = SDHCI_QUIRK_BROKEN_CARD_DETECTION |
  31505. + SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK |
  31506. + SDHCI_QUIRK_BROKEN_TIMEOUT_VAL |
  31507. + SDHCI_QUIRK_MISSING_CAPS |
  31508. + SDHCI_QUIRK_NO_HISPD_BIT |
  31509. + (sync_after_dma ? 0:SDHCI_QUIRK_MULTIBLOCK_READ_ACMD12);
  31510. +
  31511. +
  31512. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31513. + host->flags = SDHCI_USE_PLATDMA;
  31514. +#endif
  31515. +
  31516. + if (!request_mem_region(iomem->start, resource_size(iomem),
  31517. + mmc_hostname(host->mmc))) {
  31518. + dev_err(&pdev->dev, "cannot request region\n");
  31519. + ret = -EBUSY;
  31520. + goto err_request;
  31521. + }
  31522. +
  31523. + host->ioaddr = ioremap(iomem->start, resource_size(iomem));
  31524. + if (!host->ioaddr) {
  31525. + dev_err(&pdev->dev, "failed to remap registers\n");
  31526. + ret = -ENOMEM;
  31527. + goto err_remap;
  31528. + }
  31529. +
  31530. + host_priv = SDHCI_HOST_PRIV(host);
  31531. +
  31532. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31533. + host_priv->dma_wanted = 0;
  31534. +#ifdef CHECK_DMA_USE
  31535. + host_priv->dmas_pending = 0;
  31536. + host_priv->when_started = 0;
  31537. + host_priv->when_reset = 0;
  31538. + host_priv->when_stopped = 0;
  31539. +#endif
  31540. + host_priv->sg_ix = 0;
  31541. + host_priv->sg_done = 0;
  31542. + host_priv->complete = NULL;
  31543. + host_priv->dma_waits = SDHCI_BCM_DMA_WAITS;
  31544. +
  31545. + host_priv->cb_base = dma_alloc_writecombine(&pdev->dev, SZ_4K,
  31546. + &host_priv->cb_handle,
  31547. + GFP_KERNEL);
  31548. + if (!host_priv->cb_base) {
  31549. + dev_err(&pdev->dev, "cannot allocate DMA CBs\n");
  31550. + ret = -ENOMEM;
  31551. + goto err_alloc_cb;
  31552. + }
  31553. +
  31554. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_FAST,
  31555. + &host_priv->dma_chan_base,
  31556. + &host_priv->dma_irq);
  31557. + if (ret < 0) {
  31558. + dev_err(&pdev->dev, "couldn't allocate a DMA channel\n");
  31559. + goto err_add_dma;
  31560. + }
  31561. + host_priv->dma_chan = ret;
  31562. +
  31563. + ret = request_irq(host_priv->dma_irq, sdhci_bcm2708_dma_irq,
  31564. + 0 /*IRQF_SHARED*/, DRIVER_NAME " (dma)", host);
  31565. + if (ret) {
  31566. + dev_err(&pdev->dev, "cannot set DMA IRQ\n");
  31567. + goto err_add_dma_irq;
  31568. + }
  31569. + host->second_irq = host_priv->dma_irq;
  31570. + DBG("DMA CBs %p handle %08X DMA%d %p DMA IRQ %d\n",
  31571. + host_priv->cb_base, (unsigned)host_priv->cb_handle,
  31572. + host_priv->dma_chan, host_priv->dma_chan_base,
  31573. + host_priv->dma_irq);
  31574. +
  31575. + // we support 3.3V
  31576. + host->caps |= SDHCI_CAN_VDD_330;
  31577. + if (allow_highspeed)
  31578. + host->mmc->caps |= MMC_CAP_SD_HIGHSPEED | MMC_CAP_MMC_HIGHSPEED;
  31579. +
  31580. + /* single block writes cause data loss with some SD cards! */
  31581. + host->mmc->caps2 |= MMC_CAP2_FORCE_MULTIBLOCK;
  31582. +#endif
  31583. +
  31584. + ret = sdhci_add_host(host);
  31585. + if (ret)
  31586. + goto err_add_host;
  31587. +
  31588. + platform_set_drvdata(pdev, host);
  31589. + ret = device_create_file(&pdev->dev, &dev_attr_use_dma);
  31590. + ret = device_create_file(&pdev->dev, &dev_attr_dma_wait);
  31591. + ret = device_create_file(&pdev->dev, &dev_attr_status);
  31592. +
  31593. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31594. + /* enable extension fifo for paced DMA transfers */
  31595. + sdhci_bcm2708_writel(host, 1, REG_EXRDFIFO_EN);
  31596. + sdhci_bcm2708_writel(host, 4, REG_EXRDFIFO_CFG);
  31597. +#endif
  31598. +
  31599. + printk(KERN_INFO "%s: BCM2708 SDHC host at 0x%08llx DMA %d IRQ %d\n",
  31600. + mmc_hostname(host->mmc), (unsigned long long)iomem->start,
  31601. + host_priv->dma_chan, host_priv->dma_irq);
  31602. +
  31603. + return 0;
  31604. +
  31605. +err_add_host:
  31606. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31607. + free_irq(host_priv->dma_irq, host);
  31608. +err_add_dma_irq:
  31609. + bcm_dma_chan_free(host_priv->dma_chan);
  31610. +err_add_dma:
  31611. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  31612. + host_priv->cb_handle);
  31613. +err_alloc_cb:
  31614. +#endif
  31615. + iounmap(host->ioaddr);
  31616. +err_remap:
  31617. + release_mem_region(iomem->start, resource_size(iomem));
  31618. +err_request:
  31619. + sdhci_free_host(host);
  31620. +err:
  31621. + dev_err(&pdev->dev, "probe failed, err %d\n", ret);
  31622. + return ret;
  31623. +}
  31624. +
  31625. +static int sdhci_bcm2708_remove(struct platform_device *pdev)
  31626. +{
  31627. + struct sdhci_host *host = platform_get_drvdata(pdev);
  31628. + struct resource *iomem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  31629. + struct sdhci_bcm2708_priv *host_priv = SDHCI_HOST_PRIV(host);
  31630. + int dead;
  31631. + u32 scratch;
  31632. +
  31633. + dead = 0;
  31634. + scratch = sdhci_bcm2708_readl(host, SDHCI_INT_STATUS);
  31635. + if (scratch == (u32)-1)
  31636. + dead = 1;
  31637. +
  31638. + device_remove_file(&pdev->dev, &dev_attr_status);
  31639. + device_remove_file(&pdev->dev, &dev_attr_dma_wait);
  31640. + device_remove_file(&pdev->dev, &dev_attr_use_dma);
  31641. +
  31642. +#ifdef CONFIG_MMC_SDHCI_BCM2708_DMA
  31643. + free_irq(host_priv->dma_irq, host);
  31644. + dma_free_writecombine(&pdev->dev, SZ_4K, host_priv->cb_base,
  31645. + host_priv->cb_handle);
  31646. +#endif
  31647. + sdhci_remove_host(host, dead);
  31648. + iounmap(host->ioaddr);
  31649. + release_mem_region(iomem->start, resource_size(iomem));
  31650. + sdhci_free_host(host);
  31651. + platform_set_drvdata(pdev, NULL);
  31652. +
  31653. + return 0;
  31654. +}
  31655. +
  31656. +static struct platform_driver sdhci_bcm2708_driver = {
  31657. + .driver = {
  31658. + .name = DRIVER_NAME,
  31659. + .owner = THIS_MODULE,
  31660. + },
  31661. + .probe = sdhci_bcm2708_probe,
  31662. + .remove = sdhci_bcm2708_remove,
  31663. +
  31664. +#ifdef CONFIG_PM
  31665. + .suspend = sdhci_bcm2708_suspend,
  31666. + .resume = sdhci_bcm2708_resume,
  31667. +#endif
  31668. +
  31669. +};
  31670. +
  31671. +/*****************************************************************************\
  31672. + * *
  31673. + * Driver init/exit *
  31674. + * *
  31675. +\*****************************************************************************/
  31676. +
  31677. +static int __init sdhci_drv_init(void)
  31678. +{
  31679. + return platform_driver_register(&sdhci_bcm2708_driver);
  31680. +}
  31681. +
  31682. +static void __exit sdhci_drv_exit(void)
  31683. +{
  31684. + platform_driver_unregister(&sdhci_bcm2708_driver);
  31685. +}
  31686. +
  31687. +module_init(sdhci_drv_init);
  31688. +module_exit(sdhci_drv_exit);
  31689. +
  31690. +module_param(allow_highspeed, bool, 0444);
  31691. +module_param(emmc_clock_freq, int, 0444);
  31692. +module_param(sync_after_dma, bool, 0444);
  31693. +module_param(missing_status, bool, 0444);
  31694. +module_param(spurious_crc_acmd51, bool, 0444);
  31695. +module_param(enable_llm, bool, 0444);
  31696. +module_param(cycle_delay, int, 0444);
  31697. +module_param(extra_messages, bool, 0444);
  31698. +
  31699. +MODULE_DESCRIPTION("Secure Digital Host Controller Interface platform driver");
  31700. +MODULE_AUTHOR("Broadcom <info@broadcom.com>");
  31701. +MODULE_LICENSE("GPL v2");
  31702. +MODULE_ALIAS("platform:"DRIVER_NAME);
  31703. +
  31704. +MODULE_PARM_DESC(allow_highspeed, "Allow high speed transfers modes");
  31705. +MODULE_PARM_DESC(emmc_clock_freq, "Specify the speed of emmc clock");
  31706. +MODULE_PARM_DESC(sync_after_dma, "Block in driver until dma complete");
  31707. +MODULE_PARM_DESC(missing_status, "Use the missing status quirk");
  31708. +MODULE_PARM_DESC(spurious_crc_acmd51, "Use the spurious crc quirk for reading SCR (ACMD51)");
  31709. +MODULE_PARM_DESC(enable_llm, "Enable low-latency mode");
  31710. +MODULE_PARM_DESC(extra_messages, "Enable more sdcard warning messages");
  31711. +
  31712. +
  31713. diff -Nur linux-3.15/drivers/mmc/host/sdhci.c linux-rpi/drivers/mmc/host/sdhci.c
  31714. --- linux-3.15/drivers/mmc/host/sdhci.c 2014-06-08 20:19:54.000000000 +0200
  31715. +++ linux-rpi/drivers/mmc/host/sdhci.c 2014-06-11 21:05:20.000000000 +0200
  31716. @@ -28,6 +28,7 @@
  31717. #include <linux/mmc/mmc.h>
  31718. #include <linux/mmc/host.h>
  31719. #include <linux/mmc/card.h>
  31720. +#include <linux/mmc/sd.h>
  31721. #include <linux/mmc/slot-gpio.h>
  31722. #include "sdhci.h"
  31723. @@ -130,6 +131,99 @@
  31724. * Low level functions *
  31725. * *
  31726. \*****************************************************************************/
  31727. +extern bool enable_llm;
  31728. +static int sdhci_locked=0;
  31729. +void sdhci_spin_lock(struct sdhci_host *host)
  31730. +{
  31731. + spin_lock(&host->lock);
  31732. +#ifdef CONFIG_PREEMPT
  31733. + if(enable_llm)
  31734. + {
  31735. + disable_irq_nosync(host->irq);
  31736. + if(host->second_irq)
  31737. + disable_irq_nosync(host->second_irq);
  31738. + local_irq_enable();
  31739. + }
  31740. +#endif
  31741. +}
  31742. +
  31743. +void sdhci_spin_unlock(struct sdhci_host *host)
  31744. +{
  31745. +#ifdef CONFIG_PREEMPT
  31746. + if(enable_llm)
  31747. + {
  31748. + local_irq_disable();
  31749. + if(host->second_irq)
  31750. + enable_irq(host->second_irq);
  31751. + enable_irq(host->irq);
  31752. + }
  31753. +#endif
  31754. + spin_unlock(&host->lock);
  31755. +}
  31756. +
  31757. +void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags)
  31758. +{
  31759. +#ifdef CONFIG_PREEMPT
  31760. + if(enable_llm)
  31761. + {
  31762. + while(sdhci_locked)
  31763. + {
  31764. + preempt_schedule();
  31765. + }
  31766. + spin_lock_irqsave(&host->lock,*flags);
  31767. + disable_irq(host->irq);
  31768. + if(host->second_irq)
  31769. + disable_irq(host->second_irq);
  31770. + local_irq_enable();
  31771. + }
  31772. + else
  31773. +#endif
  31774. + spin_lock_irqsave(&host->lock,*flags);
  31775. +}
  31776. +
  31777. +void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags)
  31778. +{
  31779. +#ifdef CONFIG_PREEMPT
  31780. + if(enable_llm)
  31781. + {
  31782. + local_irq_disable();
  31783. + if(host->second_irq)
  31784. + enable_irq(host->second_irq);
  31785. + enable_irq(host->irq);
  31786. + }
  31787. +#endif
  31788. + spin_unlock_irqrestore(&host->lock,flags);
  31789. +}
  31790. +
  31791. +static void sdhci_spin_enable_schedule(struct sdhci_host *host)
  31792. +{
  31793. +#ifdef CONFIG_PREEMPT
  31794. + if(enable_llm)
  31795. + {
  31796. + sdhci_locked = 1;
  31797. + preempt_enable();
  31798. + }
  31799. +#endif
  31800. +}
  31801. +
  31802. +static void sdhci_spin_disable_schedule(struct sdhci_host *host)
  31803. +{
  31804. +#ifdef CONFIG_PREEMPT
  31805. + if(enable_llm)
  31806. + {
  31807. + preempt_disable();
  31808. + sdhci_locked = 0;
  31809. + }
  31810. +#endif
  31811. +}
  31812. +
  31813. +
  31814. +#undef spin_lock_irqsave
  31815. +#define spin_lock_irqsave(host_lock, flags) sdhci_spin_lock_irqsave(container_of(host_lock, struct sdhci_host, lock), &flags)
  31816. +#define spin_unlock_irqrestore(host_lock, flags) sdhci_spin_unlock_irqrestore(container_of(host_lock, struct sdhci_host, lock), flags)
  31817. +
  31818. +#define spin_lock(host_lock) sdhci_spin_lock(container_of(host_lock, struct sdhci_host, lock))
  31819. +#define spin_unlock(host_lock) sdhci_spin_unlock(container_of(host_lock, struct sdhci_host, lock))
  31820. static void sdhci_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set)
  31821. {
  31822. @@ -299,7 +393,7 @@
  31823. struct sdhci_host *host = container_of(led, struct sdhci_host, led);
  31824. unsigned long flags;
  31825. - spin_lock_irqsave(&host->lock, flags);
  31826. + sdhci_spin_lock_irqsave(host, &flags);
  31827. if (host->runtime_suspended)
  31828. goto out;
  31829. @@ -309,7 +403,7 @@
  31830. else
  31831. sdhci_activate_led(host);
  31832. out:
  31833. - spin_unlock_irqrestore(&host->lock, flags);
  31834. + sdhci_spin_unlock_irqrestore(host, flags);
  31835. }
  31836. #endif
  31837. @@ -326,7 +420,7 @@
  31838. u32 uninitialized_var(scratch);
  31839. u8 *buf;
  31840. - DBG("PIO reading\n");
  31841. + DBG("PIO reading %db\n", host->data->blksz);
  31842. blksize = host->data->blksz;
  31843. chunk = 0;
  31844. @@ -371,7 +465,7 @@
  31845. u32 scratch;
  31846. u8 *buf;
  31847. - DBG("PIO writing\n");
  31848. + DBG("PIO writing %db\n", host->data->blksz);
  31849. blksize = host->data->blksz;
  31850. chunk = 0;
  31851. @@ -410,19 +504,28 @@
  31852. local_irq_restore(flags);
  31853. }
  31854. -static void sdhci_transfer_pio(struct sdhci_host *host)
  31855. +static void sdhci_transfer_pio(struct sdhci_host *host, u32 intstate)
  31856. {
  31857. u32 mask;
  31858. + u32 state = 0;
  31859. + u32 intmask;
  31860. + int available;
  31861. BUG_ON(!host->data);
  31862. if (host->blocks == 0)
  31863. return;
  31864. - if (host->data->flags & MMC_DATA_READ)
  31865. + if (host->data->flags & MMC_DATA_READ) {
  31866. mask = SDHCI_DATA_AVAILABLE;
  31867. - else
  31868. + intmask = SDHCI_INT_DATA_AVAIL;
  31869. + } else {
  31870. mask = SDHCI_SPACE_AVAILABLE;
  31871. + intmask = SDHCI_INT_SPACE_AVAIL;
  31872. + }
  31873. +
  31874. + /* initially we can see whether we can procede using intstate */
  31875. + available = (intstate & intmask);
  31876. /*
  31877. * Some controllers (JMicron JMB38x) mess up the buffer bits
  31878. @@ -433,7 +536,7 @@
  31879. (host->data->blocks == 1))
  31880. mask = ~0;
  31881. - while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  31882. + while (available) {
  31883. if (host->quirks & SDHCI_QUIRK_PIO_NEEDS_DELAY)
  31884. udelay(100);
  31885. @@ -445,9 +548,12 @@
  31886. host->blocks--;
  31887. if (host->blocks == 0)
  31888. break;
  31889. + state = sdhci_readl(host, SDHCI_PRESENT_STATE);
  31890. + available = state & mask;
  31891. + break;
  31892. }
  31893. - DBG("PIO transfer complete.\n");
  31894. + DBG("PIO transfer complete - %d blocks left.\n", host->blocks);
  31895. }
  31896. static char *sdhci_kmap_atomic(struct scatterlist *sg, unsigned long *flags)
  31897. @@ -720,7 +826,9 @@
  31898. u32 pio_irqs = SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL;
  31899. u32 dma_irqs = SDHCI_INT_DMA_END | SDHCI_INT_ADMA_ERROR;
  31900. - if (host->flags & SDHCI_REQ_USE_DMA)
  31901. + /* platform DMA will begin on receipt of PIO irqs */
  31902. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31903. + !(host->flags & SDHCI_USE_PLATDMA))
  31904. sdhci_clear_set_irqs(host, pio_irqs, dma_irqs);
  31905. else
  31906. sdhci_clear_set_irqs(host, dma_irqs, pio_irqs);
  31907. @@ -752,44 +860,25 @@
  31908. host->data_early = 0;
  31909. host->data->bytes_xfered = 0;
  31910. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA))
  31911. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA | SDHCI_USE_PLATDMA))
  31912. host->flags |= SDHCI_REQ_USE_DMA;
  31913. /*
  31914. * FIXME: This doesn't account for merging when mapping the
  31915. * scatterlist.
  31916. */
  31917. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31918. - int broken, i;
  31919. - struct scatterlist *sg;
  31920. -
  31921. - broken = 0;
  31922. - if (host->flags & SDHCI_USE_ADMA) {
  31923. - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE)
  31924. - broken = 1;
  31925. - } else {
  31926. - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE)
  31927. - broken = 1;
  31928. - }
  31929. -
  31930. - if (unlikely(broken)) {
  31931. - for_each_sg(data->sg, sg, data->sg_len, i) {
  31932. - if (sg->length & 0x3) {
  31933. - DBG("Reverting to PIO because of "
  31934. - "transfer size (%d)\n",
  31935. - sg->length);
  31936. - host->flags &= ~SDHCI_REQ_USE_DMA;
  31937. - break;
  31938. - }
  31939. - }
  31940. - }
  31941. - }
  31942. /*
  31943. * The assumption here being that alignment is the same after
  31944. * translation to device address space.
  31945. */
  31946. - if (host->flags & SDHCI_REQ_USE_DMA) {
  31947. + if ((host->flags & (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) ==
  31948. + (SDHCI_REQ_USE_DMA | SDHCI_USE_PLATDMA)) {
  31949. +
  31950. + if (! sdhci_platdma_dmaable(host, data))
  31951. + host->flags &= ~SDHCI_REQ_USE_DMA;
  31952. +
  31953. + } else if (host->flags & SDHCI_REQ_USE_DMA) {
  31954. int broken, i;
  31955. struct scatterlist *sg;
  31956. @@ -848,7 +937,8 @@
  31957. */
  31958. WARN_ON(1);
  31959. host->flags &= ~SDHCI_REQ_USE_DMA;
  31960. - } else {
  31961. + } else
  31962. + if (!(host->flags & SDHCI_USE_PLATDMA)) {
  31963. WARN_ON(sg_cnt != 1);
  31964. sdhci_writel(host, sg_dma_address(data->sg),
  31965. SDHCI_DMA_ADDRESS);
  31966. @@ -864,11 +954,13 @@
  31967. if (host->version >= SDHCI_SPEC_200) {
  31968. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  31969. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  31970. + if (! (host->flags & SDHCI_USE_PLATDMA)) {
  31971. if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31972. (host->flags & SDHCI_USE_ADMA))
  31973. ctrl |= SDHCI_CTRL_ADMA32;
  31974. else
  31975. ctrl |= SDHCI_CTRL_SDMA;
  31976. + }
  31977. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  31978. }
  31979. @@ -925,7 +1017,8 @@
  31980. if (data->flags & MMC_DATA_READ)
  31981. mode |= SDHCI_TRNS_READ;
  31982. - if (host->flags & SDHCI_REQ_USE_DMA)
  31983. + if ((host->flags & SDHCI_REQ_USE_DMA) &&
  31984. + !(host->flags & SDHCI_USE_PLATDMA))
  31985. mode |= SDHCI_TRNS_DMA;
  31986. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  31987. @@ -941,13 +1034,16 @@
  31988. host->data = NULL;
  31989. if (host->flags & SDHCI_REQ_USE_DMA) {
  31990. - if (host->flags & SDHCI_USE_ADMA)
  31991. - sdhci_adma_table_post(host, data);
  31992. - else {
  31993. + /* we may have to abandon an ongoing platform DMA */
  31994. + if (host->flags & SDHCI_USE_PLATDMA)
  31995. + sdhci_platdma_reset(host, data);
  31996. +
  31997. + if (host->flags & (SDHCI_USE_PLATDMA | SDHCI_USE_SDMA)) {
  31998. dma_unmap_sg(mmc_dev(host->mmc), data->sg,
  31999. data->sg_len, (data->flags & MMC_DATA_READ) ?
  32000. DMA_FROM_DEVICE : DMA_TO_DEVICE);
  32001. - }
  32002. + } else if (host->flags & SDHCI_USE_ADMA)
  32003. + sdhci_adma_table_post(host, data);
  32004. }
  32005. /*
  32006. @@ -1000,6 +1096,12 @@
  32007. if ((cmd->data != NULL) || (cmd->flags & MMC_RSP_BUSY))
  32008. mask |= SDHCI_DATA_INHIBIT;
  32009. + if(host->ops->missing_status && (cmd->opcode == MMC_SEND_STATUS)) {
  32010. + timeout = 5000; // Really obscenely large delay to send the status, due to bug in controller
  32011. + // which might cause the STATUS command to get stuck when a data operation is in flow
  32012. + mask |= SDHCI_DATA_INHIBIT;
  32013. + }
  32014. +
  32015. /* We shouldn't wait for data inihibit for stop commands, even
  32016. though they might use busy signaling */
  32017. if (host->mrq->data && (cmd == host->mrq->data->stop))
  32018. @@ -1015,8 +1117,12 @@
  32019. return;
  32020. }
  32021. timeout--;
  32022. + sdhci_spin_enable_schedule(host);
  32023. mdelay(1);
  32024. + sdhci_spin_disable_schedule(host);
  32025. }
  32026. + DBG("send cmd %d - wait 0x%X irq 0x%x\n", cmd->opcode, mask,
  32027. + sdhci_readl(host, SDHCI_INT_STATUS));
  32028. timeout = jiffies;
  32029. if (!cmd->data && cmd->busy_timeout > 9000)
  32030. @@ -1026,6 +1132,10 @@
  32031. mod_timer(&host->timer, timeout);
  32032. host->cmd = cmd;
  32033. + if (host->last_cmdop == MMC_APP_CMD)
  32034. + host->last_cmdop = -cmd->opcode;
  32035. + else
  32036. + host->last_cmdop = cmd->opcode;
  32037. sdhci_prepare_data(host, cmd);
  32038. @@ -1242,7 +1352,9 @@
  32039. return;
  32040. }
  32041. timeout--;
  32042. + sdhci_spin_enable_schedule(host);
  32043. mdelay(1);
  32044. + sdhci_spin_disable_schedule(host);
  32045. }
  32046. clk |= SDHCI_CLOCK_CARD_EN;
  32047. @@ -1343,7 +1455,7 @@
  32048. sdhci_runtime_pm_get(host);
  32049. - spin_lock_irqsave(&host->lock, flags);
  32050. + sdhci_spin_lock_irqsave(host, &flags);
  32051. WARN_ON(host->mrq != NULL);
  32052. @@ -1408,9 +1520,9 @@
  32053. */
  32054. host->mrq = NULL;
  32055. - spin_unlock_irqrestore(&host->lock, flags);
  32056. + sdhci_spin_unlock_irqrestore(host, flags);
  32057. sdhci_execute_tuning(mmc, tuning_opcode);
  32058. - spin_lock_irqsave(&host->lock, flags);
  32059. + sdhci_spin_lock_irqsave(host, &flags);
  32060. /* Restore original mmc_request structure */
  32061. host->mrq = mrq;
  32062. @@ -1424,7 +1536,7 @@
  32063. }
  32064. mmiowb();
  32065. - spin_unlock_irqrestore(&host->lock, flags);
  32066. + sdhci_spin_unlock_irqrestore(host, flags);
  32067. }
  32068. static void sdhci_do_set_ios(struct sdhci_host *host, struct mmc_ios *ios)
  32069. @@ -1433,10 +1545,10 @@
  32070. int vdd_bit = -1;
  32071. u8 ctrl;
  32072. - spin_lock_irqsave(&host->lock, flags);
  32073. + sdhci_spin_lock_irqsave(host, &flags);
  32074. if (host->flags & SDHCI_DEVICE_DEAD) {
  32075. - spin_unlock_irqrestore(&host->lock, flags);
  32076. + sdhci_spin_unlock_irqrestore(host, flags);
  32077. if (host->vmmc && ios->power_mode == MMC_POWER_OFF)
  32078. mmc_regulator_set_ocr(host->mmc, host->vmmc, 0);
  32079. return;
  32080. @@ -1464,9 +1576,9 @@
  32081. vdd_bit = sdhci_set_power(host, ios->vdd);
  32082. if (host->vmmc && vdd_bit != -1) {
  32083. - spin_unlock_irqrestore(&host->lock, flags);
  32084. + sdhci_spin_unlock_irqrestore(host, flags);
  32085. mmc_regulator_set_ocr(host->mmc, host->vmmc, vdd_bit);
  32086. - spin_lock_irqsave(&host->lock, flags);
  32087. + sdhci_spin_lock_irqsave(host, &flags);
  32088. }
  32089. if (host->ops->platform_send_init_74_clocks)
  32090. @@ -1603,7 +1715,7 @@
  32091. sdhci_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA);
  32092. mmiowb();
  32093. - spin_unlock_irqrestore(&host->lock, flags);
  32094. + sdhci_spin_unlock_irqrestore(host, flags);
  32095. }
  32096. static void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
  32097. @@ -1651,7 +1763,7 @@
  32098. unsigned long flags;
  32099. int is_readonly;
  32100. - spin_lock_irqsave(&host->lock, flags);
  32101. + sdhci_spin_lock_irqsave(host, &flags);
  32102. if (host->flags & SDHCI_DEVICE_DEAD)
  32103. is_readonly = 0;
  32104. @@ -1661,7 +1773,7 @@
  32105. is_readonly = !(sdhci_readl(host, SDHCI_PRESENT_STATE)
  32106. & SDHCI_WRITE_PROTECT);
  32107. - spin_unlock_irqrestore(&host->lock, flags);
  32108. + sdhci_spin_unlock_irqrestore(host, flags);
  32109. /* This quirk needs to be replaced by a callback-function later */
  32110. return host->quirks & SDHCI_QUIRK_INVERTED_WRITE_PROTECT ?
  32111. @@ -1734,9 +1846,9 @@
  32112. struct sdhci_host *host = mmc_priv(mmc);
  32113. unsigned long flags;
  32114. - spin_lock_irqsave(&host->lock, flags);
  32115. + sdhci_spin_lock_irqsave(host, &flags);
  32116. sdhci_enable_sdio_irq_nolock(host, enable);
  32117. - spin_unlock_irqrestore(&host->lock, flags);
  32118. + sdhci_spin_unlock_irqrestore(host, flags);
  32119. }
  32120. static int sdhci_do_start_signal_voltage_switch(struct sdhci_host *host,
  32121. @@ -2086,7 +2198,7 @@
  32122. if (host->ops->card_event)
  32123. host->ops->card_event(host);
  32124. - spin_lock_irqsave(&host->lock, flags);
  32125. + sdhci_spin_lock_irqsave(host, &flags);
  32126. /* Check host->mrq first in case we are runtime suspended */
  32127. if (host->mrq && !sdhci_do_get_cd(host)) {
  32128. @@ -2102,7 +2214,7 @@
  32129. tasklet_schedule(&host->finish_tasklet);
  32130. }
  32131. - spin_unlock_irqrestore(&host->lock, flags);
  32132. + sdhci_spin_unlock_irqrestore(host, flags);
  32133. }
  32134. static const struct mmc_host_ops sdhci_ops = {
  32135. @@ -2141,14 +2253,14 @@
  32136. host = (struct sdhci_host*)param;
  32137. - spin_lock_irqsave(&host->lock, flags);
  32138. + sdhci_spin_lock_irqsave(host, &flags);
  32139. /*
  32140. * If this tasklet gets rescheduled while running, it will
  32141. * be run again afterwards but without any active request.
  32142. */
  32143. if (!host->mrq) {
  32144. - spin_unlock_irqrestore(&host->lock, flags);
  32145. + sdhci_spin_unlock_irqrestore(host, flags);
  32146. return;
  32147. }
  32148. @@ -2186,7 +2298,7 @@
  32149. #endif
  32150. mmiowb();
  32151. - spin_unlock_irqrestore(&host->lock, flags);
  32152. + sdhci_spin_unlock_irqrestore(host, flags);
  32153. mmc_request_done(host->mmc, mrq);
  32154. sdhci_runtime_pm_put(host);
  32155. @@ -2199,11 +2311,11 @@
  32156. host = (struct sdhci_host*)data;
  32157. - spin_lock_irqsave(&host->lock, flags);
  32158. + sdhci_spin_lock_irqsave(host, &flags);
  32159. if (host->mrq) {
  32160. pr_err("%s: Timeout waiting for hardware "
  32161. - "interrupt.\n", mmc_hostname(host->mmc));
  32162. + "interrupt - cmd%d.\n", mmc_hostname(host->mmc), host->last_cmdop);
  32163. sdhci_dumpregs(host);
  32164. if (host->data) {
  32165. @@ -2220,7 +2332,7 @@
  32166. }
  32167. mmiowb();
  32168. - spin_unlock_irqrestore(&host->lock, flags);
  32169. + sdhci_spin_unlock_irqrestore(host, flags);
  32170. }
  32171. static void sdhci_tuning_timer(unsigned long data)
  32172. @@ -2230,11 +2342,11 @@
  32173. host = (struct sdhci_host *)data;
  32174. - spin_lock_irqsave(&host->lock, flags);
  32175. + sdhci_spin_lock_irqsave(host, &flags);
  32176. host->flags |= SDHCI_NEEDS_RETUNING;
  32177. - spin_unlock_irqrestore(&host->lock, flags);
  32178. + sdhci_spin_unlock_irqrestore(host, flags);
  32179. }
  32180. /*****************************************************************************\
  32181. @@ -2248,10 +2360,13 @@
  32182. BUG_ON(intmask == 0);
  32183. if (!host->cmd) {
  32184. + if (!(host->ops->extra_ints)) {
  32185. pr_err("%s: Got command interrupt 0x%08x even "
  32186. "though no command operation was in progress.\n",
  32187. mmc_hostname(host->mmc), (unsigned)intmask);
  32188. sdhci_dumpregs(host);
  32189. + } else
  32190. + DBG("cmd irq 0x%08x cmd complete\n", (unsigned)intmask);
  32191. return;
  32192. }
  32193. @@ -2321,6 +2436,19 @@
  32194. static void sdhci_show_adma_error(struct sdhci_host *host) { }
  32195. #endif
  32196. +static void sdhci_data_end(struct sdhci_host *host)
  32197. +{
  32198. + if (host->cmd) {
  32199. + /*
  32200. + * Data managed to finish before the
  32201. + * command completed. Make sure we do
  32202. + * things in the proper order.
  32203. + */
  32204. + host->data_early = 1;
  32205. + } else
  32206. + sdhci_finish_data(host);
  32207. +}
  32208. +
  32209. static void sdhci_data_irq(struct sdhci_host *host, u32 intmask)
  32210. {
  32211. u32 command;
  32212. @@ -2350,23 +2478,39 @@
  32213. }
  32214. }
  32215. + if (!(host->ops->extra_ints)) {
  32216. pr_err("%s: Got data interrupt 0x%08x even "
  32217. "though no data operation was in progress.\n",
  32218. mmc_hostname(host->mmc), (unsigned)intmask);
  32219. sdhci_dumpregs(host);
  32220. + } else
  32221. + DBG("data irq 0x%08x but no data\n", (unsigned)intmask);
  32222. return;
  32223. }
  32224. if (intmask & SDHCI_INT_DATA_TIMEOUT)
  32225. host->data->error = -ETIMEDOUT;
  32226. - else if (intmask & SDHCI_INT_DATA_END_BIT)
  32227. + else if (intmask & SDHCI_INT_DATA_END_BIT) {
  32228. + DBG("end error in cmd %d\n", host->last_cmdop);
  32229. + if (host->ops->spurious_crc_acmd51 &&
  32230. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32231. + DBG("ignoring spurious data_end_bit error\n");
  32232. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32233. + } else
  32234. host->data->error = -EILSEQ;
  32235. - else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32236. + } else if ((intmask & SDHCI_INT_DATA_CRC) &&
  32237. SDHCI_GET_CMD(sdhci_readw(host, SDHCI_COMMAND))
  32238. - != MMC_BUS_TEST_R)
  32239. + != MMC_BUS_TEST_R) {
  32240. + DBG("crc error in cmd %d\n", host->last_cmdop);
  32241. + if (host->ops->spurious_crc_acmd51 &&
  32242. + host->last_cmdop == -SD_APP_SEND_SCR) {
  32243. + DBG("ignoring spurious data_crc_bit error\n");
  32244. + intmask = SDHCI_INT_DATA_AVAIL|SDHCI_INT_DATA_END;
  32245. + } else {
  32246. host->data->error = -EILSEQ;
  32247. - else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32248. + }
  32249. + } else if (intmask & SDHCI_INT_ADMA_ERROR) {
  32250. pr_err("%s: ADMA error\n", mmc_hostname(host->mmc));
  32251. sdhci_show_adma_error(host);
  32252. host->data->error = -EIO;
  32253. @@ -2374,11 +2518,18 @@
  32254. host->ops->adma_workaround(host, intmask);
  32255. }
  32256. - if (host->data->error)
  32257. + if (host->data->error) {
  32258. + DBG("finish request early on error %d\n", host->data->error);
  32259. sdhci_finish_data(host);
  32260. - else {
  32261. - if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL))
  32262. - sdhci_transfer_pio(host);
  32263. + } else {
  32264. + if (intmask & (SDHCI_INT_DATA_AVAIL | SDHCI_INT_SPACE_AVAIL)) {
  32265. + if (host->flags & SDHCI_REQ_USE_DMA) {
  32266. + /* possible only in PLATDMA mode */
  32267. + sdhci_platdma_avail(host, &intmask,
  32268. + &sdhci_data_end);
  32269. + } else
  32270. + sdhci_transfer_pio(host, intmask);
  32271. + }
  32272. /*
  32273. * We currently don't do anything fancy with DMA
  32274. @@ -2407,18 +2558,8 @@
  32275. sdhci_writel(host, dmanow, SDHCI_DMA_ADDRESS);
  32276. }
  32277. - if (intmask & SDHCI_INT_DATA_END) {
  32278. - if (host->cmd) {
  32279. - /*
  32280. - * Data managed to finish before the
  32281. - * command completed. Make sure we do
  32282. - * things in the proper order.
  32283. - */
  32284. - host->data_early = 1;
  32285. - } else {
  32286. - sdhci_finish_data(host);
  32287. - }
  32288. - }
  32289. + if (intmask & SDHCI_INT_DATA_END)
  32290. + sdhci_data_end(host);
  32291. }
  32292. }
  32293. @@ -2429,10 +2570,10 @@
  32294. u32 intmask, unexpected = 0;
  32295. int cardint = 0, max_loops = 16;
  32296. - spin_lock(&host->lock);
  32297. + sdhci_spin_lock(host);
  32298. if (host->runtime_suspended) {
  32299. - spin_unlock(&host->lock);
  32300. + sdhci_spin_unlock(host);
  32301. return IRQ_NONE;
  32302. }
  32303. @@ -2472,6 +2613,22 @@
  32304. tasklet_schedule(&host->card_tasklet);
  32305. }
  32306. + if (intmask & SDHCI_INT_ERROR_MASK & ~SDHCI_INT_ERROR)
  32307. + DBG("controller reports error 0x%x -"
  32308. + "%s%s%s%s%s%s%s%s%s%s",
  32309. + intmask,
  32310. + intmask & SDHCI_INT_TIMEOUT? " timeout": "",
  32311. + intmask & SDHCI_INT_CRC ? " crc": "",
  32312. + intmask & SDHCI_INT_END_BIT? " endbit": "",
  32313. + intmask & SDHCI_INT_INDEX? " index": "",
  32314. + intmask & SDHCI_INT_DATA_TIMEOUT? " data_timeout": "",
  32315. + intmask & SDHCI_INT_DATA_CRC? " data_crc": "",
  32316. + intmask & SDHCI_INT_DATA_END_BIT? " data_endbit": "",
  32317. + intmask & SDHCI_INT_BUS_POWER? " buspower": "",
  32318. + intmask & SDHCI_INT_ACMD12ERR? " acmd12": "",
  32319. + intmask & SDHCI_INT_ADMA_ERROR? " adma": ""
  32320. + );
  32321. +
  32322. if (intmask & SDHCI_INT_CMD_MASK) {
  32323. sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK,
  32324. SDHCI_INT_STATUS);
  32325. @@ -2486,7 +2643,13 @@
  32326. intmask &= ~(SDHCI_INT_CMD_MASK | SDHCI_INT_DATA_MASK);
  32327. - intmask &= ~SDHCI_INT_ERROR;
  32328. + if (intmask & SDHCI_INT_ERROR_MASK) {
  32329. + /* collect any uncovered errors */
  32330. + sdhci_writel(host, intmask & SDHCI_INT_ERROR_MASK,
  32331. + SDHCI_INT_STATUS);
  32332. + }
  32333. +
  32334. + intmask &= ~SDHCI_INT_ERROR_MASK;
  32335. if (intmask & SDHCI_INT_BUS_POWER) {
  32336. pr_err("%s: Card is consuming too much power!\n",
  32337. @@ -2520,7 +2683,7 @@
  32338. if (intmask && --max_loops)
  32339. goto again;
  32340. out:
  32341. - spin_unlock(&host->lock);
  32342. + sdhci_spin_unlock(host);
  32343. if (unexpected) {
  32344. pr_err("%s: Unexpected interrupt 0x%08x.\n",
  32345. @@ -2599,13 +2762,14 @@
  32346. {
  32347. int ret = 0;
  32348. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32349. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32350. + SDHCI_USE_PLATDMA)) {
  32351. if (host->ops->enable_dma)
  32352. host->ops->enable_dma(host);
  32353. }
  32354. if (!device_may_wakeup(mmc_dev(host->mmc))) {
  32355. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32356. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32357. mmc_hostname(host->mmc), host);
  32358. if (ret)
  32359. return ret;
  32360. @@ -2681,15 +2845,15 @@
  32361. host->flags &= ~SDHCI_NEEDS_RETUNING;
  32362. }
  32363. - spin_lock_irqsave(&host->lock, flags);
  32364. + sdhci_spin_lock_irqsave(host, &flags);
  32365. sdhci_mask_irqs(host, SDHCI_INT_ALL_MASK);
  32366. - spin_unlock_irqrestore(&host->lock, flags);
  32367. + sdhci_spin_unlock_irqrestore(host, flags);
  32368. synchronize_irq(host->irq);
  32369. - spin_lock_irqsave(&host->lock, flags);
  32370. + sdhci_spin_lock_irqsave(host, &flags);
  32371. host->runtime_suspended = true;
  32372. - spin_unlock_irqrestore(&host->lock, flags);
  32373. + sdhci_spin_unlock_irqrestore(host, flags);
  32374. return ret;
  32375. }
  32376. @@ -2715,16 +2879,16 @@
  32377. sdhci_do_start_signal_voltage_switch(host, &host->mmc->ios);
  32378. if ((host_flags & SDHCI_PV_ENABLED) &&
  32379. !(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) {
  32380. - spin_lock_irqsave(&host->lock, flags);
  32381. + sdhci_spin_lock_irqsave(host, &flags);
  32382. sdhci_enable_preset_value(host, true);
  32383. - spin_unlock_irqrestore(&host->lock, flags);
  32384. + sdhci_spin_unlock_irqrestore(host, flags);
  32385. }
  32386. /* Set the re-tuning expiration flag */
  32387. if (host->flags & SDHCI_USING_RETUNING_TIMER)
  32388. host->flags |= SDHCI_NEEDS_RETUNING;
  32389. - spin_lock_irqsave(&host->lock, flags);
  32390. + sdhci_spin_lock_irqsave(host, &flags);
  32391. host->runtime_suspended = false;
  32392. @@ -2735,7 +2899,7 @@
  32393. /* Enable Card Detection */
  32394. sdhci_enable_card_detection(host);
  32395. - spin_unlock_irqrestore(&host->lock, flags);
  32396. + sdhci_spin_unlock_irqrestore(host, flags);
  32397. return ret;
  32398. }
  32399. @@ -2830,14 +2994,16 @@
  32400. host->flags &= ~SDHCI_USE_ADMA;
  32401. }
  32402. - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) {
  32403. + if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32404. + SDHCI_USE_PLATDMA)) {
  32405. if (host->ops->enable_dma) {
  32406. if (host->ops->enable_dma(host)) {
  32407. pr_warning("%s: No suitable DMA "
  32408. "available. Falling back to PIO.\n",
  32409. mmc_hostname(mmc));
  32410. host->flags &=
  32411. - ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA);
  32412. + ~(SDHCI_USE_SDMA | SDHCI_USE_ADMA |
  32413. + SDHCI_USE_PLATDMA);
  32414. }
  32415. }
  32416. }
  32417. @@ -3230,8 +3396,8 @@
  32418. sdhci_init(host, 0);
  32419. - ret = request_irq(host->irq, sdhci_irq, IRQF_SHARED,
  32420. - mmc_hostname(mmc), host);
  32421. + ret = request_irq(host->irq, sdhci_irq, 0 /*IRQF_SHARED*/,
  32422. + mmc_hostname(mmc), host);
  32423. if (ret) {
  32424. pr_err("%s: Failed to request IRQ %d: %d\n",
  32425. mmc_hostname(mmc), host->irq, ret);
  32426. @@ -3264,6 +3430,7 @@
  32427. pr_info("%s: SDHCI controller on %s [%s] using %s\n",
  32428. mmc_hostname(mmc), host->hw_name, dev_name(mmc_dev(mmc)),
  32429. + (host->flags & SDHCI_USE_PLATDMA) ? "platform's DMA" :
  32430. (host->flags & SDHCI_USE_ADMA) ? "ADMA" :
  32431. (host->flags & SDHCI_USE_SDMA) ? "DMA" : "PIO");
  32432. @@ -3291,7 +3458,7 @@
  32433. unsigned long flags;
  32434. if (dead) {
  32435. - spin_lock_irqsave(&host->lock, flags);
  32436. + sdhci_spin_lock_irqsave(host, &flags);
  32437. host->flags |= SDHCI_DEVICE_DEAD;
  32438. @@ -3303,7 +3470,7 @@
  32439. tasklet_schedule(&host->finish_tasklet);
  32440. }
  32441. - spin_unlock_irqrestore(&host->lock, flags);
  32442. + sdhci_spin_unlock_irqrestore(host, flags);
  32443. }
  32444. sdhci_disable_card_detection(host);
  32445. diff -Nur linux-3.15/drivers/mmc/host/sdhci.h linux-rpi/drivers/mmc/host/sdhci.h
  32446. --- linux-3.15/drivers/mmc/host/sdhci.h 2014-06-08 20:19:54.000000000 +0200
  32447. +++ linux-rpi/drivers/mmc/host/sdhci.h 2014-06-11 21:05:20.000000000 +0200
  32448. @@ -290,6 +290,18 @@
  32449. void (*platform_reset_exit)(struct sdhci_host *host, u8 mask);
  32450. int (*platform_execute_tuning)(struct sdhci_host *host, u32 opcode);
  32451. int (*set_uhs_signaling)(struct sdhci_host *host, unsigned int uhs);
  32452. +
  32453. + int (*pdma_able)(struct sdhci_host *host,
  32454. + struct mmc_data *data);
  32455. + void (*pdma_avail)(struct sdhci_host *host,
  32456. + unsigned int *ref_intmask,
  32457. + void(*complete)(struct sdhci_host *));
  32458. + void (*pdma_reset)(struct sdhci_host *host,
  32459. + struct mmc_data *data);
  32460. + unsigned int (*extra_ints)(struct sdhci_host *host);
  32461. + unsigned int (*spurious_crc_acmd51)(struct sdhci_host *host);
  32462. + unsigned int (*missing_status)(struct sdhci_host *host);
  32463. +
  32464. void (*hw_reset)(struct sdhci_host *host);
  32465. void (*platform_suspend)(struct sdhci_host *host);
  32466. void (*platform_resume)(struct sdhci_host *host);
  32467. @@ -403,9 +415,38 @@
  32468. extern void sdhci_enable_irq_wakeups(struct sdhci_host *host);
  32469. #endif
  32470. +static inline int /*bool*/
  32471. +sdhci_platdma_dmaable(struct sdhci_host *host, struct mmc_data *data)
  32472. +{
  32473. + if (host->ops->pdma_able)
  32474. + return host->ops->pdma_able(host, data);
  32475. + else
  32476. + return 1;
  32477. +}
  32478. +static inline void
  32479. +sdhci_platdma_avail(struct sdhci_host *host, unsigned int *ref_intmask,
  32480. + void(*completion_callback)(struct sdhci_host *))
  32481. +{
  32482. + if (host->ops->pdma_avail)
  32483. + host->ops->pdma_avail(host, ref_intmask, completion_callback);
  32484. +}
  32485. +
  32486. +static inline void
  32487. +sdhci_platdma_reset(struct sdhci_host *host, struct mmc_data *data)
  32488. +{
  32489. + if (host->ops->pdma_reset)
  32490. + host->ops->pdma_reset(host, data);
  32491. +}
  32492. +
  32493. #ifdef CONFIG_PM_RUNTIME
  32494. extern int sdhci_runtime_suspend_host(struct sdhci_host *host);
  32495. extern int sdhci_runtime_resume_host(struct sdhci_host *host);
  32496. #endif
  32497. +extern void sdhci_spin_lock_irqsave(struct sdhci_host *host,unsigned long *flags);
  32498. +extern void sdhci_spin_unlock_irqrestore(struct sdhci_host *host,unsigned long flags);
  32499. +extern void sdhci_spin_lock(struct sdhci_host *host);
  32500. +extern void sdhci_spin_unlock(struct sdhci_host *host);
  32501. +
  32502. +
  32503. #endif /* __SDHCI_HW_H */
  32504. diff -Nur linux-3.15/drivers/net/usb/smsc95xx.c linux-rpi/drivers/net/usb/smsc95xx.c
  32505. --- linux-3.15/drivers/net/usb/smsc95xx.c 2014-06-08 20:19:54.000000000 +0200
  32506. +++ linux-rpi/drivers/net/usb/smsc95xx.c 2014-06-11 21:05:20.000000000 +0200
  32507. @@ -59,6 +59,7 @@
  32508. #define SUSPEND_SUSPEND3 (0x08)
  32509. #define SUSPEND_ALLMODES (SUSPEND_SUSPEND0 | SUSPEND_SUSPEND1 | \
  32510. SUSPEND_SUSPEND2 | SUSPEND_SUSPEND3)
  32511. +#define MAC_ADDR_LEN (6)
  32512. struct smsc95xx_priv {
  32513. u32 mac_cr;
  32514. @@ -74,6 +75,10 @@
  32515. module_param(turbo_mode, bool, 0644);
  32516. MODULE_PARM_DESC(turbo_mode, "Enable multiple frames per Rx transaction");
  32517. +static char *macaddr = ":";
  32518. +module_param(macaddr, charp, 0);
  32519. +MODULE_PARM_DESC(macaddr, "MAC address");
  32520. +
  32521. static int __must_check __smsc95xx_read_reg(struct usbnet *dev, u32 index,
  32522. u32 *data, int in_pm)
  32523. {
  32524. @@ -763,8 +768,59 @@
  32525. return generic_mii_ioctl(&dev->mii, if_mii(rq), cmd, NULL);
  32526. }
  32527. +/* Check the macaddr module parameter for a MAC address */
  32528. +static int smsc95xx_is_macaddr_param(struct usbnet *dev, u8 *dev_mac)
  32529. +{
  32530. + int i, j, got_num, num;
  32531. + u8 mtbl[MAC_ADDR_LEN];
  32532. +
  32533. + if (macaddr[0] == ':')
  32534. + return 0;
  32535. +
  32536. + i = 0;
  32537. + j = 0;
  32538. + num = 0;
  32539. + got_num = 0;
  32540. + while (j < MAC_ADDR_LEN) {
  32541. + if (macaddr[i] && macaddr[i] != ':') {
  32542. + got_num++;
  32543. + if ('0' <= macaddr[i] && macaddr[i] <= '9')
  32544. + num = num * 16 + macaddr[i] - '0';
  32545. + else if ('A' <= macaddr[i] && macaddr[i] <= 'F')
  32546. + num = num * 16 + 10 + macaddr[i] - 'A';
  32547. + else if ('a' <= macaddr[i] && macaddr[i] <= 'f')
  32548. + num = num * 16 + 10 + macaddr[i] - 'a';
  32549. + else
  32550. + break;
  32551. + i++;
  32552. + } else if (got_num == 2) {
  32553. + mtbl[j++] = (u8) num;
  32554. + num = 0;
  32555. + got_num = 0;
  32556. + i++;
  32557. + } else {
  32558. + break;
  32559. + }
  32560. + }
  32561. +
  32562. + if (j == MAC_ADDR_LEN) {
  32563. + netif_dbg(dev, ifup, dev->net, "Overriding MAC address with: "
  32564. + "%02x:%02x:%02x:%02x:%02x:%02x\n", mtbl[0], mtbl[1], mtbl[2],
  32565. + mtbl[3], mtbl[4], mtbl[5]);
  32566. + for (i = 0; i < MAC_ADDR_LEN; i++)
  32567. + dev_mac[i] = mtbl[i];
  32568. + return 1;
  32569. + } else {
  32570. + return 0;
  32571. + }
  32572. +}
  32573. +
  32574. static void smsc95xx_init_mac_address(struct usbnet *dev)
  32575. {
  32576. + /* Check module parameters */
  32577. + if (smsc95xx_is_macaddr_param(dev, dev->net->dev_addr))
  32578. + return;
  32579. +
  32580. /* try reading mac address from EEPROM */
  32581. if (smsc95xx_read_eeprom(dev, EEPROM_MAC_OFFSET, ETH_ALEN,
  32582. dev->net->dev_addr) == 0) {
  32583. diff -Nur linux-3.15/drivers/spi/Kconfig linux-rpi/drivers/spi/Kconfig
  32584. --- linux-3.15/drivers/spi/Kconfig 2014-06-08 20:19:54.000000000 +0200
  32585. +++ linux-rpi/drivers/spi/Kconfig 2014-06-11 21:05:30.000000000 +0200
  32586. @@ -85,6 +85,14 @@
  32587. is for the regular SPI controller. Slave mode operation is not also
  32588. not supported.
  32589. +config SPI_BCM2708
  32590. + tristate "BCM2708 SPI controller driver (SPI0)"
  32591. + depends on MACH_BCM2708
  32592. + help
  32593. + This selects a driver for the Broadcom BCM2708 SPI master (SPI0). This
  32594. + driver is not compatible with the "Universal SPI Master" or the SPI slave
  32595. + device.
  32596. +
  32597. config SPI_BFIN5XX
  32598. tristate "SPI controller driver for ADI Blackfin5xx"
  32599. depends on BLACKFIN && !BF60x
  32600. diff -Nur linux-3.15/drivers/spi/Makefile linux-rpi/drivers/spi/Makefile
  32601. --- linux-3.15/drivers/spi/Makefile 2014-06-08 20:19:54.000000000 +0200
  32602. +++ linux-rpi/drivers/spi/Makefile 2014-06-11 21:05:30.000000000 +0200
  32603. @@ -19,6 +19,7 @@
  32604. obj-$(CONFIG_SPI_BCM63XX_HSSPI) += spi-bcm63xx-hsspi.o
  32605. obj-$(CONFIG_SPI_BFIN5XX) += spi-bfin5xx.o
  32606. obj-$(CONFIG_SPI_BFIN_V3) += spi-bfin-v3.o
  32607. +obj-$(CONFIG_SPI_BCM2708) += spi-bcm2708.o
  32608. obj-$(CONFIG_SPI_BFIN_SPORT) += spi-bfin-sport.o
  32609. obj-$(CONFIG_SPI_BITBANG) += spi-bitbang.o
  32610. obj-$(CONFIG_SPI_BUTTERFLY) += spi-butterfly.o
  32611. diff -Nur linux-3.15/drivers/spi/spi-bcm2708.c linux-rpi/drivers/spi/spi-bcm2708.c
  32612. --- linux-3.15/drivers/spi/spi-bcm2708.c 1970-01-01 01:00:00.000000000 +0100
  32613. +++ linux-rpi/drivers/spi/spi-bcm2708.c 2014-06-11 21:05:30.000000000 +0200
  32614. @@ -0,0 +1,626 @@
  32615. +/*
  32616. + * Driver for Broadcom BCM2708 SPI Controllers
  32617. + *
  32618. + * Copyright (C) 2012 Chris Boot
  32619. + *
  32620. + * This driver is inspired by:
  32621. + * spi-ath79.c, Copyright (C) 2009-2011 Gabor Juhos <juhosg@openwrt.org>
  32622. + * spi-atmel.c, Copyright (C) 2006 Atmel Corporation
  32623. + *
  32624. + * This program is free software; you can redistribute it and/or modify
  32625. + * it under the terms of the GNU General Public License as published by
  32626. + * the Free Software Foundation; either version 2 of the License, or
  32627. + * (at your option) any later version.
  32628. + *
  32629. + * This program is distributed in the hope that it will be useful,
  32630. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  32631. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  32632. + * GNU General Public License for more details.
  32633. + *
  32634. + * You should have received a copy of the GNU General Public License
  32635. + * along with this program; if not, write to the Free Software
  32636. + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  32637. + */
  32638. +
  32639. +#include <linux/kernel.h>
  32640. +#include <linux/module.h>
  32641. +#include <linux/spinlock.h>
  32642. +#include <linux/clk.h>
  32643. +#include <linux/err.h>
  32644. +#include <linux/platform_device.h>
  32645. +#include <linux/io.h>
  32646. +#include <linux/spi/spi.h>
  32647. +#include <linux/interrupt.h>
  32648. +#include <linux/delay.h>
  32649. +#include <linux/log2.h>
  32650. +#include <linux/sched.h>
  32651. +#include <linux/wait.h>
  32652. +
  32653. +/* SPI register offsets */
  32654. +#define SPI_CS 0x00
  32655. +#define SPI_FIFO 0x04
  32656. +#define SPI_CLK 0x08
  32657. +#define SPI_DLEN 0x0c
  32658. +#define SPI_LTOH 0x10
  32659. +#define SPI_DC 0x14
  32660. +
  32661. +/* Bitfields in CS */
  32662. +#define SPI_CS_LEN_LONG 0x02000000
  32663. +#define SPI_CS_DMA_LEN 0x01000000
  32664. +#define SPI_CS_CSPOL2 0x00800000
  32665. +#define SPI_CS_CSPOL1 0x00400000
  32666. +#define SPI_CS_CSPOL0 0x00200000
  32667. +#define SPI_CS_RXF 0x00100000
  32668. +#define SPI_CS_RXR 0x00080000
  32669. +#define SPI_CS_TXD 0x00040000
  32670. +#define SPI_CS_RXD 0x00020000
  32671. +#define SPI_CS_DONE 0x00010000
  32672. +#define SPI_CS_LEN 0x00002000
  32673. +#define SPI_CS_REN 0x00001000
  32674. +#define SPI_CS_ADCS 0x00000800
  32675. +#define SPI_CS_INTR 0x00000400
  32676. +#define SPI_CS_INTD 0x00000200
  32677. +#define SPI_CS_DMAEN 0x00000100
  32678. +#define SPI_CS_TA 0x00000080
  32679. +#define SPI_CS_CSPOL 0x00000040
  32680. +#define SPI_CS_CLEAR_RX 0x00000020
  32681. +#define SPI_CS_CLEAR_TX 0x00000010
  32682. +#define SPI_CS_CPOL 0x00000008
  32683. +#define SPI_CS_CPHA 0x00000004
  32684. +#define SPI_CS_CS_10 0x00000002
  32685. +#define SPI_CS_CS_01 0x00000001
  32686. +
  32687. +#define SPI_TIMEOUT_MS 150
  32688. +
  32689. +#define DRV_NAME "bcm2708_spi"
  32690. +
  32691. +struct bcm2708_spi {
  32692. + spinlock_t lock;
  32693. + void __iomem *base;
  32694. + int irq;
  32695. + struct clk *clk;
  32696. + bool stopping;
  32697. +
  32698. + struct list_head queue;
  32699. + struct workqueue_struct *workq;
  32700. + struct work_struct work;
  32701. + struct completion done;
  32702. +
  32703. + const u8 *tx_buf;
  32704. + u8 *rx_buf;
  32705. + int len;
  32706. +};
  32707. +
  32708. +struct bcm2708_spi_state {
  32709. + u32 cs;
  32710. + u16 cdiv;
  32711. +};
  32712. +
  32713. +/*
  32714. + * This function sets the ALT mode on the SPI pins so that we can use them with
  32715. + * the SPI hardware.
  32716. + *
  32717. + * FIXME: This is a hack. Use pinmux / pinctrl.
  32718. + */
  32719. +static void bcm2708_init_pinmode(void)
  32720. +{
  32721. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  32722. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  32723. +
  32724. + int pin;
  32725. + u32 *gpio = ioremap(GPIO_BASE, SZ_16K);
  32726. +
  32727. + /* SPI is on GPIO 7..11 */
  32728. + for (pin = 7; pin <= 11; pin++) {
  32729. + INP_GPIO(pin); /* set mode to GPIO input first */
  32730. + SET_GPIO_ALT(pin, 0); /* set mode to ALT 0 */
  32731. + }
  32732. +
  32733. + iounmap(gpio);
  32734. +
  32735. +#undef INP_GPIO
  32736. +#undef SET_GPIO_ALT
  32737. +}
  32738. +
  32739. +static inline u32 bcm2708_rd(struct bcm2708_spi *bs, unsigned reg)
  32740. +{
  32741. + return readl(bs->base + reg);
  32742. +}
  32743. +
  32744. +static inline void bcm2708_wr(struct bcm2708_spi *bs, unsigned reg, u32 val)
  32745. +{
  32746. + writel(val, bs->base + reg);
  32747. +}
  32748. +
  32749. +static inline void bcm2708_rd_fifo(struct bcm2708_spi *bs, int len)
  32750. +{
  32751. + u8 byte;
  32752. +
  32753. + while (len--) {
  32754. + byte = bcm2708_rd(bs, SPI_FIFO);
  32755. + if (bs->rx_buf)
  32756. + *bs->rx_buf++ = byte;
  32757. + }
  32758. +}
  32759. +
  32760. +static inline void bcm2708_wr_fifo(struct bcm2708_spi *bs, int len)
  32761. +{
  32762. + u8 byte;
  32763. + u16 val;
  32764. +
  32765. + if (len > bs->len)
  32766. + len = bs->len;
  32767. +
  32768. + if (unlikely(bcm2708_rd(bs, SPI_CS) & SPI_CS_LEN)) {
  32769. + /* LoSSI mode */
  32770. + if (unlikely(len % 2)) {
  32771. + printk(KERN_ERR"bcm2708_wr_fifo: length must be even, skipping.\n");
  32772. + bs->len = 0;
  32773. + return;
  32774. + }
  32775. + while (len) {
  32776. + if (bs->tx_buf) {
  32777. + val = *(const u16 *)bs->tx_buf;
  32778. + bs->tx_buf += 2;
  32779. + } else
  32780. + val = 0;
  32781. + bcm2708_wr(bs, SPI_FIFO, val);
  32782. + bs->len -= 2;
  32783. + len -= 2;
  32784. + }
  32785. + return;
  32786. + }
  32787. +
  32788. + while (len--) {
  32789. + byte = bs->tx_buf ? *bs->tx_buf++ : 0;
  32790. + bcm2708_wr(bs, SPI_FIFO, byte);
  32791. + bs->len--;
  32792. + }
  32793. +}
  32794. +
  32795. +static irqreturn_t bcm2708_spi_interrupt(int irq, void *dev_id)
  32796. +{
  32797. + struct spi_master *master = dev_id;
  32798. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32799. + u32 cs;
  32800. +
  32801. + spin_lock(&bs->lock);
  32802. +
  32803. + cs = bcm2708_rd(bs, SPI_CS);
  32804. +
  32805. + if (cs & SPI_CS_DONE) {
  32806. + if (bs->len) { /* first interrupt in a transfer */
  32807. + /* fill the TX fifo with up to 16 bytes */
  32808. + bcm2708_wr_fifo(bs, 16);
  32809. + } else { /* transfer complete */
  32810. + /* disable interrupts */
  32811. + cs &= ~(SPI_CS_INTR | SPI_CS_INTD);
  32812. + bcm2708_wr(bs, SPI_CS, cs);
  32813. +
  32814. + /* drain RX FIFO */
  32815. + while (cs & SPI_CS_RXD) {
  32816. + bcm2708_rd_fifo(bs, 1);
  32817. + cs = bcm2708_rd(bs, SPI_CS);
  32818. + }
  32819. +
  32820. + /* wake up our bh */
  32821. + complete(&bs->done);
  32822. + }
  32823. + } else if (cs & SPI_CS_RXR) {
  32824. + /* read 12 bytes of data */
  32825. + bcm2708_rd_fifo(bs, 12);
  32826. +
  32827. + /* write up to 12 bytes */
  32828. + bcm2708_wr_fifo(bs, 12);
  32829. + }
  32830. +
  32831. + spin_unlock(&bs->lock);
  32832. +
  32833. + return IRQ_HANDLED;
  32834. +}
  32835. +
  32836. +static int bcm2708_setup_state(struct spi_master *master,
  32837. + struct device *dev, struct bcm2708_spi_state *state,
  32838. + u32 hz, u8 csel, u8 mode, u8 bpw)
  32839. +{
  32840. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  32841. + int cdiv;
  32842. + unsigned long bus_hz;
  32843. + u32 cs = 0;
  32844. +
  32845. + bus_hz = clk_get_rate(bs->clk);
  32846. +
  32847. + if (hz >= bus_hz) {
  32848. + cdiv = 2; /* bus_hz / 2 is as fast as we can go */
  32849. + } else if (hz) {
  32850. + cdiv = DIV_ROUND_UP(bus_hz, hz);
  32851. +
  32852. + /* CDIV must be a power of 2, so round up */
  32853. + cdiv = roundup_pow_of_two(cdiv);
  32854. +
  32855. + if (cdiv > 65536) {
  32856. + dev_dbg(dev,
  32857. + "setup: %d Hz too slow, cdiv %u; min %ld Hz\n",
  32858. + hz, cdiv, bus_hz / 65536);
  32859. + return -EINVAL;
  32860. + } else if (cdiv == 65536) {
  32861. + cdiv = 0;
  32862. + } else if (cdiv == 1) {
  32863. + cdiv = 2; /* 1 gets rounded down to 0; == 65536 */
  32864. + }
  32865. + } else {
  32866. + cdiv = 0;
  32867. + }
  32868. +
  32869. + switch (bpw) {
  32870. + case 8:
  32871. + break;
  32872. + case 9:
  32873. + /* Reading in LoSSI mode is a special case. See 'BCM2835 ARM Peripherals' datasheet */
  32874. + cs |= SPI_CS_LEN;
  32875. + break;
  32876. + default:
  32877. + dev_dbg(dev, "setup: invalid bits_per_word %u (must be 8 or 9)\n",
  32878. + bpw);
  32879. + return -EINVAL;
  32880. + }
  32881. +
  32882. + if (mode & SPI_CPOL)
  32883. + cs |= SPI_CS_CPOL;
  32884. + if (mode & SPI_CPHA)
  32885. + cs |= SPI_CS_CPHA;
  32886. +
  32887. + if (!(mode & SPI_NO_CS)) {
  32888. + if (mode & SPI_CS_HIGH) {
  32889. + cs |= SPI_CS_CSPOL;
  32890. + cs |= SPI_CS_CSPOL0 << csel;
  32891. + }
  32892. +
  32893. + cs |= csel;
  32894. + } else {
  32895. + cs |= SPI_CS_CS_10 | SPI_CS_CS_01;
  32896. + }
  32897. +
  32898. + if (state) {
  32899. + state->cs = cs;
  32900. + state->cdiv = cdiv;
  32901. + dev_dbg(dev, "setup: want %d Hz; "
  32902. + "bus_hz=%lu / cdiv=%u == %lu Hz; "
  32903. + "mode %u: cs 0x%08X\n",
  32904. + hz, bus_hz, cdiv, bus_hz/cdiv, mode, cs);
  32905. + }
  32906. +
  32907. + return 0;
  32908. +}
  32909. +
  32910. +static int bcm2708_process_transfer(struct bcm2708_spi *bs,
  32911. + struct spi_message *msg, struct spi_transfer *xfer)
  32912. +{
  32913. + struct spi_device *spi = msg->spi;
  32914. + struct bcm2708_spi_state state, *stp;
  32915. + int ret;
  32916. + u32 cs;
  32917. +
  32918. + if (bs->stopping)
  32919. + return -ESHUTDOWN;
  32920. +
  32921. + if (xfer->bits_per_word || xfer->speed_hz) {
  32922. + ret = bcm2708_setup_state(spi->master, &spi->dev, &state,
  32923. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  32924. + spi->chip_select, spi->mode,
  32925. + xfer->bits_per_word ? xfer->bits_per_word :
  32926. + spi->bits_per_word);
  32927. + if (ret)
  32928. + return ret;
  32929. +
  32930. + stp = &state;
  32931. + } else {
  32932. + stp = spi->controller_state;
  32933. + }
  32934. +
  32935. + reinit_completion(&bs->done);
  32936. + bs->tx_buf = xfer->tx_buf;
  32937. + bs->rx_buf = xfer->rx_buf;
  32938. + bs->len = xfer->len;
  32939. +
  32940. + cs = stp->cs | SPI_CS_INTR | SPI_CS_INTD | SPI_CS_TA;
  32941. +
  32942. + bcm2708_wr(bs, SPI_CLK, stp->cdiv);
  32943. + bcm2708_wr(bs, SPI_CS, cs);
  32944. +
  32945. + ret = wait_for_completion_timeout(&bs->done,
  32946. + msecs_to_jiffies(SPI_TIMEOUT_MS));
  32947. + if (ret == 0) {
  32948. + dev_err(&spi->dev, "transfer timed out\n");
  32949. + return -ETIMEDOUT;
  32950. + }
  32951. +
  32952. + if (xfer->delay_usecs)
  32953. + udelay(xfer->delay_usecs);
  32954. +
  32955. + if (list_is_last(&xfer->transfer_list, &msg->transfers) ||
  32956. + xfer->cs_change) {
  32957. + /* clear TA and interrupt flags */
  32958. + bcm2708_wr(bs, SPI_CS, stp->cs);
  32959. + }
  32960. +
  32961. + msg->actual_length += (xfer->len - bs->len);
  32962. +
  32963. + return 0;
  32964. +}
  32965. +
  32966. +static void bcm2708_work(struct work_struct *work)
  32967. +{
  32968. + struct bcm2708_spi *bs = container_of(work, struct bcm2708_spi, work);
  32969. + unsigned long flags;
  32970. + struct spi_message *msg;
  32971. + struct spi_transfer *xfer;
  32972. + int status = 0;
  32973. +
  32974. + spin_lock_irqsave(&bs->lock, flags);
  32975. + while (!list_empty(&bs->queue)) {
  32976. + msg = list_first_entry(&bs->queue, struct spi_message, queue);
  32977. + list_del_init(&msg->queue);
  32978. + spin_unlock_irqrestore(&bs->lock, flags);
  32979. +
  32980. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  32981. + status = bcm2708_process_transfer(bs, msg, xfer);
  32982. + if (status)
  32983. + break;
  32984. + }
  32985. +
  32986. + msg->status = status;
  32987. + msg->complete(msg->context);
  32988. +
  32989. + spin_lock_irqsave(&bs->lock, flags);
  32990. + }
  32991. + spin_unlock_irqrestore(&bs->lock, flags);
  32992. +}
  32993. +
  32994. +static int bcm2708_spi_setup(struct spi_device *spi)
  32995. +{
  32996. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  32997. + struct bcm2708_spi_state *state;
  32998. + int ret;
  32999. +
  33000. + if (bs->stopping)
  33001. + return -ESHUTDOWN;
  33002. +
  33003. + if (!(spi->mode & SPI_NO_CS) &&
  33004. + (spi->chip_select > spi->master->num_chipselect)) {
  33005. + dev_dbg(&spi->dev,
  33006. + "setup: invalid chipselect %u (%u defined)\n",
  33007. + spi->chip_select, spi->master->num_chipselect);
  33008. + return -EINVAL;
  33009. + }
  33010. +
  33011. + state = spi->controller_state;
  33012. + if (!state) {
  33013. + state = kzalloc(sizeof(*state), GFP_KERNEL);
  33014. + if (!state)
  33015. + return -ENOMEM;
  33016. +
  33017. + spi->controller_state = state;
  33018. + }
  33019. +
  33020. + ret = bcm2708_setup_state(spi->master, &spi->dev, state,
  33021. + spi->max_speed_hz, spi->chip_select, spi->mode,
  33022. + spi->bits_per_word);
  33023. + if (ret < 0) {
  33024. + kfree(state);
  33025. + spi->controller_state = NULL;
  33026. + return ret;
  33027. + }
  33028. +
  33029. + dev_dbg(&spi->dev,
  33030. + "setup: cd %d: %d Hz, bpw %u, mode 0x%x -> CS=%08x CDIV=%04x\n",
  33031. + spi->chip_select, spi->max_speed_hz, spi->bits_per_word,
  33032. + spi->mode, state->cs, state->cdiv);
  33033. +
  33034. + return 0;
  33035. +}
  33036. +
  33037. +static int bcm2708_spi_transfer(struct spi_device *spi, struct spi_message *msg)
  33038. +{
  33039. + struct bcm2708_spi *bs = spi_master_get_devdata(spi->master);
  33040. + struct spi_transfer *xfer;
  33041. + int ret;
  33042. + unsigned long flags;
  33043. +
  33044. + if (unlikely(list_empty(&msg->transfers)))
  33045. + return -EINVAL;
  33046. +
  33047. + if (bs->stopping)
  33048. + return -ESHUTDOWN;
  33049. +
  33050. + list_for_each_entry(xfer, &msg->transfers, transfer_list) {
  33051. + if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) {
  33052. + dev_dbg(&spi->dev, "missing rx or tx buf\n");
  33053. + return -EINVAL;
  33054. + }
  33055. +
  33056. + if (!xfer->bits_per_word || xfer->speed_hz)
  33057. + continue;
  33058. +
  33059. + ret = bcm2708_setup_state(spi->master, &spi->dev, NULL,
  33060. + xfer->speed_hz ? xfer->speed_hz : spi->max_speed_hz,
  33061. + spi->chip_select, spi->mode,
  33062. + xfer->bits_per_word ? xfer->bits_per_word :
  33063. + spi->bits_per_word);
  33064. + if (ret)
  33065. + return ret;
  33066. + }
  33067. +
  33068. + msg->status = -EINPROGRESS;
  33069. + msg->actual_length = 0;
  33070. +
  33071. + spin_lock_irqsave(&bs->lock, flags);
  33072. + list_add_tail(&msg->queue, &bs->queue);
  33073. + queue_work(bs->workq, &bs->work);
  33074. + spin_unlock_irqrestore(&bs->lock, flags);
  33075. +
  33076. + return 0;
  33077. +}
  33078. +
  33079. +static void bcm2708_spi_cleanup(struct spi_device *spi)
  33080. +{
  33081. + if (spi->controller_state) {
  33082. + kfree(spi->controller_state);
  33083. + spi->controller_state = NULL;
  33084. + }
  33085. +}
  33086. +
  33087. +static int bcm2708_spi_probe(struct platform_device *pdev)
  33088. +{
  33089. + struct resource *regs;
  33090. + int irq, err = -ENOMEM;
  33091. + struct clk *clk;
  33092. + struct spi_master *master;
  33093. + struct bcm2708_spi *bs;
  33094. +
  33095. + regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  33096. + if (!regs) {
  33097. + dev_err(&pdev->dev, "could not get IO memory\n");
  33098. + return -ENXIO;
  33099. + }
  33100. +
  33101. + irq = platform_get_irq(pdev, 0);
  33102. + if (irq < 0) {
  33103. + dev_err(&pdev->dev, "could not get IRQ\n");
  33104. + return irq;
  33105. + }
  33106. +
  33107. + clk = clk_get(&pdev->dev, NULL);
  33108. + if (IS_ERR(clk)) {
  33109. + dev_err(&pdev->dev, "could not find clk: %ld\n", PTR_ERR(clk));
  33110. + return PTR_ERR(clk);
  33111. + }
  33112. +
  33113. + bcm2708_init_pinmode();
  33114. +
  33115. + master = spi_alloc_master(&pdev->dev, sizeof(*bs));
  33116. + if (!master) {
  33117. + dev_err(&pdev->dev, "spi_alloc_master() failed\n");
  33118. + goto out_clk_put;
  33119. + }
  33120. +
  33121. + /* the spi->mode bits understood by this driver: */
  33122. + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_NO_CS;
  33123. +
  33124. + master->bus_num = pdev->id;
  33125. + master->num_chipselect = 3;
  33126. + master->setup = bcm2708_spi_setup;
  33127. + master->transfer = bcm2708_spi_transfer;
  33128. + master->cleanup = bcm2708_spi_cleanup;
  33129. + platform_set_drvdata(pdev, master);
  33130. +
  33131. + bs = spi_master_get_devdata(master);
  33132. +
  33133. + spin_lock_init(&bs->lock);
  33134. + INIT_LIST_HEAD(&bs->queue);
  33135. + init_completion(&bs->done);
  33136. + INIT_WORK(&bs->work, bcm2708_work);
  33137. +
  33138. + bs->base = ioremap(regs->start, resource_size(regs));
  33139. + if (!bs->base) {
  33140. + dev_err(&pdev->dev, "could not remap memory\n");
  33141. + goto out_master_put;
  33142. + }
  33143. +
  33144. + bs->workq = create_singlethread_workqueue(dev_name(&pdev->dev));
  33145. + if (!bs->workq) {
  33146. + dev_err(&pdev->dev, "could not create workqueue\n");
  33147. + goto out_iounmap;
  33148. + }
  33149. +
  33150. + bs->irq = irq;
  33151. + bs->clk = clk;
  33152. + bs->stopping = false;
  33153. +
  33154. + err = request_irq(irq, bcm2708_spi_interrupt, 0, dev_name(&pdev->dev),
  33155. + master);
  33156. + if (err) {
  33157. + dev_err(&pdev->dev, "could not request IRQ: %d\n", err);
  33158. + goto out_workqueue;
  33159. + }
  33160. +
  33161. + /* initialise the hardware */
  33162. + clk_enable(clk);
  33163. + bcm2708_wr(bs, SPI_CS, SPI_CS_REN | SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33164. +
  33165. + err = spi_register_master(master);
  33166. + if (err) {
  33167. + dev_err(&pdev->dev, "could not register SPI master: %d\n", err);
  33168. + goto out_free_irq;
  33169. + }
  33170. +
  33171. + dev_info(&pdev->dev, "SPI Controller at 0x%08lx (irq %d)\n",
  33172. + (unsigned long)regs->start, irq);
  33173. +
  33174. + return 0;
  33175. +
  33176. +out_free_irq:
  33177. + free_irq(bs->irq, master);
  33178. +out_workqueue:
  33179. + destroy_workqueue(bs->workq);
  33180. +out_iounmap:
  33181. + iounmap(bs->base);
  33182. +out_master_put:
  33183. + spi_master_put(master);
  33184. +out_clk_put:
  33185. + clk_put(clk);
  33186. + return err;
  33187. +}
  33188. +
  33189. +static int bcm2708_spi_remove(struct platform_device *pdev)
  33190. +{
  33191. + struct spi_master *master = platform_get_drvdata(pdev);
  33192. + struct bcm2708_spi *bs = spi_master_get_devdata(master);
  33193. +
  33194. + /* reset the hardware and block queue progress */
  33195. + spin_lock_irq(&bs->lock);
  33196. + bs->stopping = true;
  33197. + bcm2708_wr(bs, SPI_CS, SPI_CS_CLEAR_RX | SPI_CS_CLEAR_TX);
  33198. + spin_unlock_irq(&bs->lock);
  33199. +
  33200. + flush_work_sync(&bs->work);
  33201. +
  33202. + clk_disable(bs->clk);
  33203. + clk_put(bs->clk);
  33204. + free_irq(bs->irq, master);
  33205. + iounmap(bs->base);
  33206. +
  33207. + spi_unregister_master(master);
  33208. +
  33209. + return 0;
  33210. +}
  33211. +
  33212. +static struct platform_driver bcm2708_spi_driver = {
  33213. + .driver = {
  33214. + .name = DRV_NAME,
  33215. + .owner = THIS_MODULE,
  33216. + },
  33217. + .probe = bcm2708_spi_probe,
  33218. + .remove = bcm2708_spi_remove,
  33219. +};
  33220. +
  33221. +
  33222. +static int __init bcm2708_spi_init(void)
  33223. +{
  33224. + return platform_driver_probe(&bcm2708_spi_driver, bcm2708_spi_probe);
  33225. +}
  33226. +module_init(bcm2708_spi_init);
  33227. +
  33228. +static void __exit bcm2708_spi_exit(void)
  33229. +{
  33230. + platform_driver_unregister(&bcm2708_spi_driver);
  33231. +}
  33232. +module_exit(bcm2708_spi_exit);
  33233. +
  33234. +
  33235. +//module_platform_driver(bcm2708_spi_driver);
  33236. +
  33237. +MODULE_DESCRIPTION("SPI controller driver for Broadcom BCM2708");
  33238. +MODULE_AUTHOR("Chris Boot <bootc@bootc.net>");
  33239. +MODULE_LICENSE("GPL v2");
  33240. +MODULE_ALIAS("platform:" DRV_NAME);
  33241. diff -Nur linux-3.15/drivers/staging/media/lirc/Kconfig linux-rpi/drivers/staging/media/lirc/Kconfig
  33242. --- linux-3.15/drivers/staging/media/lirc/Kconfig 2014-06-08 20:19:54.000000000 +0200
  33243. +++ linux-rpi/drivers/staging/media/lirc/Kconfig 2014-06-11 21:03:39.000000000 +0200
  33244. @@ -38,6 +38,12 @@
  33245. help
  33246. Driver for Homebrew Parallel Port Receivers
  33247. +config LIRC_RPI
  33248. + tristate "Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi"
  33249. + depends on LIRC
  33250. + help
  33251. + Driver for Homebrew GPIO Port Receiver/Transmitter for the RaspberryPi
  33252. +
  33253. config LIRC_SASEM
  33254. tristate "Sasem USB IR Remote"
  33255. depends on LIRC && USB
  33256. diff -Nur linux-3.15/drivers/staging/media/lirc/lirc_rpi.c linux-rpi/drivers/staging/media/lirc/lirc_rpi.c
  33257. --- linux-3.15/drivers/staging/media/lirc/lirc_rpi.c 1970-01-01 01:00:00.000000000 +0100
  33258. +++ linux-rpi/drivers/staging/media/lirc/lirc_rpi.c 2014-06-11 21:05:30.000000000 +0200
  33259. @@ -0,0 +1,695 @@
  33260. +/*
  33261. + * lirc_rpi.c
  33262. + *
  33263. + * lirc_rpi - Device driver that records pulse- and pause-lengths
  33264. + * (space-lengths) (just like the lirc_serial driver does)
  33265. + * between GPIO interrupt events on the Raspberry Pi.
  33266. + * Lots of code has been taken from the lirc_serial module,
  33267. + * so I would like say thanks to the authors.
  33268. + *
  33269. + * Copyright (C) 2012 Aron Robert Szabo <aron@reon.hu>,
  33270. + * Michael Bishop <cleverca22@gmail.com>
  33271. + * This program is free software; you can redistribute it and/or modify
  33272. + * it under the terms of the GNU General Public License as published by
  33273. + * the Free Software Foundation; either version 2 of the License, or
  33274. + * (at your option) any later version.
  33275. + *
  33276. + * This program is distributed in the hope that it will be useful,
  33277. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  33278. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  33279. + * GNU General Public License for more details.
  33280. + *
  33281. + * You should have received a copy of the GNU General Public License
  33282. + * along with this program; if not, write to the Free Software
  33283. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  33284. + */
  33285. +
  33286. +#include <linux/module.h>
  33287. +#include <linux/errno.h>
  33288. +#include <linux/interrupt.h>
  33289. +#include <linux/sched.h>
  33290. +#include <linux/kernel.h>
  33291. +#include <linux/time.h>
  33292. +#include <linux/timex.h>
  33293. +#include <linux/string.h>
  33294. +#include <linux/delay.h>
  33295. +#include <linux/platform_device.h>
  33296. +#include <linux/irq.h>
  33297. +#include <linux/spinlock.h>
  33298. +#include <media/lirc.h>
  33299. +#include <media/lirc_dev.h>
  33300. +#include <linux/gpio.h>
  33301. +
  33302. +#define LIRC_DRIVER_NAME "lirc_rpi"
  33303. +#define RBUF_LEN 256
  33304. +#define LIRC_TRANSMITTER_LATENCY 50
  33305. +
  33306. +#ifndef MAX_UDELAY_MS
  33307. +#define MAX_UDELAY_US 5000
  33308. +#else
  33309. +#define MAX_UDELAY_US (MAX_UDELAY_MS*1000)
  33310. +#endif
  33311. +
  33312. +#define dprintk(fmt, args...) \
  33313. + do { \
  33314. + if (debug) \
  33315. + printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \
  33316. + fmt, ## args); \
  33317. + } while (0)
  33318. +
  33319. +/* module parameters */
  33320. +
  33321. +/* set the default GPIO input pin */
  33322. +static int gpio_in_pin = 18;
  33323. +/* set the default GPIO output pin */
  33324. +static int gpio_out_pin = 17;
  33325. +/* enable debugging messages */
  33326. +static bool debug;
  33327. +/* -1 = auto, 0 = active high, 1 = active low */
  33328. +static int sense = -1;
  33329. +/* use softcarrier by default */
  33330. +static bool softcarrier = 1;
  33331. +/* 0 = do not invert output, 1 = invert output */
  33332. +static bool invert = 0;
  33333. +
  33334. +struct gpio_chip *gpiochip;
  33335. +struct irq_chip *irqchip;
  33336. +struct irq_data *irqdata;
  33337. +
  33338. +/* forward declarations */
  33339. +static long send_pulse(unsigned long length);
  33340. +static void send_space(long length);
  33341. +static void lirc_rpi_exit(void);
  33342. +
  33343. +int valid_gpio_pins[] = { 0, 1, 2, 3, 4, 7, 8, 9, 10, 11, 14, 15, 17, 18, 21,
  33344. + 22, 23, 24, 25 ,27, 28, 29, 30, 31 };
  33345. +
  33346. +static struct platform_device *lirc_rpi_dev;
  33347. +static struct timeval lasttv = { 0, 0 };
  33348. +static struct lirc_buffer rbuf;
  33349. +static spinlock_t lock;
  33350. +
  33351. +/* initialized/set in init_timing_params() */
  33352. +static unsigned int freq = 38000;
  33353. +static unsigned int duty_cycle = 50;
  33354. +static unsigned long period;
  33355. +static unsigned long pulse_width;
  33356. +static unsigned long space_width;
  33357. +
  33358. +static void safe_udelay(unsigned long usecs)
  33359. +{
  33360. + while (usecs > MAX_UDELAY_US) {
  33361. + udelay(MAX_UDELAY_US);
  33362. + usecs -= MAX_UDELAY_US;
  33363. + }
  33364. + udelay(usecs);
  33365. +}
  33366. +
  33367. +static int init_timing_params(unsigned int new_duty_cycle,
  33368. + unsigned int new_freq)
  33369. +{
  33370. + if (1000 * 1000000L / new_freq * new_duty_cycle / 100 <=
  33371. + LIRC_TRANSMITTER_LATENCY)
  33372. + return -EINVAL;
  33373. + if (1000 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <=
  33374. + LIRC_TRANSMITTER_LATENCY)
  33375. + return -EINVAL;
  33376. + duty_cycle = new_duty_cycle;
  33377. + freq = new_freq;
  33378. + period = 1000 * 1000000L / freq;
  33379. + pulse_width = period * duty_cycle / 100;
  33380. + space_width = period - pulse_width;
  33381. + dprintk("in init_timing_params, freq=%d pulse=%ld, "
  33382. + "space=%ld\n", freq, pulse_width, space_width);
  33383. + return 0;
  33384. +}
  33385. +
  33386. +static long send_pulse_softcarrier(unsigned long length)
  33387. +{
  33388. + int flag;
  33389. + unsigned long actual, target;
  33390. + unsigned long actual_us, initial_us, target_us;
  33391. +
  33392. + length *= 1000;
  33393. +
  33394. + actual = 0; target = 0; flag = 0;
  33395. + read_current_timer(&actual_us);
  33396. +
  33397. + while (actual < length) {
  33398. + if (flag) {
  33399. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33400. + target += space_width;
  33401. + } else {
  33402. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33403. + target += pulse_width;
  33404. + }
  33405. + initial_us = actual_us;
  33406. + target_us = actual_us + (target - actual) / 1000;
  33407. + /*
  33408. + * Note - we've checked in ioctl that the pulse/space
  33409. + * widths are big enough so that d is > 0
  33410. + */
  33411. + if ((int)(target_us - actual_us) > 0)
  33412. + udelay(target_us - actual_us);
  33413. + read_current_timer(&actual_us);
  33414. + actual += (actual_us - initial_us) * 1000;
  33415. + flag = !flag;
  33416. + }
  33417. + return (actual-length) / 1000;
  33418. +}
  33419. +
  33420. +static long send_pulse(unsigned long length)
  33421. +{
  33422. + if (length <= 0)
  33423. + return 0;
  33424. +
  33425. + if (softcarrier) {
  33426. + return send_pulse_softcarrier(length);
  33427. + } else {
  33428. + gpiochip->set(gpiochip, gpio_out_pin, !invert);
  33429. + safe_udelay(length);
  33430. + return 0;
  33431. + }
  33432. +}
  33433. +
  33434. +static void send_space(long length)
  33435. +{
  33436. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33437. + if (length <= 0)
  33438. + return;
  33439. + safe_udelay(length);
  33440. +}
  33441. +
  33442. +static void rbwrite(int l)
  33443. +{
  33444. + if (lirc_buffer_full(&rbuf)) {
  33445. + /* no new signals will be accepted */
  33446. + dprintk("Buffer overrun\n");
  33447. + return;
  33448. + }
  33449. + lirc_buffer_write(&rbuf, (void *)&l);
  33450. +}
  33451. +
  33452. +static void frbwrite(int l)
  33453. +{
  33454. + /* simple noise filter */
  33455. + static int pulse, space;
  33456. + static unsigned int ptr;
  33457. +
  33458. + if (ptr > 0 && (l & PULSE_BIT)) {
  33459. + pulse += l & PULSE_MASK;
  33460. + if (pulse > 250) {
  33461. + rbwrite(space);
  33462. + rbwrite(pulse | PULSE_BIT);
  33463. + ptr = 0;
  33464. + pulse = 0;
  33465. + }
  33466. + return;
  33467. + }
  33468. + if (!(l & PULSE_BIT)) {
  33469. + if (ptr == 0) {
  33470. + if (l > 20000) {
  33471. + space = l;
  33472. + ptr++;
  33473. + return;
  33474. + }
  33475. + } else {
  33476. + if (l > 20000) {
  33477. + space += pulse;
  33478. + if (space > PULSE_MASK)
  33479. + space = PULSE_MASK;
  33480. + space += l;
  33481. + if (space > PULSE_MASK)
  33482. + space = PULSE_MASK;
  33483. + pulse = 0;
  33484. + return;
  33485. + }
  33486. + rbwrite(space);
  33487. + rbwrite(pulse | PULSE_BIT);
  33488. + ptr = 0;
  33489. + pulse = 0;
  33490. + }
  33491. + }
  33492. + rbwrite(l);
  33493. +}
  33494. +
  33495. +static irqreturn_t irq_handler(int i, void *blah, struct pt_regs *regs)
  33496. +{
  33497. + struct timeval tv;
  33498. + long deltv;
  33499. + int data;
  33500. + int signal;
  33501. +
  33502. + /* use the GPIO signal level */
  33503. + signal = gpiochip->get(gpiochip, gpio_in_pin);
  33504. +
  33505. + /* unmask the irq */
  33506. + irqchip->irq_unmask(irqdata);
  33507. +
  33508. + if (sense != -1) {
  33509. + /* get current time */
  33510. + do_gettimeofday(&tv);
  33511. +
  33512. + /* calc time since last interrupt in microseconds */
  33513. + deltv = tv.tv_sec-lasttv.tv_sec;
  33514. + if (tv.tv_sec < lasttv.tv_sec ||
  33515. + (tv.tv_sec == lasttv.tv_sec &&
  33516. + tv.tv_usec < lasttv.tv_usec)) {
  33517. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33518. + ": AIEEEE: your clock just jumped backwards\n");
  33519. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33520. + ": %d %d %lx %lx %lx %lx\n", signal, sense,
  33521. + tv.tv_sec, lasttv.tv_sec,
  33522. + tv.tv_usec, lasttv.tv_usec);
  33523. + data = PULSE_MASK;
  33524. + } else if (deltv > 15) {
  33525. + data = PULSE_MASK; /* really long time */
  33526. + if (!(signal^sense)) {
  33527. + /* sanity check */
  33528. + printk(KERN_WARNING LIRC_DRIVER_NAME
  33529. + ": AIEEEE: %d %d %lx %lx %lx %lx\n",
  33530. + signal, sense, tv.tv_sec, lasttv.tv_sec,
  33531. + tv.tv_usec, lasttv.tv_usec);
  33532. + /*
  33533. + * detecting pulse while this
  33534. + * MUST be a space!
  33535. + */
  33536. + sense = sense ? 0 : 1;
  33537. + }
  33538. + } else {
  33539. + data = (int) (deltv*1000000 +
  33540. + (tv.tv_usec - lasttv.tv_usec));
  33541. + }
  33542. + frbwrite(signal^sense ? data : (data|PULSE_BIT));
  33543. + lasttv = tv;
  33544. + wake_up_interruptible(&rbuf.wait_poll);
  33545. + }
  33546. +
  33547. + return IRQ_HANDLED;
  33548. +}
  33549. +
  33550. +static int is_right_chip(struct gpio_chip *chip, void *data)
  33551. +{
  33552. + dprintk("is_right_chip %s %d\n", chip->label, strcmp(data, chip->label));
  33553. +
  33554. + if (strcmp(data, chip->label) == 0)
  33555. + return 1;
  33556. + return 0;
  33557. +}
  33558. +
  33559. +static int init_port(void)
  33560. +{
  33561. + int i, nlow, nhigh, ret, irq;
  33562. +
  33563. + gpiochip = gpiochip_find("bcm2708_gpio", is_right_chip);
  33564. +
  33565. + if (!gpiochip)
  33566. + return -ENODEV;
  33567. +
  33568. + if (gpio_request(gpio_out_pin, LIRC_DRIVER_NAME " ir/out")) {
  33569. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33570. + ": cant claim gpio pin %d\n", gpio_out_pin);
  33571. + ret = -ENODEV;
  33572. + goto exit_init_port;
  33573. + }
  33574. +
  33575. + if (gpio_request(gpio_in_pin, LIRC_DRIVER_NAME " ir/in")) {
  33576. + printk(KERN_ALERT LIRC_DRIVER_NAME
  33577. + ": cant claim gpio pin %d\n", gpio_in_pin);
  33578. + ret = -ENODEV;
  33579. + goto exit_gpio_free_out_pin;
  33580. + }
  33581. +
  33582. + gpiochip->direction_input(gpiochip, gpio_in_pin);
  33583. + gpiochip->direction_output(gpiochip, gpio_out_pin, 1);
  33584. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33585. +
  33586. + irq = gpiochip->to_irq(gpiochip, gpio_in_pin);
  33587. + dprintk("to_irq %d\n", irq);
  33588. + irqdata = irq_get_irq_data(irq);
  33589. +
  33590. + if (irqdata && irqdata->chip) {
  33591. + irqchip = irqdata->chip;
  33592. + } else {
  33593. + ret = -ENODEV;
  33594. + goto exit_gpio_free_in_pin;
  33595. + }
  33596. +
  33597. + /* if pin is high, then this must be an active low receiver. */
  33598. + if (sense == -1) {
  33599. + /* wait 1/2 sec for the power supply */
  33600. + msleep(500);
  33601. +
  33602. + /*
  33603. + * probe 9 times every 0.04s, collect "votes" for
  33604. + * active high/low
  33605. + */
  33606. + nlow = 0;
  33607. + nhigh = 0;
  33608. + for (i = 0; i < 9; i++) {
  33609. + if (gpiochip->get(gpiochip, gpio_in_pin))
  33610. + nlow++;
  33611. + else
  33612. + nhigh++;
  33613. + msleep(40);
  33614. + }
  33615. + sense = (nlow >= nhigh ? 1 : 0);
  33616. + printk(KERN_INFO LIRC_DRIVER_NAME
  33617. + ": auto-detected active %s receiver on GPIO pin %d\n",
  33618. + sense ? "low" : "high", gpio_in_pin);
  33619. + } else {
  33620. + printk(KERN_INFO LIRC_DRIVER_NAME
  33621. + ": manually using active %s receiver on GPIO pin %d\n",
  33622. + sense ? "low" : "high", gpio_in_pin);
  33623. + }
  33624. +
  33625. + return 0;
  33626. +
  33627. + exit_gpio_free_in_pin:
  33628. + gpio_free(gpio_in_pin);
  33629. +
  33630. + exit_gpio_free_out_pin:
  33631. + gpio_free(gpio_out_pin);
  33632. +
  33633. + exit_init_port:
  33634. + return ret;
  33635. +}
  33636. +
  33637. +// called when the character device is opened
  33638. +static int set_use_inc(void *data)
  33639. +{
  33640. + int result;
  33641. + unsigned long flags;
  33642. +
  33643. + /* initialize timestamp */
  33644. + do_gettimeofday(&lasttv);
  33645. +
  33646. + result = request_irq(gpiochip->to_irq(gpiochip, gpio_in_pin),
  33647. + (irq_handler_t) irq_handler, 0,
  33648. + LIRC_DRIVER_NAME, (void*) 0);
  33649. +
  33650. + switch (result) {
  33651. + case -EBUSY:
  33652. + printk(KERN_ERR LIRC_DRIVER_NAME
  33653. + ": IRQ %d is busy\n",
  33654. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33655. + return -EBUSY;
  33656. + case -EINVAL:
  33657. + printk(KERN_ERR LIRC_DRIVER_NAME
  33658. + ": Bad irq number or handler\n");
  33659. + return -EINVAL;
  33660. + default:
  33661. + dprintk("Interrupt %d obtained\n",
  33662. + gpiochip->to_irq(gpiochip, gpio_in_pin));
  33663. + break;
  33664. + };
  33665. +
  33666. + /* initialize pulse/space widths */
  33667. + init_timing_params(duty_cycle, freq);
  33668. +
  33669. + spin_lock_irqsave(&lock, flags);
  33670. +
  33671. + /* GPIO Pin Falling/Rising Edge Detect Enable */
  33672. + irqchip->irq_set_type(irqdata,
  33673. + IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING);
  33674. +
  33675. + /* unmask the irq */
  33676. + irqchip->irq_unmask(irqdata);
  33677. +
  33678. + spin_unlock_irqrestore(&lock, flags);
  33679. +
  33680. + return 0;
  33681. +}
  33682. +
  33683. +static void set_use_dec(void *data)
  33684. +{
  33685. + unsigned long flags;
  33686. +
  33687. + spin_lock_irqsave(&lock, flags);
  33688. +
  33689. + /* GPIO Pin Falling/Rising Edge Detect Disable */
  33690. + irqchip->irq_set_type(irqdata, 0);
  33691. + irqchip->irq_mask(irqdata);
  33692. +
  33693. + spin_unlock_irqrestore(&lock, flags);
  33694. +
  33695. + free_irq(gpiochip->to_irq(gpiochip, gpio_in_pin), (void *) 0);
  33696. +
  33697. + dprintk(KERN_INFO LIRC_DRIVER_NAME
  33698. + ": freed IRQ %d\n", gpiochip->to_irq(gpiochip, gpio_in_pin));
  33699. +}
  33700. +
  33701. +static ssize_t lirc_write(struct file *file, const char *buf,
  33702. + size_t n, loff_t *ppos)
  33703. +{
  33704. + int i, count;
  33705. + unsigned long flags;
  33706. + long delta = 0;
  33707. + int *wbuf;
  33708. +
  33709. + count = n / sizeof(int);
  33710. + if (n % sizeof(int) || count % 2 == 0)
  33711. + return -EINVAL;
  33712. + wbuf = memdup_user(buf, n);
  33713. + if (IS_ERR(wbuf))
  33714. + return PTR_ERR(wbuf);
  33715. + spin_lock_irqsave(&lock, flags);
  33716. +
  33717. + for (i = 0; i < count; i++) {
  33718. + if (i%2)
  33719. + send_space(wbuf[i] - delta);
  33720. + else
  33721. + delta = send_pulse(wbuf[i]);
  33722. + }
  33723. + gpiochip->set(gpiochip, gpio_out_pin, invert);
  33724. +
  33725. + spin_unlock_irqrestore(&lock, flags);
  33726. + kfree(wbuf);
  33727. + return n;
  33728. +}
  33729. +
  33730. +static long lirc_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
  33731. +{
  33732. + int result;
  33733. + __u32 value;
  33734. +
  33735. + switch (cmd) {
  33736. + case LIRC_GET_SEND_MODE:
  33737. + return -ENOIOCTLCMD;
  33738. + break;
  33739. +
  33740. + case LIRC_SET_SEND_MODE:
  33741. + result = get_user(value, (__u32 *) arg);
  33742. + if (result)
  33743. + return result;
  33744. + /* only LIRC_MODE_PULSE supported */
  33745. + if (value != LIRC_MODE_PULSE)
  33746. + return -ENOSYS;
  33747. + break;
  33748. +
  33749. + case LIRC_GET_LENGTH:
  33750. + return -ENOSYS;
  33751. + break;
  33752. +
  33753. + case LIRC_SET_SEND_DUTY_CYCLE:
  33754. + dprintk("SET_SEND_DUTY_CYCLE\n");
  33755. + result = get_user(value, (__u32 *) arg);
  33756. + if (result)
  33757. + return result;
  33758. + if (value <= 0 || value > 100)
  33759. + return -EINVAL;
  33760. + return init_timing_params(value, freq);
  33761. + break;
  33762. +
  33763. + case LIRC_SET_SEND_CARRIER:
  33764. + dprintk("SET_SEND_CARRIER\n");
  33765. + result = get_user(value, (__u32 *) arg);
  33766. + if (result)
  33767. + return result;
  33768. + if (value > 500000 || value < 20000)
  33769. + return -EINVAL;
  33770. + return init_timing_params(duty_cycle, value);
  33771. + break;
  33772. +
  33773. + default:
  33774. + return lirc_dev_fop_ioctl(filep, cmd, arg);
  33775. + }
  33776. + return 0;
  33777. +}
  33778. +
  33779. +static const struct file_operations lirc_fops = {
  33780. + .owner = THIS_MODULE,
  33781. + .write = lirc_write,
  33782. + .unlocked_ioctl = lirc_ioctl,
  33783. + .read = lirc_dev_fop_read,
  33784. + .poll = lirc_dev_fop_poll,
  33785. + .open = lirc_dev_fop_open,
  33786. + .release = lirc_dev_fop_close,
  33787. + .llseek = no_llseek,
  33788. +};
  33789. +
  33790. +static struct lirc_driver driver = {
  33791. + .name = LIRC_DRIVER_NAME,
  33792. + .minor = -1,
  33793. + .code_length = 1,
  33794. + .sample_rate = 0,
  33795. + .data = NULL,
  33796. + .add_to_buf = NULL,
  33797. + .rbuf = &rbuf,
  33798. + .set_use_inc = set_use_inc,
  33799. + .set_use_dec = set_use_dec,
  33800. + .fops = &lirc_fops,
  33801. + .dev = NULL,
  33802. + .owner = THIS_MODULE,
  33803. +};
  33804. +
  33805. +static struct platform_driver lirc_rpi_driver = {
  33806. + .driver = {
  33807. + .name = LIRC_DRIVER_NAME,
  33808. + .owner = THIS_MODULE,
  33809. + },
  33810. +};
  33811. +
  33812. +static int __init lirc_rpi_init(void)
  33813. +{
  33814. + int result;
  33815. +
  33816. + /* Init read buffer. */
  33817. + result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN);
  33818. + if (result < 0)
  33819. + return -ENOMEM;
  33820. +
  33821. + result = platform_driver_register(&lirc_rpi_driver);
  33822. + if (result) {
  33823. + printk(KERN_ERR LIRC_DRIVER_NAME
  33824. + ": lirc register returned %d\n", result);
  33825. + goto exit_buffer_free;
  33826. + }
  33827. +
  33828. + lirc_rpi_dev = platform_device_alloc(LIRC_DRIVER_NAME, 0);
  33829. + if (!lirc_rpi_dev) {
  33830. + result = -ENOMEM;
  33831. + goto exit_driver_unregister;
  33832. + }
  33833. +
  33834. + result = platform_device_add(lirc_rpi_dev);
  33835. + if (result)
  33836. + goto exit_device_put;
  33837. +
  33838. + return 0;
  33839. +
  33840. + exit_device_put:
  33841. + platform_device_put(lirc_rpi_dev);
  33842. +
  33843. + exit_driver_unregister:
  33844. + platform_driver_unregister(&lirc_rpi_driver);
  33845. +
  33846. + exit_buffer_free:
  33847. + lirc_buffer_free(&rbuf);
  33848. +
  33849. + return result;
  33850. +}
  33851. +
  33852. +static void lirc_rpi_exit(void)
  33853. +{
  33854. + platform_device_unregister(lirc_rpi_dev);
  33855. + platform_driver_unregister(&lirc_rpi_driver);
  33856. + lirc_buffer_free(&rbuf);
  33857. +}
  33858. +
  33859. +static int __init lirc_rpi_init_module(void)
  33860. +{
  33861. + int result, i;
  33862. +
  33863. + result = lirc_rpi_init();
  33864. + if (result)
  33865. + return result;
  33866. +
  33867. + /* check if the module received valid gpio pin numbers */
  33868. + result = 0;
  33869. + if (gpio_in_pin != gpio_out_pin) {
  33870. + for(i = 0; (i < ARRAY_SIZE(valid_gpio_pins)) && (result != 2); i++) {
  33871. + if (gpio_in_pin == valid_gpio_pins[i] ||
  33872. + gpio_out_pin == valid_gpio_pins[i]) {
  33873. + result++;
  33874. + }
  33875. + }
  33876. + }
  33877. +
  33878. + if (result != 2) {
  33879. + result = -EINVAL;
  33880. + printk(KERN_ERR LIRC_DRIVER_NAME
  33881. + ": invalid GPIO pin(s) specified!\n");
  33882. + goto exit_rpi;
  33883. + }
  33884. +
  33885. + result = init_port();
  33886. + if (result < 0)
  33887. + goto exit_rpi;
  33888. +
  33889. + driver.features = LIRC_CAN_SET_SEND_DUTY_CYCLE |
  33890. + LIRC_CAN_SET_SEND_CARRIER |
  33891. + LIRC_CAN_SEND_PULSE |
  33892. + LIRC_CAN_REC_MODE2;
  33893. +
  33894. + driver.dev = &lirc_rpi_dev->dev;
  33895. + driver.minor = lirc_register_driver(&driver);
  33896. +
  33897. + if (driver.minor < 0) {
  33898. + printk(KERN_ERR LIRC_DRIVER_NAME
  33899. + ": device registration failed with %d\n", result);
  33900. + result = -EIO;
  33901. + goto exit_rpi;
  33902. + }
  33903. +
  33904. + printk(KERN_INFO LIRC_DRIVER_NAME ": driver registered!\n");
  33905. +
  33906. + return 0;
  33907. +
  33908. + exit_rpi:
  33909. + lirc_rpi_exit();
  33910. +
  33911. + return result;
  33912. +}
  33913. +
  33914. +static void __exit lirc_rpi_exit_module(void)
  33915. +{
  33916. + gpio_free(gpio_out_pin);
  33917. + gpio_free(gpio_in_pin);
  33918. +
  33919. + lirc_rpi_exit();
  33920. +
  33921. + lirc_unregister_driver(driver.minor);
  33922. + printk(KERN_INFO LIRC_DRIVER_NAME ": cleaned up module\n");
  33923. +}
  33924. +
  33925. +module_init(lirc_rpi_init_module);
  33926. +module_exit(lirc_rpi_exit_module);
  33927. +
  33928. +MODULE_DESCRIPTION("Infra-red receiver and blaster driver for Raspberry Pi GPIO.");
  33929. +MODULE_AUTHOR("Aron Robert Szabo <aron@reon.hu>");
  33930. +MODULE_AUTHOR("Michael Bishop <cleverca22@gmail.com>");
  33931. +MODULE_LICENSE("GPL");
  33932. +
  33933. +module_param(gpio_out_pin, int, S_IRUGO);
  33934. +MODULE_PARM_DESC(gpio_out_pin, "GPIO output/transmitter pin number of the BCM"
  33935. + " processor. Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11,"
  33936. + " 14, 15, 17, 18, 21, 22, 23, 24, 25, default 17");
  33937. +
  33938. +module_param(gpio_in_pin, int, S_IRUGO);
  33939. +MODULE_PARM_DESC(gpio_in_pin, "GPIO input pin number of the BCM processor."
  33940. + " Valid pin numbers are: 0, 1, 4, 8, 7, 9, 10, 11, 14, 15,"
  33941. + " 17, 18, 21, 22, 23, 24, 25, default 18");
  33942. +
  33943. +module_param(sense, int, S_IRUGO);
  33944. +MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit"
  33945. + " (0 = active high, 1 = active low )");
  33946. +
  33947. +module_param(softcarrier, bool, S_IRUGO);
  33948. +MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)");
  33949. +
  33950. +module_param(invert, bool, S_IRUGO);
  33951. +MODULE_PARM_DESC(invert, "Invert output (0 = off, 1 = on, default off");
  33952. +
  33953. +module_param(debug, bool, S_IRUGO | S_IWUSR);
  33954. +MODULE_PARM_DESC(debug, "Enable debugging messages");
  33955. diff -Nur linux-3.15/drivers/staging/media/lirc/Makefile linux-rpi/drivers/staging/media/lirc/Makefile
  33956. --- linux-3.15/drivers/staging/media/lirc/Makefile 2014-06-08 20:19:54.000000000 +0200
  33957. +++ linux-rpi/drivers/staging/media/lirc/Makefile 2014-06-11 21:03:39.000000000 +0200
  33958. @@ -7,6 +7,7 @@
  33959. obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o
  33960. obj-$(CONFIG_LIRC_IMON) += lirc_imon.o
  33961. obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o
  33962. +obj-$(CONFIG_LIRC_RPI) += lirc_rpi.o
  33963. obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o
  33964. obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o
  33965. obj-$(CONFIG_LIRC_SIR) += lirc_sir.o
  33966. diff -Nur linux-3.15/drivers/thermal/bcm2835-thermal.c linux-rpi/drivers/thermal/bcm2835-thermal.c
  33967. --- linux-3.15/drivers/thermal/bcm2835-thermal.c 1970-01-01 01:00:00.000000000 +0100
  33968. +++ linux-rpi/drivers/thermal/bcm2835-thermal.c 2014-06-11 21:03:40.000000000 +0200
  33969. @@ -0,0 +1,184 @@
  33970. +/*****************************************************************************
  33971. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  33972. +*
  33973. +* Unless you and Broadcom execute a separate written software license
  33974. +* agreement governing use of this software, this software is licensed to you
  33975. +* under the terms of the GNU General Public License version 2, available at
  33976. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  33977. +*
  33978. +* Notwithstanding the above, under no circumstances may you combine this
  33979. +* software in any way with any other Broadcom software provided under a
  33980. +* license other than the GPL, without Broadcom's express prior written
  33981. +* consent.
  33982. +*****************************************************************************/
  33983. +
  33984. +#include <linux/kernel.h>
  33985. +#include <linux/module.h>
  33986. +#include <linux/init.h>
  33987. +#include <linux/platform_device.h>
  33988. +#include <linux/slab.h>
  33989. +#include <linux/sysfs.h>
  33990. +#include <mach/vcio.h>
  33991. +#include <linux/thermal.h>
  33992. +
  33993. +
  33994. +/* --- DEFINITIONS --- */
  33995. +#define MODULE_NAME "bcm2835_thermal"
  33996. +
  33997. +/*#define THERMAL_DEBUG_ENABLE*/
  33998. +
  33999. +#ifdef THERMAL_DEBUG_ENABLE
  34000. +#define print_debug(fmt,...) printk(KERN_INFO "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  34001. +#else
  34002. +#define print_debug(fmt,...)
  34003. +#endif
  34004. +#define print_err(fmt,...) printk(KERN_ERR "%s:%s:%d: "fmt"\n", MODULE_NAME, __func__,__LINE__, ##__VA_ARGS__)
  34005. +
  34006. +#define VC_TAG_GET_TEMP 0x00030006
  34007. +#define VC_TAG_GET_MAX_TEMP 0x0003000A
  34008. +
  34009. +typedef enum {
  34010. + TEMP,
  34011. + MAX_TEMP,
  34012. +} temp_type;
  34013. +
  34014. +/* --- STRUCTS --- */
  34015. +/* tag part of the message */
  34016. +struct vc_msg_tag {
  34017. + uint32_t tag_id; /* the tag ID for the temperature */
  34018. + uint32_t buffer_size; /* size of the buffer (should be 8) */
  34019. + uint32_t request_code; /* identifies message as a request (should be 0) */
  34020. + uint32_t id; /* extra ID field (should be 0) */
  34021. + uint32_t val; /* returned value of the temperature */
  34022. +};
  34023. +
  34024. +/* message structure to be sent to videocore */
  34025. +struct vc_msg {
  34026. + uint32_t msg_size; /* simply, sizeof(struct vc_msg) */
  34027. + uint32_t request_code; /* holds various information like the success and number of bytes returned (refer to mailboxes wiki) */
  34028. + struct vc_msg_tag tag; /* the tag structure above to make */
  34029. + uint32_t end_tag; /* an end identifier, should be set to NULL */
  34030. +};
  34031. +
  34032. +struct bcm2835_thermal_data {
  34033. + struct thermal_zone_device *thermal_dev;
  34034. + struct vc_msg msg;
  34035. +};
  34036. +
  34037. +/* --- GLOBALS --- */
  34038. +static struct bcm2835_thermal_data bcm2835_data;
  34039. +
  34040. +/* Thermal Device Operations */
  34041. +static struct thermal_zone_device_ops ops;
  34042. +
  34043. +/* --- FUNCTIONS --- */
  34044. +
  34045. +static int bcm2835_get_temp_or_max(struct thermal_zone_device *thermal_dev, unsigned long *temp, unsigned tag_id)
  34046. +{
  34047. + int result = -1, retry = 3;
  34048. + print_debug("IN");
  34049. +
  34050. + *temp = 0;
  34051. + while (result != 0 && retry-- > 0) {
  34052. + /* wipe all previous message data */
  34053. + memset(&bcm2835_data.msg, 0, sizeof bcm2835_data.msg);
  34054. +
  34055. + /* prepare message */
  34056. + bcm2835_data.msg.msg_size = sizeof bcm2835_data.msg;
  34057. + bcm2835_data.msg.tag.buffer_size = 8;
  34058. + bcm2835_data.msg.tag.tag_id = tag_id;
  34059. +
  34060. + /* send the message */
  34061. + result = bcm_mailbox_property(&bcm2835_data.msg, sizeof bcm2835_data.msg);
  34062. + 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);
  34063. + if (!(bcm2835_data.msg.request_code & 0x80000000))
  34064. + result = -1;
  34065. + }
  34066. +
  34067. + /* check if it was all ok and return the rate in milli degrees C */
  34068. + if (result == 0)
  34069. + *temp = (uint)bcm2835_data.msg.tag.val;
  34070. + else
  34071. + print_err("Failed to get temperature! (%x:%d)\n", tag_id, result);
  34072. + print_debug("OUT");
  34073. + return result;
  34074. +}
  34075. +
  34076. +static int bcm2835_get_temp(struct thermal_zone_device *thermal_dev, unsigned long *temp)
  34077. +{
  34078. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_TEMP);
  34079. +}
  34080. +
  34081. +static int bcm2835_get_max_temp(struct thermal_zone_device *thermal_dev, int trip_num, unsigned long *temp)
  34082. +{
  34083. + return bcm2835_get_temp_or_max(thermal_dev, temp, VC_TAG_GET_MAX_TEMP);
  34084. +}
  34085. +
  34086. +static int bcm2835_get_trip_type(struct thermal_zone_device * thermal_dev, int trip_num, enum thermal_trip_type *trip_type)
  34087. +{
  34088. + *trip_type = THERMAL_TRIP_HOT;
  34089. + return 0;
  34090. +}
  34091. +
  34092. +
  34093. +static int bcm2835_get_mode(struct thermal_zone_device *thermal_dev, enum thermal_device_mode *dev_mode)
  34094. +{
  34095. + *dev_mode = THERMAL_DEVICE_ENABLED;
  34096. + return 0;
  34097. +}
  34098. +
  34099. +
  34100. +static int bcm2835_thermal_probe(struct platform_device *pdev)
  34101. +{
  34102. + print_debug("IN");
  34103. + print_debug("THERMAL Driver has been probed!");
  34104. +
  34105. + /* check that the device isn't null!*/
  34106. + if(pdev == NULL)
  34107. + {
  34108. + print_debug("Platform device is empty!");
  34109. + return -ENODEV;
  34110. + }
  34111. +
  34112. + if(!(bcm2835_data.thermal_dev = thermal_zone_device_register("bcm2835_thermal", 1, 0, NULL, &ops, NULL, 0, 0)))
  34113. + {
  34114. + print_debug("Unable to register the thermal device!");
  34115. + return -EFAULT;
  34116. + }
  34117. + return 0;
  34118. +}
  34119. +
  34120. +
  34121. +static int bcm2835_thermal_remove(struct platform_device *pdev)
  34122. +{
  34123. + print_debug("IN");
  34124. +
  34125. + thermal_zone_device_unregister(bcm2835_data.thermal_dev);
  34126. +
  34127. + print_debug("OUT");
  34128. +
  34129. + return 0;
  34130. +}
  34131. +
  34132. +static struct thermal_zone_device_ops ops = {
  34133. + .get_temp = bcm2835_get_temp,
  34134. + .get_trip_temp = bcm2835_get_max_temp,
  34135. + .get_trip_type = bcm2835_get_trip_type,
  34136. + .get_mode = bcm2835_get_mode,
  34137. +};
  34138. +
  34139. +/* Thermal Driver */
  34140. +static struct platform_driver bcm2835_thermal_driver = {
  34141. + .probe = bcm2835_thermal_probe,
  34142. + .remove = bcm2835_thermal_remove,
  34143. + .driver = {
  34144. + .name = "bcm2835_thermal",
  34145. + .owner = THIS_MODULE,
  34146. + },
  34147. +};
  34148. +
  34149. +MODULE_LICENSE("GPL");
  34150. +MODULE_AUTHOR("Dorian Peake");
  34151. +MODULE_DESCRIPTION("Thermal driver for bcm2835 chip");
  34152. +
  34153. +module_platform_driver(bcm2835_thermal_driver);
  34154. diff -Nur linux-3.15/drivers/thermal/Kconfig linux-rpi/drivers/thermal/Kconfig
  34155. --- linux-3.15/drivers/thermal/Kconfig 2014-06-08 20:19:54.000000000 +0200
  34156. +++ linux-rpi/drivers/thermal/Kconfig 2014-06-11 21:05:31.000000000 +0200
  34157. @@ -196,6 +196,12 @@
  34158. enforce idle time which results in more package C-state residency. The
  34159. user interface is exposed via generic thermal framework.
  34160. +config THERMAL_BCM2835
  34161. + tristate "BCM2835 Thermal Driver"
  34162. + help
  34163. + This will enable temperature monitoring for the Broadcom BCM2835
  34164. + chip. If built as a module, it will be called 'bcm2835-thermal'.
  34165. +
  34166. config X86_PKG_TEMP_THERMAL
  34167. tristate "X86 package temperature thermal driver"
  34168. depends on X86_THERMAL_VECTOR
  34169. diff -Nur linux-3.15/drivers/thermal/Makefile linux-rpi/drivers/thermal/Makefile
  34170. --- linux-3.15/drivers/thermal/Makefile 2014-06-08 20:19:54.000000000 +0200
  34171. +++ linux-rpi/drivers/thermal/Makefile 2014-06-11 21:05:31.000000000 +0200
  34172. @@ -28,6 +28,7 @@
  34173. obj-$(CONFIG_IMX_THERMAL) += imx_thermal.o
  34174. obj-$(CONFIG_DB8500_CPUFREQ_COOLING) += db8500_cpufreq_cooling.o
  34175. obj-$(CONFIG_INTEL_POWERCLAMP) += intel_powerclamp.o
  34176. +obj-$(CONFIG_THERMAL_BCM2835) += bcm2835-thermal.o
  34177. obj-$(CONFIG_X86_PKG_TEMP_THERMAL) += x86_pkg_temp_thermal.o
  34178. obj-$(CONFIG_TI_SOC_THERMAL) += ti-soc-thermal/
  34179. obj-$(CONFIG_ACPI_INT3403_THERMAL) += int3403_thermal.o
  34180. diff -Nur linux-3.15/drivers/tty/serial/amba-pl011.c linux-rpi/drivers/tty/serial/amba-pl011.c
  34181. --- linux-3.15/drivers/tty/serial/amba-pl011.c 2014-06-08 20:19:54.000000000 +0200
  34182. +++ linux-rpi/drivers/tty/serial/amba-pl011.c 2014-06-11 21:05:32.000000000 +0200
  34183. @@ -84,7 +84,7 @@
  34184. static unsigned int get_fifosize_arm(struct amba_device *dev)
  34185. {
  34186. - return amba_rev(dev) < 3 ? 16 : 32;
  34187. + return 16; //TODO: fix: amba_rev(dev) < 3 ? 16 : 32;
  34188. }
  34189. static struct vendor_data vendor_arm = {
  34190. diff -Nur linux-3.15/drivers/usb/core/generic.c linux-rpi/drivers/usb/core/generic.c
  34191. --- linux-3.15/drivers/usb/core/generic.c 2014-06-08 20:19:54.000000000 +0200
  34192. +++ linux-rpi/drivers/usb/core/generic.c 2014-06-11 21:05:32.000000000 +0200
  34193. @@ -152,6 +152,7 @@
  34194. dev_warn(&udev->dev,
  34195. "no configuration chosen from %d choice%s\n",
  34196. num_configs, plural(num_configs));
  34197. + dev_warn(&udev->dev, "No support over %dmA\n", udev->bus_mA);
  34198. }
  34199. return i;
  34200. }
  34201. diff -Nur linux-3.15/drivers/usb/core/message.c linux-rpi/drivers/usb/core/message.c
  34202. --- linux-3.15/drivers/usb/core/message.c 2014-06-08 20:19:54.000000000 +0200
  34203. +++ linux-rpi/drivers/usb/core/message.c 2014-06-11 21:05:32.000000000 +0200
  34204. @@ -1891,6 +1891,85 @@
  34205. if (cp->string == NULL &&
  34206. !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
  34207. cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
  34208. +/* Uncomment this define to enable the HS Electrical Test support */
  34209. +#define DWC_HS_ELECT_TST 1
  34210. +#ifdef DWC_HS_ELECT_TST
  34211. + /* Here we implement the HS Electrical Test support. The
  34212. + * tester uses a vendor ID of 0x1A0A to indicate we should
  34213. + * run a special test sequence. The product ID tells us
  34214. + * which sequence to run. We invoke the test sequence by
  34215. + * sending a non-standard SetFeature command to our root
  34216. + * hub port. Our dwc_otg_hcd_hub_control() routine will
  34217. + * recognize the command and perform the desired test
  34218. + * sequence.
  34219. + */
  34220. + if (dev->descriptor.idVendor == 0x1A0A) {
  34221. + /* HSOTG Electrical Test */
  34222. + dev_warn(&dev->dev, "VID from HSOTG Electrical Test Fixture\n");
  34223. +
  34224. + if (dev->bus && dev->bus->root_hub) {
  34225. + struct usb_device *hdev = dev->bus->root_hub;
  34226. + dev_warn(&dev->dev, "Got PID 0x%x\n", dev->descriptor.idProduct);
  34227. +
  34228. + switch (dev->descriptor.idProduct) {
  34229. + case 0x0101: /* TEST_SE0_NAK */
  34230. + dev_warn(&dev->dev, "TEST_SE0_NAK\n");
  34231. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34232. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34233. + USB_PORT_FEAT_TEST, 0x300, NULL, 0, HZ);
  34234. + break;
  34235. +
  34236. + case 0x0102: /* TEST_J */
  34237. + dev_warn(&dev->dev, "TEST_J\n");
  34238. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34239. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34240. + USB_PORT_FEAT_TEST, 0x100, NULL, 0, HZ);
  34241. + break;
  34242. +
  34243. + case 0x0103: /* TEST_K */
  34244. + dev_warn(&dev->dev, "TEST_K\n");
  34245. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34246. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34247. + USB_PORT_FEAT_TEST, 0x200, NULL, 0, HZ);
  34248. + break;
  34249. +
  34250. + case 0x0104: /* TEST_PACKET */
  34251. + dev_warn(&dev->dev, "TEST_PACKET\n");
  34252. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34253. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34254. + USB_PORT_FEAT_TEST, 0x400, NULL, 0, HZ);
  34255. + break;
  34256. +
  34257. + case 0x0105: /* TEST_FORCE_ENABLE */
  34258. + dev_warn(&dev->dev, "TEST_FORCE_ENABLE\n");
  34259. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34260. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34261. + USB_PORT_FEAT_TEST, 0x500, NULL, 0, HZ);
  34262. + break;
  34263. +
  34264. + case 0x0106: /* HS_HOST_PORT_SUSPEND_RESUME */
  34265. + dev_warn(&dev->dev, "HS_HOST_PORT_SUSPEND_RESUME\n");
  34266. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34267. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34268. + USB_PORT_FEAT_TEST, 0x600, NULL, 0, 40 * HZ);
  34269. + break;
  34270. +
  34271. + case 0x0107: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  34272. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup\n");
  34273. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34274. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34275. + USB_PORT_FEAT_TEST, 0x700, NULL, 0, 40 * HZ);
  34276. + break;
  34277. +
  34278. + case 0x0108: /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  34279. + dev_warn(&dev->dev, "SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute\n");
  34280. + usb_control_msg(hdev, usb_sndctrlpipe(hdev, 0),
  34281. + USB_REQ_SET_FEATURE, USB_RT_PORT,
  34282. + USB_PORT_FEAT_TEST, 0x800, NULL, 0, 40 * HZ);
  34283. + }
  34284. + }
  34285. + }
  34286. +#endif /* DWC_HS_ELECT_TST */
  34287. /* Now that the interfaces are installed, re-enable LPM. */
  34288. usb_unlocked_enable_lpm(dev);
  34289. diff -Nur linux-3.15/drivers/usb/core/otg_whitelist.h linux-rpi/drivers/usb/core/otg_whitelist.h
  34290. --- linux-3.15/drivers/usb/core/otg_whitelist.h 2014-06-08 20:19:54.000000000 +0200
  34291. +++ linux-rpi/drivers/usb/core/otg_whitelist.h 2014-06-11 21:03:42.000000000 +0200
  34292. @@ -19,33 +19,82 @@
  34293. static struct usb_device_id whitelist_table [] = {
  34294. /* hubs are optional in OTG, but very handy ... */
  34295. +#define CERT_WITHOUT_HUBS
  34296. +#if defined(CERT_WITHOUT_HUBS)
  34297. +{ USB_DEVICE( 0x0000, 0x0000 ), }, /* Root HUB Only*/
  34298. +#else
  34299. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 0), },
  34300. { USB_DEVICE_INFO(USB_CLASS_HUB, 0, 1), },
  34301. +{ USB_DEVICE_INFO(USB_CLASS_HUB, 0, 2), },
  34302. +#endif
  34303. #ifdef CONFIG_USB_PRINTER /* ignoring nonstatic linkage! */
  34304. /* FIXME actually, printers are NOT supposed to use device classes;
  34305. * they're supposed to use interface classes...
  34306. */
  34307. -{ USB_DEVICE_INFO(7, 1, 1) },
  34308. -{ USB_DEVICE_INFO(7, 1, 2) },
  34309. -{ USB_DEVICE_INFO(7, 1, 3) },
  34310. +//{ USB_DEVICE_INFO(7, 1, 1) },
  34311. +//{ USB_DEVICE_INFO(7, 1, 2) },
  34312. +//{ USB_DEVICE_INFO(7, 1, 3) },
  34313. #endif
  34314. #ifdef CONFIG_USB_NET_CDCETHER
  34315. /* Linux-USB CDC Ethernet gadget */
  34316. -{ USB_DEVICE(0x0525, 0xa4a1), },
  34317. +//{ USB_DEVICE(0x0525, 0xa4a1), },
  34318. /* Linux-USB CDC Ethernet + RNDIS gadget */
  34319. -{ USB_DEVICE(0x0525, 0xa4a2), },
  34320. +//{ USB_DEVICE(0x0525, 0xa4a2), },
  34321. #endif
  34322. #if defined(CONFIG_USB_TEST) || defined(CONFIG_USB_TEST_MODULE)
  34323. /* gadget zero, for testing */
  34324. -{ USB_DEVICE(0x0525, 0xa4a0), },
  34325. +//{ USB_DEVICE(0x0525, 0xa4a0), },
  34326. #endif
  34327. +/* OPT Tester */
  34328. +{ USB_DEVICE( 0x1a0a, 0x0101 ), }, /* TEST_SE0_NAK */
  34329. +{ USB_DEVICE( 0x1a0a, 0x0102 ), }, /* Test_J */
  34330. +{ USB_DEVICE( 0x1a0a, 0x0103 ), }, /* Test_K */
  34331. +{ USB_DEVICE( 0x1a0a, 0x0104 ), }, /* Test_PACKET */
  34332. +{ USB_DEVICE( 0x1a0a, 0x0105 ), }, /* Test_FORCE_ENABLE */
  34333. +{ USB_DEVICE( 0x1a0a, 0x0106 ), }, /* HS_PORT_SUSPEND_RESUME */
  34334. +{ USB_DEVICE( 0x1a0a, 0x0107 ), }, /* SINGLE_STEP_GET_DESCRIPTOR setup */
  34335. +{ USB_DEVICE( 0x1a0a, 0x0108 ), }, /* SINGLE_STEP_GET_DESCRIPTOR execute */
  34336. +
  34337. +/* Sony cameras */
  34338. +{ USB_DEVICE_VER(0x054c,0x0010,0x0410, 0x0500), },
  34339. +
  34340. +/* Memory Devices */
  34341. +//{ USB_DEVICE( 0x0781, 0x5150 ), }, /* SanDisk */
  34342. +//{ USB_DEVICE( 0x05DC, 0x0080 ), }, /* Lexar */
  34343. +//{ USB_DEVICE( 0x4146, 0x9281 ), }, /* IOMEGA */
  34344. +//{ USB_DEVICE( 0x067b, 0x2507 ), }, /* Hammer 20GB External HD */
  34345. +{ USB_DEVICE( 0x0EA0, 0x2168 ), }, /* Ours Technology Inc. (BUFFALO ClipDrive)*/
  34346. +//{ USB_DEVICE( 0x0457, 0x0150 ), }, /* Silicon Integrated Systems Corp. */
  34347. +
  34348. +/* HP Printers */
  34349. +//{ USB_DEVICE( 0x03F0, 0x1102 ), }, /* HP Photosmart 245 */
  34350. +//{ USB_DEVICE( 0x03F0, 0x1302 ), }, /* HP Photosmart 370 Series */
  34351. +
  34352. +/* Speakers */
  34353. +//{ USB_DEVICE( 0x0499, 0x3002 ), }, /* YAMAHA YST-MS35D USB Speakers */
  34354. +//{ USB_DEVICE( 0x0672, 0x1041 ), }, /* Labtec USB Headset */
  34355. +
  34356. { } /* Terminating entry */
  34357. };
  34358. +static inline void report_errors(struct usb_device *dev)
  34359. +{
  34360. + /* OTG MESSAGE: report errors here, customize to match your product */
  34361. + dev_info(&dev->dev, "device Vendor:%04x Product:%04x is not supported\n",
  34362. + le16_to_cpu(dev->descriptor.idVendor),
  34363. + le16_to_cpu(dev->descriptor.idProduct));
  34364. + if (USB_CLASS_HUB == dev->descriptor.bDeviceClass){
  34365. + dev_printk(KERN_CRIT, &dev->dev, "Unsupported Hub Topology\n");
  34366. + } else {
  34367. + dev_printk(KERN_CRIT, &dev->dev, "Attached Device is not Supported\n");
  34368. + }
  34369. +}
  34370. +
  34371. +
  34372. static int is_targeted(struct usb_device *dev)
  34373. {
  34374. struct usb_device_id *id = whitelist_table;
  34375. @@ -55,58 +104,83 @@
  34376. return 1;
  34377. /* HNP test device is _never_ targeted (see OTG spec 6.6.6) */
  34378. - if ((le16_to_cpu(dev->descriptor.idVendor) == 0x1a0a &&
  34379. - le16_to_cpu(dev->descriptor.idProduct) == 0xbadd))
  34380. - return 0;
  34381. + if (dev->descriptor.idVendor == 0x1a0a &&
  34382. + dev->descriptor.idProduct == 0xbadd) {
  34383. + return 0;
  34384. + } else if (!enable_whitelist) {
  34385. + return 1;
  34386. + } else {
  34387. - /* NOTE: can't use usb_match_id() since interface caches
  34388. - * aren't set up yet. this is cut/paste from that code.
  34389. - */
  34390. - for (id = whitelist_table; id->match_flags; id++) {
  34391. - if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34392. - id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34393. - continue;
  34394. -
  34395. - if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34396. - id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34397. - continue;
  34398. -
  34399. - /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34400. - greater than any unsigned number. */
  34401. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34402. - (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34403. - continue;
  34404. -
  34405. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34406. - (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34407. - continue;
  34408. -
  34409. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34410. - (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34411. - continue;
  34412. -
  34413. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34414. - (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34415. - continue;
  34416. -
  34417. - if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34418. - (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34419. - continue;
  34420. +#ifdef DEBUG
  34421. + dev_dbg(&dev->dev, "device V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34422. + dev->descriptor.idVendor,
  34423. + dev->descriptor.idProduct,
  34424. + dev->descriptor.bDeviceClass,
  34425. + dev->descriptor.bDeviceSubClass,
  34426. + dev->descriptor.bDeviceProtocol);
  34427. +#endif
  34428. return 1;
  34429. + /* NOTE: can't use usb_match_id() since interface caches
  34430. + * aren't set up yet. this is cut/paste from that code.
  34431. + */
  34432. + for (id = whitelist_table; id->match_flags; id++) {
  34433. +#ifdef DEBUG
  34434. + dev_dbg(&dev->dev,
  34435. + "ID: V:%04x P:%04x DC:%04x SC:%04x PR:%04x \n",
  34436. + id->idVendor,
  34437. + id->idProduct,
  34438. + id->bDeviceClass,
  34439. + id->bDeviceSubClass,
  34440. + id->bDeviceProtocol);
  34441. +#endif
  34442. +
  34443. + if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
  34444. + id->idVendor != le16_to_cpu(dev->descriptor.idVendor))
  34445. + continue;
  34446. +
  34447. + if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
  34448. + id->idProduct != le16_to_cpu(dev->descriptor.idProduct))
  34449. + continue;
  34450. +
  34451. + /* No need to test id->bcdDevice_lo != 0, since 0 is never
  34452. + greater than any unsigned number. */
  34453. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
  34454. + (id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice)))
  34455. + continue;
  34456. +
  34457. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
  34458. + (id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice)))
  34459. + continue;
  34460. +
  34461. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
  34462. + (id->bDeviceClass != dev->descriptor.bDeviceClass))
  34463. + continue;
  34464. +
  34465. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
  34466. + (id->bDeviceSubClass != dev->descriptor.bDeviceSubClass))
  34467. + continue;
  34468. +
  34469. + if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
  34470. + (id->bDeviceProtocol != dev->descriptor.bDeviceProtocol))
  34471. + continue;
  34472. +
  34473. + return 1;
  34474. + }
  34475. }
  34476. /* add other match criteria here ... */
  34477. -
  34478. - /* OTG MESSAGE: report errors here, customize to match your product */
  34479. - dev_err(&dev->dev, "device v%04x p%04x is not supported\n",
  34480. - le16_to_cpu(dev->descriptor.idVendor),
  34481. - le16_to_cpu(dev->descriptor.idProduct));
  34482. #ifdef CONFIG_USB_OTG_WHITELIST
  34483. + report_errors(dev);
  34484. return 0;
  34485. #else
  34486. - return 1;
  34487. + if (enable_whitelist) {
  34488. + report_errors(dev);
  34489. + return 0;
  34490. + } else {
  34491. + return 1;
  34492. + }
  34493. #endif
  34494. }
  34495. diff -Nur linux-3.15/drivers/usb/gadget/file_storage.c linux-rpi/drivers/usb/gadget/file_storage.c
  34496. --- linux-3.15/drivers/usb/gadget/file_storage.c 1970-01-01 01:00:00.000000000 +0100
  34497. +++ linux-rpi/drivers/usb/gadget/file_storage.c 2014-06-11 21:03:42.000000000 +0200
  34498. @@ -0,0 +1,3676 @@
  34499. +/*
  34500. + * file_storage.c -- File-backed USB Storage Gadget, for USB development
  34501. + *
  34502. + * Copyright (C) 2003-2008 Alan Stern
  34503. + * All rights reserved.
  34504. + *
  34505. + * Redistribution and use in source and binary forms, with or without
  34506. + * modification, are permitted provided that the following conditions
  34507. + * are met:
  34508. + * 1. Redistributions of source code must retain the above copyright
  34509. + * notice, this list of conditions, and the following disclaimer,
  34510. + * without modification.
  34511. + * 2. Redistributions in binary form must reproduce the above copyright
  34512. + * notice, this list of conditions and the following disclaimer in the
  34513. + * documentation and/or other materials provided with the distribution.
  34514. + * 3. The names of the above-listed copyright holders may not be used
  34515. + * to endorse or promote products derived from this software without
  34516. + * specific prior written permission.
  34517. + *
  34518. + * ALTERNATIVELY, this software may be distributed under the terms of the
  34519. + * GNU General Public License ("GPL") as published by the Free Software
  34520. + * Foundation, either version 2 of that License or (at your option) any
  34521. + * later version.
  34522. + *
  34523. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  34524. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  34525. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34526. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34527. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  34528. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  34529. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34530. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  34531. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  34532. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34533. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34534. + */
  34535. +
  34536. +
  34537. +/*
  34538. + * The File-backed Storage Gadget acts as a USB Mass Storage device,
  34539. + * appearing to the host as a disk drive or as a CD-ROM drive. In addition
  34540. + * to providing an example of a genuinely useful gadget driver for a USB
  34541. + * device, it also illustrates a technique of double-buffering for increased
  34542. + * throughput. Last but not least, it gives an easy way to probe the
  34543. + * behavior of the Mass Storage drivers in a USB host.
  34544. + *
  34545. + * Backing storage is provided by a regular file or a block device, specified
  34546. + * by the "file" module parameter. Access can be limited to read-only by
  34547. + * setting the optional "ro" module parameter. (For CD-ROM emulation,
  34548. + * access is always read-only.) The gadget will indicate that it has
  34549. + * removable media if the optional "removable" module parameter is set.
  34550. + *
  34551. + * The gadget supports the Control-Bulk (CB), Control-Bulk-Interrupt (CBI),
  34552. + * and Bulk-Only (also known as Bulk-Bulk-Bulk or BBB) transports, selected
  34553. + * by the optional "transport" module parameter. It also supports the
  34554. + * following protocols: RBC (0x01), ATAPI or SFF-8020i (0x02), QIC-157 (0c03),
  34555. + * UFI (0x04), SFF-8070i (0x05), and transparent SCSI (0x06), selected by
  34556. + * the optional "protocol" module parameter. In addition, the default
  34557. + * Vendor ID, Product ID, release number and serial number can be overridden.
  34558. + *
  34559. + * There is support for multiple logical units (LUNs), each of which has
  34560. + * its own backing file. The number of LUNs can be set using the optional
  34561. + * "luns" module parameter (anywhere from 1 to 8), and the corresponding
  34562. + * files are specified using comma-separated lists for "file" and "ro".
  34563. + * The default number of LUNs is taken from the number of "file" elements;
  34564. + * it is 1 if "file" is not given. If "removable" is not set then a backing
  34565. + * file must be specified for each LUN. If it is set, then an unspecified
  34566. + * or empty backing filename means the LUN's medium is not loaded. Ideally
  34567. + * each LUN would be settable independently as a disk drive or a CD-ROM
  34568. + * drive, but currently all LUNs have to be the same type. The CD-ROM
  34569. + * emulation includes a single data track and no audio tracks; hence there
  34570. + * need be only one backing file per LUN.
  34571. + *
  34572. + * Requirements are modest; only a bulk-in and a bulk-out endpoint are
  34573. + * needed (an interrupt-out endpoint is also needed for CBI). The memory
  34574. + * requirement amounts to two 16K buffers, size configurable by a parameter.
  34575. + * Support is included for both full-speed and high-speed operation.
  34576. + *
  34577. + * Note that the driver is slightly non-portable in that it assumes a
  34578. + * single memory/DMA buffer will be useable for bulk-in, bulk-out, and
  34579. + * interrupt-in endpoints. With most device controllers this isn't an
  34580. + * issue, but there may be some with hardware restrictions that prevent
  34581. + * a buffer from being used by more than one endpoint.
  34582. + *
  34583. + * Module options:
  34584. + *
  34585. + * file=filename[,filename...]
  34586. + * Required if "removable" is not set, names of
  34587. + * the files or block devices used for
  34588. + * backing storage
  34589. + * serial=HHHH... Required serial number (string of hex chars)
  34590. + * ro=b[,b...] Default false, booleans for read-only access
  34591. + * removable Default false, boolean for removable media
  34592. + * luns=N Default N = number of filenames, number of
  34593. + * LUNs to support
  34594. + * nofua=b[,b...] Default false, booleans for ignore FUA flag
  34595. + * in SCSI WRITE(10,12) commands
  34596. + * stall Default determined according to the type of
  34597. + * USB device controller (usually true),
  34598. + * boolean to permit the driver to halt
  34599. + * bulk endpoints
  34600. + * cdrom Default false, boolean for whether to emulate
  34601. + * a CD-ROM drive
  34602. + * transport=XXX Default BBB, transport name (CB, CBI, or BBB)
  34603. + * protocol=YYY Default SCSI, protocol name (RBC, 8020 or
  34604. + * ATAPI, QIC, UFI, 8070, or SCSI;
  34605. + * also 1 - 6)
  34606. + * vendor=0xVVVV Default 0x0525 (NetChip), USB Vendor ID
  34607. + * product=0xPPPP Default 0xa4a5 (FSG), USB Product ID
  34608. + * release=0xRRRR Override the USB release number (bcdDevice)
  34609. + * buflen=N Default N=16384, buffer size used (will be
  34610. + * rounded down to a multiple of
  34611. + * PAGE_CACHE_SIZE)
  34612. + *
  34613. + * If CONFIG_USB_FILE_STORAGE_TEST is not set, only the "file", "serial", "ro",
  34614. + * "removable", "luns", "nofua", "stall", and "cdrom" options are available;
  34615. + * default values are used for everything else.
  34616. + *
  34617. + * The pathnames of the backing files and the ro settings are available in
  34618. + * the attribute files "file", "nofua", and "ro" in the lun<n> subdirectory of
  34619. + * the gadget's sysfs directory. If the "removable" option is set, writing to
  34620. + * these files will simulate ejecting/loading the medium (writing an empty
  34621. + * line means eject) and adjusting a write-enable tab. Changes to the ro
  34622. + * setting are not allowed when the medium is loaded or if CD-ROM emulation
  34623. + * is being used.
  34624. + *
  34625. + * This gadget driver is heavily based on "Gadget Zero" by David Brownell.
  34626. + * The driver's SCSI command interface was based on the "Information
  34627. + * technology - Small Computer System Interface - 2" document from
  34628. + * X3T9.2 Project 375D, Revision 10L, 7-SEP-93, available at
  34629. + * <http://www.t10.org/ftp/t10/drafts/s2/s2-r10l.pdf>. The single exception
  34630. + * is opcode 0x23 (READ FORMAT CAPACITIES), which was based on the
  34631. + * "Universal Serial Bus Mass Storage Class UFI Command Specification"
  34632. + * document, Revision 1.0, December 14, 1998, available at
  34633. + * <http://www.usb.org/developers/devclass_docs/usbmass-ufi10.pdf>.
  34634. + */
  34635. +
  34636. +
  34637. +/*
  34638. + * Driver Design
  34639. + *
  34640. + * The FSG driver is fairly straightforward. There is a main kernel
  34641. + * thread that handles most of the work. Interrupt routines field
  34642. + * callbacks from the controller driver: bulk- and interrupt-request
  34643. + * completion notifications, endpoint-0 events, and disconnect events.
  34644. + * Completion events are passed to the main thread by wakeup calls. Many
  34645. + * ep0 requests are handled at interrupt time, but SetInterface,
  34646. + * SetConfiguration, and device reset requests are forwarded to the
  34647. + * thread in the form of "exceptions" using SIGUSR1 signals (since they
  34648. + * should interrupt any ongoing file I/O operations).
  34649. + *
  34650. + * The thread's main routine implements the standard command/data/status
  34651. + * parts of a SCSI interaction. It and its subroutines are full of tests
  34652. + * for pending signals/exceptions -- all this polling is necessary since
  34653. + * the kernel has no setjmp/longjmp equivalents. (Maybe this is an
  34654. + * indication that the driver really wants to be running in userspace.)
  34655. + * An important point is that so long as the thread is alive it keeps an
  34656. + * open reference to the backing file. This will prevent unmounting
  34657. + * the backing file's underlying filesystem and could cause problems
  34658. + * during system shutdown, for example. To prevent such problems, the
  34659. + * thread catches INT, TERM, and KILL signals and converts them into
  34660. + * an EXIT exception.
  34661. + *
  34662. + * In normal operation the main thread is started during the gadget's
  34663. + * fsg_bind() callback and stopped during fsg_unbind(). But it can also
  34664. + * exit when it receives a signal, and there's no point leaving the
  34665. + * gadget running when the thread is dead. So just before the thread
  34666. + * exits, it deregisters the gadget driver. This makes things a little
  34667. + * tricky: The driver is deregistered at two places, and the exiting
  34668. + * thread can indirectly call fsg_unbind() which in turn can tell the
  34669. + * thread to exit. The first problem is resolved through the use of the
  34670. + * REGISTERED atomic bitflag; the driver will only be deregistered once.
  34671. + * The second problem is resolved by having fsg_unbind() check
  34672. + * fsg->state; it won't try to stop the thread if the state is already
  34673. + * FSG_STATE_TERMINATED.
  34674. + *
  34675. + * To provide maximum throughput, the driver uses a circular pipeline of
  34676. + * buffer heads (struct fsg_buffhd). In principle the pipeline can be
  34677. + * arbitrarily long; in practice the benefits don't justify having more
  34678. + * than 2 stages (i.e., double buffering). But it helps to think of the
  34679. + * pipeline as being a long one. Each buffer head contains a bulk-in and
  34680. + * a bulk-out request pointer (since the buffer can be used for both
  34681. + * output and input -- directions always are given from the host's
  34682. + * point of view) as well as a pointer to the buffer and various state
  34683. + * variables.
  34684. + *
  34685. + * Use of the pipeline follows a simple protocol. There is a variable
  34686. + * (fsg->next_buffhd_to_fill) that points to the next buffer head to use.
  34687. + * At any time that buffer head may still be in use from an earlier
  34688. + * request, so each buffer head has a state variable indicating whether
  34689. + * it is EMPTY, FULL, or BUSY. Typical use involves waiting for the
  34690. + * buffer head to be EMPTY, filling the buffer either by file I/O or by
  34691. + * USB I/O (during which the buffer head is BUSY), and marking the buffer
  34692. + * head FULL when the I/O is complete. Then the buffer will be emptied
  34693. + * (again possibly by USB I/O, during which it is marked BUSY) and
  34694. + * finally marked EMPTY again (possibly by a completion routine).
  34695. + *
  34696. + * A module parameter tells the driver to avoid stalling the bulk
  34697. + * endpoints wherever the transport specification allows. This is
  34698. + * necessary for some UDCs like the SuperH, which cannot reliably clear a
  34699. + * halt on a bulk endpoint. However, under certain circumstances the
  34700. + * Bulk-only specification requires a stall. In such cases the driver
  34701. + * will halt the endpoint and set a flag indicating that it should clear
  34702. + * the halt in software during the next device reset. Hopefully this
  34703. + * will permit everything to work correctly. Furthermore, although the
  34704. + * specification allows the bulk-out endpoint to halt when the host sends
  34705. + * too much data, implementing this would cause an unavoidable race.
  34706. + * The driver will always use the "no-stall" approach for OUT transfers.
  34707. + *
  34708. + * One subtle point concerns sending status-stage responses for ep0
  34709. + * requests. Some of these requests, such as device reset, can involve
  34710. + * interrupting an ongoing file I/O operation, which might take an
  34711. + * arbitrarily long time. During that delay the host might give up on
  34712. + * the original ep0 request and issue a new one. When that happens the
  34713. + * driver should not notify the host about completion of the original
  34714. + * request, as the host will no longer be waiting for it. So the driver
  34715. + * assigns to each ep0 request a unique tag, and it keeps track of the
  34716. + * tag value of the request associated with a long-running exception
  34717. + * (device-reset, interface-change, or configuration-change). When the
  34718. + * exception handler is finished, the status-stage response is submitted
  34719. + * only if the current ep0 request tag is equal to the exception request
  34720. + * tag. Thus only the most recently received ep0 request will get a
  34721. + * status-stage response.
  34722. + *
  34723. + * Warning: This driver source file is too long. It ought to be split up
  34724. + * into a header file plus about 3 separate .c files, to handle the details
  34725. + * of the Gadget, USB Mass Storage, and SCSI protocols.
  34726. + */
  34727. +
  34728. +
  34729. +/* #define VERBOSE_DEBUG */
  34730. +/* #define DUMP_MSGS */
  34731. +
  34732. +
  34733. +#include <linux/blkdev.h>
  34734. +#include <linux/completion.h>
  34735. +#include <linux/dcache.h>
  34736. +#include <linux/delay.h>
  34737. +#include <linux/device.h>
  34738. +#include <linux/fcntl.h>
  34739. +#include <linux/file.h>
  34740. +#include <linux/fs.h>
  34741. +#include <linux/kref.h>
  34742. +#include <linux/kthread.h>
  34743. +#include <linux/limits.h>
  34744. +#include <linux/module.h>
  34745. +#include <linux/rwsem.h>
  34746. +#include <linux/slab.h>
  34747. +#include <linux/spinlock.h>
  34748. +#include <linux/string.h>
  34749. +#include <linux/freezer.h>
  34750. +#include <linux/utsname.h>
  34751. +
  34752. +#include <linux/usb/ch9.h>
  34753. +#include <linux/usb/gadget.h>
  34754. +
  34755. +#include "gadget_chips.h"
  34756. +
  34757. +
  34758. +
  34759. +/*
  34760. + * Kbuild is not very cooperative with respect to linking separately
  34761. + * compiled library objects into one module. So for now we won't use
  34762. + * separate compilation ... ensuring init/exit sections work to shrink
  34763. + * the runtime footprint, and giving us at least some parts of what
  34764. + * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
  34765. + */
  34766. +#include "usbstring.c"
  34767. +#include "config.c"
  34768. +#include "epautoconf.c"
  34769. +
  34770. +/*-------------------------------------------------------------------------*/
  34771. +
  34772. +#define DRIVER_DESC "File-backed Storage Gadget"
  34773. +#define DRIVER_NAME "g_file_storage"
  34774. +#define DRIVER_VERSION "1 September 2010"
  34775. +
  34776. +static char fsg_string_manufacturer[64];
  34777. +static const char fsg_string_product[] = DRIVER_DESC;
  34778. +static const char fsg_string_config[] = "Self-powered";
  34779. +static const char fsg_string_interface[] = "Mass Storage";
  34780. +
  34781. +
  34782. +#include "storage_common.c"
  34783. +
  34784. +
  34785. +MODULE_DESCRIPTION(DRIVER_DESC);
  34786. +MODULE_AUTHOR("Alan Stern");
  34787. +MODULE_LICENSE("Dual BSD/GPL");
  34788. +
  34789. +/*
  34790. + * This driver assumes self-powered hardware and has no way for users to
  34791. + * trigger remote wakeup. It uses autoconfiguration to select endpoints
  34792. + * and endpoint addresses.
  34793. + */
  34794. +
  34795. +
  34796. +/*-------------------------------------------------------------------------*/
  34797. +
  34798. +
  34799. +/* Encapsulate the module parameter settings */
  34800. +
  34801. +static struct {
  34802. + char *file[FSG_MAX_LUNS];
  34803. + char *serial;
  34804. + bool ro[FSG_MAX_LUNS];
  34805. + bool nofua[FSG_MAX_LUNS];
  34806. + unsigned int num_filenames;
  34807. + unsigned int num_ros;
  34808. + unsigned int num_nofuas;
  34809. + unsigned int nluns;
  34810. +
  34811. + bool removable;
  34812. + bool can_stall;
  34813. + bool cdrom;
  34814. +
  34815. + char *transport_parm;
  34816. + char *protocol_parm;
  34817. + unsigned short vendor;
  34818. + unsigned short product;
  34819. + unsigned short release;
  34820. + unsigned int buflen;
  34821. +
  34822. + int transport_type;
  34823. + char *transport_name;
  34824. + int protocol_type;
  34825. + char *protocol_name;
  34826. +
  34827. +} mod_data = { // Default values
  34828. + .transport_parm = "BBB",
  34829. + .protocol_parm = "SCSI",
  34830. + .removable = 0,
  34831. + .can_stall = 1,
  34832. + .cdrom = 0,
  34833. + .vendor = FSG_VENDOR_ID,
  34834. + .product = FSG_PRODUCT_ID,
  34835. + .release = 0xffff, // Use controller chip type
  34836. + .buflen = 16384,
  34837. + };
  34838. +
  34839. +
  34840. +module_param_array_named(file, mod_data.file, charp, &mod_data.num_filenames,
  34841. + S_IRUGO);
  34842. +MODULE_PARM_DESC(file, "names of backing files or devices");
  34843. +
  34844. +module_param_named(serial, mod_data.serial, charp, S_IRUGO);
  34845. +MODULE_PARM_DESC(serial, "USB serial number");
  34846. +
  34847. +module_param_array_named(ro, mod_data.ro, bool, &mod_data.num_ros, S_IRUGO);
  34848. +MODULE_PARM_DESC(ro, "true to force read-only");
  34849. +
  34850. +module_param_array_named(nofua, mod_data.nofua, bool, &mod_data.num_nofuas,
  34851. + S_IRUGO);
  34852. +MODULE_PARM_DESC(nofua, "true to ignore SCSI WRITE(10,12) FUA bit");
  34853. +
  34854. +module_param_named(luns, mod_data.nluns, uint, S_IRUGO);
  34855. +MODULE_PARM_DESC(luns, "number of LUNs");
  34856. +
  34857. +module_param_named(removable, mod_data.removable, bool, S_IRUGO);
  34858. +MODULE_PARM_DESC(removable, "true to simulate removable media");
  34859. +
  34860. +module_param_named(stall, mod_data.can_stall, bool, S_IRUGO);
  34861. +MODULE_PARM_DESC(stall, "false to prevent bulk stalls");
  34862. +
  34863. +module_param_named(cdrom, mod_data.cdrom, bool, S_IRUGO);
  34864. +MODULE_PARM_DESC(cdrom, "true to emulate cdrom instead of disk");
  34865. +
  34866. +/* In the non-TEST version, only the module parameters listed above
  34867. + * are available. */
  34868. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34869. +
  34870. +module_param_named(transport, mod_data.transport_parm, charp, S_IRUGO);
  34871. +MODULE_PARM_DESC(transport, "type of transport (BBB, CBI, or CB)");
  34872. +
  34873. +module_param_named(protocol, mod_data.protocol_parm, charp, S_IRUGO);
  34874. +MODULE_PARM_DESC(protocol, "type of protocol (RBC, 8020, QIC, UFI, "
  34875. + "8070, or SCSI)");
  34876. +
  34877. +module_param_named(vendor, mod_data.vendor, ushort, S_IRUGO);
  34878. +MODULE_PARM_DESC(vendor, "USB Vendor ID");
  34879. +
  34880. +module_param_named(product, mod_data.product, ushort, S_IRUGO);
  34881. +MODULE_PARM_DESC(product, "USB Product ID");
  34882. +
  34883. +module_param_named(release, mod_data.release, ushort, S_IRUGO);
  34884. +MODULE_PARM_DESC(release, "USB release number");
  34885. +
  34886. +module_param_named(buflen, mod_data.buflen, uint, S_IRUGO);
  34887. +MODULE_PARM_DESC(buflen, "I/O buffer size");
  34888. +
  34889. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34890. +
  34891. +
  34892. +/*
  34893. + * These definitions will permit the compiler to avoid generating code for
  34894. + * parts of the driver that aren't used in the non-TEST version. Even gcc
  34895. + * can recognize when a test of a constant expression yields a dead code
  34896. + * path.
  34897. + */
  34898. +
  34899. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  34900. +
  34901. +#define transport_is_bbb() (mod_data.transport_type == USB_PR_BULK)
  34902. +#define transport_is_cbi() (mod_data.transport_type == USB_PR_CBI)
  34903. +#define protocol_is_scsi() (mod_data.protocol_type == USB_SC_SCSI)
  34904. +
  34905. +#else
  34906. +
  34907. +#define transport_is_bbb() 1
  34908. +#define transport_is_cbi() 0
  34909. +#define protocol_is_scsi() 1
  34910. +
  34911. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  34912. +
  34913. +
  34914. +/*-------------------------------------------------------------------------*/
  34915. +
  34916. +
  34917. +struct fsg_dev {
  34918. + /* lock protects: state, all the req_busy's, and cbbuf_cmnd */
  34919. + spinlock_t lock;
  34920. + struct usb_gadget *gadget;
  34921. +
  34922. + /* filesem protects: backing files in use */
  34923. + struct rw_semaphore filesem;
  34924. +
  34925. + /* reference counting: wait until all LUNs are released */
  34926. + struct kref ref;
  34927. +
  34928. + struct usb_ep *ep0; // Handy copy of gadget->ep0
  34929. + struct usb_request *ep0req; // For control responses
  34930. + unsigned int ep0_req_tag;
  34931. + const char *ep0req_name;
  34932. +
  34933. + struct usb_request *intreq; // For interrupt responses
  34934. + int intreq_busy;
  34935. + struct fsg_buffhd *intr_buffhd;
  34936. +
  34937. + unsigned int bulk_out_maxpacket;
  34938. + enum fsg_state state; // For exception handling
  34939. + unsigned int exception_req_tag;
  34940. +
  34941. + u8 config, new_config;
  34942. +
  34943. + unsigned int running : 1;
  34944. + unsigned int bulk_in_enabled : 1;
  34945. + unsigned int bulk_out_enabled : 1;
  34946. + unsigned int intr_in_enabled : 1;
  34947. + unsigned int phase_error : 1;
  34948. + unsigned int short_packet_received : 1;
  34949. + unsigned int bad_lun_okay : 1;
  34950. +
  34951. + unsigned long atomic_bitflags;
  34952. +#define REGISTERED 0
  34953. +#define IGNORE_BULK_OUT 1
  34954. +#define SUSPENDED 2
  34955. +
  34956. + struct usb_ep *bulk_in;
  34957. + struct usb_ep *bulk_out;
  34958. + struct usb_ep *intr_in;
  34959. +
  34960. + struct fsg_buffhd *next_buffhd_to_fill;
  34961. + struct fsg_buffhd *next_buffhd_to_drain;
  34962. +
  34963. + int thread_wakeup_needed;
  34964. + struct completion thread_notifier;
  34965. + struct task_struct *thread_task;
  34966. +
  34967. + int cmnd_size;
  34968. + u8 cmnd[MAX_COMMAND_SIZE];
  34969. + enum data_direction data_dir;
  34970. + u32 data_size;
  34971. + u32 data_size_from_cmnd;
  34972. + u32 tag;
  34973. + unsigned int lun;
  34974. + u32 residue;
  34975. + u32 usb_amount_left;
  34976. +
  34977. + /* The CB protocol offers no way for a host to know when a command
  34978. + * has completed. As a result the next command may arrive early,
  34979. + * and we will still have to handle it. For that reason we need
  34980. + * a buffer to store new commands when using CB (or CBI, which
  34981. + * does not oblige a host to wait for command completion either). */
  34982. + int cbbuf_cmnd_size;
  34983. + u8 cbbuf_cmnd[MAX_COMMAND_SIZE];
  34984. +
  34985. + unsigned int nluns;
  34986. + struct fsg_lun *luns;
  34987. + struct fsg_lun *curlun;
  34988. + /* Must be the last entry */
  34989. + struct fsg_buffhd buffhds[];
  34990. +};
  34991. +
  34992. +typedef void (*fsg_routine_t)(struct fsg_dev *);
  34993. +
  34994. +static int exception_in_progress(struct fsg_dev *fsg)
  34995. +{
  34996. + return (fsg->state > FSG_STATE_IDLE);
  34997. +}
  34998. +
  34999. +/* Make bulk-out requests be divisible by the maxpacket size */
  35000. +static void set_bulk_out_req_length(struct fsg_dev *fsg,
  35001. + struct fsg_buffhd *bh, unsigned int length)
  35002. +{
  35003. + unsigned int rem;
  35004. +
  35005. + bh->bulk_out_intended_length = length;
  35006. + rem = length % fsg->bulk_out_maxpacket;
  35007. + if (rem > 0)
  35008. + length += fsg->bulk_out_maxpacket - rem;
  35009. + bh->outreq->length = length;
  35010. +}
  35011. +
  35012. +static struct fsg_dev *the_fsg;
  35013. +static struct usb_gadget_driver fsg_driver;
  35014. +
  35015. +
  35016. +/*-------------------------------------------------------------------------*/
  35017. +
  35018. +static int fsg_set_halt(struct fsg_dev *fsg, struct usb_ep *ep)
  35019. +{
  35020. + const char *name;
  35021. +
  35022. + if (ep == fsg->bulk_in)
  35023. + name = "bulk-in";
  35024. + else if (ep == fsg->bulk_out)
  35025. + name = "bulk-out";
  35026. + else
  35027. + name = ep->name;
  35028. + DBG(fsg, "%s set halt\n", name);
  35029. + return usb_ep_set_halt(ep);
  35030. +}
  35031. +
  35032. +
  35033. +/*-------------------------------------------------------------------------*/
  35034. +
  35035. +/*
  35036. + * DESCRIPTORS ... most are static, but strings and (full) configuration
  35037. + * descriptors are built on demand. Also the (static) config and interface
  35038. + * descriptors are adjusted during fsg_bind().
  35039. + */
  35040. +
  35041. +/* There is only one configuration. */
  35042. +#define CONFIG_VALUE 1
  35043. +
  35044. +static struct usb_device_descriptor
  35045. +device_desc = {
  35046. + .bLength = sizeof device_desc,
  35047. + .bDescriptorType = USB_DT_DEVICE,
  35048. +
  35049. + .bcdUSB = cpu_to_le16(0x0200),
  35050. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35051. +
  35052. + /* The next three values can be overridden by module parameters */
  35053. + .idVendor = cpu_to_le16(FSG_VENDOR_ID),
  35054. + .idProduct = cpu_to_le16(FSG_PRODUCT_ID),
  35055. + .bcdDevice = cpu_to_le16(0xffff),
  35056. +
  35057. + .iManufacturer = FSG_STRING_MANUFACTURER,
  35058. + .iProduct = FSG_STRING_PRODUCT,
  35059. + .iSerialNumber = FSG_STRING_SERIAL,
  35060. + .bNumConfigurations = 1,
  35061. +};
  35062. +
  35063. +static struct usb_config_descriptor
  35064. +config_desc = {
  35065. + .bLength = sizeof config_desc,
  35066. + .bDescriptorType = USB_DT_CONFIG,
  35067. +
  35068. + /* wTotalLength computed by usb_gadget_config_buf() */
  35069. + .bNumInterfaces = 1,
  35070. + .bConfigurationValue = CONFIG_VALUE,
  35071. + .iConfiguration = FSG_STRING_CONFIG,
  35072. + .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
  35073. + .bMaxPower = CONFIG_USB_GADGET_VBUS_DRAW / 2,
  35074. +};
  35075. +
  35076. +
  35077. +static struct usb_qualifier_descriptor
  35078. +dev_qualifier = {
  35079. + .bLength = sizeof dev_qualifier,
  35080. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  35081. +
  35082. + .bcdUSB = cpu_to_le16(0x0200),
  35083. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  35084. +
  35085. + .bNumConfigurations = 1,
  35086. +};
  35087. +
  35088. +static int populate_bos(struct fsg_dev *fsg, u8 *buf)
  35089. +{
  35090. + memcpy(buf, &fsg_bos_desc, USB_DT_BOS_SIZE);
  35091. + buf += USB_DT_BOS_SIZE;
  35092. +
  35093. + memcpy(buf, &fsg_ext_cap_desc, USB_DT_USB_EXT_CAP_SIZE);
  35094. + buf += USB_DT_USB_EXT_CAP_SIZE;
  35095. +
  35096. + memcpy(buf, &fsg_ss_cap_desc, USB_DT_USB_SS_CAP_SIZE);
  35097. +
  35098. + return USB_DT_BOS_SIZE + USB_DT_USB_SS_CAP_SIZE
  35099. + + USB_DT_USB_EXT_CAP_SIZE;
  35100. +}
  35101. +
  35102. +/*
  35103. + * Config descriptors must agree with the code that sets configurations
  35104. + * and with code managing interfaces and their altsettings. They must
  35105. + * also handle different speeds and other-speed requests.
  35106. + */
  35107. +static int populate_config_buf(struct usb_gadget *gadget,
  35108. + u8 *buf, u8 type, unsigned index)
  35109. +{
  35110. + enum usb_device_speed speed = gadget->speed;
  35111. + int len;
  35112. + const struct usb_descriptor_header **function;
  35113. +
  35114. + if (index > 0)
  35115. + return -EINVAL;
  35116. +
  35117. + if (gadget_is_dualspeed(gadget) && type == USB_DT_OTHER_SPEED_CONFIG)
  35118. + speed = (USB_SPEED_FULL + USB_SPEED_HIGH) - speed;
  35119. + function = gadget_is_dualspeed(gadget) && speed == USB_SPEED_HIGH
  35120. + ? (const struct usb_descriptor_header **)fsg_hs_function
  35121. + : (const struct usb_descriptor_header **)fsg_fs_function;
  35122. +
  35123. + /* for now, don't advertise srp-only devices */
  35124. + if (!gadget_is_otg(gadget))
  35125. + function++;
  35126. +
  35127. + len = usb_gadget_config_buf(&config_desc, buf, EP0_BUFSIZE, function);
  35128. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  35129. + return len;
  35130. +}
  35131. +
  35132. +
  35133. +/*-------------------------------------------------------------------------*/
  35134. +
  35135. +/* These routines may be called in process context or in_irq */
  35136. +
  35137. +/* Caller must hold fsg->lock */
  35138. +static void wakeup_thread(struct fsg_dev *fsg)
  35139. +{
  35140. + /* Tell the main thread that something has happened */
  35141. + fsg->thread_wakeup_needed = 1;
  35142. + if (fsg->thread_task)
  35143. + wake_up_process(fsg->thread_task);
  35144. +}
  35145. +
  35146. +
  35147. +static void raise_exception(struct fsg_dev *fsg, enum fsg_state new_state)
  35148. +{
  35149. + unsigned long flags;
  35150. +
  35151. + /* Do nothing if a higher-priority exception is already in progress.
  35152. + * If a lower-or-equal priority exception is in progress, preempt it
  35153. + * and notify the main thread by sending it a signal. */
  35154. + spin_lock_irqsave(&fsg->lock, flags);
  35155. + if (fsg->state <= new_state) {
  35156. + fsg->exception_req_tag = fsg->ep0_req_tag;
  35157. + fsg->state = new_state;
  35158. + if (fsg->thread_task)
  35159. + send_sig_info(SIGUSR1, SEND_SIG_FORCED,
  35160. + fsg->thread_task);
  35161. + }
  35162. + spin_unlock_irqrestore(&fsg->lock, flags);
  35163. +}
  35164. +
  35165. +
  35166. +/*-------------------------------------------------------------------------*/
  35167. +
  35168. +/* The disconnect callback and ep0 routines. These always run in_irq,
  35169. + * except that ep0_queue() is called in the main thread to acknowledge
  35170. + * completion of various requests: set config, set interface, and
  35171. + * Bulk-only device reset. */
  35172. +
  35173. +static void fsg_disconnect(struct usb_gadget *gadget)
  35174. +{
  35175. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35176. +
  35177. + DBG(fsg, "disconnect or port reset\n");
  35178. + raise_exception(fsg, FSG_STATE_DISCONNECT);
  35179. +}
  35180. +
  35181. +
  35182. +static int ep0_queue(struct fsg_dev *fsg)
  35183. +{
  35184. + int rc;
  35185. +
  35186. + rc = usb_ep_queue(fsg->ep0, fsg->ep0req, GFP_ATOMIC);
  35187. + if (rc != 0 && rc != -ESHUTDOWN) {
  35188. +
  35189. + /* We can't do much more than wait for a reset */
  35190. + WARNING(fsg, "error in submission: %s --> %d\n",
  35191. + fsg->ep0->name, rc);
  35192. + }
  35193. + return rc;
  35194. +}
  35195. +
  35196. +static void ep0_complete(struct usb_ep *ep, struct usb_request *req)
  35197. +{
  35198. + struct fsg_dev *fsg = ep->driver_data;
  35199. +
  35200. + if (req->actual > 0)
  35201. + dump_msg(fsg, fsg->ep0req_name, req->buf, req->actual);
  35202. + if (req->status || req->actual != req->length)
  35203. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35204. + req->status, req->actual, req->length);
  35205. + if (req->status == -ECONNRESET) // Request was cancelled
  35206. + usb_ep_fifo_flush(ep);
  35207. +
  35208. + if (req->status == 0 && req->context)
  35209. + ((fsg_routine_t) (req->context))(fsg);
  35210. +}
  35211. +
  35212. +
  35213. +/*-------------------------------------------------------------------------*/
  35214. +
  35215. +/* Bulk and interrupt endpoint completion handlers.
  35216. + * These always run in_irq. */
  35217. +
  35218. +static void bulk_in_complete(struct usb_ep *ep, struct usb_request *req)
  35219. +{
  35220. + struct fsg_dev *fsg = ep->driver_data;
  35221. + struct fsg_buffhd *bh = req->context;
  35222. +
  35223. + if (req->status || req->actual != req->length)
  35224. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35225. + req->status, req->actual, req->length);
  35226. + if (req->status == -ECONNRESET) // Request was cancelled
  35227. + usb_ep_fifo_flush(ep);
  35228. +
  35229. + /* Hold the lock while we update the request and buffer states */
  35230. + smp_wmb();
  35231. + spin_lock(&fsg->lock);
  35232. + bh->inreq_busy = 0;
  35233. + bh->state = BUF_STATE_EMPTY;
  35234. + wakeup_thread(fsg);
  35235. + spin_unlock(&fsg->lock);
  35236. +}
  35237. +
  35238. +static void bulk_out_complete(struct usb_ep *ep, struct usb_request *req)
  35239. +{
  35240. + struct fsg_dev *fsg = ep->driver_data;
  35241. + struct fsg_buffhd *bh = req->context;
  35242. +
  35243. + dump_msg(fsg, "bulk-out", req->buf, req->actual);
  35244. + if (req->status || req->actual != bh->bulk_out_intended_length)
  35245. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35246. + req->status, req->actual,
  35247. + bh->bulk_out_intended_length);
  35248. + if (req->status == -ECONNRESET) // Request was cancelled
  35249. + usb_ep_fifo_flush(ep);
  35250. +
  35251. + /* Hold the lock while we update the request and buffer states */
  35252. + smp_wmb();
  35253. + spin_lock(&fsg->lock);
  35254. + bh->outreq_busy = 0;
  35255. + bh->state = BUF_STATE_FULL;
  35256. + wakeup_thread(fsg);
  35257. + spin_unlock(&fsg->lock);
  35258. +}
  35259. +
  35260. +
  35261. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35262. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35263. +{
  35264. + struct fsg_dev *fsg = ep->driver_data;
  35265. + struct fsg_buffhd *bh = req->context;
  35266. +
  35267. + if (req->status || req->actual != req->length)
  35268. + DBG(fsg, "%s --> %d, %u/%u\n", __func__,
  35269. + req->status, req->actual, req->length);
  35270. + if (req->status == -ECONNRESET) // Request was cancelled
  35271. + usb_ep_fifo_flush(ep);
  35272. +
  35273. + /* Hold the lock while we update the request and buffer states */
  35274. + smp_wmb();
  35275. + spin_lock(&fsg->lock);
  35276. + fsg->intreq_busy = 0;
  35277. + bh->state = BUF_STATE_EMPTY;
  35278. + wakeup_thread(fsg);
  35279. + spin_unlock(&fsg->lock);
  35280. +}
  35281. +
  35282. +#else
  35283. +static void intr_in_complete(struct usb_ep *ep, struct usb_request *req)
  35284. +{}
  35285. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35286. +
  35287. +
  35288. +/*-------------------------------------------------------------------------*/
  35289. +
  35290. +/* Ep0 class-specific handlers. These always run in_irq. */
  35291. +
  35292. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  35293. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35294. +{
  35295. + struct usb_request *req = fsg->ep0req;
  35296. + static u8 cbi_reset_cmnd[6] = {
  35297. + SEND_DIAGNOSTIC, 4, 0xff, 0xff, 0xff, 0xff};
  35298. +
  35299. + /* Error in command transfer? */
  35300. + if (req->status || req->length != req->actual ||
  35301. + req->actual < 6 || req->actual > MAX_COMMAND_SIZE) {
  35302. +
  35303. + /* Not all controllers allow a protocol stall after
  35304. + * receiving control-out data, but we'll try anyway. */
  35305. + fsg_set_halt(fsg, fsg->ep0);
  35306. + return; // Wait for reset
  35307. + }
  35308. +
  35309. + /* Is it the special reset command? */
  35310. + if (req->actual >= sizeof cbi_reset_cmnd &&
  35311. + memcmp(req->buf, cbi_reset_cmnd,
  35312. + sizeof cbi_reset_cmnd) == 0) {
  35313. +
  35314. + /* Raise an exception to stop the current operation
  35315. + * and reinitialize our state. */
  35316. + DBG(fsg, "cbi reset request\n");
  35317. + raise_exception(fsg, FSG_STATE_RESET);
  35318. + return;
  35319. + }
  35320. +
  35321. + VDBG(fsg, "CB[I] accept device-specific command\n");
  35322. + spin_lock(&fsg->lock);
  35323. +
  35324. + /* Save the command for later */
  35325. + if (fsg->cbbuf_cmnd_size)
  35326. + WARNING(fsg, "CB[I] overwriting previous command\n");
  35327. + fsg->cbbuf_cmnd_size = req->actual;
  35328. + memcpy(fsg->cbbuf_cmnd, req->buf, fsg->cbbuf_cmnd_size);
  35329. +
  35330. + wakeup_thread(fsg);
  35331. + spin_unlock(&fsg->lock);
  35332. +}
  35333. +
  35334. +#else
  35335. +static void received_cbi_adsc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  35336. +{}
  35337. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  35338. +
  35339. +
  35340. +static int class_setup_req(struct fsg_dev *fsg,
  35341. + const struct usb_ctrlrequest *ctrl)
  35342. +{
  35343. + struct usb_request *req = fsg->ep0req;
  35344. + int value = -EOPNOTSUPP;
  35345. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35346. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35347. + u16 w_length = le16_to_cpu(ctrl->wLength);
  35348. +
  35349. + if (!fsg->config)
  35350. + return value;
  35351. +
  35352. + /* Handle Bulk-only class-specific requests */
  35353. + if (transport_is_bbb()) {
  35354. + switch (ctrl->bRequest) {
  35355. +
  35356. + case US_BULK_RESET_REQUEST:
  35357. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35358. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35359. + break;
  35360. + if (w_index != 0 || w_value != 0 || w_length != 0) {
  35361. + value = -EDOM;
  35362. + break;
  35363. + }
  35364. +
  35365. + /* Raise an exception to stop the current operation
  35366. + * and reinitialize our state. */
  35367. + DBG(fsg, "bulk reset request\n");
  35368. + raise_exception(fsg, FSG_STATE_RESET);
  35369. + value = DELAYED_STATUS;
  35370. + break;
  35371. +
  35372. + case US_BULK_GET_MAX_LUN:
  35373. + if (ctrl->bRequestType != (USB_DIR_IN |
  35374. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35375. + break;
  35376. + if (w_index != 0 || w_value != 0 || w_length != 1) {
  35377. + value = -EDOM;
  35378. + break;
  35379. + }
  35380. + VDBG(fsg, "get max LUN\n");
  35381. + *(u8 *) req->buf = fsg->nluns - 1;
  35382. + value = 1;
  35383. + break;
  35384. + }
  35385. + }
  35386. +
  35387. + /* Handle CBI class-specific requests */
  35388. + else {
  35389. + switch (ctrl->bRequest) {
  35390. +
  35391. + case USB_CBI_ADSC_REQUEST:
  35392. + if (ctrl->bRequestType != (USB_DIR_OUT |
  35393. + USB_TYPE_CLASS | USB_RECIP_INTERFACE))
  35394. + break;
  35395. + if (w_index != 0 || w_value != 0) {
  35396. + value = -EDOM;
  35397. + break;
  35398. + }
  35399. + if (w_length > MAX_COMMAND_SIZE) {
  35400. + value = -EOVERFLOW;
  35401. + break;
  35402. + }
  35403. + value = w_length;
  35404. + fsg->ep0req->context = received_cbi_adsc;
  35405. + break;
  35406. + }
  35407. + }
  35408. +
  35409. + if (value == -EOPNOTSUPP)
  35410. + VDBG(fsg,
  35411. + "unknown class-specific control req "
  35412. + "%02x.%02x v%04x i%04x l%u\n",
  35413. + ctrl->bRequestType, ctrl->bRequest,
  35414. + le16_to_cpu(ctrl->wValue), w_index, w_length);
  35415. + return value;
  35416. +}
  35417. +
  35418. +
  35419. +/*-------------------------------------------------------------------------*/
  35420. +
  35421. +/* Ep0 standard request handlers. These always run in_irq. */
  35422. +
  35423. +static int standard_setup_req(struct fsg_dev *fsg,
  35424. + const struct usb_ctrlrequest *ctrl)
  35425. +{
  35426. + struct usb_request *req = fsg->ep0req;
  35427. + int value = -EOPNOTSUPP;
  35428. + u16 w_index = le16_to_cpu(ctrl->wIndex);
  35429. + u16 w_value = le16_to_cpu(ctrl->wValue);
  35430. +
  35431. + /* Usually this just stores reply data in the pre-allocated ep0 buffer,
  35432. + * but config change events will also reconfigure hardware. */
  35433. + switch (ctrl->bRequest) {
  35434. +
  35435. + case USB_REQ_GET_DESCRIPTOR:
  35436. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35437. + USB_RECIP_DEVICE))
  35438. + break;
  35439. + switch (w_value >> 8) {
  35440. +
  35441. + case USB_DT_DEVICE:
  35442. + VDBG(fsg, "get device descriptor\n");
  35443. + device_desc.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35444. + value = sizeof device_desc;
  35445. + memcpy(req->buf, &device_desc, value);
  35446. + break;
  35447. + case USB_DT_DEVICE_QUALIFIER:
  35448. + VDBG(fsg, "get device qualifier\n");
  35449. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35450. + fsg->gadget->speed == USB_SPEED_SUPER)
  35451. + break;
  35452. + /*
  35453. + * Assume ep0 uses the same maxpacket value for both
  35454. + * speeds
  35455. + */
  35456. + dev_qualifier.bMaxPacketSize0 = fsg->ep0->maxpacket;
  35457. + value = sizeof dev_qualifier;
  35458. + memcpy(req->buf, &dev_qualifier, value);
  35459. + break;
  35460. +
  35461. + case USB_DT_OTHER_SPEED_CONFIG:
  35462. + VDBG(fsg, "get other-speed config descriptor\n");
  35463. + if (!gadget_is_dualspeed(fsg->gadget) ||
  35464. + fsg->gadget->speed == USB_SPEED_SUPER)
  35465. + break;
  35466. + goto get_config;
  35467. + case USB_DT_CONFIG:
  35468. + VDBG(fsg, "get configuration descriptor\n");
  35469. +get_config:
  35470. + value = populate_config_buf(fsg->gadget,
  35471. + req->buf,
  35472. + w_value >> 8,
  35473. + w_value & 0xff);
  35474. + break;
  35475. +
  35476. + case USB_DT_STRING:
  35477. + VDBG(fsg, "get string descriptor\n");
  35478. +
  35479. + /* wIndex == language code */
  35480. + value = usb_gadget_get_string(&fsg_stringtab,
  35481. + w_value & 0xff, req->buf);
  35482. + break;
  35483. +
  35484. + case USB_DT_BOS:
  35485. + VDBG(fsg, "get bos descriptor\n");
  35486. +
  35487. + if (gadget_is_superspeed(fsg->gadget))
  35488. + value = populate_bos(fsg, req->buf);
  35489. + break;
  35490. + }
  35491. +
  35492. + break;
  35493. +
  35494. + /* One config, two speeds */
  35495. + case USB_REQ_SET_CONFIGURATION:
  35496. + if (ctrl->bRequestType != (USB_DIR_OUT | USB_TYPE_STANDARD |
  35497. + USB_RECIP_DEVICE))
  35498. + break;
  35499. + VDBG(fsg, "set configuration\n");
  35500. + if (w_value == CONFIG_VALUE || w_value == 0) {
  35501. + fsg->new_config = w_value;
  35502. +
  35503. + /* Raise an exception to wipe out previous transaction
  35504. + * state (queued bufs, etc) and set the new config. */
  35505. + raise_exception(fsg, FSG_STATE_CONFIG_CHANGE);
  35506. + value = DELAYED_STATUS;
  35507. + }
  35508. + break;
  35509. + case USB_REQ_GET_CONFIGURATION:
  35510. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35511. + USB_RECIP_DEVICE))
  35512. + break;
  35513. + VDBG(fsg, "get configuration\n");
  35514. + *(u8 *) req->buf = fsg->config;
  35515. + value = 1;
  35516. + break;
  35517. +
  35518. + case USB_REQ_SET_INTERFACE:
  35519. + if (ctrl->bRequestType != (USB_DIR_OUT| USB_TYPE_STANDARD |
  35520. + USB_RECIP_INTERFACE))
  35521. + break;
  35522. + if (fsg->config && w_index == 0) {
  35523. +
  35524. + /* Raise an exception to wipe out previous transaction
  35525. + * state (queued bufs, etc) and install the new
  35526. + * interface altsetting. */
  35527. + raise_exception(fsg, FSG_STATE_INTERFACE_CHANGE);
  35528. + value = DELAYED_STATUS;
  35529. + }
  35530. + break;
  35531. + case USB_REQ_GET_INTERFACE:
  35532. + if (ctrl->bRequestType != (USB_DIR_IN | USB_TYPE_STANDARD |
  35533. + USB_RECIP_INTERFACE))
  35534. + break;
  35535. + if (!fsg->config)
  35536. + break;
  35537. + if (w_index != 0) {
  35538. + value = -EDOM;
  35539. + break;
  35540. + }
  35541. + VDBG(fsg, "get interface\n");
  35542. + *(u8 *) req->buf = 0;
  35543. + value = 1;
  35544. + break;
  35545. +
  35546. + default:
  35547. + VDBG(fsg,
  35548. + "unknown control req %02x.%02x v%04x i%04x l%u\n",
  35549. + ctrl->bRequestType, ctrl->bRequest,
  35550. + w_value, w_index, le16_to_cpu(ctrl->wLength));
  35551. + }
  35552. +
  35553. + return value;
  35554. +}
  35555. +
  35556. +
  35557. +static int fsg_setup(struct usb_gadget *gadget,
  35558. + const struct usb_ctrlrequest *ctrl)
  35559. +{
  35560. + struct fsg_dev *fsg = get_gadget_data(gadget);
  35561. + int rc;
  35562. + int w_length = le16_to_cpu(ctrl->wLength);
  35563. +
  35564. + ++fsg->ep0_req_tag; // Record arrival of a new request
  35565. + fsg->ep0req->context = NULL;
  35566. + fsg->ep0req->length = 0;
  35567. + dump_msg(fsg, "ep0-setup", (u8 *) ctrl, sizeof(*ctrl));
  35568. +
  35569. + if ((ctrl->bRequestType & USB_TYPE_MASK) == USB_TYPE_CLASS)
  35570. + rc = class_setup_req(fsg, ctrl);
  35571. + else
  35572. + rc = standard_setup_req(fsg, ctrl);
  35573. +
  35574. + /* Respond with data/status or defer until later? */
  35575. + if (rc >= 0 && rc != DELAYED_STATUS) {
  35576. + rc = min(rc, w_length);
  35577. + fsg->ep0req->length = rc;
  35578. + fsg->ep0req->zero = rc < w_length;
  35579. + fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
  35580. + "ep0-in" : "ep0-out");
  35581. + rc = ep0_queue(fsg);
  35582. + }
  35583. +
  35584. + /* Device either stalls (rc < 0) or reports success */
  35585. + return rc;
  35586. +}
  35587. +
  35588. +
  35589. +/*-------------------------------------------------------------------------*/
  35590. +
  35591. +/* All the following routines run in process context */
  35592. +
  35593. +
  35594. +/* Use this for bulk or interrupt transfers, not ep0 */
  35595. +static void start_transfer(struct fsg_dev *fsg, struct usb_ep *ep,
  35596. + struct usb_request *req, int *pbusy,
  35597. + enum fsg_buffer_state *state)
  35598. +{
  35599. + int rc;
  35600. +
  35601. + if (ep == fsg->bulk_in)
  35602. + dump_msg(fsg, "bulk-in", req->buf, req->length);
  35603. + else if (ep == fsg->intr_in)
  35604. + dump_msg(fsg, "intr-in", req->buf, req->length);
  35605. +
  35606. + spin_lock_irq(&fsg->lock);
  35607. + *pbusy = 1;
  35608. + *state = BUF_STATE_BUSY;
  35609. + spin_unlock_irq(&fsg->lock);
  35610. + rc = usb_ep_queue(ep, req, GFP_KERNEL);
  35611. + if (rc != 0) {
  35612. + *pbusy = 0;
  35613. + *state = BUF_STATE_EMPTY;
  35614. +
  35615. + /* We can't do much more than wait for a reset */
  35616. +
  35617. + /* Note: currently the net2280 driver fails zero-length
  35618. + * submissions if DMA is enabled. */
  35619. + if (rc != -ESHUTDOWN && !(rc == -EOPNOTSUPP &&
  35620. + req->length == 0))
  35621. + WARNING(fsg, "error in submission: %s --> %d\n",
  35622. + ep->name, rc);
  35623. + }
  35624. +}
  35625. +
  35626. +
  35627. +static int sleep_thread(struct fsg_dev *fsg)
  35628. +{
  35629. + int rc = 0;
  35630. +
  35631. + /* Wait until a signal arrives or we are woken up */
  35632. + for (;;) {
  35633. + try_to_freeze();
  35634. + set_current_state(TASK_INTERRUPTIBLE);
  35635. + if (signal_pending(current)) {
  35636. + rc = -EINTR;
  35637. + break;
  35638. + }
  35639. + if (fsg->thread_wakeup_needed)
  35640. + break;
  35641. + schedule();
  35642. + }
  35643. + __set_current_state(TASK_RUNNING);
  35644. + fsg->thread_wakeup_needed = 0;
  35645. + return rc;
  35646. +}
  35647. +
  35648. +
  35649. +/*-------------------------------------------------------------------------*/
  35650. +
  35651. +static int do_read(struct fsg_dev *fsg)
  35652. +{
  35653. + struct fsg_lun *curlun = fsg->curlun;
  35654. + u32 lba;
  35655. + struct fsg_buffhd *bh;
  35656. + int rc;
  35657. + u32 amount_left;
  35658. + loff_t file_offset, file_offset_tmp;
  35659. + unsigned int amount;
  35660. + ssize_t nread;
  35661. +
  35662. + /* Get the starting Logical Block Address and check that it's
  35663. + * not too big */
  35664. + if (fsg->cmnd[0] == READ_6)
  35665. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35666. + else {
  35667. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35668. +
  35669. + /* We allow DPO (Disable Page Out = don't save data in the
  35670. + * cache) and FUA (Force Unit Access = don't read from the
  35671. + * cache), but we don't implement them. */
  35672. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35673. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35674. + return -EINVAL;
  35675. + }
  35676. + }
  35677. + if (lba >= curlun->num_sectors) {
  35678. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35679. + return -EINVAL;
  35680. + }
  35681. + file_offset = ((loff_t) lba) << curlun->blkbits;
  35682. +
  35683. + /* Carry out the file reads */
  35684. + amount_left = fsg->data_size_from_cmnd;
  35685. + if (unlikely(amount_left == 0))
  35686. + return -EIO; // No default reply
  35687. +
  35688. + for (;;) {
  35689. +
  35690. + /* Figure out how much we need to read:
  35691. + * Try to read the remaining amount.
  35692. + * But don't read more than the buffer size.
  35693. + * And don't try to read past the end of the file.
  35694. + */
  35695. + amount = min((unsigned int) amount_left, mod_data.buflen);
  35696. + amount = min((loff_t) amount,
  35697. + curlun->file_length - file_offset);
  35698. +
  35699. + /* Wait for the next buffer to become available */
  35700. + bh = fsg->next_buffhd_to_fill;
  35701. + while (bh->state != BUF_STATE_EMPTY) {
  35702. + rc = sleep_thread(fsg);
  35703. + if (rc)
  35704. + return rc;
  35705. + }
  35706. +
  35707. + /* If we were asked to read past the end of file,
  35708. + * end with an empty buffer. */
  35709. + if (amount == 0) {
  35710. + curlun->sense_data =
  35711. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35712. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35713. + curlun->info_valid = 1;
  35714. + bh->inreq->length = 0;
  35715. + bh->state = BUF_STATE_FULL;
  35716. + break;
  35717. + }
  35718. +
  35719. + /* Perform the read */
  35720. + file_offset_tmp = file_offset;
  35721. + nread = vfs_read(curlun->filp,
  35722. + (char __user *) bh->buf,
  35723. + amount, &file_offset_tmp);
  35724. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  35725. + (unsigned long long) file_offset,
  35726. + (int) nread);
  35727. + if (signal_pending(current))
  35728. + return -EINTR;
  35729. +
  35730. + if (nread < 0) {
  35731. + LDBG(curlun, "error in file read: %d\n",
  35732. + (int) nread);
  35733. + nread = 0;
  35734. + } else if (nread < amount) {
  35735. + LDBG(curlun, "partial file read: %d/%u\n",
  35736. + (int) nread, amount);
  35737. + nread = round_down(nread, curlun->blksize);
  35738. + }
  35739. + file_offset += nread;
  35740. + amount_left -= nread;
  35741. + fsg->residue -= nread;
  35742. +
  35743. + /* Except at the end of the transfer, nread will be
  35744. + * equal to the buffer size, which is divisible by the
  35745. + * bulk-in maxpacket size.
  35746. + */
  35747. + bh->inreq->length = nread;
  35748. + bh->state = BUF_STATE_FULL;
  35749. +
  35750. + /* If an error occurred, report it and its position */
  35751. + if (nread < amount) {
  35752. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  35753. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35754. + curlun->info_valid = 1;
  35755. + break;
  35756. + }
  35757. +
  35758. + if (amount_left == 0)
  35759. + break; // No more left to read
  35760. +
  35761. + /* Send this buffer and go read some more */
  35762. + bh->inreq->zero = 0;
  35763. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  35764. + &bh->inreq_busy, &bh->state);
  35765. + fsg->next_buffhd_to_fill = bh->next;
  35766. + }
  35767. +
  35768. + return -EIO; // No default reply
  35769. +}
  35770. +
  35771. +
  35772. +/*-------------------------------------------------------------------------*/
  35773. +
  35774. +static int do_write(struct fsg_dev *fsg)
  35775. +{
  35776. + struct fsg_lun *curlun = fsg->curlun;
  35777. + u32 lba;
  35778. + struct fsg_buffhd *bh;
  35779. + int get_some_more;
  35780. + u32 amount_left_to_req, amount_left_to_write;
  35781. + loff_t usb_offset, file_offset, file_offset_tmp;
  35782. + unsigned int amount;
  35783. + ssize_t nwritten;
  35784. + int rc;
  35785. +
  35786. + if (curlun->ro) {
  35787. + curlun->sense_data = SS_WRITE_PROTECTED;
  35788. + return -EINVAL;
  35789. + }
  35790. + spin_lock(&curlun->filp->f_lock);
  35791. + curlun->filp->f_flags &= ~O_SYNC; // Default is not to wait
  35792. + spin_unlock(&curlun->filp->f_lock);
  35793. +
  35794. + /* Get the starting Logical Block Address and check that it's
  35795. + * not too big */
  35796. + if (fsg->cmnd[0] == WRITE_6)
  35797. + lba = get_unaligned_be24(&fsg->cmnd[1]);
  35798. + else {
  35799. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35800. +
  35801. + /* We allow DPO (Disable Page Out = don't save data in the
  35802. + * cache) and FUA (Force Unit Access = write directly to the
  35803. + * medium). We don't implement DPO; we implement FUA by
  35804. + * performing synchronous output. */
  35805. + if ((fsg->cmnd[1] & ~0x18) != 0) {
  35806. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  35807. + return -EINVAL;
  35808. + }
  35809. + /* FUA */
  35810. + if (!curlun->nofua && (fsg->cmnd[1] & 0x08)) {
  35811. + spin_lock(&curlun->filp->f_lock);
  35812. + curlun->filp->f_flags |= O_DSYNC;
  35813. + spin_unlock(&curlun->filp->f_lock);
  35814. + }
  35815. + }
  35816. + if (lba >= curlun->num_sectors) {
  35817. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35818. + return -EINVAL;
  35819. + }
  35820. +
  35821. + /* Carry out the file writes */
  35822. + get_some_more = 1;
  35823. + file_offset = usb_offset = ((loff_t) lba) << curlun->blkbits;
  35824. + amount_left_to_req = amount_left_to_write = fsg->data_size_from_cmnd;
  35825. +
  35826. + while (amount_left_to_write > 0) {
  35827. +
  35828. + /* Queue a request for more data from the host */
  35829. + bh = fsg->next_buffhd_to_fill;
  35830. + if (bh->state == BUF_STATE_EMPTY && get_some_more) {
  35831. +
  35832. + /* Figure out how much we want to get:
  35833. + * Try to get the remaining amount,
  35834. + * but not more than the buffer size.
  35835. + */
  35836. + amount = min(amount_left_to_req, mod_data.buflen);
  35837. +
  35838. + /* Beyond the end of the backing file? */
  35839. + if (usb_offset >= curlun->file_length) {
  35840. + get_some_more = 0;
  35841. + curlun->sense_data =
  35842. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35843. + curlun->sense_data_info = usb_offset >> curlun->blkbits;
  35844. + curlun->info_valid = 1;
  35845. + continue;
  35846. + }
  35847. +
  35848. + /* Get the next buffer */
  35849. + usb_offset += amount;
  35850. + fsg->usb_amount_left -= amount;
  35851. + amount_left_to_req -= amount;
  35852. + if (amount_left_to_req == 0)
  35853. + get_some_more = 0;
  35854. +
  35855. + /* Except at the end of the transfer, amount will be
  35856. + * equal to the buffer size, which is divisible by
  35857. + * the bulk-out maxpacket size.
  35858. + */
  35859. + set_bulk_out_req_length(fsg, bh, amount);
  35860. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  35861. + &bh->outreq_busy, &bh->state);
  35862. + fsg->next_buffhd_to_fill = bh->next;
  35863. + continue;
  35864. + }
  35865. +
  35866. + /* Write the received data to the backing file */
  35867. + bh = fsg->next_buffhd_to_drain;
  35868. + if (bh->state == BUF_STATE_EMPTY && !get_some_more)
  35869. + break; // We stopped early
  35870. + if (bh->state == BUF_STATE_FULL) {
  35871. + smp_rmb();
  35872. + fsg->next_buffhd_to_drain = bh->next;
  35873. + bh->state = BUF_STATE_EMPTY;
  35874. +
  35875. + /* Did something go wrong with the transfer? */
  35876. + if (bh->outreq->status != 0) {
  35877. + curlun->sense_data = SS_COMMUNICATION_FAILURE;
  35878. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35879. + curlun->info_valid = 1;
  35880. + break;
  35881. + }
  35882. +
  35883. + amount = bh->outreq->actual;
  35884. + if (curlun->file_length - file_offset < amount) {
  35885. + LERROR(curlun,
  35886. + "write %u @ %llu beyond end %llu\n",
  35887. + amount, (unsigned long long) file_offset,
  35888. + (unsigned long long) curlun->file_length);
  35889. + amount = curlun->file_length - file_offset;
  35890. + }
  35891. +
  35892. + /* Don't accept excess data. The spec doesn't say
  35893. + * what to do in this case. We'll ignore the error.
  35894. + */
  35895. + amount = min(amount, bh->bulk_out_intended_length);
  35896. +
  35897. + /* Don't write a partial block */
  35898. + amount = round_down(amount, curlun->blksize);
  35899. + if (amount == 0)
  35900. + goto empty_write;
  35901. +
  35902. + /* Perform the write */
  35903. + file_offset_tmp = file_offset;
  35904. + nwritten = vfs_write(curlun->filp,
  35905. + (char __user *) bh->buf,
  35906. + amount, &file_offset_tmp);
  35907. + VLDBG(curlun, "file write %u @ %llu -> %d\n", amount,
  35908. + (unsigned long long) file_offset,
  35909. + (int) nwritten);
  35910. + if (signal_pending(current))
  35911. + return -EINTR; // Interrupted!
  35912. +
  35913. + if (nwritten < 0) {
  35914. + LDBG(curlun, "error in file write: %d\n",
  35915. + (int) nwritten);
  35916. + nwritten = 0;
  35917. + } else if (nwritten < amount) {
  35918. + LDBG(curlun, "partial file write: %d/%u\n",
  35919. + (int) nwritten, amount);
  35920. + nwritten = round_down(nwritten, curlun->blksize);
  35921. + }
  35922. + file_offset += nwritten;
  35923. + amount_left_to_write -= nwritten;
  35924. + fsg->residue -= nwritten;
  35925. +
  35926. + /* If an error occurred, report it and its position */
  35927. + if (nwritten < amount) {
  35928. + curlun->sense_data = SS_WRITE_ERROR;
  35929. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  35930. + curlun->info_valid = 1;
  35931. + break;
  35932. + }
  35933. +
  35934. + empty_write:
  35935. + /* Did the host decide to stop early? */
  35936. + if (bh->outreq->actual < bh->bulk_out_intended_length) {
  35937. + fsg->short_packet_received = 1;
  35938. + break;
  35939. + }
  35940. + continue;
  35941. + }
  35942. +
  35943. + /* Wait for something to happen */
  35944. + rc = sleep_thread(fsg);
  35945. + if (rc)
  35946. + return rc;
  35947. + }
  35948. +
  35949. + return -EIO; // No default reply
  35950. +}
  35951. +
  35952. +
  35953. +/*-------------------------------------------------------------------------*/
  35954. +
  35955. +static int do_synchronize_cache(struct fsg_dev *fsg)
  35956. +{
  35957. + struct fsg_lun *curlun = fsg->curlun;
  35958. + int rc;
  35959. +
  35960. + /* We ignore the requested LBA and write out all file's
  35961. + * dirty data buffers. */
  35962. + rc = fsg_lun_fsync_sub(curlun);
  35963. + if (rc)
  35964. + curlun->sense_data = SS_WRITE_ERROR;
  35965. + return 0;
  35966. +}
  35967. +
  35968. +
  35969. +/*-------------------------------------------------------------------------*/
  35970. +
  35971. +static void invalidate_sub(struct fsg_lun *curlun)
  35972. +{
  35973. + struct file *filp = curlun->filp;
  35974. + struct inode *inode = filp->f_path.dentry->d_inode;
  35975. + unsigned long rc;
  35976. +
  35977. + rc = invalidate_mapping_pages(inode->i_mapping, 0, -1);
  35978. + VLDBG(curlun, "invalidate_mapping_pages -> %ld\n", rc);
  35979. +}
  35980. +
  35981. +static int do_verify(struct fsg_dev *fsg)
  35982. +{
  35983. + struct fsg_lun *curlun = fsg->curlun;
  35984. + u32 lba;
  35985. + u32 verification_length;
  35986. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  35987. + loff_t file_offset, file_offset_tmp;
  35988. + u32 amount_left;
  35989. + unsigned int amount;
  35990. + ssize_t nread;
  35991. +
  35992. + /* Get the starting Logical Block Address and check that it's
  35993. + * not too big */
  35994. + lba = get_unaligned_be32(&fsg->cmnd[2]);
  35995. + if (lba >= curlun->num_sectors) {
  35996. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  35997. + return -EINVAL;
  35998. + }
  35999. +
  36000. + /* We allow DPO (Disable Page Out = don't save data in the
  36001. + * cache) but we don't implement it. */
  36002. + if ((fsg->cmnd[1] & ~0x10) != 0) {
  36003. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36004. + return -EINVAL;
  36005. + }
  36006. +
  36007. + verification_length = get_unaligned_be16(&fsg->cmnd[7]);
  36008. + if (unlikely(verification_length == 0))
  36009. + return -EIO; // No default reply
  36010. +
  36011. + /* Prepare to carry out the file verify */
  36012. + amount_left = verification_length << curlun->blkbits;
  36013. + file_offset = ((loff_t) lba) << curlun->blkbits;
  36014. +
  36015. + /* Write out all the dirty buffers before invalidating them */
  36016. + fsg_lun_fsync_sub(curlun);
  36017. + if (signal_pending(current))
  36018. + return -EINTR;
  36019. +
  36020. + invalidate_sub(curlun);
  36021. + if (signal_pending(current))
  36022. + return -EINTR;
  36023. +
  36024. + /* Just try to read the requested blocks */
  36025. + while (amount_left > 0) {
  36026. +
  36027. + /* Figure out how much we need to read:
  36028. + * Try to read the remaining amount, but not more than
  36029. + * the buffer size.
  36030. + * And don't try to read past the end of the file.
  36031. + */
  36032. + amount = min((unsigned int) amount_left, mod_data.buflen);
  36033. + amount = min((loff_t) amount,
  36034. + curlun->file_length - file_offset);
  36035. + if (amount == 0) {
  36036. + curlun->sense_data =
  36037. + SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36038. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36039. + curlun->info_valid = 1;
  36040. + break;
  36041. + }
  36042. +
  36043. + /* Perform the read */
  36044. + file_offset_tmp = file_offset;
  36045. + nread = vfs_read(curlun->filp,
  36046. + (char __user *) bh->buf,
  36047. + amount, &file_offset_tmp);
  36048. + VLDBG(curlun, "file read %u @ %llu -> %d\n", amount,
  36049. + (unsigned long long) file_offset,
  36050. + (int) nread);
  36051. + if (signal_pending(current))
  36052. + return -EINTR;
  36053. +
  36054. + if (nread < 0) {
  36055. + LDBG(curlun, "error in file verify: %d\n",
  36056. + (int) nread);
  36057. + nread = 0;
  36058. + } else if (nread < amount) {
  36059. + LDBG(curlun, "partial file verify: %d/%u\n",
  36060. + (int) nread, amount);
  36061. + nread = round_down(nread, curlun->blksize);
  36062. + }
  36063. + if (nread == 0) {
  36064. + curlun->sense_data = SS_UNRECOVERED_READ_ERROR;
  36065. + curlun->sense_data_info = file_offset >> curlun->blkbits;
  36066. + curlun->info_valid = 1;
  36067. + break;
  36068. + }
  36069. + file_offset += nread;
  36070. + amount_left -= nread;
  36071. + }
  36072. + return 0;
  36073. +}
  36074. +
  36075. +
  36076. +/*-------------------------------------------------------------------------*/
  36077. +
  36078. +static int do_inquiry(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36079. +{
  36080. + u8 *buf = (u8 *) bh->buf;
  36081. +
  36082. + static char vendor_id[] = "Linux ";
  36083. + static char product_disk_id[] = "File-Stor Gadget";
  36084. + static char product_cdrom_id[] = "File-CD Gadget ";
  36085. +
  36086. + if (!fsg->curlun) { // Unsupported LUNs are okay
  36087. + fsg->bad_lun_okay = 1;
  36088. + memset(buf, 0, 36);
  36089. + buf[0] = 0x7f; // Unsupported, no device-type
  36090. + buf[4] = 31; // Additional length
  36091. + return 36;
  36092. + }
  36093. +
  36094. + memset(buf, 0, 8);
  36095. + buf[0] = (mod_data.cdrom ? TYPE_ROM : TYPE_DISK);
  36096. + if (mod_data.removable)
  36097. + buf[1] = 0x80;
  36098. + buf[2] = 2; // ANSI SCSI level 2
  36099. + buf[3] = 2; // SCSI-2 INQUIRY data format
  36100. + buf[4] = 31; // Additional length
  36101. + // No special options
  36102. + sprintf(buf + 8, "%-8s%-16s%04x", vendor_id,
  36103. + (mod_data.cdrom ? product_cdrom_id :
  36104. + product_disk_id),
  36105. + mod_data.release);
  36106. + return 36;
  36107. +}
  36108. +
  36109. +
  36110. +static int do_request_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36111. +{
  36112. + struct fsg_lun *curlun = fsg->curlun;
  36113. + u8 *buf = (u8 *) bh->buf;
  36114. + u32 sd, sdinfo;
  36115. + int valid;
  36116. +
  36117. + /*
  36118. + * From the SCSI-2 spec., section 7.9 (Unit attention condition):
  36119. + *
  36120. + * If a REQUEST SENSE command is received from an initiator
  36121. + * with a pending unit attention condition (before the target
  36122. + * generates the contingent allegiance condition), then the
  36123. + * target shall either:
  36124. + * a) report any pending sense data and preserve the unit
  36125. + * attention condition on the logical unit, or,
  36126. + * b) report the unit attention condition, may discard any
  36127. + * pending sense data, and clear the unit attention
  36128. + * condition on the logical unit for that initiator.
  36129. + *
  36130. + * FSG normally uses option a); enable this code to use option b).
  36131. + */
  36132. +#if 0
  36133. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE) {
  36134. + curlun->sense_data = curlun->unit_attention_data;
  36135. + curlun->unit_attention_data = SS_NO_SENSE;
  36136. + }
  36137. +#endif
  36138. +
  36139. + if (!curlun) { // Unsupported LUNs are okay
  36140. + fsg->bad_lun_okay = 1;
  36141. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36142. + sdinfo = 0;
  36143. + valid = 0;
  36144. + } else {
  36145. + sd = curlun->sense_data;
  36146. + sdinfo = curlun->sense_data_info;
  36147. + valid = curlun->info_valid << 7;
  36148. + curlun->sense_data = SS_NO_SENSE;
  36149. + curlun->sense_data_info = 0;
  36150. + curlun->info_valid = 0;
  36151. + }
  36152. +
  36153. + memset(buf, 0, 18);
  36154. + buf[0] = valid | 0x70; // Valid, current error
  36155. + buf[2] = SK(sd);
  36156. + put_unaligned_be32(sdinfo, &buf[3]); /* Sense information */
  36157. + buf[7] = 18 - 8; // Additional sense length
  36158. + buf[12] = ASC(sd);
  36159. + buf[13] = ASCQ(sd);
  36160. + return 18;
  36161. +}
  36162. +
  36163. +
  36164. +static int do_read_capacity(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36165. +{
  36166. + struct fsg_lun *curlun = fsg->curlun;
  36167. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36168. + int pmi = fsg->cmnd[8];
  36169. + u8 *buf = (u8 *) bh->buf;
  36170. +
  36171. + /* Check the PMI and LBA fields */
  36172. + if (pmi > 1 || (pmi == 0 && lba != 0)) {
  36173. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36174. + return -EINVAL;
  36175. + }
  36176. +
  36177. + put_unaligned_be32(curlun->num_sectors - 1, &buf[0]);
  36178. + /* Max logical block */
  36179. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36180. + return 8;
  36181. +}
  36182. +
  36183. +
  36184. +static int do_read_header(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36185. +{
  36186. + struct fsg_lun *curlun = fsg->curlun;
  36187. + int msf = fsg->cmnd[1] & 0x02;
  36188. + u32 lba = get_unaligned_be32(&fsg->cmnd[2]);
  36189. + u8 *buf = (u8 *) bh->buf;
  36190. +
  36191. + if ((fsg->cmnd[1] & ~0x02) != 0) { /* Mask away MSF */
  36192. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36193. + return -EINVAL;
  36194. + }
  36195. + if (lba >= curlun->num_sectors) {
  36196. + curlun->sense_data = SS_LOGICAL_BLOCK_ADDRESS_OUT_OF_RANGE;
  36197. + return -EINVAL;
  36198. + }
  36199. +
  36200. + memset(buf, 0, 8);
  36201. + buf[0] = 0x01; /* 2048 bytes of user data, rest is EC */
  36202. + store_cdrom_address(&buf[4], msf, lba);
  36203. + return 8;
  36204. +}
  36205. +
  36206. +
  36207. +static int do_read_toc(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36208. +{
  36209. + struct fsg_lun *curlun = fsg->curlun;
  36210. + int msf = fsg->cmnd[1] & 0x02;
  36211. + int start_track = fsg->cmnd[6];
  36212. + u8 *buf = (u8 *) bh->buf;
  36213. +
  36214. + if ((fsg->cmnd[1] & ~0x02) != 0 || /* Mask away MSF */
  36215. + start_track > 1) {
  36216. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36217. + return -EINVAL;
  36218. + }
  36219. +
  36220. + memset(buf, 0, 20);
  36221. + buf[1] = (20-2); /* TOC data length */
  36222. + buf[2] = 1; /* First track number */
  36223. + buf[3] = 1; /* Last track number */
  36224. + buf[5] = 0x16; /* Data track, copying allowed */
  36225. + buf[6] = 0x01; /* Only track is number 1 */
  36226. + store_cdrom_address(&buf[8], msf, 0);
  36227. +
  36228. + buf[13] = 0x16; /* Lead-out track is data */
  36229. + buf[14] = 0xAA; /* Lead-out track number */
  36230. + store_cdrom_address(&buf[16], msf, curlun->num_sectors);
  36231. + return 20;
  36232. +}
  36233. +
  36234. +
  36235. +static int do_mode_sense(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36236. +{
  36237. + struct fsg_lun *curlun = fsg->curlun;
  36238. + int mscmnd = fsg->cmnd[0];
  36239. + u8 *buf = (u8 *) bh->buf;
  36240. + u8 *buf0 = buf;
  36241. + int pc, page_code;
  36242. + int changeable_values, all_pages;
  36243. + int valid_page = 0;
  36244. + int len, limit;
  36245. +
  36246. + if ((fsg->cmnd[1] & ~0x08) != 0) { // Mask away DBD
  36247. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36248. + return -EINVAL;
  36249. + }
  36250. + pc = fsg->cmnd[2] >> 6;
  36251. + page_code = fsg->cmnd[2] & 0x3f;
  36252. + if (pc == 3) {
  36253. + curlun->sense_data = SS_SAVING_PARAMETERS_NOT_SUPPORTED;
  36254. + return -EINVAL;
  36255. + }
  36256. + changeable_values = (pc == 1);
  36257. + all_pages = (page_code == 0x3f);
  36258. +
  36259. + /* Write the mode parameter header. Fixed values are: default
  36260. + * medium type, no cache control (DPOFUA), and no block descriptors.
  36261. + * The only variable value is the WriteProtect bit. We will fill in
  36262. + * the mode data length later. */
  36263. + memset(buf, 0, 8);
  36264. + if (mscmnd == MODE_SENSE) {
  36265. + buf[2] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36266. + buf += 4;
  36267. + limit = 255;
  36268. + } else { // MODE_SENSE_10
  36269. + buf[3] = (curlun->ro ? 0x80 : 0x00); // WP, DPOFUA
  36270. + buf += 8;
  36271. + limit = 65535; // Should really be mod_data.buflen
  36272. + }
  36273. +
  36274. + /* No block descriptors */
  36275. +
  36276. + /* The mode pages, in numerical order. The only page we support
  36277. + * is the Caching page. */
  36278. + if (page_code == 0x08 || all_pages) {
  36279. + valid_page = 1;
  36280. + buf[0] = 0x08; // Page code
  36281. + buf[1] = 10; // Page length
  36282. + memset(buf+2, 0, 10); // None of the fields are changeable
  36283. +
  36284. + if (!changeable_values) {
  36285. + buf[2] = 0x04; // Write cache enable,
  36286. + // Read cache not disabled
  36287. + // No cache retention priorities
  36288. + put_unaligned_be16(0xffff, &buf[4]);
  36289. + /* Don't disable prefetch */
  36290. + /* Minimum prefetch = 0 */
  36291. + put_unaligned_be16(0xffff, &buf[8]);
  36292. + /* Maximum prefetch */
  36293. + put_unaligned_be16(0xffff, &buf[10]);
  36294. + /* Maximum prefetch ceiling */
  36295. + }
  36296. + buf += 12;
  36297. + }
  36298. +
  36299. + /* Check that a valid page was requested and the mode data length
  36300. + * isn't too long. */
  36301. + len = buf - buf0;
  36302. + if (!valid_page || len > limit) {
  36303. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36304. + return -EINVAL;
  36305. + }
  36306. +
  36307. + /* Store the mode data length */
  36308. + if (mscmnd == MODE_SENSE)
  36309. + buf0[0] = len - 1;
  36310. + else
  36311. + put_unaligned_be16(len - 2, buf0);
  36312. + return len;
  36313. +}
  36314. +
  36315. +
  36316. +static int do_start_stop(struct fsg_dev *fsg)
  36317. +{
  36318. + struct fsg_lun *curlun = fsg->curlun;
  36319. + int loej, start;
  36320. +
  36321. + if (!mod_data.removable) {
  36322. + curlun->sense_data = SS_INVALID_COMMAND;
  36323. + return -EINVAL;
  36324. + }
  36325. +
  36326. + // int immed = fsg->cmnd[1] & 0x01;
  36327. + loej = fsg->cmnd[4] & 0x02;
  36328. + start = fsg->cmnd[4] & 0x01;
  36329. +
  36330. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  36331. + if ((fsg->cmnd[1] & ~0x01) != 0 || // Mask away Immed
  36332. + (fsg->cmnd[4] & ~0x03) != 0) { // Mask LoEj, Start
  36333. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36334. + return -EINVAL;
  36335. + }
  36336. +
  36337. + if (!start) {
  36338. +
  36339. + /* Are we allowed to unload the media? */
  36340. + if (curlun->prevent_medium_removal) {
  36341. + LDBG(curlun, "unload attempt prevented\n");
  36342. + curlun->sense_data = SS_MEDIUM_REMOVAL_PREVENTED;
  36343. + return -EINVAL;
  36344. + }
  36345. + if (loej) { // Simulate an unload/eject
  36346. + up_read(&fsg->filesem);
  36347. + down_write(&fsg->filesem);
  36348. + fsg_lun_close(curlun);
  36349. + up_write(&fsg->filesem);
  36350. + down_read(&fsg->filesem);
  36351. + }
  36352. + } else {
  36353. +
  36354. + /* Our emulation doesn't support mounting; the medium is
  36355. + * available for use as soon as it is loaded. */
  36356. + if (!fsg_lun_is_open(curlun)) {
  36357. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36358. + return -EINVAL;
  36359. + }
  36360. + }
  36361. +#endif
  36362. + return 0;
  36363. +}
  36364. +
  36365. +
  36366. +static int do_prevent_allow(struct fsg_dev *fsg)
  36367. +{
  36368. + struct fsg_lun *curlun = fsg->curlun;
  36369. + int prevent;
  36370. +
  36371. + if (!mod_data.removable) {
  36372. + curlun->sense_data = SS_INVALID_COMMAND;
  36373. + return -EINVAL;
  36374. + }
  36375. +
  36376. + prevent = fsg->cmnd[4] & 0x01;
  36377. + if ((fsg->cmnd[4] & ~0x01) != 0) { // Mask away Prevent
  36378. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36379. + return -EINVAL;
  36380. + }
  36381. +
  36382. + if (curlun->prevent_medium_removal && !prevent)
  36383. + fsg_lun_fsync_sub(curlun);
  36384. + curlun->prevent_medium_removal = prevent;
  36385. + return 0;
  36386. +}
  36387. +
  36388. +
  36389. +static int do_read_format_capacities(struct fsg_dev *fsg,
  36390. + struct fsg_buffhd *bh)
  36391. +{
  36392. + struct fsg_lun *curlun = fsg->curlun;
  36393. + u8 *buf = (u8 *) bh->buf;
  36394. +
  36395. + buf[0] = buf[1] = buf[2] = 0;
  36396. + buf[3] = 8; // Only the Current/Maximum Capacity Descriptor
  36397. + buf += 4;
  36398. +
  36399. + put_unaligned_be32(curlun->num_sectors, &buf[0]);
  36400. + /* Number of blocks */
  36401. + put_unaligned_be32(curlun->blksize, &buf[4]); /* Block length */
  36402. + buf[4] = 0x02; /* Current capacity */
  36403. + return 12;
  36404. +}
  36405. +
  36406. +
  36407. +static int do_mode_select(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  36408. +{
  36409. + struct fsg_lun *curlun = fsg->curlun;
  36410. +
  36411. + /* We don't support MODE SELECT */
  36412. + curlun->sense_data = SS_INVALID_COMMAND;
  36413. + return -EINVAL;
  36414. +}
  36415. +
  36416. +
  36417. +/*-------------------------------------------------------------------------*/
  36418. +
  36419. +static int halt_bulk_in_endpoint(struct fsg_dev *fsg)
  36420. +{
  36421. + int rc;
  36422. +
  36423. + rc = fsg_set_halt(fsg, fsg->bulk_in);
  36424. + if (rc == -EAGAIN)
  36425. + VDBG(fsg, "delayed bulk-in endpoint halt\n");
  36426. + while (rc != 0) {
  36427. + if (rc != -EAGAIN) {
  36428. + WARNING(fsg, "usb_ep_set_halt -> %d\n", rc);
  36429. + rc = 0;
  36430. + break;
  36431. + }
  36432. +
  36433. + /* Wait for a short time and then try again */
  36434. + if (msleep_interruptible(100) != 0)
  36435. + return -EINTR;
  36436. + rc = usb_ep_set_halt(fsg->bulk_in);
  36437. + }
  36438. + return rc;
  36439. +}
  36440. +
  36441. +static int wedge_bulk_in_endpoint(struct fsg_dev *fsg)
  36442. +{
  36443. + int rc;
  36444. +
  36445. + DBG(fsg, "bulk-in set wedge\n");
  36446. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36447. + if (rc == -EAGAIN)
  36448. + VDBG(fsg, "delayed bulk-in endpoint wedge\n");
  36449. + while (rc != 0) {
  36450. + if (rc != -EAGAIN) {
  36451. + WARNING(fsg, "usb_ep_set_wedge -> %d\n", rc);
  36452. + rc = 0;
  36453. + break;
  36454. + }
  36455. +
  36456. + /* Wait for a short time and then try again */
  36457. + if (msleep_interruptible(100) != 0)
  36458. + return -EINTR;
  36459. + rc = usb_ep_set_wedge(fsg->bulk_in);
  36460. + }
  36461. + return rc;
  36462. +}
  36463. +
  36464. +static int throw_away_data(struct fsg_dev *fsg)
  36465. +{
  36466. + struct fsg_buffhd *bh;
  36467. + u32 amount;
  36468. + int rc;
  36469. +
  36470. + while ((bh = fsg->next_buffhd_to_drain)->state != BUF_STATE_EMPTY ||
  36471. + fsg->usb_amount_left > 0) {
  36472. +
  36473. + /* Throw away the data in a filled buffer */
  36474. + if (bh->state == BUF_STATE_FULL) {
  36475. + smp_rmb();
  36476. + bh->state = BUF_STATE_EMPTY;
  36477. + fsg->next_buffhd_to_drain = bh->next;
  36478. +
  36479. + /* A short packet or an error ends everything */
  36480. + if (bh->outreq->actual < bh->bulk_out_intended_length ||
  36481. + bh->outreq->status != 0) {
  36482. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36483. + return -EINTR;
  36484. + }
  36485. + continue;
  36486. + }
  36487. +
  36488. + /* Try to submit another request if we need one */
  36489. + bh = fsg->next_buffhd_to_fill;
  36490. + if (bh->state == BUF_STATE_EMPTY && fsg->usb_amount_left > 0) {
  36491. + amount = min(fsg->usb_amount_left,
  36492. + (u32) mod_data.buflen);
  36493. +
  36494. + /* Except at the end of the transfer, amount will be
  36495. + * equal to the buffer size, which is divisible by
  36496. + * the bulk-out maxpacket size.
  36497. + */
  36498. + set_bulk_out_req_length(fsg, bh, amount);
  36499. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  36500. + &bh->outreq_busy, &bh->state);
  36501. + fsg->next_buffhd_to_fill = bh->next;
  36502. + fsg->usb_amount_left -= amount;
  36503. + continue;
  36504. + }
  36505. +
  36506. + /* Otherwise wait for something to happen */
  36507. + rc = sleep_thread(fsg);
  36508. + if (rc)
  36509. + return rc;
  36510. + }
  36511. + return 0;
  36512. +}
  36513. +
  36514. +
  36515. +static int finish_reply(struct fsg_dev *fsg)
  36516. +{
  36517. + struct fsg_buffhd *bh = fsg->next_buffhd_to_fill;
  36518. + int rc = 0;
  36519. +
  36520. + switch (fsg->data_dir) {
  36521. + case DATA_DIR_NONE:
  36522. + break; // Nothing to send
  36523. +
  36524. + /* If we don't know whether the host wants to read or write,
  36525. + * this must be CB or CBI with an unknown command. We mustn't
  36526. + * try to send or receive any data. So stall both bulk pipes
  36527. + * if we can and wait for a reset. */
  36528. + case DATA_DIR_UNKNOWN:
  36529. + if (mod_data.can_stall) {
  36530. + fsg_set_halt(fsg, fsg->bulk_out);
  36531. + rc = halt_bulk_in_endpoint(fsg);
  36532. + }
  36533. + break;
  36534. +
  36535. + /* All but the last buffer of data must have already been sent */
  36536. + case DATA_DIR_TO_HOST:
  36537. + if (fsg->data_size == 0)
  36538. + ; // Nothing to send
  36539. +
  36540. + /* If there's no residue, simply send the last buffer */
  36541. + else if (fsg->residue == 0) {
  36542. + bh->inreq->zero = 0;
  36543. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36544. + &bh->inreq_busy, &bh->state);
  36545. + fsg->next_buffhd_to_fill = bh->next;
  36546. + }
  36547. +
  36548. + /* There is a residue. For CB and CBI, simply mark the end
  36549. + * of the data with a short packet. However, if we are
  36550. + * allowed to stall, there was no data at all (residue ==
  36551. + * data_size), and the command failed (invalid LUN or
  36552. + * sense data is set), then halt the bulk-in endpoint
  36553. + * instead. */
  36554. + else if (!transport_is_bbb()) {
  36555. + if (mod_data.can_stall &&
  36556. + fsg->residue == fsg->data_size &&
  36557. + (!fsg->curlun || fsg->curlun->sense_data != SS_NO_SENSE)) {
  36558. + bh->state = BUF_STATE_EMPTY;
  36559. + rc = halt_bulk_in_endpoint(fsg);
  36560. + } else {
  36561. + bh->inreq->zero = 1;
  36562. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36563. + &bh->inreq_busy, &bh->state);
  36564. + fsg->next_buffhd_to_fill = bh->next;
  36565. + }
  36566. + }
  36567. +
  36568. + /*
  36569. + * For Bulk-only, mark the end of the data with a short
  36570. + * packet. If we are allowed to stall, halt the bulk-in
  36571. + * endpoint. (Note: This violates the Bulk-Only Transport
  36572. + * specification, which requires us to pad the data if we
  36573. + * don't halt the endpoint. Presumably nobody will mind.)
  36574. + */
  36575. + else {
  36576. + bh->inreq->zero = 1;
  36577. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36578. + &bh->inreq_busy, &bh->state);
  36579. + fsg->next_buffhd_to_fill = bh->next;
  36580. + if (mod_data.can_stall)
  36581. + rc = halt_bulk_in_endpoint(fsg);
  36582. + }
  36583. + break;
  36584. +
  36585. + /* We have processed all we want from the data the host has sent.
  36586. + * There may still be outstanding bulk-out requests. */
  36587. + case DATA_DIR_FROM_HOST:
  36588. + if (fsg->residue == 0)
  36589. + ; // Nothing to receive
  36590. +
  36591. + /* Did the host stop sending unexpectedly early? */
  36592. + else if (fsg->short_packet_received) {
  36593. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36594. + rc = -EINTR;
  36595. + }
  36596. +
  36597. + /* We haven't processed all the incoming data. Even though
  36598. + * we may be allowed to stall, doing so would cause a race.
  36599. + * The controller may already have ACK'ed all the remaining
  36600. + * bulk-out packets, in which case the host wouldn't see a
  36601. + * STALL. Not realizing the endpoint was halted, it wouldn't
  36602. + * clear the halt -- leading to problems later on. */
  36603. +#if 0
  36604. + else if (mod_data.can_stall) {
  36605. + fsg_set_halt(fsg, fsg->bulk_out);
  36606. + raise_exception(fsg, FSG_STATE_ABORT_BULK_OUT);
  36607. + rc = -EINTR;
  36608. + }
  36609. +#endif
  36610. +
  36611. + /* We can't stall. Read in the excess data and throw it
  36612. + * all away. */
  36613. + else
  36614. + rc = throw_away_data(fsg);
  36615. + break;
  36616. + }
  36617. + return rc;
  36618. +}
  36619. +
  36620. +
  36621. +static int send_status(struct fsg_dev *fsg)
  36622. +{
  36623. + struct fsg_lun *curlun = fsg->curlun;
  36624. + struct fsg_buffhd *bh;
  36625. + int rc;
  36626. + u8 status = US_BULK_STAT_OK;
  36627. + u32 sd, sdinfo = 0;
  36628. +
  36629. + /* Wait for the next buffer to become available */
  36630. + bh = fsg->next_buffhd_to_fill;
  36631. + while (bh->state != BUF_STATE_EMPTY) {
  36632. + rc = sleep_thread(fsg);
  36633. + if (rc)
  36634. + return rc;
  36635. + }
  36636. +
  36637. + if (curlun) {
  36638. + sd = curlun->sense_data;
  36639. + sdinfo = curlun->sense_data_info;
  36640. + } else if (fsg->bad_lun_okay)
  36641. + sd = SS_NO_SENSE;
  36642. + else
  36643. + sd = SS_LOGICAL_UNIT_NOT_SUPPORTED;
  36644. +
  36645. + if (fsg->phase_error) {
  36646. + DBG(fsg, "sending phase-error status\n");
  36647. + status = US_BULK_STAT_PHASE;
  36648. + sd = SS_INVALID_COMMAND;
  36649. + } else if (sd != SS_NO_SENSE) {
  36650. + DBG(fsg, "sending command-failure status\n");
  36651. + status = US_BULK_STAT_FAIL;
  36652. + VDBG(fsg, " sense data: SK x%02x, ASC x%02x, ASCQ x%02x;"
  36653. + " info x%x\n",
  36654. + SK(sd), ASC(sd), ASCQ(sd), sdinfo);
  36655. + }
  36656. +
  36657. + if (transport_is_bbb()) {
  36658. + struct bulk_cs_wrap *csw = bh->buf;
  36659. +
  36660. + /* Store and send the Bulk-only CSW */
  36661. + csw->Signature = cpu_to_le32(US_BULK_CS_SIGN);
  36662. + csw->Tag = fsg->tag;
  36663. + csw->Residue = cpu_to_le32(fsg->residue);
  36664. + csw->Status = status;
  36665. +
  36666. + bh->inreq->length = US_BULK_CS_WRAP_LEN;
  36667. + bh->inreq->zero = 0;
  36668. + start_transfer(fsg, fsg->bulk_in, bh->inreq,
  36669. + &bh->inreq_busy, &bh->state);
  36670. +
  36671. + } else if (mod_data.transport_type == USB_PR_CB) {
  36672. +
  36673. + /* Control-Bulk transport has no status phase! */
  36674. + return 0;
  36675. +
  36676. + } else { // USB_PR_CBI
  36677. + struct interrupt_data *buf = bh->buf;
  36678. +
  36679. + /* Store and send the Interrupt data. UFI sends the ASC
  36680. + * and ASCQ bytes. Everything else sends a Type (which
  36681. + * is always 0) and the status Value. */
  36682. + if (mod_data.protocol_type == USB_SC_UFI) {
  36683. + buf->bType = ASC(sd);
  36684. + buf->bValue = ASCQ(sd);
  36685. + } else {
  36686. + buf->bType = 0;
  36687. + buf->bValue = status;
  36688. + }
  36689. + fsg->intreq->length = CBI_INTERRUPT_DATA_LEN;
  36690. +
  36691. + fsg->intr_buffhd = bh; // Point to the right buffhd
  36692. + fsg->intreq->buf = bh->inreq->buf;
  36693. + fsg->intreq->context = bh;
  36694. + start_transfer(fsg, fsg->intr_in, fsg->intreq,
  36695. + &fsg->intreq_busy, &bh->state);
  36696. + }
  36697. +
  36698. + fsg->next_buffhd_to_fill = bh->next;
  36699. + return 0;
  36700. +}
  36701. +
  36702. +
  36703. +/*-------------------------------------------------------------------------*/
  36704. +
  36705. +/* Check whether the command is properly formed and whether its data size
  36706. + * and direction agree with the values we already have. */
  36707. +static int check_command(struct fsg_dev *fsg, int cmnd_size,
  36708. + enum data_direction data_dir, unsigned int mask,
  36709. + int needs_medium, const char *name)
  36710. +{
  36711. + int i;
  36712. + int lun = fsg->cmnd[1] >> 5;
  36713. + static const char dirletter[4] = {'u', 'o', 'i', 'n'};
  36714. + char hdlen[20];
  36715. + struct fsg_lun *curlun;
  36716. +
  36717. + /* Adjust the expected cmnd_size for protocol encapsulation padding.
  36718. + * Transparent SCSI doesn't pad. */
  36719. + if (protocol_is_scsi())
  36720. + ;
  36721. +
  36722. + /* There's some disagreement as to whether RBC pads commands or not.
  36723. + * We'll play it safe and accept either form. */
  36724. + else if (mod_data.protocol_type == USB_SC_RBC) {
  36725. + if (fsg->cmnd_size == 12)
  36726. + cmnd_size = 12;
  36727. +
  36728. + /* All the other protocols pad to 12 bytes */
  36729. + } else
  36730. + cmnd_size = 12;
  36731. +
  36732. + hdlen[0] = 0;
  36733. + if (fsg->data_dir != DATA_DIR_UNKNOWN)
  36734. + sprintf(hdlen, ", H%c=%u", dirletter[(int) fsg->data_dir],
  36735. + fsg->data_size);
  36736. + VDBG(fsg, "SCSI command: %s; Dc=%d, D%c=%u; Hc=%d%s\n",
  36737. + name, cmnd_size, dirletter[(int) data_dir],
  36738. + fsg->data_size_from_cmnd, fsg->cmnd_size, hdlen);
  36739. +
  36740. + /* We can't reply at all until we know the correct data direction
  36741. + * and size. */
  36742. + if (fsg->data_size_from_cmnd == 0)
  36743. + data_dir = DATA_DIR_NONE;
  36744. + if (fsg->data_dir == DATA_DIR_UNKNOWN) { // CB or CBI
  36745. + fsg->data_dir = data_dir;
  36746. + fsg->data_size = fsg->data_size_from_cmnd;
  36747. +
  36748. + } else { // Bulk-only
  36749. + if (fsg->data_size < fsg->data_size_from_cmnd) {
  36750. +
  36751. + /* Host data size < Device data size is a phase error.
  36752. + * Carry out the command, but only transfer as much
  36753. + * as we are allowed. */
  36754. + fsg->data_size_from_cmnd = fsg->data_size;
  36755. + fsg->phase_error = 1;
  36756. + }
  36757. + }
  36758. + fsg->residue = fsg->usb_amount_left = fsg->data_size;
  36759. +
  36760. + /* Conflicting data directions is a phase error */
  36761. + if (fsg->data_dir != data_dir && fsg->data_size_from_cmnd > 0) {
  36762. + fsg->phase_error = 1;
  36763. + return -EINVAL;
  36764. + }
  36765. +
  36766. + /* Verify the length of the command itself */
  36767. + if (cmnd_size != fsg->cmnd_size) {
  36768. +
  36769. + /* Special case workaround: There are plenty of buggy SCSI
  36770. + * implementations. Many have issues with cbw->Length
  36771. + * field passing a wrong command size. For those cases we
  36772. + * always try to work around the problem by using the length
  36773. + * sent by the host side provided it is at least as large
  36774. + * as the correct command length.
  36775. + * Examples of such cases would be MS-Windows, which issues
  36776. + * REQUEST SENSE with cbw->Length == 12 where it should
  36777. + * be 6, and xbox360 issuing INQUIRY, TEST UNIT READY and
  36778. + * REQUEST SENSE with cbw->Length == 10 where it should
  36779. + * be 6 as well.
  36780. + */
  36781. + if (cmnd_size <= fsg->cmnd_size) {
  36782. + DBG(fsg, "%s is buggy! Expected length %d "
  36783. + "but we got %d\n", name,
  36784. + cmnd_size, fsg->cmnd_size);
  36785. + cmnd_size = fsg->cmnd_size;
  36786. + } else {
  36787. + fsg->phase_error = 1;
  36788. + return -EINVAL;
  36789. + }
  36790. + }
  36791. +
  36792. + /* Check that the LUN values are consistent */
  36793. + if (transport_is_bbb()) {
  36794. + if (fsg->lun != lun)
  36795. + DBG(fsg, "using LUN %d from CBW, "
  36796. + "not LUN %d from CDB\n",
  36797. + fsg->lun, lun);
  36798. + }
  36799. +
  36800. + /* Check the LUN */
  36801. + curlun = fsg->curlun;
  36802. + if (curlun) {
  36803. + if (fsg->cmnd[0] != REQUEST_SENSE) {
  36804. + curlun->sense_data = SS_NO_SENSE;
  36805. + curlun->sense_data_info = 0;
  36806. + curlun->info_valid = 0;
  36807. + }
  36808. + } else {
  36809. + fsg->bad_lun_okay = 0;
  36810. +
  36811. + /* INQUIRY and REQUEST SENSE commands are explicitly allowed
  36812. + * to use unsupported LUNs; all others may not. */
  36813. + if (fsg->cmnd[0] != INQUIRY &&
  36814. + fsg->cmnd[0] != REQUEST_SENSE) {
  36815. + DBG(fsg, "unsupported LUN %d\n", fsg->lun);
  36816. + return -EINVAL;
  36817. + }
  36818. + }
  36819. +
  36820. + /* If a unit attention condition exists, only INQUIRY and
  36821. + * REQUEST SENSE commands are allowed; anything else must fail. */
  36822. + if (curlun && curlun->unit_attention_data != SS_NO_SENSE &&
  36823. + fsg->cmnd[0] != INQUIRY &&
  36824. + fsg->cmnd[0] != REQUEST_SENSE) {
  36825. + curlun->sense_data = curlun->unit_attention_data;
  36826. + curlun->unit_attention_data = SS_NO_SENSE;
  36827. + return -EINVAL;
  36828. + }
  36829. +
  36830. + /* Check that only command bytes listed in the mask are non-zero */
  36831. + fsg->cmnd[1] &= 0x1f; // Mask away the LUN
  36832. + for (i = 1; i < cmnd_size; ++i) {
  36833. + if (fsg->cmnd[i] && !(mask & (1 << i))) {
  36834. + if (curlun)
  36835. + curlun->sense_data = SS_INVALID_FIELD_IN_CDB;
  36836. + return -EINVAL;
  36837. + }
  36838. + }
  36839. +
  36840. + /* If the medium isn't mounted and the command needs to access
  36841. + * it, return an error. */
  36842. + if (curlun && !fsg_lun_is_open(curlun) && needs_medium) {
  36843. + curlun->sense_data = SS_MEDIUM_NOT_PRESENT;
  36844. + return -EINVAL;
  36845. + }
  36846. +
  36847. + return 0;
  36848. +}
  36849. +
  36850. +/* wrapper of check_command for data size in blocks handling */
  36851. +static int check_command_size_in_blocks(struct fsg_dev *fsg, int cmnd_size,
  36852. + enum data_direction data_dir, unsigned int mask,
  36853. + int needs_medium, const char *name)
  36854. +{
  36855. + if (fsg->curlun)
  36856. + fsg->data_size_from_cmnd <<= fsg->curlun->blkbits;
  36857. + return check_command(fsg, cmnd_size, data_dir,
  36858. + mask, needs_medium, name);
  36859. +}
  36860. +
  36861. +static int do_scsi_command(struct fsg_dev *fsg)
  36862. +{
  36863. + struct fsg_buffhd *bh;
  36864. + int rc;
  36865. + int reply = -EINVAL;
  36866. + int i;
  36867. + static char unknown[16];
  36868. +
  36869. + dump_cdb(fsg);
  36870. +
  36871. + /* Wait for the next buffer to become available for data or status */
  36872. + bh = fsg->next_buffhd_to_drain = fsg->next_buffhd_to_fill;
  36873. + while (bh->state != BUF_STATE_EMPTY) {
  36874. + rc = sleep_thread(fsg);
  36875. + if (rc)
  36876. + return rc;
  36877. + }
  36878. + fsg->phase_error = 0;
  36879. + fsg->short_packet_received = 0;
  36880. +
  36881. + down_read(&fsg->filesem); // We're using the backing file
  36882. + switch (fsg->cmnd[0]) {
  36883. +
  36884. + case INQUIRY:
  36885. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36886. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36887. + (1<<4), 0,
  36888. + "INQUIRY")) == 0)
  36889. + reply = do_inquiry(fsg, bh);
  36890. + break;
  36891. +
  36892. + case MODE_SELECT:
  36893. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36894. + if ((reply = check_command(fsg, 6, DATA_DIR_FROM_HOST,
  36895. + (1<<1) | (1<<4), 0,
  36896. + "MODE SELECT(6)")) == 0)
  36897. + reply = do_mode_select(fsg, bh);
  36898. + break;
  36899. +
  36900. + case MODE_SELECT_10:
  36901. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36902. + if ((reply = check_command(fsg, 10, DATA_DIR_FROM_HOST,
  36903. + (1<<1) | (3<<7), 0,
  36904. + "MODE SELECT(10)")) == 0)
  36905. + reply = do_mode_select(fsg, bh);
  36906. + break;
  36907. +
  36908. + case MODE_SENSE:
  36909. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36910. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36911. + (1<<1) | (1<<2) | (1<<4), 0,
  36912. + "MODE SENSE(6)")) == 0)
  36913. + reply = do_mode_sense(fsg, bh);
  36914. + break;
  36915. +
  36916. + case MODE_SENSE_10:
  36917. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36918. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36919. + (1<<1) | (1<<2) | (3<<7), 0,
  36920. + "MODE SENSE(10)")) == 0)
  36921. + reply = do_mode_sense(fsg, bh);
  36922. + break;
  36923. +
  36924. + case ALLOW_MEDIUM_REMOVAL:
  36925. + fsg->data_size_from_cmnd = 0;
  36926. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  36927. + (1<<4), 0,
  36928. + "PREVENT-ALLOW MEDIUM REMOVAL")) == 0)
  36929. + reply = do_prevent_allow(fsg);
  36930. + break;
  36931. +
  36932. + case READ_6:
  36933. + i = fsg->cmnd[4];
  36934. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  36935. + if ((reply = check_command_size_in_blocks(fsg, 6,
  36936. + DATA_DIR_TO_HOST,
  36937. + (7<<1) | (1<<4), 1,
  36938. + "READ(6)")) == 0)
  36939. + reply = do_read(fsg);
  36940. + break;
  36941. +
  36942. + case READ_10:
  36943. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36944. + if ((reply = check_command_size_in_blocks(fsg, 10,
  36945. + DATA_DIR_TO_HOST,
  36946. + (1<<1) | (0xf<<2) | (3<<7), 1,
  36947. + "READ(10)")) == 0)
  36948. + reply = do_read(fsg);
  36949. + break;
  36950. +
  36951. + case READ_12:
  36952. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  36953. + if ((reply = check_command_size_in_blocks(fsg, 12,
  36954. + DATA_DIR_TO_HOST,
  36955. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  36956. + "READ(12)")) == 0)
  36957. + reply = do_read(fsg);
  36958. + break;
  36959. +
  36960. + case READ_CAPACITY:
  36961. + fsg->data_size_from_cmnd = 8;
  36962. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36963. + (0xf<<2) | (1<<8), 1,
  36964. + "READ CAPACITY")) == 0)
  36965. + reply = do_read_capacity(fsg, bh);
  36966. + break;
  36967. +
  36968. + case READ_HEADER:
  36969. + if (!mod_data.cdrom)
  36970. + goto unknown_cmnd;
  36971. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36972. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36973. + (3<<7) | (0x1f<<1), 1,
  36974. + "READ HEADER")) == 0)
  36975. + reply = do_read_header(fsg, bh);
  36976. + break;
  36977. +
  36978. + case READ_TOC:
  36979. + if (!mod_data.cdrom)
  36980. + goto unknown_cmnd;
  36981. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36982. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36983. + (7<<6) | (1<<1), 1,
  36984. + "READ TOC")) == 0)
  36985. + reply = do_read_toc(fsg, bh);
  36986. + break;
  36987. +
  36988. + case READ_FORMAT_CAPACITIES:
  36989. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  36990. + if ((reply = check_command(fsg, 10, DATA_DIR_TO_HOST,
  36991. + (3<<7), 1,
  36992. + "READ FORMAT CAPACITIES")) == 0)
  36993. + reply = do_read_format_capacities(fsg, bh);
  36994. + break;
  36995. +
  36996. + case REQUEST_SENSE:
  36997. + fsg->data_size_from_cmnd = fsg->cmnd[4];
  36998. + if ((reply = check_command(fsg, 6, DATA_DIR_TO_HOST,
  36999. + (1<<4), 0,
  37000. + "REQUEST SENSE")) == 0)
  37001. + reply = do_request_sense(fsg, bh);
  37002. + break;
  37003. +
  37004. + case START_STOP:
  37005. + fsg->data_size_from_cmnd = 0;
  37006. + if ((reply = check_command(fsg, 6, DATA_DIR_NONE,
  37007. + (1<<1) | (1<<4), 0,
  37008. + "START-STOP UNIT")) == 0)
  37009. + reply = do_start_stop(fsg);
  37010. + break;
  37011. +
  37012. + case SYNCHRONIZE_CACHE:
  37013. + fsg->data_size_from_cmnd = 0;
  37014. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37015. + (0xf<<2) | (3<<7), 1,
  37016. + "SYNCHRONIZE CACHE")) == 0)
  37017. + reply = do_synchronize_cache(fsg);
  37018. + break;
  37019. +
  37020. + case TEST_UNIT_READY:
  37021. + fsg->data_size_from_cmnd = 0;
  37022. + reply = check_command(fsg, 6, DATA_DIR_NONE,
  37023. + 0, 1,
  37024. + "TEST UNIT READY");
  37025. + break;
  37026. +
  37027. + /* Although optional, this command is used by MS-Windows. We
  37028. + * support a minimal version: BytChk must be 0. */
  37029. + case VERIFY:
  37030. + fsg->data_size_from_cmnd = 0;
  37031. + if ((reply = check_command(fsg, 10, DATA_DIR_NONE,
  37032. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37033. + "VERIFY")) == 0)
  37034. + reply = do_verify(fsg);
  37035. + break;
  37036. +
  37037. + case WRITE_6:
  37038. + i = fsg->cmnd[4];
  37039. + fsg->data_size_from_cmnd = (i == 0) ? 256 : i;
  37040. + if ((reply = check_command_size_in_blocks(fsg, 6,
  37041. + DATA_DIR_FROM_HOST,
  37042. + (7<<1) | (1<<4), 1,
  37043. + "WRITE(6)")) == 0)
  37044. + reply = do_write(fsg);
  37045. + break;
  37046. +
  37047. + case WRITE_10:
  37048. + fsg->data_size_from_cmnd = get_unaligned_be16(&fsg->cmnd[7]);
  37049. + if ((reply = check_command_size_in_blocks(fsg, 10,
  37050. + DATA_DIR_FROM_HOST,
  37051. + (1<<1) | (0xf<<2) | (3<<7), 1,
  37052. + "WRITE(10)")) == 0)
  37053. + reply = do_write(fsg);
  37054. + break;
  37055. +
  37056. + case WRITE_12:
  37057. + fsg->data_size_from_cmnd = get_unaligned_be32(&fsg->cmnd[6]);
  37058. + if ((reply = check_command_size_in_blocks(fsg, 12,
  37059. + DATA_DIR_FROM_HOST,
  37060. + (1<<1) | (0xf<<2) | (0xf<<6), 1,
  37061. + "WRITE(12)")) == 0)
  37062. + reply = do_write(fsg);
  37063. + break;
  37064. +
  37065. + /* Some mandatory commands that we recognize but don't implement.
  37066. + * They don't mean much in this setting. It's left as an exercise
  37067. + * for anyone interested to implement RESERVE and RELEASE in terms
  37068. + * of Posix locks. */
  37069. + case FORMAT_UNIT:
  37070. + case RELEASE:
  37071. + case RESERVE:
  37072. + case SEND_DIAGNOSTIC:
  37073. + // Fall through
  37074. +
  37075. + default:
  37076. + unknown_cmnd:
  37077. + fsg->data_size_from_cmnd = 0;
  37078. + sprintf(unknown, "Unknown x%02x", fsg->cmnd[0]);
  37079. + if ((reply = check_command(fsg, fsg->cmnd_size,
  37080. + DATA_DIR_UNKNOWN, ~0, 0, unknown)) == 0) {
  37081. + fsg->curlun->sense_data = SS_INVALID_COMMAND;
  37082. + reply = -EINVAL;
  37083. + }
  37084. + break;
  37085. + }
  37086. + up_read(&fsg->filesem);
  37087. +
  37088. + if (reply == -EINTR || signal_pending(current))
  37089. + return -EINTR;
  37090. +
  37091. + /* Set up the single reply buffer for finish_reply() */
  37092. + if (reply == -EINVAL)
  37093. + reply = 0; // Error reply length
  37094. + if (reply >= 0 && fsg->data_dir == DATA_DIR_TO_HOST) {
  37095. + reply = min((u32) reply, fsg->data_size_from_cmnd);
  37096. + bh->inreq->length = reply;
  37097. + bh->state = BUF_STATE_FULL;
  37098. + fsg->residue -= reply;
  37099. + } // Otherwise it's already set
  37100. +
  37101. + return 0;
  37102. +}
  37103. +
  37104. +
  37105. +/*-------------------------------------------------------------------------*/
  37106. +
  37107. +static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
  37108. +{
  37109. + struct usb_request *req = bh->outreq;
  37110. + struct bulk_cb_wrap *cbw = req->buf;
  37111. +
  37112. + /* Was this a real packet? Should it be ignored? */
  37113. + if (req->status || test_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37114. + return -EINVAL;
  37115. +
  37116. + /* Is the CBW valid? */
  37117. + if (req->actual != US_BULK_CB_WRAP_LEN ||
  37118. + cbw->Signature != cpu_to_le32(
  37119. + US_BULK_CB_SIGN)) {
  37120. + DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
  37121. + req->actual,
  37122. + le32_to_cpu(cbw->Signature));
  37123. +
  37124. + /* The Bulk-only spec says we MUST stall the IN endpoint
  37125. + * (6.6.1), so it's unavoidable. It also says we must
  37126. + * retain this state until the next reset, but there's
  37127. + * no way to tell the controller driver it should ignore
  37128. + * Clear-Feature(HALT) requests.
  37129. + *
  37130. + * We aren't required to halt the OUT endpoint; instead
  37131. + * we can simply accept and discard any data received
  37132. + * until the next reset. */
  37133. + wedge_bulk_in_endpoint(fsg);
  37134. + set_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37135. + return -EINVAL;
  37136. + }
  37137. +
  37138. + /* Is the CBW meaningful? */
  37139. + if (cbw->Lun >= FSG_MAX_LUNS || cbw->Flags & ~US_BULK_FLAG_IN ||
  37140. + cbw->Length <= 0 || cbw->Length > MAX_COMMAND_SIZE) {
  37141. + DBG(fsg, "non-meaningful CBW: lun = %u, flags = 0x%x, "
  37142. + "cmdlen %u\n",
  37143. + cbw->Lun, cbw->Flags, cbw->Length);
  37144. +
  37145. + /* We can do anything we want here, so let's stall the
  37146. + * bulk pipes if we are allowed to. */
  37147. + if (mod_data.can_stall) {
  37148. + fsg_set_halt(fsg, fsg->bulk_out);
  37149. + halt_bulk_in_endpoint(fsg);
  37150. + }
  37151. + return -EINVAL;
  37152. + }
  37153. +
  37154. + /* Save the command for later */
  37155. + fsg->cmnd_size = cbw->Length;
  37156. + memcpy(fsg->cmnd, cbw->CDB, fsg->cmnd_size);
  37157. + if (cbw->Flags & US_BULK_FLAG_IN)
  37158. + fsg->data_dir = DATA_DIR_TO_HOST;
  37159. + else
  37160. + fsg->data_dir = DATA_DIR_FROM_HOST;
  37161. + fsg->data_size = le32_to_cpu(cbw->DataTransferLength);
  37162. + if (fsg->data_size == 0)
  37163. + fsg->data_dir = DATA_DIR_NONE;
  37164. + fsg->lun = cbw->Lun;
  37165. + fsg->tag = cbw->Tag;
  37166. + return 0;
  37167. +}
  37168. +
  37169. +
  37170. +static int get_next_command(struct fsg_dev *fsg)
  37171. +{
  37172. + struct fsg_buffhd *bh;
  37173. + int rc = 0;
  37174. +
  37175. + if (transport_is_bbb()) {
  37176. +
  37177. + /* Wait for the next buffer to become available */
  37178. + bh = fsg->next_buffhd_to_fill;
  37179. + while (bh->state != BUF_STATE_EMPTY) {
  37180. + rc = sleep_thread(fsg);
  37181. + if (rc)
  37182. + return rc;
  37183. + }
  37184. +
  37185. + /* Queue a request to read a Bulk-only CBW */
  37186. + set_bulk_out_req_length(fsg, bh, US_BULK_CB_WRAP_LEN);
  37187. + start_transfer(fsg, fsg->bulk_out, bh->outreq,
  37188. + &bh->outreq_busy, &bh->state);
  37189. +
  37190. + /* We will drain the buffer in software, which means we
  37191. + * can reuse it for the next filling. No need to advance
  37192. + * next_buffhd_to_fill. */
  37193. +
  37194. + /* Wait for the CBW to arrive */
  37195. + while (bh->state != BUF_STATE_FULL) {
  37196. + rc = sleep_thread(fsg);
  37197. + if (rc)
  37198. + return rc;
  37199. + }
  37200. + smp_rmb();
  37201. + rc = received_cbw(fsg, bh);
  37202. + bh->state = BUF_STATE_EMPTY;
  37203. +
  37204. + } else { // USB_PR_CB or USB_PR_CBI
  37205. +
  37206. + /* Wait for the next command to arrive */
  37207. + while (fsg->cbbuf_cmnd_size == 0) {
  37208. + rc = sleep_thread(fsg);
  37209. + if (rc)
  37210. + return rc;
  37211. + }
  37212. +
  37213. + /* Is the previous status interrupt request still busy?
  37214. + * The host is allowed to skip reading the status,
  37215. + * so we must cancel it. */
  37216. + if (fsg->intreq_busy)
  37217. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37218. +
  37219. + /* Copy the command and mark the buffer empty */
  37220. + fsg->data_dir = DATA_DIR_UNKNOWN;
  37221. + spin_lock_irq(&fsg->lock);
  37222. + fsg->cmnd_size = fsg->cbbuf_cmnd_size;
  37223. + memcpy(fsg->cmnd, fsg->cbbuf_cmnd, fsg->cmnd_size);
  37224. + fsg->cbbuf_cmnd_size = 0;
  37225. + spin_unlock_irq(&fsg->lock);
  37226. +
  37227. + /* Use LUN from the command */
  37228. + fsg->lun = fsg->cmnd[1] >> 5;
  37229. + }
  37230. +
  37231. + /* Update current lun */
  37232. + if (fsg->lun >= 0 && fsg->lun < fsg->nluns)
  37233. + fsg->curlun = &fsg->luns[fsg->lun];
  37234. + else
  37235. + fsg->curlun = NULL;
  37236. +
  37237. + return rc;
  37238. +}
  37239. +
  37240. +
  37241. +/*-------------------------------------------------------------------------*/
  37242. +
  37243. +static int enable_endpoint(struct fsg_dev *fsg, struct usb_ep *ep,
  37244. + const struct usb_endpoint_descriptor *d)
  37245. +{
  37246. + int rc;
  37247. +
  37248. + ep->driver_data = fsg;
  37249. + ep->desc = d;
  37250. + rc = usb_ep_enable(ep);
  37251. + if (rc)
  37252. + ERROR(fsg, "can't enable %s, result %d\n", ep->name, rc);
  37253. + return rc;
  37254. +}
  37255. +
  37256. +static int alloc_request(struct fsg_dev *fsg, struct usb_ep *ep,
  37257. + struct usb_request **preq)
  37258. +{
  37259. + *preq = usb_ep_alloc_request(ep, GFP_ATOMIC);
  37260. + if (*preq)
  37261. + return 0;
  37262. + ERROR(fsg, "can't allocate request for %s\n", ep->name);
  37263. + return -ENOMEM;
  37264. +}
  37265. +
  37266. +/*
  37267. + * Reset interface setting and re-init endpoint state (toggle etc).
  37268. + * Call with altsetting < 0 to disable the interface. The only other
  37269. + * available altsetting is 0, which enables the interface.
  37270. + */
  37271. +static int do_set_interface(struct fsg_dev *fsg, int altsetting)
  37272. +{
  37273. + int rc = 0;
  37274. + int i;
  37275. + const struct usb_endpoint_descriptor *d;
  37276. +
  37277. + if (fsg->running)
  37278. + DBG(fsg, "reset interface\n");
  37279. +
  37280. +reset:
  37281. + /* Deallocate the requests */
  37282. + for (i = 0; i < fsg_num_buffers; ++i) {
  37283. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37284. +
  37285. + if (bh->inreq) {
  37286. + usb_ep_free_request(fsg->bulk_in, bh->inreq);
  37287. + bh->inreq = NULL;
  37288. + }
  37289. + if (bh->outreq) {
  37290. + usb_ep_free_request(fsg->bulk_out, bh->outreq);
  37291. + bh->outreq = NULL;
  37292. + }
  37293. + }
  37294. + if (fsg->intreq) {
  37295. + usb_ep_free_request(fsg->intr_in, fsg->intreq);
  37296. + fsg->intreq = NULL;
  37297. + }
  37298. +
  37299. + /* Disable the endpoints */
  37300. + if (fsg->bulk_in_enabled) {
  37301. + usb_ep_disable(fsg->bulk_in);
  37302. + fsg->bulk_in_enabled = 0;
  37303. + }
  37304. + if (fsg->bulk_out_enabled) {
  37305. + usb_ep_disable(fsg->bulk_out);
  37306. + fsg->bulk_out_enabled = 0;
  37307. + }
  37308. + if (fsg->intr_in_enabled) {
  37309. + usb_ep_disable(fsg->intr_in);
  37310. + fsg->intr_in_enabled = 0;
  37311. + }
  37312. +
  37313. + fsg->running = 0;
  37314. + if (altsetting < 0 || rc != 0)
  37315. + return rc;
  37316. +
  37317. + DBG(fsg, "set interface %d\n", altsetting);
  37318. +
  37319. + /* Enable the endpoints */
  37320. + d = fsg_ep_desc(fsg->gadget,
  37321. + &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc,
  37322. + &fsg_ss_bulk_in_desc);
  37323. + if ((rc = enable_endpoint(fsg, fsg->bulk_in, d)) != 0)
  37324. + goto reset;
  37325. + fsg->bulk_in_enabled = 1;
  37326. +
  37327. + d = fsg_ep_desc(fsg->gadget,
  37328. + &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc,
  37329. + &fsg_ss_bulk_out_desc);
  37330. + if ((rc = enable_endpoint(fsg, fsg->bulk_out, d)) != 0)
  37331. + goto reset;
  37332. + fsg->bulk_out_enabled = 1;
  37333. + fsg->bulk_out_maxpacket = usb_endpoint_maxp(d);
  37334. + clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags);
  37335. +
  37336. + if (transport_is_cbi()) {
  37337. + d = fsg_ep_desc(fsg->gadget,
  37338. + &fsg_fs_intr_in_desc, &fsg_hs_intr_in_desc,
  37339. + &fsg_ss_intr_in_desc);
  37340. + if ((rc = enable_endpoint(fsg, fsg->intr_in, d)) != 0)
  37341. + goto reset;
  37342. + fsg->intr_in_enabled = 1;
  37343. + }
  37344. +
  37345. + /* Allocate the requests */
  37346. + for (i = 0; i < fsg_num_buffers; ++i) {
  37347. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  37348. +
  37349. + if ((rc = alloc_request(fsg, fsg->bulk_in, &bh->inreq)) != 0)
  37350. + goto reset;
  37351. + if ((rc = alloc_request(fsg, fsg->bulk_out, &bh->outreq)) != 0)
  37352. + goto reset;
  37353. + bh->inreq->buf = bh->outreq->buf = bh->buf;
  37354. + bh->inreq->context = bh->outreq->context = bh;
  37355. + bh->inreq->complete = bulk_in_complete;
  37356. + bh->outreq->complete = bulk_out_complete;
  37357. + }
  37358. + if (transport_is_cbi()) {
  37359. + if ((rc = alloc_request(fsg, fsg->intr_in, &fsg->intreq)) != 0)
  37360. + goto reset;
  37361. + fsg->intreq->complete = intr_in_complete;
  37362. + }
  37363. +
  37364. + fsg->running = 1;
  37365. + for (i = 0; i < fsg->nluns; ++i)
  37366. + fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37367. + return rc;
  37368. +}
  37369. +
  37370. +
  37371. +/*
  37372. + * Change our operational configuration. This code must agree with the code
  37373. + * that returns config descriptors, and with interface altsetting code.
  37374. + *
  37375. + * It's also responsible for power management interactions. Some
  37376. + * configurations might not work with our current power sources.
  37377. + * For now we just assume the gadget is always self-powered.
  37378. + */
  37379. +static int do_set_config(struct fsg_dev *fsg, u8 new_config)
  37380. +{
  37381. + int rc = 0;
  37382. +
  37383. + /* Disable the single interface */
  37384. + if (fsg->config != 0) {
  37385. + DBG(fsg, "reset config\n");
  37386. + fsg->config = 0;
  37387. + rc = do_set_interface(fsg, -1);
  37388. + }
  37389. +
  37390. + /* Enable the interface */
  37391. + if (new_config != 0) {
  37392. + fsg->config = new_config;
  37393. + if ((rc = do_set_interface(fsg, 0)) != 0)
  37394. + fsg->config = 0; // Reset on errors
  37395. + else
  37396. + INFO(fsg, "%s config #%d\n",
  37397. + usb_speed_string(fsg->gadget->speed),
  37398. + fsg->config);
  37399. + }
  37400. + return rc;
  37401. +}
  37402. +
  37403. +
  37404. +/*-------------------------------------------------------------------------*/
  37405. +
  37406. +static void handle_exception(struct fsg_dev *fsg)
  37407. +{
  37408. + siginfo_t info;
  37409. + int sig;
  37410. + int i;
  37411. + int num_active;
  37412. + struct fsg_buffhd *bh;
  37413. + enum fsg_state old_state;
  37414. + u8 new_config;
  37415. + struct fsg_lun *curlun;
  37416. + unsigned int exception_req_tag;
  37417. + int rc;
  37418. +
  37419. + /* Clear the existing signals. Anything but SIGUSR1 is converted
  37420. + * into a high-priority EXIT exception. */
  37421. + for (;;) {
  37422. + sig = dequeue_signal_lock(current, &current->blocked, &info);
  37423. + if (!sig)
  37424. + break;
  37425. + if (sig != SIGUSR1) {
  37426. + if (fsg->state < FSG_STATE_EXIT)
  37427. + DBG(fsg, "Main thread exiting on signal\n");
  37428. + raise_exception(fsg, FSG_STATE_EXIT);
  37429. + }
  37430. + }
  37431. +
  37432. + /* Cancel all the pending transfers */
  37433. + if (fsg->intreq_busy)
  37434. + usb_ep_dequeue(fsg->intr_in, fsg->intreq);
  37435. + for (i = 0; i < fsg_num_buffers; ++i) {
  37436. + bh = &fsg->buffhds[i];
  37437. + if (bh->inreq_busy)
  37438. + usb_ep_dequeue(fsg->bulk_in, bh->inreq);
  37439. + if (bh->outreq_busy)
  37440. + usb_ep_dequeue(fsg->bulk_out, bh->outreq);
  37441. + }
  37442. +
  37443. + /* Wait until everything is idle */
  37444. + for (;;) {
  37445. + num_active = fsg->intreq_busy;
  37446. + for (i = 0; i < fsg_num_buffers; ++i) {
  37447. + bh = &fsg->buffhds[i];
  37448. + num_active += bh->inreq_busy + bh->outreq_busy;
  37449. + }
  37450. + if (num_active == 0)
  37451. + break;
  37452. + if (sleep_thread(fsg))
  37453. + return;
  37454. + }
  37455. +
  37456. + /* Clear out the controller's fifos */
  37457. + if (fsg->bulk_in_enabled)
  37458. + usb_ep_fifo_flush(fsg->bulk_in);
  37459. + if (fsg->bulk_out_enabled)
  37460. + usb_ep_fifo_flush(fsg->bulk_out);
  37461. + if (fsg->intr_in_enabled)
  37462. + usb_ep_fifo_flush(fsg->intr_in);
  37463. +
  37464. + /* Reset the I/O buffer states and pointers, the SCSI
  37465. + * state, and the exception. Then invoke the handler. */
  37466. + spin_lock_irq(&fsg->lock);
  37467. +
  37468. + for (i = 0; i < fsg_num_buffers; ++i) {
  37469. + bh = &fsg->buffhds[i];
  37470. + bh->state = BUF_STATE_EMPTY;
  37471. + }
  37472. + fsg->next_buffhd_to_fill = fsg->next_buffhd_to_drain =
  37473. + &fsg->buffhds[0];
  37474. +
  37475. + exception_req_tag = fsg->exception_req_tag;
  37476. + new_config = fsg->new_config;
  37477. + old_state = fsg->state;
  37478. +
  37479. + if (old_state == FSG_STATE_ABORT_BULK_OUT)
  37480. + fsg->state = FSG_STATE_STATUS_PHASE;
  37481. + else {
  37482. + for (i = 0; i < fsg->nluns; ++i) {
  37483. + curlun = &fsg->luns[i];
  37484. + curlun->prevent_medium_removal = 0;
  37485. + curlun->sense_data = curlun->unit_attention_data =
  37486. + SS_NO_SENSE;
  37487. + curlun->sense_data_info = 0;
  37488. + curlun->info_valid = 0;
  37489. + }
  37490. + fsg->state = FSG_STATE_IDLE;
  37491. + }
  37492. + spin_unlock_irq(&fsg->lock);
  37493. +
  37494. + /* Carry out any extra actions required for the exception */
  37495. + switch (old_state) {
  37496. + default:
  37497. + break;
  37498. +
  37499. + case FSG_STATE_ABORT_BULK_OUT:
  37500. + send_status(fsg);
  37501. + spin_lock_irq(&fsg->lock);
  37502. + if (fsg->state == FSG_STATE_STATUS_PHASE)
  37503. + fsg->state = FSG_STATE_IDLE;
  37504. + spin_unlock_irq(&fsg->lock);
  37505. + break;
  37506. +
  37507. + case FSG_STATE_RESET:
  37508. + /* In case we were forced against our will to halt a
  37509. + * bulk endpoint, clear the halt now. (The SuperH UDC
  37510. + * requires this.) */
  37511. + if (test_and_clear_bit(IGNORE_BULK_OUT, &fsg->atomic_bitflags))
  37512. + usb_ep_clear_halt(fsg->bulk_in);
  37513. +
  37514. + if (transport_is_bbb()) {
  37515. + if (fsg->ep0_req_tag == exception_req_tag)
  37516. + ep0_queue(fsg); // Complete the status stage
  37517. +
  37518. + } else if (transport_is_cbi())
  37519. + send_status(fsg); // Status by interrupt pipe
  37520. +
  37521. + /* Technically this should go here, but it would only be
  37522. + * a waste of time. Ditto for the INTERFACE_CHANGE and
  37523. + * CONFIG_CHANGE cases. */
  37524. + // for (i = 0; i < fsg->nluns; ++i)
  37525. + // fsg->luns[i].unit_attention_data = SS_RESET_OCCURRED;
  37526. + break;
  37527. +
  37528. + case FSG_STATE_INTERFACE_CHANGE:
  37529. + rc = do_set_interface(fsg, 0);
  37530. + if (fsg->ep0_req_tag != exception_req_tag)
  37531. + break;
  37532. + if (rc != 0) // STALL on errors
  37533. + fsg_set_halt(fsg, fsg->ep0);
  37534. + else // Complete the status stage
  37535. + ep0_queue(fsg);
  37536. + break;
  37537. +
  37538. + case FSG_STATE_CONFIG_CHANGE:
  37539. + rc = do_set_config(fsg, new_config);
  37540. + if (fsg->ep0_req_tag != exception_req_tag)
  37541. + break;
  37542. + if (rc != 0) // STALL on errors
  37543. + fsg_set_halt(fsg, fsg->ep0);
  37544. + else // Complete the status stage
  37545. + ep0_queue(fsg);
  37546. + break;
  37547. +
  37548. + case FSG_STATE_DISCONNECT:
  37549. + for (i = 0; i < fsg->nluns; ++i)
  37550. + fsg_lun_fsync_sub(fsg->luns + i);
  37551. + do_set_config(fsg, 0); // Unconfigured state
  37552. + break;
  37553. +
  37554. + case FSG_STATE_EXIT:
  37555. + case FSG_STATE_TERMINATED:
  37556. + do_set_config(fsg, 0); // Free resources
  37557. + spin_lock_irq(&fsg->lock);
  37558. + fsg->state = FSG_STATE_TERMINATED; // Stop the thread
  37559. + spin_unlock_irq(&fsg->lock);
  37560. + break;
  37561. + }
  37562. +}
  37563. +
  37564. +
  37565. +/*-------------------------------------------------------------------------*/
  37566. +
  37567. +static int fsg_main_thread(void *fsg_)
  37568. +{
  37569. + struct fsg_dev *fsg = fsg_;
  37570. +
  37571. + /* Allow the thread to be killed by a signal, but set the signal mask
  37572. + * to block everything but INT, TERM, KILL, and USR1. */
  37573. + allow_signal(SIGINT);
  37574. + allow_signal(SIGTERM);
  37575. + allow_signal(SIGKILL);
  37576. + allow_signal(SIGUSR1);
  37577. +
  37578. + /* Allow the thread to be frozen */
  37579. + set_freezable();
  37580. +
  37581. + /* Arrange for userspace references to be interpreted as kernel
  37582. + * pointers. That way we can pass a kernel pointer to a routine
  37583. + * that expects a __user pointer and it will work okay. */
  37584. + set_fs(get_ds());
  37585. +
  37586. + /* The main loop */
  37587. + while (fsg->state != FSG_STATE_TERMINATED) {
  37588. + if (exception_in_progress(fsg) || signal_pending(current)) {
  37589. + handle_exception(fsg);
  37590. + continue;
  37591. + }
  37592. +
  37593. + if (!fsg->running) {
  37594. + sleep_thread(fsg);
  37595. + continue;
  37596. + }
  37597. +
  37598. + if (get_next_command(fsg))
  37599. + continue;
  37600. +
  37601. + spin_lock_irq(&fsg->lock);
  37602. + if (!exception_in_progress(fsg))
  37603. + fsg->state = FSG_STATE_DATA_PHASE;
  37604. + spin_unlock_irq(&fsg->lock);
  37605. +
  37606. + if (do_scsi_command(fsg) || finish_reply(fsg))
  37607. + continue;
  37608. +
  37609. + spin_lock_irq(&fsg->lock);
  37610. + if (!exception_in_progress(fsg))
  37611. + fsg->state = FSG_STATE_STATUS_PHASE;
  37612. + spin_unlock_irq(&fsg->lock);
  37613. +
  37614. + if (send_status(fsg))
  37615. + continue;
  37616. +
  37617. + spin_lock_irq(&fsg->lock);
  37618. + if (!exception_in_progress(fsg))
  37619. + fsg->state = FSG_STATE_IDLE;
  37620. + spin_unlock_irq(&fsg->lock);
  37621. + }
  37622. +
  37623. + spin_lock_irq(&fsg->lock);
  37624. + fsg->thread_task = NULL;
  37625. + spin_unlock_irq(&fsg->lock);
  37626. +
  37627. + /* If we are exiting because of a signal, unregister the
  37628. + * gadget driver. */
  37629. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  37630. + usb_gadget_unregister_driver(&fsg_driver);
  37631. +
  37632. + /* Let the unbind and cleanup routines know the thread has exited */
  37633. + complete_and_exit(&fsg->thread_notifier, 0);
  37634. +}
  37635. +
  37636. +
  37637. +/*-------------------------------------------------------------------------*/
  37638. +
  37639. +
  37640. +/* The write permissions and store_xxx pointers are set in fsg_bind() */
  37641. +static DEVICE_ATTR(ro, 0444, fsg_show_ro, NULL);
  37642. +static DEVICE_ATTR(nofua, 0644, fsg_show_nofua, NULL);
  37643. +static DEVICE_ATTR(file, 0444, fsg_show_file, NULL);
  37644. +
  37645. +
  37646. +/*-------------------------------------------------------------------------*/
  37647. +
  37648. +static void fsg_release(struct kref *ref)
  37649. +{
  37650. + struct fsg_dev *fsg = container_of(ref, struct fsg_dev, ref);
  37651. +
  37652. + kfree(fsg->luns);
  37653. + kfree(fsg);
  37654. +}
  37655. +
  37656. +static void lun_release(struct device *dev)
  37657. +{
  37658. + struct rw_semaphore *filesem = dev_get_drvdata(dev);
  37659. + struct fsg_dev *fsg =
  37660. + container_of(filesem, struct fsg_dev, filesem);
  37661. +
  37662. + kref_put(&fsg->ref, fsg_release);
  37663. +}
  37664. +
  37665. +static void /* __init_or_exit */ fsg_unbind(struct usb_gadget *gadget)
  37666. +{
  37667. + struct fsg_dev *fsg = get_gadget_data(gadget);
  37668. + int i;
  37669. + struct fsg_lun *curlun;
  37670. + struct usb_request *req = fsg->ep0req;
  37671. +
  37672. + DBG(fsg, "unbind\n");
  37673. + clear_bit(REGISTERED, &fsg->atomic_bitflags);
  37674. +
  37675. + /* If the thread isn't already dead, tell it to exit now */
  37676. + if (fsg->state != FSG_STATE_TERMINATED) {
  37677. + raise_exception(fsg, FSG_STATE_EXIT);
  37678. + wait_for_completion(&fsg->thread_notifier);
  37679. +
  37680. + /* The cleanup routine waits for this completion also */
  37681. + complete(&fsg->thread_notifier);
  37682. + }
  37683. +
  37684. + /* Unregister the sysfs attribute files and the LUNs */
  37685. + for (i = 0; i < fsg->nluns; ++i) {
  37686. + curlun = &fsg->luns[i];
  37687. + if (curlun->registered) {
  37688. + device_remove_file(&curlun->dev, &dev_attr_nofua);
  37689. + device_remove_file(&curlun->dev, &dev_attr_ro);
  37690. + device_remove_file(&curlun->dev, &dev_attr_file);
  37691. + fsg_lun_close(curlun);
  37692. + device_unregister(&curlun->dev);
  37693. + curlun->registered = 0;
  37694. + }
  37695. + }
  37696. +
  37697. + /* Free the data buffers */
  37698. + for (i = 0; i < fsg_num_buffers; ++i)
  37699. + kfree(fsg->buffhds[i].buf);
  37700. +
  37701. + /* Free the request and buffer for endpoint 0 */
  37702. + if (req) {
  37703. + kfree(req->buf);
  37704. + usb_ep_free_request(fsg->ep0, req);
  37705. + }
  37706. +
  37707. + set_gadget_data(gadget, NULL);
  37708. +}
  37709. +
  37710. +
  37711. +static int __init check_parameters(struct fsg_dev *fsg)
  37712. +{
  37713. + int prot;
  37714. + int gcnum;
  37715. +
  37716. + /* Store the default values */
  37717. + mod_data.transport_type = USB_PR_BULK;
  37718. + mod_data.transport_name = "Bulk-only";
  37719. + mod_data.protocol_type = USB_SC_SCSI;
  37720. + mod_data.protocol_name = "Transparent SCSI";
  37721. +
  37722. + /* Some peripheral controllers are known not to be able to
  37723. + * halt bulk endpoints correctly. If one of them is present,
  37724. + * disable stalls.
  37725. + */
  37726. + if (gadget_is_at91(fsg->gadget))
  37727. + mod_data.can_stall = 0;
  37728. +
  37729. + if (mod_data.release == 0xffff) { // Parameter wasn't set
  37730. + gcnum = usb_gadget_controller_number(fsg->gadget);
  37731. + if (gcnum >= 0)
  37732. + mod_data.release = 0x0300 + gcnum;
  37733. + else {
  37734. + WARNING(fsg, "controller '%s' not recognized\n",
  37735. + fsg->gadget->name);
  37736. + mod_data.release = 0x0399;
  37737. + }
  37738. + }
  37739. +
  37740. + prot = simple_strtol(mod_data.protocol_parm, NULL, 0);
  37741. +
  37742. +#ifdef CONFIG_USB_FILE_STORAGE_TEST
  37743. + if (strnicmp(mod_data.transport_parm, "BBB", 10) == 0) {
  37744. + ; // Use default setting
  37745. + } else if (strnicmp(mod_data.transport_parm, "CB", 10) == 0) {
  37746. + mod_data.transport_type = USB_PR_CB;
  37747. + mod_data.transport_name = "Control-Bulk";
  37748. + } else if (strnicmp(mod_data.transport_parm, "CBI", 10) == 0) {
  37749. + mod_data.transport_type = USB_PR_CBI;
  37750. + mod_data.transport_name = "Control-Bulk-Interrupt";
  37751. + } else {
  37752. + ERROR(fsg, "invalid transport: %s\n", mod_data.transport_parm);
  37753. + return -EINVAL;
  37754. + }
  37755. +
  37756. + if (strnicmp(mod_data.protocol_parm, "SCSI", 10) == 0 ||
  37757. + prot == USB_SC_SCSI) {
  37758. + ; // Use default setting
  37759. + } else if (strnicmp(mod_data.protocol_parm, "RBC", 10) == 0 ||
  37760. + prot == USB_SC_RBC) {
  37761. + mod_data.protocol_type = USB_SC_RBC;
  37762. + mod_data.protocol_name = "RBC";
  37763. + } else if (strnicmp(mod_data.protocol_parm, "8020", 4) == 0 ||
  37764. + strnicmp(mod_data.protocol_parm, "ATAPI", 10) == 0 ||
  37765. + prot == USB_SC_8020) {
  37766. + mod_data.protocol_type = USB_SC_8020;
  37767. + mod_data.protocol_name = "8020i (ATAPI)";
  37768. + } else if (strnicmp(mod_data.protocol_parm, "QIC", 3) == 0 ||
  37769. + prot == USB_SC_QIC) {
  37770. + mod_data.protocol_type = USB_SC_QIC;
  37771. + mod_data.protocol_name = "QIC-157";
  37772. + } else if (strnicmp(mod_data.protocol_parm, "UFI", 10) == 0 ||
  37773. + prot == USB_SC_UFI) {
  37774. + mod_data.protocol_type = USB_SC_UFI;
  37775. + mod_data.protocol_name = "UFI";
  37776. + } else if (strnicmp(mod_data.protocol_parm, "8070", 4) == 0 ||
  37777. + prot == USB_SC_8070) {
  37778. + mod_data.protocol_type = USB_SC_8070;
  37779. + mod_data.protocol_name = "8070i";
  37780. + } else {
  37781. + ERROR(fsg, "invalid protocol: %s\n", mod_data.protocol_parm);
  37782. + return -EINVAL;
  37783. + }
  37784. +
  37785. + mod_data.buflen &= PAGE_CACHE_MASK;
  37786. + if (mod_data.buflen <= 0) {
  37787. + ERROR(fsg, "invalid buflen\n");
  37788. + return -ETOOSMALL;
  37789. + }
  37790. +
  37791. +#endif /* CONFIG_USB_FILE_STORAGE_TEST */
  37792. +
  37793. + /* Serial string handling.
  37794. + * On a real device, the serial string would be loaded
  37795. + * from permanent storage. */
  37796. + if (mod_data.serial) {
  37797. + const char *ch;
  37798. + unsigned len = 0;
  37799. +
  37800. + /* Sanity check :
  37801. + * The CB[I] specification limits the serial string to
  37802. + * 12 uppercase hexadecimal characters.
  37803. + * BBB need at least 12 uppercase hexadecimal characters,
  37804. + * with a maximum of 126. */
  37805. + for (ch = mod_data.serial; *ch; ++ch) {
  37806. + ++len;
  37807. + if ((*ch < '0' || *ch > '9') &&
  37808. + (*ch < 'A' || *ch > 'F')) { /* not uppercase hex */
  37809. + WARNING(fsg,
  37810. + "Invalid serial string character: %c\n",
  37811. + *ch);
  37812. + goto no_serial;
  37813. + }
  37814. + }
  37815. + if (len > 126 ||
  37816. + (mod_data.transport_type == USB_PR_BULK && len < 12) ||
  37817. + (mod_data.transport_type != USB_PR_BULK && len > 12)) {
  37818. + WARNING(fsg, "Invalid serial string length!\n");
  37819. + goto no_serial;
  37820. + }
  37821. + fsg_strings[FSG_STRING_SERIAL - 1].s = mod_data.serial;
  37822. + } else {
  37823. + WARNING(fsg, "No serial-number string provided!\n");
  37824. + no_serial:
  37825. + device_desc.iSerialNumber = 0;
  37826. + }
  37827. +
  37828. + return 0;
  37829. +}
  37830. +
  37831. +
  37832. +static int __init fsg_bind(struct usb_gadget *gadget)
  37833. +{
  37834. + struct fsg_dev *fsg = the_fsg;
  37835. + int rc;
  37836. + int i;
  37837. + struct fsg_lun *curlun;
  37838. + struct usb_ep *ep;
  37839. + struct usb_request *req;
  37840. + char *pathbuf, *p;
  37841. +
  37842. + fsg->gadget = gadget;
  37843. + set_gadget_data(gadget, fsg);
  37844. + fsg->ep0 = gadget->ep0;
  37845. + fsg->ep0->driver_data = fsg;
  37846. +
  37847. + if ((rc = check_parameters(fsg)) != 0)
  37848. + goto out;
  37849. +
  37850. + if (mod_data.removable) { // Enable the store_xxx attributes
  37851. + dev_attr_file.attr.mode = 0644;
  37852. + dev_attr_file.store = fsg_store_file;
  37853. + if (!mod_data.cdrom) {
  37854. + dev_attr_ro.attr.mode = 0644;
  37855. + dev_attr_ro.store = fsg_store_ro;
  37856. + }
  37857. + }
  37858. +
  37859. + /* Only for removable media? */
  37860. + dev_attr_nofua.attr.mode = 0644;
  37861. + dev_attr_nofua.store = fsg_store_nofua;
  37862. +
  37863. + /* Find out how many LUNs there should be */
  37864. + i = mod_data.nluns;
  37865. + if (i == 0)
  37866. + i = max(mod_data.num_filenames, 1u);
  37867. + if (i > FSG_MAX_LUNS) {
  37868. + ERROR(fsg, "invalid number of LUNs: %d\n", i);
  37869. + rc = -EINVAL;
  37870. + goto out;
  37871. + }
  37872. +
  37873. + /* Create the LUNs, open their backing files, and register the
  37874. + * LUN devices in sysfs. */
  37875. + fsg->luns = kzalloc(i * sizeof(struct fsg_lun), GFP_KERNEL);
  37876. + if (!fsg->luns) {
  37877. + rc = -ENOMEM;
  37878. + goto out;
  37879. + }
  37880. + fsg->nluns = i;
  37881. +
  37882. + for (i = 0; i < fsg->nluns; ++i) {
  37883. + curlun = &fsg->luns[i];
  37884. + curlun->cdrom = !!mod_data.cdrom;
  37885. + curlun->ro = mod_data.cdrom || mod_data.ro[i];
  37886. + curlun->initially_ro = curlun->ro;
  37887. + curlun->removable = mod_data.removable;
  37888. + curlun->nofua = mod_data.nofua[i];
  37889. + curlun->dev.release = lun_release;
  37890. + curlun->dev.parent = &gadget->dev;
  37891. + curlun->dev.driver = &fsg_driver.driver;
  37892. + dev_set_drvdata(&curlun->dev, &fsg->filesem);
  37893. + dev_set_name(&curlun->dev,"%s-lun%d",
  37894. + dev_name(&gadget->dev), i);
  37895. +
  37896. + kref_get(&fsg->ref);
  37897. + rc = device_register(&curlun->dev);
  37898. + if (rc) {
  37899. + INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
  37900. + put_device(&curlun->dev);
  37901. + goto out;
  37902. + }
  37903. + curlun->registered = 1;
  37904. +
  37905. + rc = device_create_file(&curlun->dev, &dev_attr_ro);
  37906. + if (rc)
  37907. + goto out;
  37908. + rc = device_create_file(&curlun->dev, &dev_attr_nofua);
  37909. + if (rc)
  37910. + goto out;
  37911. + rc = device_create_file(&curlun->dev, &dev_attr_file);
  37912. + if (rc)
  37913. + goto out;
  37914. +
  37915. + if (mod_data.file[i] && *mod_data.file[i]) {
  37916. + rc = fsg_lun_open(curlun, mod_data.file[i]);
  37917. + if (rc)
  37918. + goto out;
  37919. + } else if (!mod_data.removable) {
  37920. + ERROR(fsg, "no file given for LUN%d\n", i);
  37921. + rc = -EINVAL;
  37922. + goto out;
  37923. + }
  37924. + }
  37925. +
  37926. + /* Find all the endpoints we will use */
  37927. + usb_ep_autoconfig_reset(gadget);
  37928. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_in_desc);
  37929. + if (!ep)
  37930. + goto autoconf_fail;
  37931. + ep->driver_data = fsg; // claim the endpoint
  37932. + fsg->bulk_in = ep;
  37933. +
  37934. + ep = usb_ep_autoconfig(gadget, &fsg_fs_bulk_out_desc);
  37935. + if (!ep)
  37936. + goto autoconf_fail;
  37937. + ep->driver_data = fsg; // claim the endpoint
  37938. + fsg->bulk_out = ep;
  37939. +
  37940. + if (transport_is_cbi()) {
  37941. + ep = usb_ep_autoconfig(gadget, &fsg_fs_intr_in_desc);
  37942. + if (!ep)
  37943. + goto autoconf_fail;
  37944. + ep->driver_data = fsg; // claim the endpoint
  37945. + fsg->intr_in = ep;
  37946. + }
  37947. +
  37948. + /* Fix up the descriptors */
  37949. + device_desc.idVendor = cpu_to_le16(mod_data.vendor);
  37950. + device_desc.idProduct = cpu_to_le16(mod_data.product);
  37951. + device_desc.bcdDevice = cpu_to_le16(mod_data.release);
  37952. +
  37953. + i = (transport_is_cbi() ? 3 : 2); // Number of endpoints
  37954. + fsg_intf_desc.bNumEndpoints = i;
  37955. + fsg_intf_desc.bInterfaceSubClass = mod_data.protocol_type;
  37956. + fsg_intf_desc.bInterfaceProtocol = mod_data.transport_type;
  37957. + fsg_fs_function[i + FSG_FS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37958. +
  37959. + if (gadget_is_dualspeed(gadget)) {
  37960. + fsg_hs_function[i + FSG_HS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37961. +
  37962. + /* Assume endpoint addresses are the same for both speeds */
  37963. + fsg_hs_bulk_in_desc.bEndpointAddress =
  37964. + fsg_fs_bulk_in_desc.bEndpointAddress;
  37965. + fsg_hs_bulk_out_desc.bEndpointAddress =
  37966. + fsg_fs_bulk_out_desc.bEndpointAddress;
  37967. + fsg_hs_intr_in_desc.bEndpointAddress =
  37968. + fsg_fs_intr_in_desc.bEndpointAddress;
  37969. + }
  37970. +
  37971. + if (gadget_is_superspeed(gadget)) {
  37972. + unsigned max_burst;
  37973. +
  37974. + fsg_ss_function[i + FSG_SS_FUNCTION_PRE_EP_ENTRIES] = NULL;
  37975. +
  37976. + /* Calculate bMaxBurst, we know packet size is 1024 */
  37977. + max_burst = min_t(unsigned, mod_data.buflen / 1024, 15);
  37978. +
  37979. + /* Assume endpoint addresses are the same for both speeds */
  37980. + fsg_ss_bulk_in_desc.bEndpointAddress =
  37981. + fsg_fs_bulk_in_desc.bEndpointAddress;
  37982. + fsg_ss_bulk_in_comp_desc.bMaxBurst = max_burst;
  37983. +
  37984. + fsg_ss_bulk_out_desc.bEndpointAddress =
  37985. + fsg_fs_bulk_out_desc.bEndpointAddress;
  37986. + fsg_ss_bulk_out_comp_desc.bMaxBurst = max_burst;
  37987. + }
  37988. +
  37989. + if (gadget_is_otg(gadget))
  37990. + fsg_otg_desc.bmAttributes |= USB_OTG_HNP;
  37991. +
  37992. + rc = -ENOMEM;
  37993. +
  37994. + /* Allocate the request and buffer for endpoint 0 */
  37995. + fsg->ep0req = req = usb_ep_alloc_request(fsg->ep0, GFP_KERNEL);
  37996. + if (!req)
  37997. + goto out;
  37998. + req->buf = kmalloc(EP0_BUFSIZE, GFP_KERNEL);
  37999. + if (!req->buf)
  38000. + goto out;
  38001. + req->complete = ep0_complete;
  38002. +
  38003. + /* Allocate the data buffers */
  38004. + for (i = 0; i < fsg_num_buffers; ++i) {
  38005. + struct fsg_buffhd *bh = &fsg->buffhds[i];
  38006. +
  38007. + /* Allocate for the bulk-in endpoint. We assume that
  38008. + * the buffer will also work with the bulk-out (and
  38009. + * interrupt-in) endpoint. */
  38010. + bh->buf = kmalloc(mod_data.buflen, GFP_KERNEL);
  38011. + if (!bh->buf)
  38012. + goto out;
  38013. + bh->next = bh + 1;
  38014. + }
  38015. + fsg->buffhds[fsg_num_buffers - 1].next = &fsg->buffhds[0];
  38016. +
  38017. + /* This should reflect the actual gadget power source */
  38018. + usb_gadget_set_selfpowered(gadget);
  38019. +
  38020. + snprintf(fsg_string_manufacturer, sizeof fsg_string_manufacturer,
  38021. + "%s %s with %s",
  38022. + init_utsname()->sysname, init_utsname()->release,
  38023. + gadget->name);
  38024. +
  38025. + fsg->thread_task = kthread_create(fsg_main_thread, fsg,
  38026. + "file-storage-gadget");
  38027. + if (IS_ERR(fsg->thread_task)) {
  38028. + rc = PTR_ERR(fsg->thread_task);
  38029. + goto out;
  38030. + }
  38031. +
  38032. + INFO(fsg, DRIVER_DESC ", version: " DRIVER_VERSION "\n");
  38033. + INFO(fsg, "NOTE: This driver is deprecated. "
  38034. + "Consider using g_mass_storage instead.\n");
  38035. + INFO(fsg, "Number of LUNs=%d\n", fsg->nluns);
  38036. +
  38037. + pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
  38038. + for (i = 0; i < fsg->nluns; ++i) {
  38039. + curlun = &fsg->luns[i];
  38040. + if (fsg_lun_is_open(curlun)) {
  38041. + p = NULL;
  38042. + if (pathbuf) {
  38043. + p = d_path(&curlun->filp->f_path,
  38044. + pathbuf, PATH_MAX);
  38045. + if (IS_ERR(p))
  38046. + p = NULL;
  38047. + }
  38048. + LINFO(curlun, "ro=%d, nofua=%d, file: %s\n",
  38049. + curlun->ro, curlun->nofua, (p ? p : "(error)"));
  38050. + }
  38051. + }
  38052. + kfree(pathbuf);
  38053. +
  38054. + DBG(fsg, "transport=%s (x%02x)\n",
  38055. + mod_data.transport_name, mod_data.transport_type);
  38056. + DBG(fsg, "protocol=%s (x%02x)\n",
  38057. + mod_data.protocol_name, mod_data.protocol_type);
  38058. + DBG(fsg, "VendorID=x%04x, ProductID=x%04x, Release=x%04x\n",
  38059. + mod_data.vendor, mod_data.product, mod_data.release);
  38060. + DBG(fsg, "removable=%d, stall=%d, cdrom=%d, buflen=%u\n",
  38061. + mod_data.removable, mod_data.can_stall,
  38062. + mod_data.cdrom, mod_data.buflen);
  38063. + DBG(fsg, "I/O thread pid: %d\n", task_pid_nr(fsg->thread_task));
  38064. +
  38065. + set_bit(REGISTERED, &fsg->atomic_bitflags);
  38066. +
  38067. + /* Tell the thread to start working */
  38068. + wake_up_process(fsg->thread_task);
  38069. + return 0;
  38070. +
  38071. +autoconf_fail:
  38072. + ERROR(fsg, "unable to autoconfigure all endpoints\n");
  38073. + rc = -ENOTSUPP;
  38074. +
  38075. +out:
  38076. + fsg->state = FSG_STATE_TERMINATED; // The thread is dead
  38077. + fsg_unbind(gadget);
  38078. + complete(&fsg->thread_notifier);
  38079. + return rc;
  38080. +}
  38081. +
  38082. +
  38083. +/*-------------------------------------------------------------------------*/
  38084. +
  38085. +static void fsg_suspend(struct usb_gadget *gadget)
  38086. +{
  38087. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38088. +
  38089. + DBG(fsg, "suspend\n");
  38090. + set_bit(SUSPENDED, &fsg->atomic_bitflags);
  38091. +}
  38092. +
  38093. +static void fsg_resume(struct usb_gadget *gadget)
  38094. +{
  38095. + struct fsg_dev *fsg = get_gadget_data(gadget);
  38096. +
  38097. + DBG(fsg, "resume\n");
  38098. + clear_bit(SUSPENDED, &fsg->atomic_bitflags);
  38099. +}
  38100. +
  38101. +
  38102. +/*-------------------------------------------------------------------------*/
  38103. +
  38104. +static struct usb_gadget_driver fsg_driver = {
  38105. + .max_speed = USB_SPEED_SUPER,
  38106. + .function = (char *) fsg_string_product,
  38107. + .unbind = fsg_unbind,
  38108. + .disconnect = fsg_disconnect,
  38109. + .setup = fsg_setup,
  38110. + .suspend = fsg_suspend,
  38111. + .resume = fsg_resume,
  38112. +
  38113. + .driver = {
  38114. + .name = DRIVER_NAME,
  38115. + .owner = THIS_MODULE,
  38116. + // .release = ...
  38117. + // .suspend = ...
  38118. + // .resume = ...
  38119. + },
  38120. +};
  38121. +
  38122. +
  38123. +static int __init fsg_alloc(void)
  38124. +{
  38125. + struct fsg_dev *fsg;
  38126. +
  38127. + fsg = kzalloc(sizeof *fsg +
  38128. + fsg_num_buffers * sizeof *(fsg->buffhds), GFP_KERNEL);
  38129. +
  38130. + if (!fsg)
  38131. + return -ENOMEM;
  38132. + spin_lock_init(&fsg->lock);
  38133. + init_rwsem(&fsg->filesem);
  38134. + kref_init(&fsg->ref);
  38135. + init_completion(&fsg->thread_notifier);
  38136. +
  38137. + the_fsg = fsg;
  38138. + return 0;
  38139. +}
  38140. +
  38141. +
  38142. +static int __init fsg_init(void)
  38143. +{
  38144. + int rc;
  38145. + struct fsg_dev *fsg;
  38146. +
  38147. + rc = fsg_num_buffers_validate();
  38148. + if (rc != 0)
  38149. + return rc;
  38150. +
  38151. + if ((rc = fsg_alloc()) != 0)
  38152. + return rc;
  38153. + fsg = the_fsg;
  38154. + if ((rc = usb_gadget_probe_driver(&fsg_driver, fsg_bind)) != 0)
  38155. + kref_put(&fsg->ref, fsg_release);
  38156. + return rc;
  38157. +}
  38158. +module_init(fsg_init);
  38159. +
  38160. +
  38161. +static void __exit fsg_cleanup(void)
  38162. +{
  38163. + struct fsg_dev *fsg = the_fsg;
  38164. +
  38165. + /* Unregister the driver iff the thread hasn't already done so */
  38166. + if (test_and_clear_bit(REGISTERED, &fsg->atomic_bitflags))
  38167. + usb_gadget_unregister_driver(&fsg_driver);
  38168. +
  38169. + /* Wait for the thread to finish up */
  38170. + wait_for_completion(&fsg->thread_notifier);
  38171. +
  38172. + kref_put(&fsg->ref, fsg_release);
  38173. +}
  38174. +module_exit(fsg_cleanup);
  38175. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/changes.txt linux-rpi/drivers/usb/host/dwc_common_port/changes.txt
  38176. --- linux-3.15/drivers/usb/host/dwc_common_port/changes.txt 1970-01-01 01:00:00.000000000 +0100
  38177. +++ linux-rpi/drivers/usb/host/dwc_common_port/changes.txt 2014-06-11 21:03:43.000000000 +0200
  38178. @@ -0,0 +1,174 @@
  38179. +
  38180. +dwc_read_reg32() and friends now take an additional parameter, a pointer to an
  38181. +IO context struct. The IO context struct should live in an os-dependent struct
  38182. +in your driver. As an example, the dwc_usb3 driver has an os-dependent struct
  38183. +named 'os_dep' embedded in the main device struct. So there these calls look
  38184. +like this:
  38185. +
  38186. + dwc_read_reg32(&usb3_dev->os_dep.ioctx, &pcd->dev_global_regs->dcfg);
  38187. +
  38188. + dwc_write_reg32(&usb3_dev->os_dep.ioctx,
  38189. + &pcd->dev_global_regs->dcfg, 0);
  38190. +
  38191. +Note that for the existing Linux driver ports, it is not necessary to actually
  38192. +define the 'ioctx' member in the os-dependent struct. Since Linux does not
  38193. +require an IO context, its macros for dwc_read_reg32() and friends do not
  38194. +use the context pointer, so it is optimized away by the compiler. But it is
  38195. +necessary to add the pointer parameter to all of the call sites, to be ready
  38196. +for any future ports (such as FreeBSD) which do require an IO context.
  38197. +
  38198. +
  38199. +Similarly, dwc_alloc(), dwc_alloc_atomic(), dwc_strdup(), and dwc_free() now
  38200. +take an additional parameter, a pointer to a memory context. Examples:
  38201. +
  38202. + addr = dwc_alloc(&usb3_dev->os_dep.memctx, size);
  38203. +
  38204. + dwc_free(&usb3_dev->os_dep.memctx, addr);
  38205. +
  38206. +Again, for the Linux ports, it is not necessary to actually define the memctx
  38207. +member, but it is necessary to add the pointer parameter to all of the call
  38208. +sites.
  38209. +
  38210. +
  38211. +Same for dwc_dma_alloc() and dwc_dma_free(). Examples:
  38212. +
  38213. + virt_addr = dwc_dma_alloc(&usb3_dev->os_dep.dmactx, size, &phys_addr);
  38214. +
  38215. + dwc_dma_free(&usb3_dev->os_dep.dmactx, size, virt_addr, phys_addr);
  38216. +
  38217. +
  38218. +Same for dwc_mutex_alloc() and dwc_mutex_free(). Examples:
  38219. +
  38220. + mutex = dwc_mutex_alloc(&usb3_dev->os_dep.mtxctx);
  38221. +
  38222. + dwc_mutex_free(&usb3_dev->os_dep.mtxctx, mutex);
  38223. +
  38224. +
  38225. +Same for dwc_spinlock_alloc() and dwc_spinlock_free(). Examples:
  38226. +
  38227. + lock = dwc_spinlock_alloc(&usb3_dev->osdep.splctx);
  38228. +
  38229. + dwc_spinlock_free(&usb3_dev->osdep.splctx, lock);
  38230. +
  38231. +
  38232. +Same for dwc_timer_alloc(). Example:
  38233. +
  38234. + timer = dwc_timer_alloc(&usb3_dev->os_dep.tmrctx, "dwc_usb3_tmr1",
  38235. + cb_func, cb_data);
  38236. +
  38237. +
  38238. +Same for dwc_waitq_alloc(). Example:
  38239. +
  38240. + waitq = dwc_waitq_alloc(&usb3_dev->os_dep.wtqctx);
  38241. +
  38242. +
  38243. +Same for dwc_thread_run(). Example:
  38244. +
  38245. + thread = dwc_thread_run(&usb3_dev->os_dep.thdctx, func,
  38246. + "dwc_usb3_thd1", data);
  38247. +
  38248. +
  38249. +Same for dwc_workq_alloc(). Example:
  38250. +
  38251. + workq = dwc_workq_alloc(&usb3_dev->osdep.wkqctx, "dwc_usb3_wkq1");
  38252. +
  38253. +
  38254. +Same for dwc_task_alloc(). Example:
  38255. +
  38256. + task = dwc_task_alloc(&usb3_dev->os_dep.tskctx, "dwc_usb3_tsk1",
  38257. + cb_func, cb_data);
  38258. +
  38259. +
  38260. +In addition to the context pointer additions, a few core functions have had
  38261. +other changes made to their parameters:
  38262. +
  38263. +The 'flags' parameter to dwc_spinlock_irqsave() and dwc_spinunlock_irqrestore()
  38264. +has been changed from a uint64_t to a dwc_irqflags_t.
  38265. +
  38266. +dwc_thread_should_stop() now takes a 'dwc_thread_t *' parameter, because the
  38267. +FreeBSD equivalent of that function requires it.
  38268. +
  38269. +And, in addition to the context pointer, dwc_task_alloc() also adds a
  38270. +'char *name' parameter, to be consistent with dwc_thread_run() and
  38271. +dwc_workq_alloc(), and because the FreeBSD equivalent of that function
  38272. +requires a unique name.
  38273. +
  38274. +
  38275. +Here is a complete list of the core functions that now take a pointer to a
  38276. +context as their first parameter:
  38277. +
  38278. + dwc_read_reg32
  38279. + dwc_read_reg64
  38280. + dwc_write_reg32
  38281. + dwc_write_reg64
  38282. + dwc_modify_reg32
  38283. + dwc_modify_reg64
  38284. + dwc_alloc
  38285. + dwc_alloc_atomic
  38286. + dwc_strdup
  38287. + dwc_free
  38288. + dwc_dma_alloc
  38289. + dwc_dma_free
  38290. + dwc_mutex_alloc
  38291. + dwc_mutex_free
  38292. + dwc_spinlock_alloc
  38293. + dwc_spinlock_free
  38294. + dwc_timer_alloc
  38295. + dwc_waitq_alloc
  38296. + dwc_thread_run
  38297. + dwc_workq_alloc
  38298. + dwc_task_alloc Also adds a 'char *name' as its 2nd parameter
  38299. +
  38300. +And here are the core functions that have other changes to their parameters:
  38301. +
  38302. + dwc_spinlock_irqsave 'flags' param is now a 'dwc_irqflags_t *'
  38303. + dwc_spinunlock_irqrestore 'flags' param is now a 'dwc_irqflags_t'
  38304. + dwc_thread_should_stop Adds a 'dwc_thread_t *' parameter
  38305. +
  38306. +
  38307. +
  38308. +The changes to the core functions also require some of the other library
  38309. +functions to change:
  38310. +
  38311. + dwc_cc_if_alloc() and dwc_cc_if_free() now take a 'void *memctx'
  38312. + (for memory allocation) as the 1st param and a 'void *mtxctx'
  38313. + (for mutex allocation) as the 2nd param.
  38314. +
  38315. + dwc_cc_clear(), dwc_cc_add(), dwc_cc_change(), dwc_cc_remove(),
  38316. + dwc_cc_data_for_save(), and dwc_cc_restore_from_data() now take a
  38317. + 'void *memctx' as the 1st param.
  38318. +
  38319. + dwc_dh_modpow(), dwc_dh_pk(), and dwc_dh_derive_keys() now take a
  38320. + 'void *memctx' as the 1st param.
  38321. +
  38322. + dwc_modpow() now takes a 'void *memctx' as the 1st param.
  38323. +
  38324. + dwc_alloc_notification_manager() now takes a 'void *memctx' as the
  38325. + 1st param and a 'void *wkqctx' (for work queue allocation) as the 2nd
  38326. + param, and also now returns an integer value that is non-zero if
  38327. + allocation of its data structures or work queue fails.
  38328. +
  38329. + dwc_register_notifier() now takes a 'void *memctx' as the 1st param.
  38330. +
  38331. + dwc_memory_debug_start() now takes a 'void *mem_ctx' as the first
  38332. + param, and also now returns an integer value that is non-zero if
  38333. + allocation of its data structures fails.
  38334. +
  38335. +
  38336. +
  38337. +Other miscellaneous changes:
  38338. +
  38339. +The DEBUG_MEMORY and DEBUG_REGS #define's have been renamed to
  38340. +DWC_DEBUG_MEMORY and DWC_DEBUG_REGS.
  38341. +
  38342. +The following #define's have been added to allow selectively compiling library
  38343. +features:
  38344. +
  38345. + DWC_CCLIB
  38346. + DWC_CRYPTOLIB
  38347. + DWC_NOTIFYLIB
  38348. + DWC_UTFLIB
  38349. +
  38350. +A DWC_LIBMODULE #define has also been added. If this is not defined, then the
  38351. +module code in dwc_common_linux.c is not compiled in. This allows linking the
  38352. +library code directly into a driver module, instead of as a standalone module.
  38353. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg
  38354. --- linux-3.15/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  38355. +++ linux-rpi/drivers/usb/host/dwc_common_port/doc/doxygen.cfg 2014-06-11 21:03:43.000000000 +0200
  38356. @@ -0,0 +1,270 @@
  38357. +# Doxyfile 1.4.5
  38358. +
  38359. +#---------------------------------------------------------------------------
  38360. +# Project related configuration options
  38361. +#---------------------------------------------------------------------------
  38362. +PROJECT_NAME = "Synopsys DWC Portability and Common Library for UWB"
  38363. +PROJECT_NUMBER =
  38364. +OUTPUT_DIRECTORY = doc
  38365. +CREATE_SUBDIRS = NO
  38366. +OUTPUT_LANGUAGE = English
  38367. +BRIEF_MEMBER_DESC = YES
  38368. +REPEAT_BRIEF = YES
  38369. +ABBREVIATE_BRIEF = "The $name class" \
  38370. + "The $name widget" \
  38371. + "The $name file" \
  38372. + is \
  38373. + provides \
  38374. + specifies \
  38375. + contains \
  38376. + represents \
  38377. + a \
  38378. + an \
  38379. + the
  38380. +ALWAYS_DETAILED_SEC = YES
  38381. +INLINE_INHERITED_MEMB = NO
  38382. +FULL_PATH_NAMES = NO
  38383. +STRIP_FROM_PATH = ..
  38384. +STRIP_FROM_INC_PATH =
  38385. +SHORT_NAMES = NO
  38386. +JAVADOC_AUTOBRIEF = YES
  38387. +MULTILINE_CPP_IS_BRIEF = NO
  38388. +DETAILS_AT_TOP = YES
  38389. +INHERIT_DOCS = YES
  38390. +SEPARATE_MEMBER_PAGES = NO
  38391. +TAB_SIZE = 8
  38392. +ALIASES =
  38393. +OPTIMIZE_OUTPUT_FOR_C = YES
  38394. +OPTIMIZE_OUTPUT_JAVA = NO
  38395. +BUILTIN_STL_SUPPORT = NO
  38396. +DISTRIBUTE_GROUP_DOC = NO
  38397. +SUBGROUPING = NO
  38398. +#---------------------------------------------------------------------------
  38399. +# Build related configuration options
  38400. +#---------------------------------------------------------------------------
  38401. +EXTRACT_ALL = NO
  38402. +EXTRACT_PRIVATE = NO
  38403. +EXTRACT_STATIC = YES
  38404. +EXTRACT_LOCAL_CLASSES = NO
  38405. +EXTRACT_LOCAL_METHODS = NO
  38406. +HIDE_UNDOC_MEMBERS = NO
  38407. +HIDE_UNDOC_CLASSES = NO
  38408. +HIDE_FRIEND_COMPOUNDS = NO
  38409. +HIDE_IN_BODY_DOCS = NO
  38410. +INTERNAL_DOCS = NO
  38411. +CASE_SENSE_NAMES = YES
  38412. +HIDE_SCOPE_NAMES = NO
  38413. +SHOW_INCLUDE_FILES = NO
  38414. +INLINE_INFO = YES
  38415. +SORT_MEMBER_DOCS = NO
  38416. +SORT_BRIEF_DOCS = NO
  38417. +SORT_BY_SCOPE_NAME = NO
  38418. +GENERATE_TODOLIST = YES
  38419. +GENERATE_TESTLIST = YES
  38420. +GENERATE_BUGLIST = YES
  38421. +GENERATE_DEPRECATEDLIST= YES
  38422. +ENABLED_SECTIONS =
  38423. +MAX_INITIALIZER_LINES = 30
  38424. +SHOW_USED_FILES = YES
  38425. +SHOW_DIRECTORIES = YES
  38426. +FILE_VERSION_FILTER =
  38427. +#---------------------------------------------------------------------------
  38428. +# configuration options related to warning and progress messages
  38429. +#---------------------------------------------------------------------------
  38430. +QUIET = YES
  38431. +WARNINGS = YES
  38432. +WARN_IF_UNDOCUMENTED = NO
  38433. +WARN_IF_DOC_ERROR = YES
  38434. +WARN_NO_PARAMDOC = YES
  38435. +WARN_FORMAT = "$file:$line: $text"
  38436. +WARN_LOGFILE =
  38437. +#---------------------------------------------------------------------------
  38438. +# configuration options related to the input files
  38439. +#---------------------------------------------------------------------------
  38440. +INPUT = .
  38441. +FILE_PATTERNS = *.c \
  38442. + *.cc \
  38443. + *.cxx \
  38444. + *.cpp \
  38445. + *.c++ \
  38446. + *.d \
  38447. + *.java \
  38448. + *.ii \
  38449. + *.ixx \
  38450. + *.ipp \
  38451. + *.i++ \
  38452. + *.inl \
  38453. + *.h \
  38454. + *.hh \
  38455. + *.hxx \
  38456. + *.hpp \
  38457. + *.h++ \
  38458. + *.idl \
  38459. + *.odl \
  38460. + *.cs \
  38461. + *.php \
  38462. + *.php3 \
  38463. + *.inc \
  38464. + *.m \
  38465. + *.mm \
  38466. + *.dox \
  38467. + *.py \
  38468. + *.C \
  38469. + *.CC \
  38470. + *.C++ \
  38471. + *.II \
  38472. + *.I++ \
  38473. + *.H \
  38474. + *.HH \
  38475. + *.H++ \
  38476. + *.CS \
  38477. + *.PHP \
  38478. + *.PHP3 \
  38479. + *.M \
  38480. + *.MM \
  38481. + *.PY
  38482. +RECURSIVE = NO
  38483. +EXCLUDE =
  38484. +EXCLUDE_SYMLINKS = NO
  38485. +EXCLUDE_PATTERNS =
  38486. +EXAMPLE_PATH =
  38487. +EXAMPLE_PATTERNS = *
  38488. +EXAMPLE_RECURSIVE = NO
  38489. +IMAGE_PATH =
  38490. +INPUT_FILTER =
  38491. +FILTER_PATTERNS =
  38492. +FILTER_SOURCE_FILES = NO
  38493. +#---------------------------------------------------------------------------
  38494. +# configuration options related to source browsing
  38495. +#---------------------------------------------------------------------------
  38496. +SOURCE_BROWSER = NO
  38497. +INLINE_SOURCES = NO
  38498. +STRIP_CODE_COMMENTS = YES
  38499. +REFERENCED_BY_RELATION = YES
  38500. +REFERENCES_RELATION = YES
  38501. +USE_HTAGS = NO
  38502. +VERBATIM_HEADERS = NO
  38503. +#---------------------------------------------------------------------------
  38504. +# configuration options related to the alphabetical class index
  38505. +#---------------------------------------------------------------------------
  38506. +ALPHABETICAL_INDEX = NO
  38507. +COLS_IN_ALPHA_INDEX = 5
  38508. +IGNORE_PREFIX =
  38509. +#---------------------------------------------------------------------------
  38510. +# configuration options related to the HTML output
  38511. +#---------------------------------------------------------------------------
  38512. +GENERATE_HTML = YES
  38513. +HTML_OUTPUT = html
  38514. +HTML_FILE_EXTENSION = .html
  38515. +HTML_HEADER =
  38516. +HTML_FOOTER =
  38517. +HTML_STYLESHEET =
  38518. +HTML_ALIGN_MEMBERS = YES
  38519. +GENERATE_HTMLHELP = NO
  38520. +CHM_FILE =
  38521. +HHC_LOCATION =
  38522. +GENERATE_CHI = NO
  38523. +BINARY_TOC = NO
  38524. +TOC_EXPAND = NO
  38525. +DISABLE_INDEX = NO
  38526. +ENUM_VALUES_PER_LINE = 4
  38527. +GENERATE_TREEVIEW = YES
  38528. +TREEVIEW_WIDTH = 250
  38529. +#---------------------------------------------------------------------------
  38530. +# configuration options related to the LaTeX output
  38531. +#---------------------------------------------------------------------------
  38532. +GENERATE_LATEX = NO
  38533. +LATEX_OUTPUT = latex
  38534. +LATEX_CMD_NAME = latex
  38535. +MAKEINDEX_CMD_NAME = makeindex
  38536. +COMPACT_LATEX = NO
  38537. +PAPER_TYPE = a4wide
  38538. +EXTRA_PACKAGES =
  38539. +LATEX_HEADER =
  38540. +PDF_HYPERLINKS = NO
  38541. +USE_PDFLATEX = NO
  38542. +LATEX_BATCHMODE = NO
  38543. +LATEX_HIDE_INDICES = NO
  38544. +#---------------------------------------------------------------------------
  38545. +# configuration options related to the RTF output
  38546. +#---------------------------------------------------------------------------
  38547. +GENERATE_RTF = NO
  38548. +RTF_OUTPUT = rtf
  38549. +COMPACT_RTF = NO
  38550. +RTF_HYPERLINKS = NO
  38551. +RTF_STYLESHEET_FILE =
  38552. +RTF_EXTENSIONS_FILE =
  38553. +#---------------------------------------------------------------------------
  38554. +# configuration options related to the man page output
  38555. +#---------------------------------------------------------------------------
  38556. +GENERATE_MAN = NO
  38557. +MAN_OUTPUT = man
  38558. +MAN_EXTENSION = .3
  38559. +MAN_LINKS = NO
  38560. +#---------------------------------------------------------------------------
  38561. +# configuration options related to the XML output
  38562. +#---------------------------------------------------------------------------
  38563. +GENERATE_XML = NO
  38564. +XML_OUTPUT = xml
  38565. +XML_SCHEMA =
  38566. +XML_DTD =
  38567. +XML_PROGRAMLISTING = YES
  38568. +#---------------------------------------------------------------------------
  38569. +# configuration options for the AutoGen Definitions output
  38570. +#---------------------------------------------------------------------------
  38571. +GENERATE_AUTOGEN_DEF = NO
  38572. +#---------------------------------------------------------------------------
  38573. +# configuration options related to the Perl module output
  38574. +#---------------------------------------------------------------------------
  38575. +GENERATE_PERLMOD = NO
  38576. +PERLMOD_LATEX = NO
  38577. +PERLMOD_PRETTY = YES
  38578. +PERLMOD_MAKEVAR_PREFIX =
  38579. +#---------------------------------------------------------------------------
  38580. +# Configuration options related to the preprocessor
  38581. +#---------------------------------------------------------------------------
  38582. +ENABLE_PREPROCESSING = YES
  38583. +MACRO_EXPANSION = NO
  38584. +EXPAND_ONLY_PREDEF = NO
  38585. +SEARCH_INCLUDES = YES
  38586. +INCLUDE_PATH =
  38587. +INCLUDE_FILE_PATTERNS =
  38588. +PREDEFINED = DEBUG DEBUG_MEMORY
  38589. +EXPAND_AS_DEFINED =
  38590. +SKIP_FUNCTION_MACROS = YES
  38591. +#---------------------------------------------------------------------------
  38592. +# Configuration::additions related to external references
  38593. +#---------------------------------------------------------------------------
  38594. +TAGFILES =
  38595. +GENERATE_TAGFILE =
  38596. +ALLEXTERNALS = NO
  38597. +EXTERNAL_GROUPS = YES
  38598. +PERL_PATH = /usr/bin/perl
  38599. +#---------------------------------------------------------------------------
  38600. +# Configuration options related to the dot tool
  38601. +#---------------------------------------------------------------------------
  38602. +CLASS_DIAGRAMS = YES
  38603. +HIDE_UNDOC_RELATIONS = YES
  38604. +HAVE_DOT = NO
  38605. +CLASS_GRAPH = YES
  38606. +COLLABORATION_GRAPH = YES
  38607. +GROUP_GRAPHS = YES
  38608. +UML_LOOK = NO
  38609. +TEMPLATE_RELATIONS = NO
  38610. +INCLUDE_GRAPH = NO
  38611. +INCLUDED_BY_GRAPH = YES
  38612. +CALL_GRAPH = NO
  38613. +GRAPHICAL_HIERARCHY = YES
  38614. +DIRECTORY_GRAPH = YES
  38615. +DOT_IMAGE_FORMAT = png
  38616. +DOT_PATH =
  38617. +DOTFILE_DIRS =
  38618. +MAX_DOT_GRAPH_DEPTH = 1000
  38619. +DOT_TRANSPARENT = NO
  38620. +DOT_MULTI_TARGETS = NO
  38621. +GENERATE_LEGEND = YES
  38622. +DOT_CLEANUP = YES
  38623. +#---------------------------------------------------------------------------
  38624. +# Configuration::additions related to the search engine
  38625. +#---------------------------------------------------------------------------
  38626. +SEARCHENGINE = NO
  38627. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_cc.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c
  38628. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_cc.c 1970-01-01 01:00:00.000000000 +0100
  38629. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.c 2014-06-11 21:03:43.000000000 +0200
  38630. @@ -0,0 +1,532 @@
  38631. +/* =========================================================================
  38632. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.c $
  38633. + * $Revision: #4 $
  38634. + * $Date: 2010/11/04 $
  38635. + * $Change: 1621692 $
  38636. + *
  38637. + * Synopsys Portability Library Software and documentation
  38638. + * (hereinafter, "Software") is an Unsupported proprietary work of
  38639. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  38640. + * between Synopsys and you.
  38641. + *
  38642. + * The Software IS NOT an item of Licensed Software or Licensed Product
  38643. + * under any End User Software License Agreement or Agreement for
  38644. + * Licensed Product with Synopsys or any supplement thereto. You are
  38645. + * permitted to use and redistribute this Software in source and binary
  38646. + * forms, with or without modification, provided that redistributions
  38647. + * of source code must retain this notice. You may not view, use,
  38648. + * disclose, copy or distribute this file or any information contained
  38649. + * herein except pursuant to this license grant from Synopsys. If you
  38650. + * do not agree with this notice, including the disclaimer below, then
  38651. + * you are not authorized to use the Software.
  38652. + *
  38653. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  38654. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  38655. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  38656. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  38657. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  38658. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  38659. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  38660. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  38661. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38662. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  38663. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  38664. + * DAMAGE.
  38665. + * ========================================================================= */
  38666. +#ifdef DWC_CCLIB
  38667. +
  38668. +#include "dwc_cc.h"
  38669. +
  38670. +typedef struct dwc_cc
  38671. +{
  38672. + uint32_t uid;
  38673. + uint8_t chid[16];
  38674. + uint8_t cdid[16];
  38675. + uint8_t ck[16];
  38676. + uint8_t *name;
  38677. + uint8_t length;
  38678. + DWC_CIRCLEQ_ENTRY(dwc_cc) list_entry;
  38679. +} dwc_cc_t;
  38680. +
  38681. +DWC_CIRCLEQ_HEAD(context_list, dwc_cc);
  38682. +
  38683. +/** The main structure for CC management. */
  38684. +struct dwc_cc_if
  38685. +{
  38686. + dwc_mutex_t *mutex;
  38687. + char *filename;
  38688. +
  38689. + unsigned is_host:1;
  38690. +
  38691. + dwc_notifier_t *notifier;
  38692. +
  38693. + struct context_list list;
  38694. +};
  38695. +
  38696. +#ifdef DEBUG
  38697. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  38698. +{
  38699. + int i;
  38700. + DWC_PRINTF("%s: ", name);
  38701. + for (i=0; i<len; i++) {
  38702. + DWC_PRINTF("%02x ", bytes[i]);
  38703. + }
  38704. + DWC_PRINTF("\n");
  38705. +}
  38706. +#else
  38707. +#define dump_bytes(x...)
  38708. +#endif
  38709. +
  38710. +static dwc_cc_t *alloc_cc(void *mem_ctx, uint8_t *name, uint32_t length)
  38711. +{
  38712. + dwc_cc_t *cc = dwc_alloc(mem_ctx, sizeof(dwc_cc_t));
  38713. + if (!cc) {
  38714. + return NULL;
  38715. + }
  38716. + DWC_MEMSET(cc, 0, sizeof(dwc_cc_t));
  38717. +
  38718. + if (name) {
  38719. + cc->length = length;
  38720. + cc->name = dwc_alloc(mem_ctx, length);
  38721. + if (!cc->name) {
  38722. + dwc_free(mem_ctx, cc);
  38723. + return NULL;
  38724. + }
  38725. +
  38726. + DWC_MEMCPY(cc->name, name, length);
  38727. + }
  38728. +
  38729. + return cc;
  38730. +}
  38731. +
  38732. +static void free_cc(void *mem_ctx, dwc_cc_t *cc)
  38733. +{
  38734. + if (cc->name) {
  38735. + dwc_free(mem_ctx, cc->name);
  38736. + }
  38737. + dwc_free(mem_ctx, cc);
  38738. +}
  38739. +
  38740. +static uint32_t next_uid(dwc_cc_if_t *cc_if)
  38741. +{
  38742. + uint32_t uid = 0;
  38743. + dwc_cc_t *cc;
  38744. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38745. + if (cc->uid > uid) {
  38746. + uid = cc->uid;
  38747. + }
  38748. + }
  38749. +
  38750. + if (uid == 0) {
  38751. + uid = 255;
  38752. + }
  38753. +
  38754. + return uid + 1;
  38755. +}
  38756. +
  38757. +static dwc_cc_t *cc_find(dwc_cc_if_t *cc_if, uint32_t uid)
  38758. +{
  38759. + dwc_cc_t *cc;
  38760. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38761. + if (cc->uid == uid) {
  38762. + return cc;
  38763. + }
  38764. + }
  38765. + return NULL;
  38766. +}
  38767. +
  38768. +static unsigned int cc_data_size(dwc_cc_if_t *cc_if)
  38769. +{
  38770. + unsigned int size = 0;
  38771. + dwc_cc_t *cc;
  38772. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38773. + size += (48 + 1);
  38774. + if (cc->name) {
  38775. + size += cc->length;
  38776. + }
  38777. + }
  38778. + return size;
  38779. +}
  38780. +
  38781. +static uint32_t cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  38782. +{
  38783. + uint32_t uid = 0;
  38784. + dwc_cc_t *cc;
  38785. +
  38786. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38787. + if (DWC_MEMCMP(cc->chid, chid, 16) == 0) {
  38788. + uid = cc->uid;
  38789. + break;
  38790. + }
  38791. + }
  38792. + return uid;
  38793. +}
  38794. +static uint32_t cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  38795. +{
  38796. + uint32_t uid = 0;
  38797. + dwc_cc_t *cc;
  38798. +
  38799. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  38800. + if (DWC_MEMCMP(cc->cdid, cdid, 16) == 0) {
  38801. + uid = cc->uid;
  38802. + break;
  38803. + }
  38804. + }
  38805. + return uid;
  38806. +}
  38807. +
  38808. +/* Internal cc_add */
  38809. +static int32_t cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38810. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38811. +{
  38812. + dwc_cc_t *cc;
  38813. + uint32_t uid;
  38814. +
  38815. + if (cc_if->is_host) {
  38816. + uid = cc_match_cdid(cc_if, cdid);
  38817. + }
  38818. + else {
  38819. + uid = cc_match_chid(cc_if, chid);
  38820. + }
  38821. +
  38822. + if (uid) {
  38823. + DWC_DEBUGC("Replacing previous connection context id=%d name=%p name_len=%d", uid, name, length);
  38824. + cc = cc_find(cc_if, uid);
  38825. + }
  38826. + else {
  38827. + cc = alloc_cc(mem_ctx, name, length);
  38828. + cc->uid = next_uid(cc_if);
  38829. + DWC_CIRCLEQ_INSERT_TAIL(&cc_if->list, cc, list_entry);
  38830. + }
  38831. +
  38832. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38833. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38834. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38835. +
  38836. + DWC_DEBUGC("Added connection context id=%d name=%p name_len=%d", cc->uid, name, length);
  38837. + dump_bytes("CHID", cc->chid, 16);
  38838. + dump_bytes("CDID", cc->cdid, 16);
  38839. + dump_bytes("CK", cc->ck, 16);
  38840. + return cc->uid;
  38841. +}
  38842. +
  38843. +/* Internal cc_clear */
  38844. +static void cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38845. +{
  38846. + while (!DWC_CIRCLEQ_EMPTY(&cc_if->list)) {
  38847. + dwc_cc_t *cc = DWC_CIRCLEQ_FIRST(&cc_if->list);
  38848. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38849. + free_cc(mem_ctx, cc);
  38850. + }
  38851. +}
  38852. +
  38853. +dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  38854. + dwc_notifier_t *notifier, unsigned is_host)
  38855. +{
  38856. + dwc_cc_if_t *cc_if = NULL;
  38857. +
  38858. + /* Allocate a common_cc_if structure */
  38859. + cc_if = dwc_alloc(mem_ctx, sizeof(dwc_cc_if_t));
  38860. +
  38861. + if (!cc_if)
  38862. + return NULL;
  38863. +
  38864. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38865. + DWC_MUTEX_ALLOC_LINUX_DEBUG(cc_if->mutex);
  38866. +#else
  38867. + cc_if->mutex = dwc_mutex_alloc(mtx_ctx);
  38868. +#endif
  38869. + if (!cc_if->mutex) {
  38870. + dwc_free(mem_ctx, cc_if);
  38871. + return NULL;
  38872. + }
  38873. +
  38874. + DWC_CIRCLEQ_INIT(&cc_if->list);
  38875. + cc_if->is_host = is_host;
  38876. + cc_if->notifier = notifier;
  38877. + return cc_if;
  38878. +}
  38879. +
  38880. +void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if)
  38881. +{
  38882. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  38883. + DWC_MUTEX_FREE(cc_if->mutex);
  38884. +#else
  38885. + dwc_mutex_free(mtx_ctx, cc_if->mutex);
  38886. +#endif
  38887. + cc_clear(mem_ctx, cc_if);
  38888. + dwc_free(mem_ctx, cc_if);
  38889. +}
  38890. +
  38891. +static void cc_changed(dwc_cc_if_t *cc_if)
  38892. +{
  38893. + if (cc_if->notifier) {
  38894. + dwc_notify(cc_if->notifier, DWC_CC_LIST_CHANGED_NOTIFICATION, cc_if);
  38895. + }
  38896. +}
  38897. +
  38898. +void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if)
  38899. +{
  38900. + DWC_MUTEX_LOCK(cc_if->mutex);
  38901. + cc_clear(mem_ctx, cc_if);
  38902. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38903. + cc_changed(cc_if);
  38904. +}
  38905. +
  38906. +int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  38907. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38908. +{
  38909. + uint32_t uid;
  38910. +
  38911. + DWC_MUTEX_LOCK(cc_if->mutex);
  38912. + uid = cc_add(mem_ctx, cc_if, chid, cdid, ck, name, length);
  38913. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38914. + cc_changed(cc_if);
  38915. +
  38916. + return uid;
  38917. +}
  38918. +
  38919. +void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id, uint8_t *chid,
  38920. + uint8_t *cdid, uint8_t *ck, uint8_t *name, uint8_t length)
  38921. +{
  38922. + dwc_cc_t* cc;
  38923. +
  38924. + DWC_DEBUGC("Change connection context %d", id);
  38925. +
  38926. + DWC_MUTEX_LOCK(cc_if->mutex);
  38927. + cc = cc_find(cc_if, id);
  38928. + if (!cc) {
  38929. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38930. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38931. + return;
  38932. + }
  38933. +
  38934. + if (chid) {
  38935. + DWC_MEMCPY(&(cc->chid[0]), chid, 16);
  38936. + }
  38937. + if (cdid) {
  38938. + DWC_MEMCPY(&(cc->cdid[0]), cdid, 16);
  38939. + }
  38940. + if (ck) {
  38941. + DWC_MEMCPY(&(cc->ck[0]), ck, 16);
  38942. + }
  38943. +
  38944. + if (name) {
  38945. + if (cc->name) {
  38946. + dwc_free(mem_ctx, cc->name);
  38947. + }
  38948. + cc->name = dwc_alloc(mem_ctx, length);
  38949. + if (!cc->name) {
  38950. + DWC_ERROR("Out of memory in dwc_cc_change()\n");
  38951. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38952. + return;
  38953. + }
  38954. + cc->length = length;
  38955. + DWC_MEMCPY(cc->name, name, length);
  38956. + }
  38957. +
  38958. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38959. +
  38960. + cc_changed(cc_if);
  38961. +
  38962. + DWC_DEBUGC("Changed connection context id=%d\n", id);
  38963. + dump_bytes("New CHID", cc->chid, 16);
  38964. + dump_bytes("New CDID", cc->cdid, 16);
  38965. + dump_bytes("New CK", cc->ck, 16);
  38966. +}
  38967. +
  38968. +void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id)
  38969. +{
  38970. + dwc_cc_t *cc;
  38971. +
  38972. + DWC_DEBUGC("Removing connection context %d", id);
  38973. +
  38974. + DWC_MUTEX_LOCK(cc_if->mutex);
  38975. + cc = cc_find(cc_if, id);
  38976. + if (!cc) {
  38977. + DWC_ERROR("Uid %d not found in cc list\n", id);
  38978. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38979. + return;
  38980. + }
  38981. +
  38982. + DWC_CIRCLEQ_REMOVE_INIT(&cc_if->list, cc, list_entry);
  38983. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38984. + free_cc(mem_ctx, cc);
  38985. +
  38986. + cc_changed(cc_if);
  38987. +}
  38988. +
  38989. +uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if, unsigned int *length)
  38990. +{
  38991. + uint8_t *buf, *x;
  38992. + uint8_t zero = 0;
  38993. + dwc_cc_t *cc;
  38994. +
  38995. + DWC_MUTEX_LOCK(cc_if->mutex);
  38996. + *length = cc_data_size(cc_if);
  38997. + if (!(*length)) {
  38998. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  38999. + return NULL;
  39000. + }
  39001. +
  39002. + DWC_DEBUGC("Creating data for saving (length=%d)", *length);
  39003. +
  39004. + buf = dwc_alloc(mem_ctx, *length);
  39005. + if (!buf) {
  39006. + *length = 0;
  39007. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39008. + return NULL;
  39009. + }
  39010. +
  39011. + x = buf;
  39012. + DWC_CIRCLEQ_FOREACH(cc, &cc_if->list, list_entry) {
  39013. + DWC_MEMCPY(x, cc->chid, 16);
  39014. + x += 16;
  39015. + DWC_MEMCPY(x, cc->cdid, 16);
  39016. + x += 16;
  39017. + DWC_MEMCPY(x, cc->ck, 16);
  39018. + x += 16;
  39019. + if (cc->name) {
  39020. + DWC_MEMCPY(x, &cc->length, 1);
  39021. + x += 1;
  39022. + DWC_MEMCPY(x, cc->name, cc->length);
  39023. + x += cc->length;
  39024. + }
  39025. + else {
  39026. + DWC_MEMCPY(x, &zero, 1);
  39027. + x += 1;
  39028. + }
  39029. + }
  39030. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39031. +
  39032. + return buf;
  39033. +}
  39034. +
  39035. +void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *data, uint32_t length)
  39036. +{
  39037. + uint8_t name_length;
  39038. + uint8_t *name;
  39039. + uint8_t *chid;
  39040. + uint8_t *cdid;
  39041. + uint8_t *ck;
  39042. + uint32_t i = 0;
  39043. +
  39044. + DWC_MUTEX_LOCK(cc_if->mutex);
  39045. + cc_clear(mem_ctx, cc_if);
  39046. +
  39047. + while (i < length) {
  39048. + chid = &data[i];
  39049. + i += 16;
  39050. + cdid = &data[i];
  39051. + i += 16;
  39052. + ck = &data[i];
  39053. + i += 16;
  39054. +
  39055. + name_length = data[i];
  39056. + i ++;
  39057. +
  39058. + if (name_length) {
  39059. + name = &data[i];
  39060. + i += name_length;
  39061. + }
  39062. + else {
  39063. + name = NULL;
  39064. + }
  39065. +
  39066. + /* check to see if we haven't overflown the buffer */
  39067. + if (i > length) {
  39068. + DWC_ERROR("Data format error while attempting to load CCs "
  39069. + "(nlen=%d, iter=%d, buflen=%d).\n", name_length, i, length);
  39070. + break;
  39071. + }
  39072. +
  39073. + cc_add(mem_ctx, cc_if, chid, cdid, ck, name, name_length);
  39074. + }
  39075. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39076. +
  39077. + cc_changed(cc_if);
  39078. +}
  39079. +
  39080. +uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid)
  39081. +{
  39082. + uint32_t uid = 0;
  39083. +
  39084. + DWC_MUTEX_LOCK(cc_if->mutex);
  39085. + uid = cc_match_chid(cc_if, chid);
  39086. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39087. + return uid;
  39088. +}
  39089. +uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid)
  39090. +{
  39091. + uint32_t uid = 0;
  39092. +
  39093. + DWC_MUTEX_LOCK(cc_if->mutex);
  39094. + uid = cc_match_cdid(cc_if, cdid);
  39095. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39096. + return uid;
  39097. +}
  39098. +
  39099. +uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id)
  39100. +{
  39101. + uint8_t *ck = NULL;
  39102. + dwc_cc_t *cc;
  39103. +
  39104. + DWC_MUTEX_LOCK(cc_if->mutex);
  39105. + cc = cc_find(cc_if, id);
  39106. + if (cc) {
  39107. + ck = cc->ck;
  39108. + }
  39109. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39110. +
  39111. + return ck;
  39112. +
  39113. +}
  39114. +
  39115. +uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id)
  39116. +{
  39117. + uint8_t *retval = NULL;
  39118. + dwc_cc_t *cc;
  39119. +
  39120. + DWC_MUTEX_LOCK(cc_if->mutex);
  39121. + cc = cc_find(cc_if, id);
  39122. + if (cc) {
  39123. + retval = cc->chid;
  39124. + }
  39125. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39126. +
  39127. + return retval;
  39128. +}
  39129. +
  39130. +uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id)
  39131. +{
  39132. + uint8_t *retval = NULL;
  39133. + dwc_cc_t *cc;
  39134. +
  39135. + DWC_MUTEX_LOCK(cc_if->mutex);
  39136. + cc = cc_find(cc_if, id);
  39137. + if (cc) {
  39138. + retval = cc->cdid;
  39139. + }
  39140. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39141. +
  39142. + return retval;
  39143. +}
  39144. +
  39145. +uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length)
  39146. +{
  39147. + uint8_t *retval = NULL;
  39148. + dwc_cc_t *cc;
  39149. +
  39150. + DWC_MUTEX_LOCK(cc_if->mutex);
  39151. + *length = 0;
  39152. + cc = cc_find(cc_if, id);
  39153. + if (cc) {
  39154. + *length = cc->length;
  39155. + retval = cc->name;
  39156. + }
  39157. + DWC_MUTEX_UNLOCK(cc_if->mutex);
  39158. +
  39159. + return retval;
  39160. +}
  39161. +
  39162. +#endif /* DWC_CCLIB */
  39163. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_cc.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h
  39164. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_cc.h 1970-01-01 01:00:00.000000000 +0100
  39165. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_cc.h 2014-06-11 21:03:43.000000000 +0200
  39166. @@ -0,0 +1,224 @@
  39167. +/* =========================================================================
  39168. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_cc.h $
  39169. + * $Revision: #4 $
  39170. + * $Date: 2010/09/28 $
  39171. + * $Change: 1596182 $
  39172. + *
  39173. + * Synopsys Portability Library Software and documentation
  39174. + * (hereinafter, "Software") is an Unsupported proprietary work of
  39175. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  39176. + * between Synopsys and you.
  39177. + *
  39178. + * The Software IS NOT an item of Licensed Software or Licensed Product
  39179. + * under any End User Software License Agreement or Agreement for
  39180. + * Licensed Product with Synopsys or any supplement thereto. You are
  39181. + * permitted to use and redistribute this Software in source and binary
  39182. + * forms, with or without modification, provided that redistributions
  39183. + * of source code must retain this notice. You may not view, use,
  39184. + * disclose, copy or distribute this file or any information contained
  39185. + * herein except pursuant to this license grant from Synopsys. If you
  39186. + * do not agree with this notice, including the disclaimer below, then
  39187. + * you are not authorized to use the Software.
  39188. + *
  39189. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  39190. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  39191. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  39192. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  39193. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  39194. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  39195. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  39196. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  39197. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  39198. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  39199. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  39200. + * DAMAGE.
  39201. + * ========================================================================= */
  39202. +#ifndef _DWC_CC_H_
  39203. +#define _DWC_CC_H_
  39204. +
  39205. +#ifdef __cplusplus
  39206. +extern "C" {
  39207. +#endif
  39208. +
  39209. +/** @file
  39210. + *
  39211. + * This file defines the Context Context library.
  39212. + *
  39213. + * The main data structure is dwc_cc_if_t which is returned by either the
  39214. + * dwc_cc_if_alloc function or returned by the module to the user via a provided
  39215. + * function. The data structure is opaque and should only be manipulated via the
  39216. + * functions provied in this API.
  39217. + *
  39218. + * It manages a list of connection contexts and operations can be performed to
  39219. + * add, remove, query, search, and change, those contexts. Additionally,
  39220. + * a dwc_notifier_t object can be requested from the manager so that
  39221. + * the user can be notified whenever the context list has changed.
  39222. + */
  39223. +
  39224. +#include "dwc_os.h"
  39225. +#include "dwc_list.h"
  39226. +#include "dwc_notifier.h"
  39227. +
  39228. +
  39229. +/* Notifications */
  39230. +#define DWC_CC_LIST_CHANGED_NOTIFICATION "DWC_CC_LIST_CHANGED_NOTIFICATION"
  39231. +
  39232. +struct dwc_cc_if;
  39233. +typedef struct dwc_cc_if dwc_cc_if_t;
  39234. +
  39235. +
  39236. +/** @name Connection Context Operations */
  39237. +/** @{ */
  39238. +
  39239. +/** This function allocates memory for a dwc_cc_if_t structure, initializes
  39240. + * fields to default values, and returns a pointer to the structure or NULL on
  39241. + * error. */
  39242. +extern dwc_cc_if_t *dwc_cc_if_alloc(void *mem_ctx, void *mtx_ctx,
  39243. + dwc_notifier_t *notifier, unsigned is_host);
  39244. +
  39245. +/** Frees the memory for the specified CC structure allocated from
  39246. + * dwc_cc_if_alloc(). */
  39247. +extern void dwc_cc_if_free(void *mem_ctx, void *mtx_ctx, dwc_cc_if_t *cc_if);
  39248. +
  39249. +/** Removes all contexts from the connection context list */
  39250. +extern void dwc_cc_clear(void *mem_ctx, dwc_cc_if_t *cc_if);
  39251. +
  39252. +/** Adds a connection context (CHID, CK, CDID, Name) to the connection context list.
  39253. + * If a CHID already exists, the CK and name are overwritten. Statistics are
  39254. + * not overwritten.
  39255. + *
  39256. + * @param cc_if The cc_if structure.
  39257. + * @param chid A pointer to the 16-byte CHID. This value will be copied.
  39258. + * @param ck A pointer to the 16-byte CK. This value will be copied.
  39259. + * @param cdid A pointer to the 16-byte CDID. This value will be copied.
  39260. + * @param name An optional host friendly name as defined in the association model
  39261. + * spec. Must be a UTF16-LE unicode string. Can be NULL to indicated no name.
  39262. + * @param length The length othe unicode string.
  39263. + * @return A unique identifier used to refer to this context that is valid for
  39264. + * as long as this context is still in the list. */
  39265. +extern int32_t dwc_cc_add(void *mem_ctx, dwc_cc_if_t *cc_if, uint8_t *chid,
  39266. + uint8_t *cdid, uint8_t *ck, uint8_t *name,
  39267. + uint8_t length);
  39268. +
  39269. +/** Changes the CHID, CK, CDID, or Name values of a connection context in the
  39270. + * list, preserving any accumulated statistics. This would typically be called
  39271. + * if the host decideds to change the context with a SET_CONNECTION request.
  39272. + *
  39273. + * @param cc_if The cc_if structure.
  39274. + * @param id The identifier of the connection context.
  39275. + * @param chid A pointer to the 16-byte CHID. This value will be copied. NULL
  39276. + * indicates no change.
  39277. + * @param cdid A pointer to the 16-byte CDID. This value will be copied. NULL
  39278. + * indicates no change.
  39279. + * @param ck A pointer to the 16-byte CK. This value will be copied. NULL
  39280. + * indicates no change.
  39281. + * @param name Host friendly name UTF16-LE. NULL indicates no change.
  39282. + * @param length Length of name. */
  39283. +extern void dwc_cc_change(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id,
  39284. + uint8_t *chid, uint8_t *cdid, uint8_t *ck,
  39285. + uint8_t *name, uint8_t length);
  39286. +
  39287. +/** Remove the specified connection context.
  39288. + * @param cc_if The cc_if structure.
  39289. + * @param id The identifier of the connection context to remove. */
  39290. +extern void dwc_cc_remove(void *mem_ctx, dwc_cc_if_t *cc_if, int32_t id);
  39291. +
  39292. +/** Get a binary block of data for the connection context list and attributes.
  39293. + * This data can be used by the OS specific driver to save the connection
  39294. + * context list into non-volatile memory.
  39295. + *
  39296. + * @param cc_if The cc_if structure.
  39297. + * @param length Return the length of the data buffer.
  39298. + * @return A pointer to the data buffer. The memory for this buffer should be
  39299. + * freed with DWC_FREE() after use. */
  39300. +extern uint8_t *dwc_cc_data_for_save(void *mem_ctx, dwc_cc_if_t *cc_if,
  39301. + unsigned int *length);
  39302. +
  39303. +/** Restore the connection context list from the binary data that was previously
  39304. + * returned from a call to dwc_cc_data_for_save. This can be used by the OS specific
  39305. + * driver to load a connection context list from non-volatile memory.
  39306. + *
  39307. + * @param cc_if The cc_if structure.
  39308. + * @param data The data bytes as returned from dwc_cc_data_for_save.
  39309. + * @param length The length of the data. */
  39310. +extern void dwc_cc_restore_from_data(void *mem_ctx, dwc_cc_if_t *cc_if,
  39311. + uint8_t *data, unsigned int length);
  39312. +
  39313. +/** Find the connection context from the specified CHID.
  39314. + *
  39315. + * @param cc_if The cc_if structure.
  39316. + * @param chid A pointer to the CHID data.
  39317. + * @return A non-zero identifier of the connection context if the CHID matches.
  39318. + * Otherwise returns 0. */
  39319. +extern uint32_t dwc_cc_match_chid(dwc_cc_if_t *cc_if, uint8_t *chid);
  39320. +
  39321. +/** Find the connection context from the specified CDID.
  39322. + *
  39323. + * @param cc_if The cc_if structure.
  39324. + * @param cdid A pointer to the CDID data.
  39325. + * @return A non-zero identifier of the connection context if the CHID matches.
  39326. + * Otherwise returns 0. */
  39327. +extern uint32_t dwc_cc_match_cdid(dwc_cc_if_t *cc_if, uint8_t *cdid);
  39328. +
  39329. +/** Retrieve the CK from the specified connection context.
  39330. + *
  39331. + * @param cc_if The cc_if structure.
  39332. + * @param id The identifier of the connection context.
  39333. + * @return A pointer to the CK data. The memory does not need to be freed. */
  39334. +extern uint8_t *dwc_cc_ck(dwc_cc_if_t *cc_if, int32_t id);
  39335. +
  39336. +/** Retrieve the CHID from the specified connection context.
  39337. + *
  39338. + * @param cc_if The cc_if structure.
  39339. + * @param id The identifier of the connection context.
  39340. + * @return A pointer to the CHID data. The memory does not need to be freed. */
  39341. +extern uint8_t *dwc_cc_chid(dwc_cc_if_t *cc_if, int32_t id);
  39342. +
  39343. +/** Retrieve the CDID from the specified connection context.
  39344. + *
  39345. + * @param cc_if The cc_if structure.
  39346. + * @param id The identifier of the connection context.
  39347. + * @return A pointer to the CDID data. The memory does not need to be freed. */
  39348. +extern uint8_t *dwc_cc_cdid(dwc_cc_if_t *cc_if, int32_t id);
  39349. +
  39350. +extern uint8_t *dwc_cc_name(dwc_cc_if_t *cc_if, int32_t id, uint8_t *length);
  39351. +
  39352. +/** Checks a buffer for non-zero.
  39353. + * @param id A pointer to a 16 byte buffer.
  39354. + * @return true if the 16 byte value is non-zero. */
  39355. +static inline unsigned dwc_assoc_is_not_zero_id(uint8_t *id) {
  39356. + int i;
  39357. + for (i=0; i<16; i++) {
  39358. + if (id[i]) return 1;
  39359. + }
  39360. + return 0;
  39361. +}
  39362. +
  39363. +/** Checks a buffer for zero.
  39364. + * @param id A pointer to a 16 byte buffer.
  39365. + * @return true if the 16 byte value is zero. */
  39366. +static inline unsigned dwc_assoc_is_zero_id(uint8_t *id) {
  39367. + return !dwc_assoc_is_not_zero_id(id);
  39368. +}
  39369. +
  39370. +/** Prints an ASCII representation for the 16-byte chid, cdid, or ck, into
  39371. + * buffer. */
  39372. +static inline int dwc_print_id_string(char *buffer, uint8_t *id) {
  39373. + char *ptr = buffer;
  39374. + int i;
  39375. + for (i=0; i<16; i++) {
  39376. + ptr += DWC_SPRINTF(ptr, "%02x", id[i]);
  39377. + if (i < 15) {
  39378. + ptr += DWC_SPRINTF(ptr, " ");
  39379. + }
  39380. + }
  39381. + return ptr - buffer;
  39382. +}
  39383. +
  39384. +/** @} */
  39385. +
  39386. +#ifdef __cplusplus
  39387. +}
  39388. +#endif
  39389. +
  39390. +#endif /* _DWC_CC_H_ */
  39391. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c
  39392. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 1970-01-01 01:00:00.000000000 +0100
  39393. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_fbsd.c 2014-06-11 21:03:43.000000000 +0200
  39394. @@ -0,0 +1,1308 @@
  39395. +#include "dwc_os.h"
  39396. +#include "dwc_list.h"
  39397. +
  39398. +#ifdef DWC_CCLIB
  39399. +# include "dwc_cc.h"
  39400. +#endif
  39401. +
  39402. +#ifdef DWC_CRYPTOLIB
  39403. +# include "dwc_modpow.h"
  39404. +# include "dwc_dh.h"
  39405. +# include "dwc_crypto.h"
  39406. +#endif
  39407. +
  39408. +#ifdef DWC_NOTIFYLIB
  39409. +# include "dwc_notifier.h"
  39410. +#endif
  39411. +
  39412. +/* OS-Level Implementations */
  39413. +
  39414. +/* This is the FreeBSD 7.0 kernel implementation of the DWC platform library. */
  39415. +
  39416. +
  39417. +/* MISC */
  39418. +
  39419. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  39420. +{
  39421. + return memset(dest, byte, size);
  39422. +}
  39423. +
  39424. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  39425. +{
  39426. + return memcpy(dest, src, size);
  39427. +}
  39428. +
  39429. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  39430. +{
  39431. + bcopy(src, dest, size);
  39432. + return dest;
  39433. +}
  39434. +
  39435. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  39436. +{
  39437. + return memcmp(m1, m2, size);
  39438. +}
  39439. +
  39440. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  39441. +{
  39442. + return strncmp(s1, s2, size);
  39443. +}
  39444. +
  39445. +int DWC_STRCMP(void *s1, void *s2)
  39446. +{
  39447. + return strcmp(s1, s2);
  39448. +}
  39449. +
  39450. +int DWC_STRLEN(char const *str)
  39451. +{
  39452. + return strlen(str);
  39453. +}
  39454. +
  39455. +char *DWC_STRCPY(char *to, char const *from)
  39456. +{
  39457. + return strcpy(to, from);
  39458. +}
  39459. +
  39460. +char *DWC_STRDUP(char const *str)
  39461. +{
  39462. + int len = DWC_STRLEN(str) + 1;
  39463. + char *new = DWC_ALLOC_ATOMIC(len);
  39464. +
  39465. + if (!new) {
  39466. + return NULL;
  39467. + }
  39468. +
  39469. + DWC_MEMCPY(new, str, len);
  39470. + return new;
  39471. +}
  39472. +
  39473. +int DWC_ATOI(char *str, int32_t *value)
  39474. +{
  39475. + char *end = NULL;
  39476. +
  39477. + *value = strtol(str, &end, 0);
  39478. + if (*end == '\0') {
  39479. + return 0;
  39480. + }
  39481. +
  39482. + return -1;
  39483. +}
  39484. +
  39485. +int DWC_ATOUI(char *str, uint32_t *value)
  39486. +{
  39487. + char *end = NULL;
  39488. +
  39489. + *value = strtoul(str, &end, 0);
  39490. + if (*end == '\0') {
  39491. + return 0;
  39492. + }
  39493. +
  39494. + return -1;
  39495. +}
  39496. +
  39497. +
  39498. +#ifdef DWC_UTFLIB
  39499. +/* From usbstring.c */
  39500. +
  39501. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  39502. +{
  39503. + int count = 0;
  39504. + u8 c;
  39505. + u16 uchar;
  39506. +
  39507. + /* this insists on correct encodings, though not minimal ones.
  39508. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  39509. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  39510. + */
  39511. + while (len != 0 && (c = (u8) *s++) != 0) {
  39512. + if (unlikely(c & 0x80)) {
  39513. + // 2-byte sequence:
  39514. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  39515. + if ((c & 0xe0) == 0xc0) {
  39516. + uchar = (c & 0x1f) << 6;
  39517. +
  39518. + c = (u8) *s++;
  39519. + if ((c & 0xc0) != 0xc0)
  39520. + goto fail;
  39521. + c &= 0x3f;
  39522. + uchar |= c;
  39523. +
  39524. + // 3-byte sequence (most CJKV characters):
  39525. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  39526. + } else if ((c & 0xf0) == 0xe0) {
  39527. + uchar = (c & 0x0f) << 12;
  39528. +
  39529. + c = (u8) *s++;
  39530. + if ((c & 0xc0) != 0xc0)
  39531. + goto fail;
  39532. + c &= 0x3f;
  39533. + uchar |= c << 6;
  39534. +
  39535. + c = (u8) *s++;
  39536. + if ((c & 0xc0) != 0xc0)
  39537. + goto fail;
  39538. + c &= 0x3f;
  39539. + uchar |= c;
  39540. +
  39541. + /* no bogus surrogates */
  39542. + if (0xd800 <= uchar && uchar <= 0xdfff)
  39543. + goto fail;
  39544. +
  39545. + // 4-byte sequence (surrogate pairs, currently rare):
  39546. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  39547. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  39548. + // (uuuuu = wwww + 1)
  39549. + // FIXME accept the surrogate code points (only)
  39550. + } else
  39551. + goto fail;
  39552. + } else
  39553. + uchar = c;
  39554. + put_unaligned (cpu_to_le16 (uchar), cp++);
  39555. + count++;
  39556. + len--;
  39557. + }
  39558. + return count;
  39559. +fail:
  39560. + return -1;
  39561. +}
  39562. +
  39563. +#endif /* DWC_UTFLIB */
  39564. +
  39565. +
  39566. +/* dwc_debug.h */
  39567. +
  39568. +dwc_bool_t DWC_IN_IRQ(void)
  39569. +{
  39570. +// return in_irq();
  39571. + return 0;
  39572. +}
  39573. +
  39574. +dwc_bool_t DWC_IN_BH(void)
  39575. +{
  39576. +// return in_softirq();
  39577. + return 0;
  39578. +}
  39579. +
  39580. +void DWC_VPRINTF(char *format, va_list args)
  39581. +{
  39582. + vprintf(format, args);
  39583. +}
  39584. +
  39585. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  39586. +{
  39587. + return vsnprintf(str, size, format, args);
  39588. +}
  39589. +
  39590. +void DWC_PRINTF(char *format, ...)
  39591. +{
  39592. + va_list args;
  39593. +
  39594. + va_start(args, format);
  39595. + DWC_VPRINTF(format, args);
  39596. + va_end(args);
  39597. +}
  39598. +
  39599. +int DWC_SPRINTF(char *buffer, char *format, ...)
  39600. +{
  39601. + int retval;
  39602. + va_list args;
  39603. +
  39604. + va_start(args, format);
  39605. + retval = vsprintf(buffer, format, args);
  39606. + va_end(args);
  39607. + return retval;
  39608. +}
  39609. +
  39610. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  39611. +{
  39612. + int retval;
  39613. + va_list args;
  39614. +
  39615. + va_start(args, format);
  39616. + retval = vsnprintf(buffer, size, format, args);
  39617. + va_end(args);
  39618. + return retval;
  39619. +}
  39620. +
  39621. +void __DWC_WARN(char *format, ...)
  39622. +{
  39623. + va_list args;
  39624. +
  39625. + va_start(args, format);
  39626. + DWC_VPRINTF(format, args);
  39627. + va_end(args);
  39628. +}
  39629. +
  39630. +void __DWC_ERROR(char *format, ...)
  39631. +{
  39632. + va_list args;
  39633. +
  39634. + va_start(args, format);
  39635. + DWC_VPRINTF(format, args);
  39636. + va_end(args);
  39637. +}
  39638. +
  39639. +void DWC_EXCEPTION(char *format, ...)
  39640. +{
  39641. + va_list args;
  39642. +
  39643. + va_start(args, format);
  39644. + DWC_VPRINTF(format, args);
  39645. + va_end(args);
  39646. +// BUG_ON(1); ???
  39647. +}
  39648. +
  39649. +#ifdef DEBUG
  39650. +void __DWC_DEBUG(char *format, ...)
  39651. +{
  39652. + va_list args;
  39653. +
  39654. + va_start(args, format);
  39655. + DWC_VPRINTF(format, args);
  39656. + va_end(args);
  39657. +}
  39658. +#endif
  39659. +
  39660. +
  39661. +/* dwc_mem.h */
  39662. +
  39663. +#if 0
  39664. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  39665. + uint32_t align,
  39666. + uint32_t alloc)
  39667. +{
  39668. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  39669. + size, align, alloc);
  39670. + return (dwc_pool_t *)pool;
  39671. +}
  39672. +
  39673. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  39674. +{
  39675. + dma_pool_destroy((struct dma_pool *)pool);
  39676. +}
  39677. +
  39678. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39679. +{
  39680. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  39681. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  39682. +}
  39683. +
  39684. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  39685. +{
  39686. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  39687. + memset(..);
  39688. +}
  39689. +
  39690. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  39691. +{
  39692. + dma_pool_free(pool, vaddr, daddr);
  39693. +}
  39694. +#endif
  39695. +
  39696. +static void dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
  39697. +{
  39698. + if (error)
  39699. + return;
  39700. + *(bus_addr_t *)arg = segs[0].ds_addr;
  39701. +}
  39702. +
  39703. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  39704. +{
  39705. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39706. + int error;
  39707. +
  39708. + error = bus_dma_tag_create(
  39709. +#if __FreeBSD_version >= 700000
  39710. + bus_get_dma_tag(dma->dev), /* parent */
  39711. +#else
  39712. + NULL, /* parent */
  39713. +#endif
  39714. + 4, 0, /* alignment, bounds */
  39715. + BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
  39716. + BUS_SPACE_MAXADDR, /* highaddr */
  39717. + NULL, NULL, /* filter, filterarg */
  39718. + size, /* maxsize */
  39719. + 1, /* nsegments */
  39720. + size, /* maxsegsize */
  39721. + 0, /* flags */
  39722. + NULL, /* lockfunc */
  39723. + NULL, /* lockarg */
  39724. + &dma->dma_tag);
  39725. + if (error) {
  39726. + device_printf(dma->dev, "%s: bus_dma_tag_create failed: %d\n",
  39727. + __func__, error);
  39728. + goto fail_0;
  39729. + }
  39730. +
  39731. + error = bus_dmamem_alloc(dma->dma_tag, &dma->dma_vaddr,
  39732. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT, &dma->dma_map);
  39733. + if (error) {
  39734. + device_printf(dma->dev, "%s: bus_dmamem_alloc(%ju) failed: %d\n",
  39735. + __func__, (uintmax_t)size, error);
  39736. + goto fail_1;
  39737. + }
  39738. +
  39739. + dma->dma_paddr = 0;
  39740. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr, size,
  39741. + dmamap_cb, &dma->dma_paddr, BUS_DMA_NOWAIT);
  39742. + if (error || dma->dma_paddr == 0) {
  39743. + device_printf(dma->dev, "%s: bus_dmamap_load failed: %d\n",
  39744. + __func__, error);
  39745. + goto fail_2;
  39746. + }
  39747. +
  39748. + *dma_addr = dma->dma_paddr;
  39749. + return dma->dma_vaddr;
  39750. +
  39751. +fail_2:
  39752. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39753. +fail_1:
  39754. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39755. + bus_dma_tag_destroy(dma->dma_tag);
  39756. +fail_0:
  39757. + dma->dma_map = NULL;
  39758. + dma->dma_tag = NULL;
  39759. +
  39760. + return NULL;
  39761. +}
  39762. +
  39763. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  39764. +{
  39765. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  39766. +
  39767. + if (dma->dma_tag == NULL)
  39768. + return;
  39769. + if (dma->dma_map != NULL) {
  39770. + bus_dmamap_sync(dma->dma_tag, dma->dma_map,
  39771. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  39772. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  39773. + bus_dmamem_free(dma->dma_tag, dma->dma_vaddr, dma->dma_map);
  39774. + dma->dma_map = NULL;
  39775. + }
  39776. +
  39777. + bus_dma_tag_destroy(dma->dma_tag);
  39778. + dma->dma_tag = NULL;
  39779. +}
  39780. +
  39781. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  39782. +{
  39783. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  39784. +}
  39785. +
  39786. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  39787. +{
  39788. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  39789. +}
  39790. +
  39791. +void __DWC_FREE(void *mem_ctx, void *addr)
  39792. +{
  39793. + free(addr, M_DEVBUF);
  39794. +}
  39795. +
  39796. +
  39797. +#ifdef DWC_CRYPTOLIB
  39798. +/* dwc_crypto.h */
  39799. +
  39800. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  39801. +{
  39802. + get_random_bytes(buffer, length);
  39803. +}
  39804. +
  39805. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  39806. +{
  39807. + struct crypto_blkcipher *tfm;
  39808. + struct blkcipher_desc desc;
  39809. + struct scatterlist sgd;
  39810. + struct scatterlist sgs;
  39811. +
  39812. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  39813. + if (tfm == NULL) {
  39814. + printk("failed to load transform for aes CBC\n");
  39815. + return -1;
  39816. + }
  39817. +
  39818. + crypto_blkcipher_setkey(tfm, key, keylen);
  39819. + crypto_blkcipher_set_iv(tfm, iv, 16);
  39820. +
  39821. + sg_init_one(&sgd, out, messagelen);
  39822. + sg_init_one(&sgs, message, messagelen);
  39823. +
  39824. + desc.tfm = tfm;
  39825. + desc.flags = 0;
  39826. +
  39827. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  39828. + crypto_free_blkcipher(tfm);
  39829. + DWC_ERROR("AES CBC encryption failed");
  39830. + return -1;
  39831. + }
  39832. +
  39833. + crypto_free_blkcipher(tfm);
  39834. + return 0;
  39835. +}
  39836. +
  39837. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  39838. +{
  39839. + struct crypto_hash *tfm;
  39840. + struct hash_desc desc;
  39841. + struct scatterlist sg;
  39842. +
  39843. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  39844. + if (IS_ERR(tfm)) {
  39845. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  39846. + return 0;
  39847. + }
  39848. + desc.tfm = tfm;
  39849. + desc.flags = 0;
  39850. +
  39851. + sg_init_one(&sg, message, len);
  39852. + crypto_hash_digest(&desc, &sg, len, out);
  39853. + crypto_free_hash(tfm);
  39854. +
  39855. + return 1;
  39856. +}
  39857. +
  39858. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  39859. + uint8_t *key, uint32_t keylen, uint8_t *out)
  39860. +{
  39861. + struct crypto_hash *tfm;
  39862. + struct hash_desc desc;
  39863. + struct scatterlist sg;
  39864. +
  39865. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  39866. + if (IS_ERR(tfm)) {
  39867. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  39868. + return 0;
  39869. + }
  39870. + desc.tfm = tfm;
  39871. + desc.flags = 0;
  39872. +
  39873. + sg_init_one(&sg, message, messagelen);
  39874. + crypto_hash_setkey(tfm, key, keylen);
  39875. + crypto_hash_digest(&desc, &sg, messagelen, out);
  39876. + crypto_free_hash(tfm);
  39877. +
  39878. + return 1;
  39879. +}
  39880. +
  39881. +#endif /* DWC_CRYPTOLIB */
  39882. +
  39883. +
  39884. +/* Byte Ordering Conversions */
  39885. +
  39886. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  39887. +{
  39888. +#ifdef __LITTLE_ENDIAN
  39889. + return *p;
  39890. +#else
  39891. + uint8_t *u_p = (uint8_t *)p;
  39892. +
  39893. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39894. +#endif
  39895. +}
  39896. +
  39897. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  39898. +{
  39899. +#ifdef __BIG_ENDIAN
  39900. + return *p;
  39901. +#else
  39902. + uint8_t *u_p = (uint8_t *)p;
  39903. +
  39904. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39905. +#endif
  39906. +}
  39907. +
  39908. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  39909. +{
  39910. +#ifdef __LITTLE_ENDIAN
  39911. + return *p;
  39912. +#else
  39913. + uint8_t *u_p = (uint8_t *)p;
  39914. +
  39915. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39916. +#endif
  39917. +}
  39918. +
  39919. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  39920. +{
  39921. +#ifdef __BIG_ENDIAN
  39922. + return *p;
  39923. +#else
  39924. + uint8_t *u_p = (uint8_t *)p;
  39925. +
  39926. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  39927. +#endif
  39928. +}
  39929. +
  39930. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  39931. +{
  39932. +#ifdef __LITTLE_ENDIAN
  39933. + return *p;
  39934. +#else
  39935. + uint8_t *u_p = (uint8_t *)p;
  39936. + return (u_p[1] | (u_p[0] << 8));
  39937. +#endif
  39938. +}
  39939. +
  39940. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  39941. +{
  39942. +#ifdef __BIG_ENDIAN
  39943. + return *p;
  39944. +#else
  39945. + uint8_t *u_p = (uint8_t *)p;
  39946. + return (u_p[1] | (u_p[0] << 8));
  39947. +#endif
  39948. +}
  39949. +
  39950. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  39951. +{
  39952. +#ifdef __LITTLE_ENDIAN
  39953. + return *p;
  39954. +#else
  39955. + uint8_t *u_p = (uint8_t *)p;
  39956. + return (u_p[1] | (u_p[0] << 8));
  39957. +#endif
  39958. +}
  39959. +
  39960. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  39961. +{
  39962. +#ifdef __BIG_ENDIAN
  39963. + return *p;
  39964. +#else
  39965. + uint8_t *u_p = (uint8_t *)p;
  39966. + return (u_p[1] | (u_p[0] << 8));
  39967. +#endif
  39968. +}
  39969. +
  39970. +
  39971. +/* Registers */
  39972. +
  39973. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  39974. +{
  39975. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39976. + bus_size_t ior = (bus_size_t)reg;
  39977. +
  39978. + return bus_space_read_4(io->iot, io->ioh, ior);
  39979. +}
  39980. +
  39981. +#if 0
  39982. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  39983. +{
  39984. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39985. + bus_size_t ior = (bus_size_t)reg;
  39986. +
  39987. + return bus_space_read_8(io->iot, io->ioh, ior);
  39988. +}
  39989. +#endif
  39990. +
  39991. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  39992. +{
  39993. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  39994. + bus_size_t ior = (bus_size_t)reg;
  39995. +
  39996. + bus_space_write_4(io->iot, io->ioh, ior, value);
  39997. +}
  39998. +
  39999. +#if 0
  40000. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  40001. +{
  40002. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40003. + bus_size_t ior = (bus_size_t)reg;
  40004. +
  40005. + bus_space_write_8(io->iot, io->ioh, ior, value);
  40006. +}
  40007. +#endif
  40008. +
  40009. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  40010. + uint32_t set_mask)
  40011. +{
  40012. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40013. + bus_size_t ior = (bus_size_t)reg;
  40014. +
  40015. + bus_space_write_4(io->iot, io->ioh, ior,
  40016. + (bus_space_read_4(io->iot, io->ioh, ior) &
  40017. + ~clear_mask) | set_mask);
  40018. +}
  40019. +
  40020. +#if 0
  40021. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  40022. + uint64_t set_mask)
  40023. +{
  40024. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  40025. + bus_size_t ior = (bus_size_t)reg;
  40026. +
  40027. + bus_space_write_8(io->iot, io->ioh, ior,
  40028. + (bus_space_read_8(io->iot, io->ioh, ior) &
  40029. + ~clear_mask) | set_mask);
  40030. +}
  40031. +#endif
  40032. +
  40033. +
  40034. +/* Locking */
  40035. +
  40036. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  40037. +{
  40038. + struct mtx *sl = DWC_ALLOC(sizeof(*sl));
  40039. +
  40040. + if (!sl) {
  40041. + DWC_ERROR("Cannot allocate memory for spinlock");
  40042. + return NULL;
  40043. + }
  40044. +
  40045. + mtx_init(sl, "dw3spn", NULL, MTX_SPIN);
  40046. + return (dwc_spinlock_t *)sl;
  40047. +}
  40048. +
  40049. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  40050. +{
  40051. + struct mtx *sl = (struct mtx *)lock;
  40052. +
  40053. + mtx_destroy(sl);
  40054. + DWC_FREE(sl);
  40055. +}
  40056. +
  40057. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  40058. +{
  40059. + mtx_lock_spin((struct mtx *)lock); // ???
  40060. +}
  40061. +
  40062. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  40063. +{
  40064. + mtx_unlock_spin((struct mtx *)lock); // ???
  40065. +}
  40066. +
  40067. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  40068. +{
  40069. + mtx_lock_spin((struct mtx *)lock);
  40070. +}
  40071. +
  40072. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  40073. +{
  40074. + mtx_unlock_spin((struct mtx *)lock);
  40075. +}
  40076. +
  40077. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  40078. +{
  40079. + struct mtx *m;
  40080. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mtx));
  40081. +
  40082. + if (!mutex) {
  40083. + DWC_ERROR("Cannot allocate memory for mutex");
  40084. + return NULL;
  40085. + }
  40086. +
  40087. + m = (struct mtx *)mutex;
  40088. + mtx_init(m, "dw3mtx", NULL, MTX_DEF);
  40089. + return mutex;
  40090. +}
  40091. +
  40092. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  40093. +#else
  40094. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  40095. +{
  40096. + mtx_destroy((struct mtx *)mutex);
  40097. + DWC_FREE(mutex);
  40098. +}
  40099. +#endif
  40100. +
  40101. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  40102. +{
  40103. + struct mtx *m = (struct mtx *)mutex;
  40104. +
  40105. + mtx_lock(m);
  40106. +}
  40107. +
  40108. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  40109. +{
  40110. + struct mtx *m = (struct mtx *)mutex;
  40111. +
  40112. + return mtx_trylock(m);
  40113. +}
  40114. +
  40115. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  40116. +{
  40117. + struct mtx *m = (struct mtx *)mutex;
  40118. +
  40119. + mtx_unlock(m);
  40120. +}
  40121. +
  40122. +
  40123. +/* Timing */
  40124. +
  40125. +void DWC_UDELAY(uint32_t usecs)
  40126. +{
  40127. + DELAY(usecs);
  40128. +}
  40129. +
  40130. +void DWC_MDELAY(uint32_t msecs)
  40131. +{
  40132. + do {
  40133. + DELAY(1000);
  40134. + } while (--msecs);
  40135. +}
  40136. +
  40137. +void DWC_MSLEEP(uint32_t msecs)
  40138. +{
  40139. + struct timeval tv;
  40140. +
  40141. + tv.tv_sec = msecs / 1000;
  40142. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40143. + pause("dw3slp", tvtohz(&tv));
  40144. +}
  40145. +
  40146. +uint32_t DWC_TIME(void)
  40147. +{
  40148. + struct timeval tv;
  40149. +
  40150. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  40151. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  40152. +}
  40153. +
  40154. +
  40155. +/* Timers */
  40156. +
  40157. +struct dwc_timer {
  40158. + struct callout t;
  40159. + char *name;
  40160. + dwc_spinlock_t *lock;
  40161. + dwc_timer_callback_t cb;
  40162. + void *data;
  40163. +};
  40164. +
  40165. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  40166. +{
  40167. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  40168. +
  40169. + if (!t) {
  40170. + DWC_ERROR("Cannot allocate memory for timer");
  40171. + return NULL;
  40172. + }
  40173. +
  40174. + callout_init(&t->t, 1);
  40175. +
  40176. + t->name = DWC_STRDUP(name);
  40177. + if (!t->name) {
  40178. + DWC_ERROR("Cannot allocate memory for timer->name");
  40179. + goto no_name;
  40180. + }
  40181. +
  40182. + t->lock = DWC_SPINLOCK_ALLOC();
  40183. + if (!t->lock) {
  40184. + DWC_ERROR("Cannot allocate memory for lock");
  40185. + goto no_lock;
  40186. + }
  40187. +
  40188. + t->cb = cb;
  40189. + t->data = data;
  40190. +
  40191. + return t;
  40192. +
  40193. + no_lock:
  40194. + DWC_FREE(t->name);
  40195. + no_name:
  40196. + DWC_FREE(t);
  40197. +
  40198. + return NULL;
  40199. +}
  40200. +
  40201. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  40202. +{
  40203. + callout_stop(&timer->t);
  40204. + DWC_SPINLOCK_FREE(timer->lock);
  40205. + DWC_FREE(timer->name);
  40206. + DWC_FREE(timer);
  40207. +}
  40208. +
  40209. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  40210. +{
  40211. + struct timeval tv;
  40212. +
  40213. + tv.tv_sec = time / 1000;
  40214. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40215. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  40216. +}
  40217. +
  40218. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  40219. +{
  40220. + callout_stop(&timer->t);
  40221. +}
  40222. +
  40223. +
  40224. +/* Wait Queues */
  40225. +
  40226. +struct dwc_waitq {
  40227. + struct mtx lock;
  40228. + int abort;
  40229. +};
  40230. +
  40231. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  40232. +{
  40233. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  40234. +
  40235. + if (!wq) {
  40236. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40237. + return NULL;
  40238. + }
  40239. +
  40240. + mtx_init(&wq->lock, "dw3wtq", NULL, MTX_DEF);
  40241. + wq->abort = 0;
  40242. +
  40243. + return wq;
  40244. +}
  40245. +
  40246. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  40247. +{
  40248. + mtx_destroy(&wq->lock);
  40249. + DWC_FREE(wq);
  40250. +}
  40251. +
  40252. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  40253. +{
  40254. +// intrmask_t ipl;
  40255. + int result = 0;
  40256. +
  40257. + mtx_lock(&wq->lock);
  40258. +// ipl = splbio();
  40259. +
  40260. + /* Skip the sleep if already aborted or triggered */
  40261. + if (!wq->abort && !cond(data)) {
  40262. +// splx(ipl);
  40263. + result = msleep(wq, &wq->lock, PCATCH, "dw3wat", 0); // infinite timeout
  40264. +// ipl = splbio();
  40265. + }
  40266. +
  40267. + if (result == ERESTART) { // signaled - restart
  40268. + result = -DWC_E_RESTART;
  40269. +
  40270. + } else if (result == EINTR) { // signaled - interrupt
  40271. + result = -DWC_E_ABORT;
  40272. +
  40273. + } else if (wq->abort) {
  40274. + result = -DWC_E_ABORT;
  40275. +
  40276. + } else {
  40277. + result = 0;
  40278. + }
  40279. +
  40280. + wq->abort = 0;
  40281. +// splx(ipl);
  40282. + mtx_unlock(&wq->lock);
  40283. + return result;
  40284. +}
  40285. +
  40286. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  40287. + void *data, int32_t msecs)
  40288. +{
  40289. + struct timeval tv, tv1, tv2;
  40290. +// intrmask_t ipl;
  40291. + int result = 0;
  40292. +
  40293. + tv.tv_sec = msecs / 1000;
  40294. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  40295. +
  40296. + mtx_lock(&wq->lock);
  40297. +// ipl = splbio();
  40298. +
  40299. + /* Skip the sleep if already aborted or triggered */
  40300. + if (!wq->abort && !cond(data)) {
  40301. +// splx(ipl);
  40302. + getmicrouptime(&tv1);
  40303. + result = msleep(wq, &wq->lock, PCATCH, "dw3wto", tvtohz(&tv));
  40304. + getmicrouptime(&tv2);
  40305. +// ipl = splbio();
  40306. + }
  40307. +
  40308. + if (result == 0) { // awoken
  40309. + if (wq->abort) {
  40310. + result = -DWC_E_ABORT;
  40311. + } else {
  40312. + tv2.tv_usec -= tv1.tv_usec;
  40313. + if (tv2.tv_usec < 0) {
  40314. + tv2.tv_usec += 1000000;
  40315. + tv2.tv_sec--;
  40316. + }
  40317. +
  40318. + tv2.tv_sec -= tv1.tv_sec;
  40319. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  40320. + result = msecs - result;
  40321. + if (result <= 0)
  40322. + result = 1;
  40323. + }
  40324. + } else if (result == ERESTART) { // signaled - restart
  40325. + result = -DWC_E_RESTART;
  40326. +
  40327. + } else if (result == EINTR) { // signaled - interrupt
  40328. + result = -DWC_E_ABORT;
  40329. +
  40330. + } else { // timed out
  40331. + result = -DWC_E_TIMEOUT;
  40332. + }
  40333. +
  40334. + wq->abort = 0;
  40335. +// splx(ipl);
  40336. + mtx_unlock(&wq->lock);
  40337. + return result;
  40338. +}
  40339. +
  40340. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  40341. +{
  40342. + wakeup(wq);
  40343. +}
  40344. +
  40345. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  40346. +{
  40347. +// intrmask_t ipl;
  40348. +
  40349. + mtx_lock(&wq->lock);
  40350. +// ipl = splbio();
  40351. + wq->abort = 1;
  40352. + wakeup(wq);
  40353. +// splx(ipl);
  40354. + mtx_unlock(&wq->lock);
  40355. +}
  40356. +
  40357. +
  40358. +/* Threading */
  40359. +
  40360. +struct dwc_thread {
  40361. + struct proc *proc;
  40362. + int abort;
  40363. +};
  40364. +
  40365. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  40366. +{
  40367. + int retval;
  40368. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  40369. +
  40370. + if (!thread) {
  40371. + return NULL;
  40372. + }
  40373. +
  40374. + thread->abort = 0;
  40375. + retval = kthread_create((void (*)(void *))func, data, &thread->proc,
  40376. + RFPROC | RFNOWAIT, 0, "%s", name);
  40377. + if (retval) {
  40378. + DWC_FREE(thread);
  40379. + return NULL;
  40380. + }
  40381. +
  40382. + return thread;
  40383. +}
  40384. +
  40385. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  40386. +{
  40387. + int retval;
  40388. +
  40389. + thread->abort = 1;
  40390. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  40391. +
  40392. + if (retval == 0) {
  40393. + /* DWC_THREAD_EXIT() will free the thread struct */
  40394. + return 0;
  40395. + }
  40396. +
  40397. + /* NOTE: We leak the thread struct if thread doesn't die */
  40398. +
  40399. + if (retval == EWOULDBLOCK) {
  40400. + return -DWC_E_TIMEOUT;
  40401. + }
  40402. +
  40403. + return -DWC_E_UNKNOWN;
  40404. +}
  40405. +
  40406. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  40407. +{
  40408. + return thread->abort;
  40409. +}
  40410. +
  40411. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  40412. +{
  40413. + wakeup(&thread->abort);
  40414. + DWC_FREE(thread);
  40415. + kthread_exit(0);
  40416. +}
  40417. +
  40418. +
  40419. +/* tasklets
  40420. + - Runs in interrupt context (cannot sleep)
  40421. + - Each tasklet runs on a single CPU [ How can we ensure this on FreeBSD? Does it matter? ]
  40422. + - Different tasklets can be running simultaneously on different CPUs [ shouldn't matter ]
  40423. + */
  40424. +struct dwc_tasklet {
  40425. + struct task t;
  40426. + dwc_tasklet_callback_t cb;
  40427. + void *data;
  40428. +};
  40429. +
  40430. +static void tasklet_callback(void *data, int pending) // what to do with pending ???
  40431. +{
  40432. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  40433. +
  40434. + task->cb(task->data);
  40435. +}
  40436. +
  40437. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  40438. +{
  40439. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  40440. +
  40441. + if (task) {
  40442. + task->cb = cb;
  40443. + task->data = data;
  40444. + TASK_INIT(&task->t, 0, tasklet_callback, task);
  40445. + } else {
  40446. + DWC_ERROR("Cannot allocate memory for tasklet");
  40447. + }
  40448. +
  40449. + return task;
  40450. +}
  40451. +
  40452. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  40453. +{
  40454. + taskqueue_drain(taskqueue_fast, &task->t); // ???
  40455. + DWC_FREE(task);
  40456. +}
  40457. +
  40458. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  40459. +{
  40460. + /* Uses predefined system queue */
  40461. + taskqueue_enqueue_fast(taskqueue_fast, &task->t);
  40462. +}
  40463. +
  40464. +
  40465. +/* workqueues
  40466. + - Runs in process context (can sleep)
  40467. + */
  40468. +typedef struct work_container {
  40469. + dwc_work_callback_t cb;
  40470. + void *data;
  40471. + dwc_workq_t *wq;
  40472. + char *name;
  40473. + int hz;
  40474. +
  40475. +#ifdef DEBUG
  40476. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  40477. +#endif
  40478. + struct task task;
  40479. +} work_container_t;
  40480. +
  40481. +#ifdef DEBUG
  40482. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  40483. +#endif
  40484. +
  40485. +struct dwc_workq {
  40486. + struct taskqueue *taskq;
  40487. + dwc_spinlock_t *lock;
  40488. + dwc_waitq_t *waitq;
  40489. + int pending;
  40490. +
  40491. +#ifdef DEBUG
  40492. + struct work_container_queue entries;
  40493. +#endif
  40494. +};
  40495. +
  40496. +static void do_work(void *data, int pending) // what to do with pending ???
  40497. +{
  40498. + work_container_t *container = (work_container_t *)data;
  40499. + dwc_workq_t *wq = container->wq;
  40500. + dwc_irqflags_t flags;
  40501. +
  40502. + if (container->hz) {
  40503. + pause("dw3wrk", container->hz);
  40504. + }
  40505. +
  40506. + container->cb(container->data);
  40507. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  40508. +
  40509. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40510. +
  40511. +#ifdef DEBUG
  40512. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  40513. +#endif
  40514. + if (container->name)
  40515. + DWC_FREE(container->name);
  40516. + DWC_FREE(container);
  40517. + wq->pending--;
  40518. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40519. + DWC_WAITQ_TRIGGER(wq->waitq);
  40520. +}
  40521. +
  40522. +static int work_done(void *data)
  40523. +{
  40524. + dwc_workq_t *workq = (dwc_workq_t *)data;
  40525. +
  40526. + return workq->pending == 0;
  40527. +}
  40528. +
  40529. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  40530. +{
  40531. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  40532. +}
  40533. +
  40534. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  40535. +{
  40536. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  40537. +
  40538. + if (!wq) {
  40539. + DWC_ERROR("Cannot allocate memory for workqueue");
  40540. + return NULL;
  40541. + }
  40542. +
  40543. + wq->taskq = taskqueue_create(name, M_NOWAIT, taskqueue_thread_enqueue, &wq->taskq);
  40544. + if (!wq->taskq) {
  40545. + DWC_ERROR("Cannot allocate memory for taskqueue");
  40546. + goto no_taskq;
  40547. + }
  40548. +
  40549. + wq->pending = 0;
  40550. +
  40551. + wq->lock = DWC_SPINLOCK_ALLOC();
  40552. + if (!wq->lock) {
  40553. + DWC_ERROR("Cannot allocate memory for spinlock");
  40554. + goto no_lock;
  40555. + }
  40556. +
  40557. + wq->waitq = DWC_WAITQ_ALLOC();
  40558. + if (!wq->waitq) {
  40559. + DWC_ERROR("Cannot allocate memory for waitqueue");
  40560. + goto no_waitq;
  40561. + }
  40562. +
  40563. + taskqueue_start_threads(&wq->taskq, 1, PWAIT, "%s taskq", "dw3tsk");
  40564. +
  40565. +#ifdef DEBUG
  40566. + DWC_CIRCLEQ_INIT(&wq->entries);
  40567. +#endif
  40568. + return wq;
  40569. +
  40570. + no_waitq:
  40571. + DWC_SPINLOCK_FREE(wq->lock);
  40572. + no_lock:
  40573. + taskqueue_free(wq->taskq);
  40574. + no_taskq:
  40575. + DWC_FREE(wq);
  40576. +
  40577. + return NULL;
  40578. +}
  40579. +
  40580. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  40581. +{
  40582. +#ifdef DEBUG
  40583. + dwc_irqflags_t flags;
  40584. +
  40585. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40586. +
  40587. + if (wq->pending != 0) {
  40588. + struct work_container *container;
  40589. +
  40590. + DWC_ERROR("Destroying work queue with pending work");
  40591. +
  40592. + DWC_CIRCLEQ_FOREACH(container, &wq->entries, entry) {
  40593. + DWC_ERROR("Work %s still pending", container->name);
  40594. + }
  40595. + }
  40596. +
  40597. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40598. +#endif
  40599. + DWC_WAITQ_FREE(wq->waitq);
  40600. + DWC_SPINLOCK_FREE(wq->lock);
  40601. + taskqueue_free(wq->taskq);
  40602. + DWC_FREE(wq);
  40603. +}
  40604. +
  40605. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  40606. + char *format, ...)
  40607. +{
  40608. + dwc_irqflags_t flags;
  40609. + work_container_t *container;
  40610. + static char name[128];
  40611. + va_list args;
  40612. +
  40613. + va_start(args, format);
  40614. + DWC_VSNPRINTF(name, 128, format, args);
  40615. + va_end(args);
  40616. +
  40617. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40618. + wq->pending++;
  40619. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40620. + DWC_WAITQ_TRIGGER(wq->waitq);
  40621. +
  40622. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40623. + if (!container) {
  40624. + DWC_ERROR("Cannot allocate memory for container");
  40625. + return;
  40626. + }
  40627. +
  40628. + container->name = DWC_STRDUP(name);
  40629. + if (!container->name) {
  40630. + DWC_ERROR("Cannot allocate memory for container->name");
  40631. + DWC_FREE(container);
  40632. + return;
  40633. + }
  40634. +
  40635. + container->cb = cb;
  40636. + container->data = data;
  40637. + container->wq = wq;
  40638. + container->hz = 0;
  40639. +
  40640. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40641. +
  40642. + TASK_INIT(&container->task, 0, do_work, container);
  40643. +
  40644. +#ifdef DEBUG
  40645. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40646. +#endif
  40647. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40648. +}
  40649. +
  40650. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  40651. + void *data, uint32_t time, char *format, ...)
  40652. +{
  40653. + dwc_irqflags_t flags;
  40654. + work_container_t *container;
  40655. + static char name[128];
  40656. + struct timeval tv;
  40657. + va_list args;
  40658. +
  40659. + va_start(args, format);
  40660. + DWC_VSNPRINTF(name, 128, format, args);
  40661. + va_end(args);
  40662. +
  40663. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  40664. + wq->pending++;
  40665. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  40666. + DWC_WAITQ_TRIGGER(wq->waitq);
  40667. +
  40668. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  40669. + if (!container) {
  40670. + DWC_ERROR("Cannot allocate memory for container");
  40671. + return;
  40672. + }
  40673. +
  40674. + container->name = DWC_STRDUP(name);
  40675. + if (!container->name) {
  40676. + DWC_ERROR("Cannot allocate memory for container->name");
  40677. + DWC_FREE(container);
  40678. + return;
  40679. + }
  40680. +
  40681. + container->cb = cb;
  40682. + container->data = data;
  40683. + container->wq = wq;
  40684. +
  40685. + tv.tv_sec = time / 1000;
  40686. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  40687. + container->hz = tvtohz(&tv);
  40688. +
  40689. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  40690. +
  40691. + TASK_INIT(&container->task, 0, do_work, container);
  40692. +
  40693. +#ifdef DEBUG
  40694. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  40695. +#endif
  40696. + taskqueue_enqueue_fast(wq->taskq, &container->task);
  40697. +}
  40698. +
  40699. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  40700. +{
  40701. + return wq->pending;
  40702. +}
  40703. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_linux.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c
  40704. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_linux.c 1970-01-01 01:00:00.000000000 +0100
  40705. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_linux.c 2014-06-11 21:03:43.000000000 +0200
  40706. @@ -0,0 +1,1432 @@
  40707. +#include <linux/kernel.h>
  40708. +#include <linux/init.h>
  40709. +#include <linux/module.h>
  40710. +#include <linux/kthread.h>
  40711. +
  40712. +#ifdef DWC_CCLIB
  40713. +# include "dwc_cc.h"
  40714. +#endif
  40715. +
  40716. +#ifdef DWC_CRYPTOLIB
  40717. +# include "dwc_modpow.h"
  40718. +# include "dwc_dh.h"
  40719. +# include "dwc_crypto.h"
  40720. +#endif
  40721. +
  40722. +#ifdef DWC_NOTIFYLIB
  40723. +# include "dwc_notifier.h"
  40724. +#endif
  40725. +
  40726. +/* OS-Level Implementations */
  40727. +
  40728. +/* This is the Linux kernel implementation of the DWC platform library. */
  40729. +#include <linux/moduleparam.h>
  40730. +#include <linux/ctype.h>
  40731. +#include <linux/crypto.h>
  40732. +#include <linux/delay.h>
  40733. +#include <linux/device.h>
  40734. +#include <linux/dma-mapping.h>
  40735. +#include <linux/cdev.h>
  40736. +#include <linux/errno.h>
  40737. +#include <linux/interrupt.h>
  40738. +#include <linux/jiffies.h>
  40739. +#include <linux/list.h>
  40740. +#include <linux/pci.h>
  40741. +#include <linux/random.h>
  40742. +#include <linux/scatterlist.h>
  40743. +#include <linux/slab.h>
  40744. +#include <linux/stat.h>
  40745. +#include <linux/string.h>
  40746. +#include <linux/timer.h>
  40747. +#include <linux/usb.h>
  40748. +
  40749. +#include <linux/version.h>
  40750. +
  40751. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  40752. +# include <linux/usb/gadget.h>
  40753. +#else
  40754. +# include <linux/usb_gadget.h>
  40755. +#endif
  40756. +
  40757. +#include <asm/io.h>
  40758. +#include <asm/page.h>
  40759. +#include <asm/uaccess.h>
  40760. +#include <asm/unaligned.h>
  40761. +
  40762. +#include "dwc_os.h"
  40763. +#include "dwc_list.h"
  40764. +
  40765. +
  40766. +/* MISC */
  40767. +
  40768. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  40769. +{
  40770. + return memset(dest, byte, size);
  40771. +}
  40772. +
  40773. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  40774. +{
  40775. + return memcpy(dest, src, size);
  40776. +}
  40777. +
  40778. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  40779. +{
  40780. + return memmove(dest, src, size);
  40781. +}
  40782. +
  40783. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  40784. +{
  40785. + return memcmp(m1, m2, size);
  40786. +}
  40787. +
  40788. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  40789. +{
  40790. + return strncmp(s1, s2, size);
  40791. +}
  40792. +
  40793. +int DWC_STRCMP(void *s1, void *s2)
  40794. +{
  40795. + return strcmp(s1, s2);
  40796. +}
  40797. +
  40798. +int DWC_STRLEN(char const *str)
  40799. +{
  40800. + return strlen(str);
  40801. +}
  40802. +
  40803. +char *DWC_STRCPY(char *to, char const *from)
  40804. +{
  40805. + return strcpy(to, from);
  40806. +}
  40807. +
  40808. +char *DWC_STRDUP(char const *str)
  40809. +{
  40810. + int len = DWC_STRLEN(str) + 1;
  40811. + char *new = DWC_ALLOC_ATOMIC(len);
  40812. +
  40813. + if (!new) {
  40814. + return NULL;
  40815. + }
  40816. +
  40817. + DWC_MEMCPY(new, str, len);
  40818. + return new;
  40819. +}
  40820. +
  40821. +int DWC_ATOI(const char *str, int32_t *value)
  40822. +{
  40823. + char *end = NULL;
  40824. +
  40825. + *value = simple_strtol(str, &end, 0);
  40826. + if (*end == '\0') {
  40827. + return 0;
  40828. + }
  40829. +
  40830. + return -1;
  40831. +}
  40832. +
  40833. +int DWC_ATOUI(const char *str, uint32_t *value)
  40834. +{
  40835. + char *end = NULL;
  40836. +
  40837. + *value = simple_strtoul(str, &end, 0);
  40838. + if (*end == '\0') {
  40839. + return 0;
  40840. + }
  40841. +
  40842. + return -1;
  40843. +}
  40844. +
  40845. +
  40846. +#ifdef DWC_UTFLIB
  40847. +/* From usbstring.c */
  40848. +
  40849. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  40850. +{
  40851. + int count = 0;
  40852. + u8 c;
  40853. + u16 uchar;
  40854. +
  40855. + /* this insists on correct encodings, though not minimal ones.
  40856. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  40857. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  40858. + */
  40859. + while (len != 0 && (c = (u8) *s++) != 0) {
  40860. + if (unlikely(c & 0x80)) {
  40861. + // 2-byte sequence:
  40862. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  40863. + if ((c & 0xe0) == 0xc0) {
  40864. + uchar = (c & 0x1f) << 6;
  40865. +
  40866. + c = (u8) *s++;
  40867. + if ((c & 0xc0) != 0xc0)
  40868. + goto fail;
  40869. + c &= 0x3f;
  40870. + uchar |= c;
  40871. +
  40872. + // 3-byte sequence (most CJKV characters):
  40873. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  40874. + } else if ((c & 0xf0) == 0xe0) {
  40875. + uchar = (c & 0x0f) << 12;
  40876. +
  40877. + c = (u8) *s++;
  40878. + if ((c & 0xc0) != 0xc0)
  40879. + goto fail;
  40880. + c &= 0x3f;
  40881. + uchar |= c << 6;
  40882. +
  40883. + c = (u8) *s++;
  40884. + if ((c & 0xc0) != 0xc0)
  40885. + goto fail;
  40886. + c &= 0x3f;
  40887. + uchar |= c;
  40888. +
  40889. + /* no bogus surrogates */
  40890. + if (0xd800 <= uchar && uchar <= 0xdfff)
  40891. + goto fail;
  40892. +
  40893. + // 4-byte sequence (surrogate pairs, currently rare):
  40894. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  40895. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  40896. + // (uuuuu = wwww + 1)
  40897. + // FIXME accept the surrogate code points (only)
  40898. + } else
  40899. + goto fail;
  40900. + } else
  40901. + uchar = c;
  40902. + put_unaligned (cpu_to_le16 (uchar), cp++);
  40903. + count++;
  40904. + len--;
  40905. + }
  40906. + return count;
  40907. +fail:
  40908. + return -1;
  40909. +}
  40910. +#endif /* DWC_UTFLIB */
  40911. +
  40912. +
  40913. +/* dwc_debug.h */
  40914. +
  40915. +dwc_bool_t DWC_IN_IRQ(void)
  40916. +{
  40917. + return in_irq();
  40918. +}
  40919. +
  40920. +dwc_bool_t DWC_IN_BH(void)
  40921. +{
  40922. + return in_softirq();
  40923. +}
  40924. +
  40925. +void DWC_VPRINTF(char *format, va_list args)
  40926. +{
  40927. + vprintk(format, args);
  40928. +}
  40929. +
  40930. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  40931. +{
  40932. + return vsnprintf(str, size, format, args);
  40933. +}
  40934. +
  40935. +void DWC_PRINTF(char *format, ...)
  40936. +{
  40937. + va_list args;
  40938. +
  40939. + va_start(args, format);
  40940. + DWC_VPRINTF(format, args);
  40941. + va_end(args);
  40942. +}
  40943. +
  40944. +int DWC_SPRINTF(char *buffer, char *format, ...)
  40945. +{
  40946. + int retval;
  40947. + va_list args;
  40948. +
  40949. + va_start(args, format);
  40950. + retval = vsprintf(buffer, format, args);
  40951. + va_end(args);
  40952. + return retval;
  40953. +}
  40954. +
  40955. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  40956. +{
  40957. + int retval;
  40958. + va_list args;
  40959. +
  40960. + va_start(args, format);
  40961. + retval = vsnprintf(buffer, size, format, args);
  40962. + va_end(args);
  40963. + return retval;
  40964. +}
  40965. +
  40966. +void __DWC_WARN(char *format, ...)
  40967. +{
  40968. + va_list args;
  40969. +
  40970. + va_start(args, format);
  40971. + DWC_PRINTF(KERN_WARNING);
  40972. + DWC_VPRINTF(format, args);
  40973. + va_end(args);
  40974. +}
  40975. +
  40976. +void __DWC_ERROR(char *format, ...)
  40977. +{
  40978. + va_list args;
  40979. +
  40980. + va_start(args, format);
  40981. + DWC_PRINTF(KERN_ERR);
  40982. + DWC_VPRINTF(format, args);
  40983. + va_end(args);
  40984. +}
  40985. +
  40986. +void DWC_EXCEPTION(char *format, ...)
  40987. +{
  40988. + va_list args;
  40989. +
  40990. + va_start(args, format);
  40991. + DWC_PRINTF(KERN_ERR);
  40992. + DWC_VPRINTF(format, args);
  40993. + va_end(args);
  40994. + BUG_ON(1);
  40995. +}
  40996. +
  40997. +#ifdef DEBUG
  40998. +void __DWC_DEBUG(char *format, ...)
  40999. +{
  41000. + va_list args;
  41001. +
  41002. + va_start(args, format);
  41003. + DWC_PRINTF(KERN_DEBUG);
  41004. + DWC_VPRINTF(format, args);
  41005. + va_end(args);
  41006. +}
  41007. +#endif
  41008. +
  41009. +
  41010. +/* dwc_mem.h */
  41011. +
  41012. +#if 0
  41013. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  41014. + uint32_t align,
  41015. + uint32_t alloc)
  41016. +{
  41017. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  41018. + size, align, alloc);
  41019. + return (dwc_pool_t *)pool;
  41020. +}
  41021. +
  41022. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  41023. +{
  41024. + dma_pool_destroy((struct dma_pool *)pool);
  41025. +}
  41026. +
  41027. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41028. +{
  41029. + return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  41030. +}
  41031. +
  41032. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  41033. +{
  41034. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  41035. + memset(..);
  41036. +}
  41037. +
  41038. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  41039. +{
  41040. + dma_pool_free(pool, vaddr, daddr);
  41041. +}
  41042. +#endif
  41043. +
  41044. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41045. +{
  41046. +#ifdef xxCOSIM /* Only works for 32-bit cosim */
  41047. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL);
  41048. +#else
  41049. + void *buf = dma_alloc_coherent(dma_ctx, (size_t)size, dma_addr, GFP_KERNEL | GFP_DMA32);
  41050. +#endif
  41051. + if (!buf) {
  41052. + return NULL;
  41053. + }
  41054. +
  41055. + memset(buf, 0, (size_t)size);
  41056. + return buf;
  41057. +}
  41058. +
  41059. +void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  41060. +{
  41061. + void *buf = dma_alloc_coherent(NULL, (size_t)size, dma_addr, GFP_ATOMIC);
  41062. + if (!buf) {
  41063. + return NULL;
  41064. + }
  41065. + memset(buf, 0, (size_t)size);
  41066. + return buf;
  41067. +}
  41068. +
  41069. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  41070. +{
  41071. + dma_free_coherent(dma_ctx, size, virt_addr, dma_addr);
  41072. +}
  41073. +
  41074. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  41075. +{
  41076. + return kzalloc(size, GFP_KERNEL);
  41077. +}
  41078. +
  41079. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  41080. +{
  41081. + return kzalloc(size, GFP_ATOMIC);
  41082. +}
  41083. +
  41084. +void __DWC_FREE(void *mem_ctx, void *addr)
  41085. +{
  41086. + kfree(addr);
  41087. +}
  41088. +
  41089. +
  41090. +#ifdef DWC_CRYPTOLIB
  41091. +/* dwc_crypto.h */
  41092. +
  41093. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  41094. +{
  41095. + get_random_bytes(buffer, length);
  41096. +}
  41097. +
  41098. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  41099. +{
  41100. + struct crypto_blkcipher *tfm;
  41101. + struct blkcipher_desc desc;
  41102. + struct scatterlist sgd;
  41103. + struct scatterlist sgs;
  41104. +
  41105. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  41106. + if (tfm == NULL) {
  41107. + printk("failed to load transform for aes CBC\n");
  41108. + return -1;
  41109. + }
  41110. +
  41111. + crypto_blkcipher_setkey(tfm, key, keylen);
  41112. + crypto_blkcipher_set_iv(tfm, iv, 16);
  41113. +
  41114. + sg_init_one(&sgd, out, messagelen);
  41115. + sg_init_one(&sgs, message, messagelen);
  41116. +
  41117. + desc.tfm = tfm;
  41118. + desc.flags = 0;
  41119. +
  41120. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  41121. + crypto_free_blkcipher(tfm);
  41122. + DWC_ERROR("AES CBC encryption failed");
  41123. + return -1;
  41124. + }
  41125. +
  41126. + crypto_free_blkcipher(tfm);
  41127. + return 0;
  41128. +}
  41129. +
  41130. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  41131. +{
  41132. + struct crypto_hash *tfm;
  41133. + struct hash_desc desc;
  41134. + struct scatterlist sg;
  41135. +
  41136. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  41137. + if (IS_ERR(tfm)) {
  41138. + DWC_ERROR("Failed to load transform for sha256: %ld\n", PTR_ERR(tfm));
  41139. + return 0;
  41140. + }
  41141. + desc.tfm = tfm;
  41142. + desc.flags = 0;
  41143. +
  41144. + sg_init_one(&sg, message, len);
  41145. + crypto_hash_digest(&desc, &sg, len, out);
  41146. + crypto_free_hash(tfm);
  41147. +
  41148. + return 1;
  41149. +}
  41150. +
  41151. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  41152. + uint8_t *key, uint32_t keylen, uint8_t *out)
  41153. +{
  41154. + struct crypto_hash *tfm;
  41155. + struct hash_desc desc;
  41156. + struct scatterlist sg;
  41157. +
  41158. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  41159. + if (IS_ERR(tfm)) {
  41160. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld\n", PTR_ERR(tfm));
  41161. + return 0;
  41162. + }
  41163. + desc.tfm = tfm;
  41164. + desc.flags = 0;
  41165. +
  41166. + sg_init_one(&sg, message, messagelen);
  41167. + crypto_hash_setkey(tfm, key, keylen);
  41168. + crypto_hash_digest(&desc, &sg, messagelen, out);
  41169. + crypto_free_hash(tfm);
  41170. +
  41171. + return 1;
  41172. +}
  41173. +#endif /* DWC_CRYPTOLIB */
  41174. +
  41175. +
  41176. +/* Byte Ordering Conversions */
  41177. +
  41178. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  41179. +{
  41180. +#ifdef __LITTLE_ENDIAN
  41181. + return *p;
  41182. +#else
  41183. + uint8_t *u_p = (uint8_t *)p;
  41184. +
  41185. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41186. +#endif
  41187. +}
  41188. +
  41189. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  41190. +{
  41191. +#ifdef __BIG_ENDIAN
  41192. + return *p;
  41193. +#else
  41194. + uint8_t *u_p = (uint8_t *)p;
  41195. +
  41196. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41197. +#endif
  41198. +}
  41199. +
  41200. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  41201. +{
  41202. +#ifdef __LITTLE_ENDIAN
  41203. + return *p;
  41204. +#else
  41205. + uint8_t *u_p = (uint8_t *)p;
  41206. +
  41207. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41208. +#endif
  41209. +}
  41210. +
  41211. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  41212. +{
  41213. +#ifdef __BIG_ENDIAN
  41214. + return *p;
  41215. +#else
  41216. + uint8_t *u_p = (uint8_t *)p;
  41217. +
  41218. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  41219. +#endif
  41220. +}
  41221. +
  41222. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  41223. +{
  41224. +#ifdef __LITTLE_ENDIAN
  41225. + return *p;
  41226. +#else
  41227. + uint8_t *u_p = (uint8_t *)p;
  41228. + return (u_p[1] | (u_p[0] << 8));
  41229. +#endif
  41230. +}
  41231. +
  41232. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  41233. +{
  41234. +#ifdef __BIG_ENDIAN
  41235. + return *p;
  41236. +#else
  41237. + uint8_t *u_p = (uint8_t *)p;
  41238. + return (u_p[1] | (u_p[0] << 8));
  41239. +#endif
  41240. +}
  41241. +
  41242. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  41243. +{
  41244. +#ifdef __LITTLE_ENDIAN
  41245. + return *p;
  41246. +#else
  41247. + uint8_t *u_p = (uint8_t *)p;
  41248. + return (u_p[1] | (u_p[0] << 8));
  41249. +#endif
  41250. +}
  41251. +
  41252. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  41253. +{
  41254. +#ifdef __BIG_ENDIAN
  41255. + return *p;
  41256. +#else
  41257. + uint8_t *u_p = (uint8_t *)p;
  41258. + return (u_p[1] | (u_p[0] << 8));
  41259. +#endif
  41260. +}
  41261. +
  41262. +
  41263. +/* Registers */
  41264. +
  41265. +uint32_t DWC_READ_REG32(uint32_t volatile *reg)
  41266. +{
  41267. + return readl(reg);
  41268. +}
  41269. +
  41270. +#if 0
  41271. +uint64_t DWC_READ_REG64(uint64_t volatile *reg)
  41272. +{
  41273. +}
  41274. +#endif
  41275. +
  41276. +void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value)
  41277. +{
  41278. + writel(value, reg);
  41279. +}
  41280. +
  41281. +#if 0
  41282. +void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value)
  41283. +{
  41284. +}
  41285. +#endif
  41286. +
  41287. +void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask)
  41288. +{
  41289. + unsigned long flags;
  41290. +
  41291. + local_irq_save(flags);
  41292. + local_fiq_disable();
  41293. + writel((readl(reg) & ~clear_mask) | set_mask, reg);
  41294. + local_fiq_enable();
  41295. + local_irq_restore(flags);
  41296. +}
  41297. +
  41298. +#if 0
  41299. +void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask)
  41300. +{
  41301. +}
  41302. +#endif
  41303. +
  41304. +
  41305. +/* Locking */
  41306. +
  41307. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  41308. +{
  41309. + spinlock_t *sl = (spinlock_t *)1;
  41310. +
  41311. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41312. + sl = DWC_ALLOC(sizeof(*sl));
  41313. + if (!sl) {
  41314. + DWC_ERROR("Cannot allocate memory for spinlock\n");
  41315. + return NULL;
  41316. + }
  41317. +
  41318. + spin_lock_init(sl);
  41319. +#endif
  41320. + return (dwc_spinlock_t *)sl;
  41321. +}
  41322. +
  41323. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  41324. +{
  41325. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41326. + DWC_FREE(lock);
  41327. +#endif
  41328. +}
  41329. +
  41330. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  41331. +{
  41332. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41333. + spin_lock((spinlock_t *)lock);
  41334. +#endif
  41335. +}
  41336. +
  41337. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  41338. +{
  41339. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41340. + spin_unlock((spinlock_t *)lock);
  41341. +#endif
  41342. +}
  41343. +
  41344. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  41345. +{
  41346. + dwc_irqflags_t f;
  41347. +
  41348. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41349. + spin_lock_irqsave((spinlock_t *)lock, f);
  41350. +#else
  41351. + local_irq_save(f);
  41352. +#endif
  41353. + *flags = f;
  41354. +}
  41355. +
  41356. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  41357. +{
  41358. +#if defined(CONFIG_PREEMPT) || defined(CONFIG_SMP)
  41359. + spin_unlock_irqrestore((spinlock_t *)lock, flags);
  41360. +#else
  41361. + local_irq_restore(flags);
  41362. +#endif
  41363. +}
  41364. +
  41365. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  41366. +{
  41367. + struct mutex *m;
  41368. + dwc_mutex_t *mutex = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex));
  41369. +
  41370. + if (!mutex) {
  41371. + DWC_ERROR("Cannot allocate memory for mutex\n");
  41372. + return NULL;
  41373. + }
  41374. +
  41375. + m = (struct mutex *)mutex;
  41376. + mutex_init(m);
  41377. + return mutex;
  41378. +}
  41379. +
  41380. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  41381. +#else
  41382. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  41383. +{
  41384. + mutex_destroy((struct mutex *)mutex);
  41385. + DWC_FREE(mutex);
  41386. +}
  41387. +#endif
  41388. +
  41389. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  41390. +{
  41391. + struct mutex *m = (struct mutex *)mutex;
  41392. + mutex_lock(m);
  41393. +}
  41394. +
  41395. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  41396. +{
  41397. + struct mutex *m = (struct mutex *)mutex;
  41398. + return mutex_trylock(m);
  41399. +}
  41400. +
  41401. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  41402. +{
  41403. + struct mutex *m = (struct mutex *)mutex;
  41404. + mutex_unlock(m);
  41405. +}
  41406. +
  41407. +
  41408. +/* Timing */
  41409. +
  41410. +void DWC_UDELAY(uint32_t usecs)
  41411. +{
  41412. + udelay(usecs);
  41413. +}
  41414. +
  41415. +void DWC_MDELAY(uint32_t msecs)
  41416. +{
  41417. + mdelay(msecs);
  41418. +}
  41419. +
  41420. +void DWC_MSLEEP(uint32_t msecs)
  41421. +{
  41422. + msleep(msecs);
  41423. +}
  41424. +
  41425. +uint32_t DWC_TIME(void)
  41426. +{
  41427. + return jiffies_to_msecs(jiffies);
  41428. +}
  41429. +
  41430. +
  41431. +/* Timers */
  41432. +
  41433. +struct dwc_timer {
  41434. + struct timer_list *t;
  41435. + char *name;
  41436. + dwc_timer_callback_t cb;
  41437. + void *data;
  41438. + uint8_t scheduled;
  41439. + dwc_spinlock_t *lock;
  41440. +};
  41441. +
  41442. +static void timer_callback(unsigned long data)
  41443. +{
  41444. + dwc_timer_t *timer = (dwc_timer_t *)data;
  41445. + dwc_irqflags_t flags;
  41446. +
  41447. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41448. + timer->scheduled = 0;
  41449. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41450. + DWC_DEBUGC("Timer %s callback", timer->name);
  41451. + timer->cb(timer->data);
  41452. +}
  41453. +
  41454. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  41455. +{
  41456. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  41457. +
  41458. + if (!t) {
  41459. + DWC_ERROR("Cannot allocate memory for timer");
  41460. + return NULL;
  41461. + }
  41462. +
  41463. + t->t = DWC_ALLOC(sizeof(*t->t));
  41464. + if (!t->t) {
  41465. + DWC_ERROR("Cannot allocate memory for timer->t");
  41466. + goto no_timer;
  41467. + }
  41468. +
  41469. + t->name = DWC_STRDUP(name);
  41470. + if (!t->name) {
  41471. + DWC_ERROR("Cannot allocate memory for timer->name");
  41472. + goto no_name;
  41473. + }
  41474. +
  41475. + t->lock = DWC_SPINLOCK_ALLOC();
  41476. + if (!t->lock) {
  41477. + DWC_ERROR("Cannot allocate memory for lock");
  41478. + goto no_lock;
  41479. + }
  41480. +
  41481. + t->scheduled = 0;
  41482. + t->t->base = &boot_tvec_bases;
  41483. + t->t->expires = jiffies;
  41484. + setup_timer(t->t, timer_callback, (unsigned long)t);
  41485. +
  41486. + t->cb = cb;
  41487. + t->data = data;
  41488. +
  41489. + return t;
  41490. +
  41491. + no_lock:
  41492. + DWC_FREE(t->name);
  41493. + no_name:
  41494. + DWC_FREE(t->t);
  41495. + no_timer:
  41496. + DWC_FREE(t);
  41497. + return NULL;
  41498. +}
  41499. +
  41500. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  41501. +{
  41502. + dwc_irqflags_t flags;
  41503. +
  41504. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41505. +
  41506. + if (timer->scheduled) {
  41507. + del_timer(timer->t);
  41508. + timer->scheduled = 0;
  41509. + }
  41510. +
  41511. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41512. + DWC_SPINLOCK_FREE(timer->lock);
  41513. + DWC_FREE(timer->t);
  41514. + DWC_FREE(timer->name);
  41515. + DWC_FREE(timer);
  41516. +}
  41517. +
  41518. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  41519. +{
  41520. + dwc_irqflags_t flags;
  41521. +
  41522. + DWC_SPINLOCK_IRQSAVE(timer->lock, &flags);
  41523. +
  41524. + if (!timer->scheduled) {
  41525. + timer->scheduled = 1;
  41526. + DWC_DEBUGC("Scheduling timer %s to expire in +%d msec", timer->name, time);
  41527. + timer->t->expires = jiffies + msecs_to_jiffies(time);
  41528. + add_timer(timer->t);
  41529. + } else {
  41530. + DWC_DEBUGC("Modifying timer %s to expire in +%d msec", timer->name, time);
  41531. + mod_timer(timer->t, jiffies + msecs_to_jiffies(time));
  41532. + }
  41533. +
  41534. + DWC_SPINUNLOCK_IRQRESTORE(timer->lock, flags);
  41535. +}
  41536. +
  41537. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  41538. +{
  41539. + del_timer(timer->t);
  41540. +}
  41541. +
  41542. +
  41543. +/* Wait Queues */
  41544. +
  41545. +struct dwc_waitq {
  41546. + wait_queue_head_t queue;
  41547. + int abort;
  41548. +};
  41549. +
  41550. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  41551. +{
  41552. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  41553. +
  41554. + if (!wq) {
  41555. + DWC_ERROR("Cannot allocate memory for waitqueue\n");
  41556. + return NULL;
  41557. + }
  41558. +
  41559. + init_waitqueue_head(&wq->queue);
  41560. + wq->abort = 0;
  41561. + return wq;
  41562. +}
  41563. +
  41564. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  41565. +{
  41566. + DWC_FREE(wq);
  41567. +}
  41568. +
  41569. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  41570. +{
  41571. + int result = wait_event_interruptible(wq->queue,
  41572. + cond(data) || wq->abort);
  41573. + if (result == -ERESTARTSYS) {
  41574. + wq->abort = 0;
  41575. + return -DWC_E_RESTART;
  41576. + }
  41577. +
  41578. + if (wq->abort == 1) {
  41579. + wq->abort = 0;
  41580. + return -DWC_E_ABORT;
  41581. + }
  41582. +
  41583. + wq->abort = 0;
  41584. +
  41585. + if (result == 0) {
  41586. + return 0;
  41587. + }
  41588. +
  41589. + return -DWC_E_UNKNOWN;
  41590. +}
  41591. +
  41592. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  41593. + void *data, int32_t msecs)
  41594. +{
  41595. + int32_t tmsecs;
  41596. + int result = wait_event_interruptible_timeout(wq->queue,
  41597. + cond(data) || wq->abort,
  41598. + msecs_to_jiffies(msecs));
  41599. + if (result == -ERESTARTSYS) {
  41600. + wq->abort = 0;
  41601. + return -DWC_E_RESTART;
  41602. + }
  41603. +
  41604. + if (wq->abort == 1) {
  41605. + wq->abort = 0;
  41606. + return -DWC_E_ABORT;
  41607. + }
  41608. +
  41609. + wq->abort = 0;
  41610. +
  41611. + if (result > 0) {
  41612. + tmsecs = jiffies_to_msecs(result);
  41613. + if (!tmsecs) {
  41614. + return 1;
  41615. + }
  41616. +
  41617. + return tmsecs;
  41618. + }
  41619. +
  41620. + if (result == 0) {
  41621. + return -DWC_E_TIMEOUT;
  41622. + }
  41623. +
  41624. + return -DWC_E_UNKNOWN;
  41625. +}
  41626. +
  41627. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  41628. +{
  41629. + wq->abort = 0;
  41630. + wake_up_interruptible(&wq->queue);
  41631. +}
  41632. +
  41633. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  41634. +{
  41635. + wq->abort = 1;
  41636. + wake_up_interruptible(&wq->queue);
  41637. +}
  41638. +
  41639. +
  41640. +/* Threading */
  41641. +
  41642. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  41643. +{
  41644. + struct task_struct *thread = kthread_run(func, data, name);
  41645. +
  41646. + if (thread == ERR_PTR(-ENOMEM)) {
  41647. + return NULL;
  41648. + }
  41649. +
  41650. + return (dwc_thread_t *)thread;
  41651. +}
  41652. +
  41653. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  41654. +{
  41655. + return kthread_stop((struct task_struct *)thread);
  41656. +}
  41657. +
  41658. +dwc_bool_t DWC_THREAD_SHOULD_STOP(void)
  41659. +{
  41660. + return kthread_should_stop();
  41661. +}
  41662. +
  41663. +
  41664. +/* tasklets
  41665. + - run in interrupt context (cannot sleep)
  41666. + - each tasklet runs on a single CPU
  41667. + - different tasklets can be running simultaneously on different CPUs
  41668. + */
  41669. +struct dwc_tasklet {
  41670. + struct tasklet_struct t;
  41671. + dwc_tasklet_callback_t cb;
  41672. + void *data;
  41673. +};
  41674. +
  41675. +static void tasklet_callback(unsigned long data)
  41676. +{
  41677. + dwc_tasklet_t *t = (dwc_tasklet_t *)data;
  41678. + t->cb(t->data);
  41679. +}
  41680. +
  41681. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  41682. +{
  41683. + dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t));
  41684. +
  41685. + if (t) {
  41686. + t->cb = cb;
  41687. + t->data = data;
  41688. + tasklet_init(&t->t, tasklet_callback, (unsigned long)t);
  41689. + } else {
  41690. + DWC_ERROR("Cannot allocate memory for tasklet\n");
  41691. + }
  41692. +
  41693. + return t;
  41694. +}
  41695. +
  41696. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  41697. +{
  41698. + DWC_FREE(task);
  41699. +}
  41700. +
  41701. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  41702. +{
  41703. + tasklet_schedule(&task->t);
  41704. +}
  41705. +
  41706. +void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task)
  41707. +{
  41708. + tasklet_hi_schedule(&task->t);
  41709. +}
  41710. +
  41711. +
  41712. +/* workqueues
  41713. + - run in process context (can sleep)
  41714. + */
  41715. +typedef struct work_container {
  41716. + dwc_work_callback_t cb;
  41717. + void *data;
  41718. + dwc_workq_t *wq;
  41719. + char *name;
  41720. +
  41721. +#ifdef DEBUG
  41722. + DWC_CIRCLEQ_ENTRY(work_container) entry;
  41723. +#endif
  41724. + struct delayed_work work;
  41725. +} work_container_t;
  41726. +
  41727. +#ifdef DEBUG
  41728. +DWC_CIRCLEQ_HEAD(work_container_queue, work_container);
  41729. +#endif
  41730. +
  41731. +struct dwc_workq {
  41732. + struct workqueue_struct *wq;
  41733. + dwc_spinlock_t *lock;
  41734. + dwc_waitq_t *waitq;
  41735. + int pending;
  41736. +
  41737. +#ifdef DEBUG
  41738. + struct work_container_queue entries;
  41739. +#endif
  41740. +};
  41741. +
  41742. +static void do_work(struct work_struct *work)
  41743. +{
  41744. + dwc_irqflags_t flags;
  41745. + struct delayed_work *dw = container_of(work, struct delayed_work, work);
  41746. + work_container_t *container = container_of(dw, struct work_container, work);
  41747. + dwc_workq_t *wq = container->wq;
  41748. +
  41749. + container->cb(container->data);
  41750. +
  41751. +#ifdef DEBUG
  41752. + DWC_CIRCLEQ_REMOVE(&wq->entries, container, entry);
  41753. +#endif
  41754. + DWC_DEBUGC("Work done: %s, container=%p", container->name, container);
  41755. + if (container->name) {
  41756. + DWC_FREE(container->name);
  41757. + }
  41758. + DWC_FREE(container);
  41759. +
  41760. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41761. + wq->pending--;
  41762. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41763. + DWC_WAITQ_TRIGGER(wq->waitq);
  41764. +}
  41765. +
  41766. +static int work_done(void *data)
  41767. +{
  41768. + dwc_workq_t *workq = (dwc_workq_t *)data;
  41769. + return workq->pending == 0;
  41770. +}
  41771. +
  41772. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  41773. +{
  41774. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  41775. +}
  41776. +
  41777. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  41778. +{
  41779. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  41780. +
  41781. + if (!wq) {
  41782. + return NULL;
  41783. + }
  41784. +
  41785. + wq->wq = create_singlethread_workqueue(name);
  41786. + if (!wq->wq) {
  41787. + goto no_wq;
  41788. + }
  41789. +
  41790. + wq->pending = 0;
  41791. +
  41792. + wq->lock = DWC_SPINLOCK_ALLOC();
  41793. + if (!wq->lock) {
  41794. + goto no_lock;
  41795. + }
  41796. +
  41797. + wq->waitq = DWC_WAITQ_ALLOC();
  41798. + if (!wq->waitq) {
  41799. + goto no_waitq;
  41800. + }
  41801. +
  41802. +#ifdef DEBUG
  41803. + DWC_CIRCLEQ_INIT(&wq->entries);
  41804. +#endif
  41805. + return wq;
  41806. +
  41807. + no_waitq:
  41808. + DWC_SPINLOCK_FREE(wq->lock);
  41809. + no_lock:
  41810. + destroy_workqueue(wq->wq);
  41811. + no_wq:
  41812. + DWC_FREE(wq);
  41813. +
  41814. + return NULL;
  41815. +}
  41816. +
  41817. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  41818. +{
  41819. +#ifdef DEBUG
  41820. + if (wq->pending != 0) {
  41821. + struct work_container *wc;
  41822. + DWC_ERROR("Destroying work queue with pending work");
  41823. + DWC_CIRCLEQ_FOREACH(wc, &wq->entries, entry) {
  41824. + DWC_ERROR("Work %s still pending", wc->name);
  41825. + }
  41826. + }
  41827. +#endif
  41828. + destroy_workqueue(wq->wq);
  41829. + DWC_SPINLOCK_FREE(wq->lock);
  41830. + DWC_WAITQ_FREE(wq->waitq);
  41831. + DWC_FREE(wq);
  41832. +}
  41833. +
  41834. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  41835. + char *format, ...)
  41836. +{
  41837. + dwc_irqflags_t flags;
  41838. + work_container_t *container;
  41839. + static char name[128];
  41840. + va_list args;
  41841. +
  41842. + va_start(args, format);
  41843. + DWC_VSNPRINTF(name, 128, format, args);
  41844. + va_end(args);
  41845. +
  41846. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41847. + wq->pending++;
  41848. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41849. + DWC_WAITQ_TRIGGER(wq->waitq);
  41850. +
  41851. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41852. + if (!container) {
  41853. + DWC_ERROR("Cannot allocate memory for container\n");
  41854. + return;
  41855. + }
  41856. +
  41857. + container->name = DWC_STRDUP(name);
  41858. + if (!container->name) {
  41859. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41860. + DWC_FREE(container);
  41861. + return;
  41862. + }
  41863. +
  41864. + container->cb = cb;
  41865. + container->data = data;
  41866. + container->wq = wq;
  41867. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41868. + INIT_WORK(&container->work.work, do_work);
  41869. +
  41870. +#ifdef DEBUG
  41871. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41872. +#endif
  41873. + queue_work(wq->wq, &container->work.work);
  41874. +}
  41875. +
  41876. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  41877. + void *data, uint32_t time, char *format, ...)
  41878. +{
  41879. + dwc_irqflags_t flags;
  41880. + work_container_t *container;
  41881. + static char name[128];
  41882. + va_list args;
  41883. +
  41884. + va_start(args, format);
  41885. + DWC_VSNPRINTF(name, 128, format, args);
  41886. + va_end(args);
  41887. +
  41888. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  41889. + wq->pending++;
  41890. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  41891. + DWC_WAITQ_TRIGGER(wq->waitq);
  41892. +
  41893. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  41894. + if (!container) {
  41895. + DWC_ERROR("Cannot allocate memory for container\n");
  41896. + return;
  41897. + }
  41898. +
  41899. + container->name = DWC_STRDUP(name);
  41900. + if (!container->name) {
  41901. + DWC_ERROR("Cannot allocate memory for container->name\n");
  41902. + DWC_FREE(container);
  41903. + return;
  41904. + }
  41905. +
  41906. + container->cb = cb;
  41907. + container->data = data;
  41908. + container->wq = wq;
  41909. + DWC_DEBUGC("Queueing work: %s, container=%p", container->name, container);
  41910. + INIT_DELAYED_WORK(&container->work, do_work);
  41911. +
  41912. +#ifdef DEBUG
  41913. + DWC_CIRCLEQ_INSERT_TAIL(&wq->entries, container, entry);
  41914. +#endif
  41915. + queue_delayed_work(wq->wq, &container->work, msecs_to_jiffies(time));
  41916. +}
  41917. +
  41918. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  41919. +{
  41920. + return wq->pending;
  41921. +}
  41922. +
  41923. +
  41924. +#ifdef DWC_LIBMODULE
  41925. +
  41926. +#ifdef DWC_CCLIB
  41927. +/* CC */
  41928. +EXPORT_SYMBOL(dwc_cc_if_alloc);
  41929. +EXPORT_SYMBOL(dwc_cc_if_free);
  41930. +EXPORT_SYMBOL(dwc_cc_clear);
  41931. +EXPORT_SYMBOL(dwc_cc_add);
  41932. +EXPORT_SYMBOL(dwc_cc_remove);
  41933. +EXPORT_SYMBOL(dwc_cc_change);
  41934. +EXPORT_SYMBOL(dwc_cc_data_for_save);
  41935. +EXPORT_SYMBOL(dwc_cc_restore_from_data);
  41936. +EXPORT_SYMBOL(dwc_cc_match_chid);
  41937. +EXPORT_SYMBOL(dwc_cc_match_cdid);
  41938. +EXPORT_SYMBOL(dwc_cc_ck);
  41939. +EXPORT_SYMBOL(dwc_cc_chid);
  41940. +EXPORT_SYMBOL(dwc_cc_cdid);
  41941. +EXPORT_SYMBOL(dwc_cc_name);
  41942. +#endif /* DWC_CCLIB */
  41943. +
  41944. +#ifdef DWC_CRYPTOLIB
  41945. +# ifndef CONFIG_MACH_IPMATE
  41946. +/* Modpow */
  41947. +EXPORT_SYMBOL(dwc_modpow);
  41948. +
  41949. +/* DH */
  41950. +EXPORT_SYMBOL(dwc_dh_modpow);
  41951. +EXPORT_SYMBOL(dwc_dh_derive_keys);
  41952. +EXPORT_SYMBOL(dwc_dh_pk);
  41953. +# endif /* CONFIG_MACH_IPMATE */
  41954. +
  41955. +/* Crypto */
  41956. +EXPORT_SYMBOL(dwc_wusb_aes_encrypt);
  41957. +EXPORT_SYMBOL(dwc_wusb_cmf);
  41958. +EXPORT_SYMBOL(dwc_wusb_prf);
  41959. +EXPORT_SYMBOL(dwc_wusb_fill_ccm_nonce);
  41960. +EXPORT_SYMBOL(dwc_wusb_gen_nonce);
  41961. +EXPORT_SYMBOL(dwc_wusb_gen_key);
  41962. +EXPORT_SYMBOL(dwc_wusb_gen_mic);
  41963. +#endif /* DWC_CRYPTOLIB */
  41964. +
  41965. +/* Notification */
  41966. +#ifdef DWC_NOTIFYLIB
  41967. +EXPORT_SYMBOL(dwc_alloc_notification_manager);
  41968. +EXPORT_SYMBOL(dwc_free_notification_manager);
  41969. +EXPORT_SYMBOL(dwc_register_notifier);
  41970. +EXPORT_SYMBOL(dwc_unregister_notifier);
  41971. +EXPORT_SYMBOL(dwc_add_observer);
  41972. +EXPORT_SYMBOL(dwc_remove_observer);
  41973. +EXPORT_SYMBOL(dwc_notify);
  41974. +#endif
  41975. +
  41976. +/* Memory Debugging Routines */
  41977. +#ifdef DWC_DEBUG_MEMORY
  41978. +EXPORT_SYMBOL(dwc_alloc_debug);
  41979. +EXPORT_SYMBOL(dwc_alloc_atomic_debug);
  41980. +EXPORT_SYMBOL(dwc_free_debug);
  41981. +EXPORT_SYMBOL(dwc_dma_alloc_debug);
  41982. +EXPORT_SYMBOL(dwc_dma_free_debug);
  41983. +#endif
  41984. +
  41985. +EXPORT_SYMBOL(DWC_MEMSET);
  41986. +EXPORT_SYMBOL(DWC_MEMCPY);
  41987. +EXPORT_SYMBOL(DWC_MEMMOVE);
  41988. +EXPORT_SYMBOL(DWC_MEMCMP);
  41989. +EXPORT_SYMBOL(DWC_STRNCMP);
  41990. +EXPORT_SYMBOL(DWC_STRCMP);
  41991. +EXPORT_SYMBOL(DWC_STRLEN);
  41992. +EXPORT_SYMBOL(DWC_STRCPY);
  41993. +EXPORT_SYMBOL(DWC_STRDUP);
  41994. +EXPORT_SYMBOL(DWC_ATOI);
  41995. +EXPORT_SYMBOL(DWC_ATOUI);
  41996. +
  41997. +#ifdef DWC_UTFLIB
  41998. +EXPORT_SYMBOL(DWC_UTF8_TO_UTF16LE);
  41999. +#endif /* DWC_UTFLIB */
  42000. +
  42001. +EXPORT_SYMBOL(DWC_IN_IRQ);
  42002. +EXPORT_SYMBOL(DWC_IN_BH);
  42003. +EXPORT_SYMBOL(DWC_VPRINTF);
  42004. +EXPORT_SYMBOL(DWC_VSNPRINTF);
  42005. +EXPORT_SYMBOL(DWC_PRINTF);
  42006. +EXPORT_SYMBOL(DWC_SPRINTF);
  42007. +EXPORT_SYMBOL(DWC_SNPRINTF);
  42008. +EXPORT_SYMBOL(__DWC_WARN);
  42009. +EXPORT_SYMBOL(__DWC_ERROR);
  42010. +EXPORT_SYMBOL(DWC_EXCEPTION);
  42011. +
  42012. +#ifdef DEBUG
  42013. +EXPORT_SYMBOL(__DWC_DEBUG);
  42014. +#endif
  42015. +
  42016. +EXPORT_SYMBOL(__DWC_DMA_ALLOC);
  42017. +EXPORT_SYMBOL(__DWC_DMA_ALLOC_ATOMIC);
  42018. +EXPORT_SYMBOL(__DWC_DMA_FREE);
  42019. +EXPORT_SYMBOL(__DWC_ALLOC);
  42020. +EXPORT_SYMBOL(__DWC_ALLOC_ATOMIC);
  42021. +EXPORT_SYMBOL(__DWC_FREE);
  42022. +
  42023. +#ifdef DWC_CRYPTOLIB
  42024. +EXPORT_SYMBOL(DWC_RANDOM_BYTES);
  42025. +EXPORT_SYMBOL(DWC_AES_CBC);
  42026. +EXPORT_SYMBOL(DWC_SHA256);
  42027. +EXPORT_SYMBOL(DWC_HMAC_SHA256);
  42028. +#endif
  42029. +
  42030. +EXPORT_SYMBOL(DWC_CPU_TO_LE32);
  42031. +EXPORT_SYMBOL(DWC_CPU_TO_BE32);
  42032. +EXPORT_SYMBOL(DWC_LE32_TO_CPU);
  42033. +EXPORT_SYMBOL(DWC_BE32_TO_CPU);
  42034. +EXPORT_SYMBOL(DWC_CPU_TO_LE16);
  42035. +EXPORT_SYMBOL(DWC_CPU_TO_BE16);
  42036. +EXPORT_SYMBOL(DWC_LE16_TO_CPU);
  42037. +EXPORT_SYMBOL(DWC_BE16_TO_CPU);
  42038. +EXPORT_SYMBOL(DWC_READ_REG32);
  42039. +EXPORT_SYMBOL(DWC_WRITE_REG32);
  42040. +EXPORT_SYMBOL(DWC_MODIFY_REG32);
  42041. +
  42042. +#if 0
  42043. +EXPORT_SYMBOL(DWC_READ_REG64);
  42044. +EXPORT_SYMBOL(DWC_WRITE_REG64);
  42045. +EXPORT_SYMBOL(DWC_MODIFY_REG64);
  42046. +#endif
  42047. +
  42048. +EXPORT_SYMBOL(DWC_SPINLOCK_ALLOC);
  42049. +EXPORT_SYMBOL(DWC_SPINLOCK_FREE);
  42050. +EXPORT_SYMBOL(DWC_SPINLOCK);
  42051. +EXPORT_SYMBOL(DWC_SPINUNLOCK);
  42052. +EXPORT_SYMBOL(DWC_SPINLOCK_IRQSAVE);
  42053. +EXPORT_SYMBOL(DWC_SPINUNLOCK_IRQRESTORE);
  42054. +EXPORT_SYMBOL(DWC_MUTEX_ALLOC);
  42055. +
  42056. +#if (!defined(DWC_LINUX) || !defined(CONFIG_DEBUG_MUTEXES))
  42057. +EXPORT_SYMBOL(DWC_MUTEX_FREE);
  42058. +#endif
  42059. +
  42060. +EXPORT_SYMBOL(DWC_MUTEX_LOCK);
  42061. +EXPORT_SYMBOL(DWC_MUTEX_TRYLOCK);
  42062. +EXPORT_SYMBOL(DWC_MUTEX_UNLOCK);
  42063. +EXPORT_SYMBOL(DWC_UDELAY);
  42064. +EXPORT_SYMBOL(DWC_MDELAY);
  42065. +EXPORT_SYMBOL(DWC_MSLEEP);
  42066. +EXPORT_SYMBOL(DWC_TIME);
  42067. +EXPORT_SYMBOL(DWC_TIMER_ALLOC);
  42068. +EXPORT_SYMBOL(DWC_TIMER_FREE);
  42069. +EXPORT_SYMBOL(DWC_TIMER_SCHEDULE);
  42070. +EXPORT_SYMBOL(DWC_TIMER_CANCEL);
  42071. +EXPORT_SYMBOL(DWC_WAITQ_ALLOC);
  42072. +EXPORT_SYMBOL(DWC_WAITQ_FREE);
  42073. +EXPORT_SYMBOL(DWC_WAITQ_WAIT);
  42074. +EXPORT_SYMBOL(DWC_WAITQ_WAIT_TIMEOUT);
  42075. +EXPORT_SYMBOL(DWC_WAITQ_TRIGGER);
  42076. +EXPORT_SYMBOL(DWC_WAITQ_ABORT);
  42077. +EXPORT_SYMBOL(DWC_THREAD_RUN);
  42078. +EXPORT_SYMBOL(DWC_THREAD_STOP);
  42079. +EXPORT_SYMBOL(DWC_THREAD_SHOULD_STOP);
  42080. +EXPORT_SYMBOL(DWC_TASK_ALLOC);
  42081. +EXPORT_SYMBOL(DWC_TASK_FREE);
  42082. +EXPORT_SYMBOL(DWC_TASK_SCHEDULE);
  42083. +EXPORT_SYMBOL(DWC_WORKQ_WAIT_WORK_DONE);
  42084. +EXPORT_SYMBOL(DWC_WORKQ_ALLOC);
  42085. +EXPORT_SYMBOL(DWC_WORKQ_FREE);
  42086. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE);
  42087. +EXPORT_SYMBOL(DWC_WORKQ_SCHEDULE_DELAYED);
  42088. +EXPORT_SYMBOL(DWC_WORKQ_PENDING);
  42089. +
  42090. +static int dwc_common_port_init_module(void)
  42091. +{
  42092. + int result = 0;
  42093. +
  42094. + printk(KERN_DEBUG "Module dwc_common_port init\n" );
  42095. +
  42096. +#ifdef DWC_DEBUG_MEMORY
  42097. + result = dwc_memory_debug_start(NULL);
  42098. + if (result) {
  42099. + printk(KERN_ERR
  42100. + "dwc_memory_debug_start() failed with error %d\n",
  42101. + result);
  42102. + return result;
  42103. + }
  42104. +#endif
  42105. +
  42106. +#ifdef DWC_NOTIFYLIB
  42107. + result = dwc_alloc_notification_manager(NULL, NULL);
  42108. + if (result) {
  42109. + printk(KERN_ERR
  42110. + "dwc_alloc_notification_manager() failed with error %d\n",
  42111. + result);
  42112. + return result;
  42113. + }
  42114. +#endif
  42115. + return result;
  42116. +}
  42117. +
  42118. +static void dwc_common_port_exit_module(void)
  42119. +{
  42120. + printk(KERN_DEBUG "Module dwc_common_port exit\n" );
  42121. +
  42122. +#ifdef DWC_NOTIFYLIB
  42123. + dwc_free_notification_manager();
  42124. +#endif
  42125. +
  42126. +#ifdef DWC_DEBUG_MEMORY
  42127. + dwc_memory_debug_stop();
  42128. +#endif
  42129. +}
  42130. +
  42131. +module_init(dwc_common_port_init_module);
  42132. +module_exit(dwc_common_port_exit_module);
  42133. +
  42134. +MODULE_DESCRIPTION("DWC Common Library - Portable version");
  42135. +MODULE_AUTHOR("Synopsys Inc.");
  42136. +MODULE_LICENSE ("GPL");
  42137. +
  42138. +#endif /* DWC_LIBMODULE */
  42139. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c
  42140. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 1970-01-01 01:00:00.000000000 +0100
  42141. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_common_nbsd.c 2014-06-11 21:03:43.000000000 +0200
  42142. @@ -0,0 +1,1275 @@
  42143. +#include "dwc_os.h"
  42144. +#include "dwc_list.h"
  42145. +
  42146. +#ifdef DWC_CCLIB
  42147. +# include "dwc_cc.h"
  42148. +#endif
  42149. +
  42150. +#ifdef DWC_CRYPTOLIB
  42151. +# include "dwc_modpow.h"
  42152. +# include "dwc_dh.h"
  42153. +# include "dwc_crypto.h"
  42154. +#endif
  42155. +
  42156. +#ifdef DWC_NOTIFYLIB
  42157. +# include "dwc_notifier.h"
  42158. +#endif
  42159. +
  42160. +/* OS-Level Implementations */
  42161. +
  42162. +/* This is the NetBSD 4.0.1 kernel implementation of the DWC platform library. */
  42163. +
  42164. +
  42165. +/* MISC */
  42166. +
  42167. +void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size)
  42168. +{
  42169. + return memset(dest, byte, size);
  42170. +}
  42171. +
  42172. +void *DWC_MEMCPY(void *dest, void const *src, uint32_t size)
  42173. +{
  42174. + return memcpy(dest, src, size);
  42175. +}
  42176. +
  42177. +void *DWC_MEMMOVE(void *dest, void *src, uint32_t size)
  42178. +{
  42179. + bcopy(src, dest, size);
  42180. + return dest;
  42181. +}
  42182. +
  42183. +int DWC_MEMCMP(void *m1, void *m2, uint32_t size)
  42184. +{
  42185. + return memcmp(m1, m2, size);
  42186. +}
  42187. +
  42188. +int DWC_STRNCMP(void *s1, void *s2, uint32_t size)
  42189. +{
  42190. + return strncmp(s1, s2, size);
  42191. +}
  42192. +
  42193. +int DWC_STRCMP(void *s1, void *s2)
  42194. +{
  42195. + return strcmp(s1, s2);
  42196. +}
  42197. +
  42198. +int DWC_STRLEN(char const *str)
  42199. +{
  42200. + return strlen(str);
  42201. +}
  42202. +
  42203. +char *DWC_STRCPY(char *to, char const *from)
  42204. +{
  42205. + return strcpy(to, from);
  42206. +}
  42207. +
  42208. +char *DWC_STRDUP(char const *str)
  42209. +{
  42210. + int len = DWC_STRLEN(str) + 1;
  42211. + char *new = DWC_ALLOC_ATOMIC(len);
  42212. +
  42213. + if (!new) {
  42214. + return NULL;
  42215. + }
  42216. +
  42217. + DWC_MEMCPY(new, str, len);
  42218. + return new;
  42219. +}
  42220. +
  42221. +int DWC_ATOI(char *str, int32_t *value)
  42222. +{
  42223. + char *end = NULL;
  42224. +
  42225. + /* NetBSD doesn't have 'strtol' in the kernel, but 'strtoul'
  42226. + * should be equivalent on 2's complement machines
  42227. + */
  42228. + *value = strtoul(str, &end, 0);
  42229. + if (*end == '\0') {
  42230. + return 0;
  42231. + }
  42232. +
  42233. + return -1;
  42234. +}
  42235. +
  42236. +int DWC_ATOUI(char *str, uint32_t *value)
  42237. +{
  42238. + char *end = NULL;
  42239. +
  42240. + *value = strtoul(str, &end, 0);
  42241. + if (*end == '\0') {
  42242. + return 0;
  42243. + }
  42244. +
  42245. + return -1;
  42246. +}
  42247. +
  42248. +
  42249. +#ifdef DWC_UTFLIB
  42250. +/* From usbstring.c */
  42251. +
  42252. +int DWC_UTF8_TO_UTF16LE(uint8_t const *s, uint16_t *cp, unsigned len)
  42253. +{
  42254. + int count = 0;
  42255. + u8 c;
  42256. + u16 uchar;
  42257. +
  42258. + /* this insists on correct encodings, though not minimal ones.
  42259. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  42260. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  42261. + */
  42262. + while (len != 0 && (c = (u8) *s++) != 0) {
  42263. + if (unlikely(c & 0x80)) {
  42264. + // 2-byte sequence:
  42265. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  42266. + if ((c & 0xe0) == 0xc0) {
  42267. + uchar = (c & 0x1f) << 6;
  42268. +
  42269. + c = (u8) *s++;
  42270. + if ((c & 0xc0) != 0xc0)
  42271. + goto fail;
  42272. + c &= 0x3f;
  42273. + uchar |= c;
  42274. +
  42275. + // 3-byte sequence (most CJKV characters):
  42276. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  42277. + } else if ((c & 0xf0) == 0xe0) {
  42278. + uchar = (c & 0x0f) << 12;
  42279. +
  42280. + c = (u8) *s++;
  42281. + if ((c & 0xc0) != 0xc0)
  42282. + goto fail;
  42283. + c &= 0x3f;
  42284. + uchar |= c << 6;
  42285. +
  42286. + c = (u8) *s++;
  42287. + if ((c & 0xc0) != 0xc0)
  42288. + goto fail;
  42289. + c &= 0x3f;
  42290. + uchar |= c;
  42291. +
  42292. + /* no bogus surrogates */
  42293. + if (0xd800 <= uchar && uchar <= 0xdfff)
  42294. + goto fail;
  42295. +
  42296. + // 4-byte sequence (surrogate pairs, currently rare):
  42297. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  42298. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  42299. + // (uuuuu = wwww + 1)
  42300. + // FIXME accept the surrogate code points (only)
  42301. + } else
  42302. + goto fail;
  42303. + } else
  42304. + uchar = c;
  42305. + put_unaligned (cpu_to_le16 (uchar), cp++);
  42306. + count++;
  42307. + len--;
  42308. + }
  42309. + return count;
  42310. +fail:
  42311. + return -1;
  42312. +}
  42313. +
  42314. +#endif /* DWC_UTFLIB */
  42315. +
  42316. +
  42317. +/* dwc_debug.h */
  42318. +
  42319. +dwc_bool_t DWC_IN_IRQ(void)
  42320. +{
  42321. +// return in_irq();
  42322. + return 0;
  42323. +}
  42324. +
  42325. +dwc_bool_t DWC_IN_BH(void)
  42326. +{
  42327. +// return in_softirq();
  42328. + return 0;
  42329. +}
  42330. +
  42331. +void DWC_VPRINTF(char *format, va_list args)
  42332. +{
  42333. + vprintf(format, args);
  42334. +}
  42335. +
  42336. +int DWC_VSNPRINTF(char *str, int size, char *format, va_list args)
  42337. +{
  42338. + return vsnprintf(str, size, format, args);
  42339. +}
  42340. +
  42341. +void DWC_PRINTF(char *format, ...)
  42342. +{
  42343. + va_list args;
  42344. +
  42345. + va_start(args, format);
  42346. + DWC_VPRINTF(format, args);
  42347. + va_end(args);
  42348. +}
  42349. +
  42350. +int DWC_SPRINTF(char *buffer, char *format, ...)
  42351. +{
  42352. + int retval;
  42353. + va_list args;
  42354. +
  42355. + va_start(args, format);
  42356. + retval = vsprintf(buffer, format, args);
  42357. + va_end(args);
  42358. + return retval;
  42359. +}
  42360. +
  42361. +int DWC_SNPRINTF(char *buffer, int size, char *format, ...)
  42362. +{
  42363. + int retval;
  42364. + va_list args;
  42365. +
  42366. + va_start(args, format);
  42367. + retval = vsnprintf(buffer, size, format, args);
  42368. + va_end(args);
  42369. + return retval;
  42370. +}
  42371. +
  42372. +void __DWC_WARN(char *format, ...)
  42373. +{
  42374. + va_list args;
  42375. +
  42376. + va_start(args, format);
  42377. + DWC_VPRINTF(format, args);
  42378. + va_end(args);
  42379. +}
  42380. +
  42381. +void __DWC_ERROR(char *format, ...)
  42382. +{
  42383. + va_list args;
  42384. +
  42385. + va_start(args, format);
  42386. + DWC_VPRINTF(format, args);
  42387. + va_end(args);
  42388. +}
  42389. +
  42390. +void DWC_EXCEPTION(char *format, ...)
  42391. +{
  42392. + va_list args;
  42393. +
  42394. + va_start(args, format);
  42395. + DWC_VPRINTF(format, args);
  42396. + va_end(args);
  42397. +// BUG_ON(1); ???
  42398. +}
  42399. +
  42400. +#ifdef DEBUG
  42401. +void __DWC_DEBUG(char *format, ...)
  42402. +{
  42403. + va_list args;
  42404. +
  42405. + va_start(args, format);
  42406. + DWC_VPRINTF(format, args);
  42407. + va_end(args);
  42408. +}
  42409. +#endif
  42410. +
  42411. +
  42412. +/* dwc_mem.h */
  42413. +
  42414. +#if 0
  42415. +dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size,
  42416. + uint32_t align,
  42417. + uint32_t alloc)
  42418. +{
  42419. + struct dma_pool *pool = dma_pool_create("Pool", NULL,
  42420. + size, align, alloc);
  42421. + return (dwc_pool_t *)pool;
  42422. +}
  42423. +
  42424. +void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool)
  42425. +{
  42426. + dma_pool_destroy((struct dma_pool *)pool);
  42427. +}
  42428. +
  42429. +void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42430. +{
  42431. +// return dma_pool_alloc((struct dma_pool *)pool, GFP_KERNEL, dma_addr);
  42432. + return dma_pool_alloc((struct dma_pool *)pool, M_WAITOK, dma_addr);
  42433. +}
  42434. +
  42435. +void *DWC_DMA_POOL_ZALLOC(dwc_pool_t *pool, uint64_t *dma_addr)
  42436. +{
  42437. + void *vaddr = DWC_DMA_POOL_ALLOC(pool, dma_addr);
  42438. + memset(..);
  42439. +}
  42440. +
  42441. +void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr)
  42442. +{
  42443. + dma_pool_free(pool, vaddr, daddr);
  42444. +}
  42445. +#endif
  42446. +
  42447. +void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr)
  42448. +{
  42449. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42450. + int error;
  42451. +
  42452. + error = bus_dmamem_alloc(dma->dma_tag, size, 1, size, dma->segs,
  42453. + sizeof(dma->segs) / sizeof(dma->segs[0]),
  42454. + &dma->nsegs, BUS_DMA_NOWAIT);
  42455. + if (error) {
  42456. + printf("%s: bus_dmamem_alloc(%ju) failed: %d\n", __func__,
  42457. + (uintmax_t)size, error);
  42458. + goto fail_0;
  42459. + }
  42460. +
  42461. + error = bus_dmamem_map(dma->dma_tag, dma->segs, dma->nsegs, size,
  42462. + (caddr_t *)&dma->dma_vaddr,
  42463. + BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
  42464. + if (error) {
  42465. + printf("%s: bus_dmamem_map failed: %d\n", __func__, error);
  42466. + goto fail_1;
  42467. + }
  42468. +
  42469. + error = bus_dmamap_create(dma->dma_tag, size, 1, size, 0,
  42470. + BUS_DMA_NOWAIT, &dma->dma_map);
  42471. + if (error) {
  42472. + printf("%s: bus_dmamap_create failed: %d\n", __func__, error);
  42473. + goto fail_2;
  42474. + }
  42475. +
  42476. + error = bus_dmamap_load(dma->dma_tag, dma->dma_map, dma->dma_vaddr,
  42477. + size, NULL, BUS_DMA_NOWAIT);
  42478. + if (error) {
  42479. + printf("%s: bus_dmamap_load failed: %d\n", __func__, error);
  42480. + goto fail_3;
  42481. + }
  42482. +
  42483. + dma->dma_paddr = (bus_addr_t)dma->segs[0].ds_addr;
  42484. + *dma_addr = dma->dma_paddr;
  42485. + return dma->dma_vaddr;
  42486. +
  42487. +fail_3:
  42488. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42489. +fail_2:
  42490. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42491. +fail_1:
  42492. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42493. +fail_0:
  42494. + dma->dma_map = NULL;
  42495. + dma->dma_vaddr = NULL;
  42496. + dma->nsegs = 0;
  42497. +
  42498. + return NULL;
  42499. +}
  42500. +
  42501. +void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr)
  42502. +{
  42503. + dwc_dmactx_t *dma = (dwc_dmactx_t *)dma_ctx;
  42504. +
  42505. + if (dma->dma_map != NULL) {
  42506. + bus_dmamap_sync(dma->dma_tag, dma->dma_map, 0, size,
  42507. + BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE);
  42508. + bus_dmamap_unload(dma->dma_tag, dma->dma_map);
  42509. + bus_dmamap_destroy(dma->dma_tag, dma->dma_map);
  42510. + bus_dmamem_unmap(dma->dma_tag, dma->dma_vaddr, size);
  42511. + bus_dmamem_free(dma->dma_tag, dma->segs, dma->nsegs);
  42512. + dma->dma_paddr = 0;
  42513. + dma->dma_map = NULL;
  42514. + dma->dma_vaddr = NULL;
  42515. + dma->nsegs = 0;
  42516. + }
  42517. +}
  42518. +
  42519. +void *__DWC_ALLOC(void *mem_ctx, uint32_t size)
  42520. +{
  42521. + return malloc(size, M_DEVBUF, M_WAITOK | M_ZERO);
  42522. +}
  42523. +
  42524. +void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size)
  42525. +{
  42526. + return malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO);
  42527. +}
  42528. +
  42529. +void __DWC_FREE(void *mem_ctx, void *addr)
  42530. +{
  42531. + free(addr, M_DEVBUF);
  42532. +}
  42533. +
  42534. +
  42535. +#ifdef DWC_CRYPTOLIB
  42536. +/* dwc_crypto.h */
  42537. +
  42538. +void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length)
  42539. +{
  42540. + get_random_bytes(buffer, length);
  42541. +}
  42542. +
  42543. +int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out)
  42544. +{
  42545. + struct crypto_blkcipher *tfm;
  42546. + struct blkcipher_desc desc;
  42547. + struct scatterlist sgd;
  42548. + struct scatterlist sgs;
  42549. +
  42550. + tfm = crypto_alloc_blkcipher("cbc(aes)", 0, CRYPTO_ALG_ASYNC);
  42551. + if (tfm == NULL) {
  42552. + printk("failed to load transform for aes CBC\n");
  42553. + return -1;
  42554. + }
  42555. +
  42556. + crypto_blkcipher_setkey(tfm, key, keylen);
  42557. + crypto_blkcipher_set_iv(tfm, iv, 16);
  42558. +
  42559. + sg_init_one(&sgd, out, messagelen);
  42560. + sg_init_one(&sgs, message, messagelen);
  42561. +
  42562. + desc.tfm = tfm;
  42563. + desc.flags = 0;
  42564. +
  42565. + if (crypto_blkcipher_encrypt(&desc, &sgd, &sgs, messagelen)) {
  42566. + crypto_free_blkcipher(tfm);
  42567. + DWC_ERROR("AES CBC encryption failed");
  42568. + return -1;
  42569. + }
  42570. +
  42571. + crypto_free_blkcipher(tfm);
  42572. + return 0;
  42573. +}
  42574. +
  42575. +int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out)
  42576. +{
  42577. + struct crypto_hash *tfm;
  42578. + struct hash_desc desc;
  42579. + struct scatterlist sg;
  42580. +
  42581. + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
  42582. + if (IS_ERR(tfm)) {
  42583. + DWC_ERROR("Failed to load transform for sha256: %ld", PTR_ERR(tfm));
  42584. + return 0;
  42585. + }
  42586. + desc.tfm = tfm;
  42587. + desc.flags = 0;
  42588. +
  42589. + sg_init_one(&sg, message, len);
  42590. + crypto_hash_digest(&desc, &sg, len, out);
  42591. + crypto_free_hash(tfm);
  42592. +
  42593. + return 1;
  42594. +}
  42595. +
  42596. +int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen,
  42597. + uint8_t *key, uint32_t keylen, uint8_t *out)
  42598. +{
  42599. + struct crypto_hash *tfm;
  42600. + struct hash_desc desc;
  42601. + struct scatterlist sg;
  42602. +
  42603. + tfm = crypto_alloc_hash("hmac(sha256)", 0, CRYPTO_ALG_ASYNC);
  42604. + if (IS_ERR(tfm)) {
  42605. + DWC_ERROR("Failed to load transform for hmac(sha256): %ld", PTR_ERR(tfm));
  42606. + return 0;
  42607. + }
  42608. + desc.tfm = tfm;
  42609. + desc.flags = 0;
  42610. +
  42611. + sg_init_one(&sg, message, messagelen);
  42612. + crypto_hash_setkey(tfm, key, keylen);
  42613. + crypto_hash_digest(&desc, &sg, messagelen, out);
  42614. + crypto_free_hash(tfm);
  42615. +
  42616. + return 1;
  42617. +}
  42618. +
  42619. +#endif /* DWC_CRYPTOLIB */
  42620. +
  42621. +
  42622. +/* Byte Ordering Conversions */
  42623. +
  42624. +uint32_t DWC_CPU_TO_LE32(uint32_t *p)
  42625. +{
  42626. +#ifdef __LITTLE_ENDIAN
  42627. + return *p;
  42628. +#else
  42629. + uint8_t *u_p = (uint8_t *)p;
  42630. +
  42631. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42632. +#endif
  42633. +}
  42634. +
  42635. +uint32_t DWC_CPU_TO_BE32(uint32_t *p)
  42636. +{
  42637. +#ifdef __BIG_ENDIAN
  42638. + return *p;
  42639. +#else
  42640. + uint8_t *u_p = (uint8_t *)p;
  42641. +
  42642. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42643. +#endif
  42644. +}
  42645. +
  42646. +uint32_t DWC_LE32_TO_CPU(uint32_t *p)
  42647. +{
  42648. +#ifdef __LITTLE_ENDIAN
  42649. + return *p;
  42650. +#else
  42651. + uint8_t *u_p = (uint8_t *)p;
  42652. +
  42653. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42654. +#endif
  42655. +}
  42656. +
  42657. +uint32_t DWC_BE32_TO_CPU(uint32_t *p)
  42658. +{
  42659. +#ifdef __BIG_ENDIAN
  42660. + return *p;
  42661. +#else
  42662. + uint8_t *u_p = (uint8_t *)p;
  42663. +
  42664. + return (u_p[3] | (u_p[2] << 8) | (u_p[1] << 16) | (u_p[0] << 24));
  42665. +#endif
  42666. +}
  42667. +
  42668. +uint16_t DWC_CPU_TO_LE16(uint16_t *p)
  42669. +{
  42670. +#ifdef __LITTLE_ENDIAN
  42671. + return *p;
  42672. +#else
  42673. + uint8_t *u_p = (uint8_t *)p;
  42674. + return (u_p[1] | (u_p[0] << 8));
  42675. +#endif
  42676. +}
  42677. +
  42678. +uint16_t DWC_CPU_TO_BE16(uint16_t *p)
  42679. +{
  42680. +#ifdef __BIG_ENDIAN
  42681. + return *p;
  42682. +#else
  42683. + uint8_t *u_p = (uint8_t *)p;
  42684. + return (u_p[1] | (u_p[0] << 8));
  42685. +#endif
  42686. +}
  42687. +
  42688. +uint16_t DWC_LE16_TO_CPU(uint16_t *p)
  42689. +{
  42690. +#ifdef __LITTLE_ENDIAN
  42691. + return *p;
  42692. +#else
  42693. + uint8_t *u_p = (uint8_t *)p;
  42694. + return (u_p[1] | (u_p[0] << 8));
  42695. +#endif
  42696. +}
  42697. +
  42698. +uint16_t DWC_BE16_TO_CPU(uint16_t *p)
  42699. +{
  42700. +#ifdef __BIG_ENDIAN
  42701. + return *p;
  42702. +#else
  42703. + uint8_t *u_p = (uint8_t *)p;
  42704. + return (u_p[1] | (u_p[0] << 8));
  42705. +#endif
  42706. +}
  42707. +
  42708. +
  42709. +/* Registers */
  42710. +
  42711. +uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg)
  42712. +{
  42713. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42714. + bus_size_t ior = (bus_size_t)reg;
  42715. +
  42716. + return bus_space_read_4(io->iot, io->ioh, ior);
  42717. +}
  42718. +
  42719. +#if 0
  42720. +uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg)
  42721. +{
  42722. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42723. + bus_size_t ior = (bus_size_t)reg;
  42724. +
  42725. + return bus_space_read_8(io->iot, io->ioh, ior);
  42726. +}
  42727. +#endif
  42728. +
  42729. +void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value)
  42730. +{
  42731. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42732. + bus_size_t ior = (bus_size_t)reg;
  42733. +
  42734. + bus_space_write_4(io->iot, io->ioh, ior, value);
  42735. +}
  42736. +
  42737. +#if 0
  42738. +void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value)
  42739. +{
  42740. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42741. + bus_size_t ior = (bus_size_t)reg;
  42742. +
  42743. + bus_space_write_8(io->iot, io->ioh, ior, value);
  42744. +}
  42745. +#endif
  42746. +
  42747. +void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask,
  42748. + uint32_t set_mask)
  42749. +{
  42750. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42751. + bus_size_t ior = (bus_size_t)reg;
  42752. +
  42753. + bus_space_write_4(io->iot, io->ioh, ior,
  42754. + (bus_space_read_4(io->iot, io->ioh, ior) &
  42755. + ~clear_mask) | set_mask);
  42756. +}
  42757. +
  42758. +#if 0
  42759. +void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask,
  42760. + uint64_t set_mask)
  42761. +{
  42762. + dwc_ioctx_t *io = (dwc_ioctx_t *)io_ctx;
  42763. + bus_size_t ior = (bus_size_t)reg;
  42764. +
  42765. + bus_space_write_8(io->iot, io->ioh, ior,
  42766. + (bus_space_read_8(io->iot, io->ioh, ior) &
  42767. + ~clear_mask) | set_mask);
  42768. +}
  42769. +#endif
  42770. +
  42771. +
  42772. +/* Locking */
  42773. +
  42774. +dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void)
  42775. +{
  42776. + struct simplelock *sl = DWC_ALLOC(sizeof(*sl));
  42777. +
  42778. + if (!sl) {
  42779. + DWC_ERROR("Cannot allocate memory for spinlock");
  42780. + return NULL;
  42781. + }
  42782. +
  42783. + simple_lock_init(sl);
  42784. + return (dwc_spinlock_t *)sl;
  42785. +}
  42786. +
  42787. +void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock)
  42788. +{
  42789. + struct simplelock *sl = (struct simplelock *)lock;
  42790. +
  42791. + DWC_FREE(sl);
  42792. +}
  42793. +
  42794. +void DWC_SPINLOCK(dwc_spinlock_t *lock)
  42795. +{
  42796. + simple_lock((struct simplelock *)lock);
  42797. +}
  42798. +
  42799. +void DWC_SPINUNLOCK(dwc_spinlock_t *lock)
  42800. +{
  42801. + simple_unlock((struct simplelock *)lock);
  42802. +}
  42803. +
  42804. +void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags)
  42805. +{
  42806. + simple_lock((struct simplelock *)lock);
  42807. + *flags = splbio();
  42808. +}
  42809. +
  42810. +void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags)
  42811. +{
  42812. + splx(flags);
  42813. + simple_unlock((struct simplelock *)lock);
  42814. +}
  42815. +
  42816. +dwc_mutex_t *DWC_MUTEX_ALLOC(void)
  42817. +{
  42818. + dwc_mutex_t *mutex = DWC_ALLOC(sizeof(struct lock));
  42819. +
  42820. + if (!mutex) {
  42821. + DWC_ERROR("Cannot allocate memory for mutex");
  42822. + return NULL;
  42823. + }
  42824. +
  42825. + lockinit((struct lock *)mutex, 0, "dw3mtx", 0, 0);
  42826. + return mutex;
  42827. +}
  42828. +
  42829. +#if (defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES))
  42830. +#else
  42831. +void DWC_MUTEX_FREE(dwc_mutex_t *mutex)
  42832. +{
  42833. + DWC_FREE(mutex);
  42834. +}
  42835. +#endif
  42836. +
  42837. +void DWC_MUTEX_LOCK(dwc_mutex_t *mutex)
  42838. +{
  42839. + lockmgr((struct lock *)mutex, LK_EXCLUSIVE, NULL);
  42840. +}
  42841. +
  42842. +int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex)
  42843. +{
  42844. + int status;
  42845. +
  42846. + status = lockmgr((struct lock *)mutex, LK_EXCLUSIVE | LK_NOWAIT, NULL);
  42847. + return status == 0;
  42848. +}
  42849. +
  42850. +void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex)
  42851. +{
  42852. + lockmgr((struct lock *)mutex, LK_RELEASE, NULL);
  42853. +}
  42854. +
  42855. +
  42856. +/* Timing */
  42857. +
  42858. +void DWC_UDELAY(uint32_t usecs)
  42859. +{
  42860. + DELAY(usecs);
  42861. +}
  42862. +
  42863. +void DWC_MDELAY(uint32_t msecs)
  42864. +{
  42865. + do {
  42866. + DELAY(1000);
  42867. + } while (--msecs);
  42868. +}
  42869. +
  42870. +void DWC_MSLEEP(uint32_t msecs)
  42871. +{
  42872. + struct timeval tv;
  42873. +
  42874. + tv.tv_sec = msecs / 1000;
  42875. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  42876. + tsleep(&tv, 0, "dw3slp", tvtohz(&tv));
  42877. +}
  42878. +
  42879. +uint32_t DWC_TIME(void)
  42880. +{
  42881. + struct timeval tv;
  42882. +
  42883. + microuptime(&tv); // or getmicrouptime? (less precise, but faster)
  42884. + return tv.tv_sec * 1000 + tv.tv_usec / 1000;
  42885. +}
  42886. +
  42887. +
  42888. +/* Timers */
  42889. +
  42890. +struct dwc_timer {
  42891. + struct callout t;
  42892. + char *name;
  42893. + dwc_spinlock_t *lock;
  42894. + dwc_timer_callback_t cb;
  42895. + void *data;
  42896. +};
  42897. +
  42898. +dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data)
  42899. +{
  42900. + dwc_timer_t *t = DWC_ALLOC(sizeof(*t));
  42901. +
  42902. + if (!t) {
  42903. + DWC_ERROR("Cannot allocate memory for timer");
  42904. + return NULL;
  42905. + }
  42906. +
  42907. + callout_init(&t->t);
  42908. +
  42909. + t->name = DWC_STRDUP(name);
  42910. + if (!t->name) {
  42911. + DWC_ERROR("Cannot allocate memory for timer->name");
  42912. + goto no_name;
  42913. + }
  42914. +
  42915. + t->lock = DWC_SPINLOCK_ALLOC();
  42916. + if (!t->lock) {
  42917. + DWC_ERROR("Cannot allocate memory for timer->lock");
  42918. + goto no_lock;
  42919. + }
  42920. +
  42921. + t->cb = cb;
  42922. + t->data = data;
  42923. +
  42924. + return t;
  42925. +
  42926. + no_lock:
  42927. + DWC_FREE(t->name);
  42928. + no_name:
  42929. + DWC_FREE(t);
  42930. +
  42931. + return NULL;
  42932. +}
  42933. +
  42934. +void DWC_TIMER_FREE(dwc_timer_t *timer)
  42935. +{
  42936. + callout_stop(&timer->t);
  42937. + DWC_SPINLOCK_FREE(timer->lock);
  42938. + DWC_FREE(timer->name);
  42939. + DWC_FREE(timer);
  42940. +}
  42941. +
  42942. +void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time)
  42943. +{
  42944. + struct timeval tv;
  42945. +
  42946. + tv.tv_sec = time / 1000;
  42947. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  42948. + callout_reset(&timer->t, tvtohz(&tv), timer->cb, timer->data);
  42949. +}
  42950. +
  42951. +void DWC_TIMER_CANCEL(dwc_timer_t *timer)
  42952. +{
  42953. + callout_stop(&timer->t);
  42954. +}
  42955. +
  42956. +
  42957. +/* Wait Queues */
  42958. +
  42959. +struct dwc_waitq {
  42960. + struct simplelock lock;
  42961. + int abort;
  42962. +};
  42963. +
  42964. +dwc_waitq_t *DWC_WAITQ_ALLOC(void)
  42965. +{
  42966. + dwc_waitq_t *wq = DWC_ALLOC(sizeof(*wq));
  42967. +
  42968. + if (!wq) {
  42969. + DWC_ERROR("Cannot allocate memory for waitqueue");
  42970. + return NULL;
  42971. + }
  42972. +
  42973. + simple_lock_init(&wq->lock);
  42974. + wq->abort = 0;
  42975. +
  42976. + return wq;
  42977. +}
  42978. +
  42979. +void DWC_WAITQ_FREE(dwc_waitq_t *wq)
  42980. +{
  42981. + DWC_FREE(wq);
  42982. +}
  42983. +
  42984. +int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data)
  42985. +{
  42986. + int ipl;
  42987. + int result = 0;
  42988. +
  42989. + simple_lock(&wq->lock);
  42990. + ipl = splbio();
  42991. +
  42992. + /* Skip the sleep if already aborted or triggered */
  42993. + if (!wq->abort && !cond(data)) {
  42994. + splx(ipl);
  42995. + result = ltsleep(wq, PCATCH, "dw3wat", 0, &wq->lock); // infinite timeout
  42996. + ipl = splbio();
  42997. + }
  42998. +
  42999. + if (result == 0) { // awoken
  43000. + if (wq->abort) {
  43001. + wq->abort = 0;
  43002. + result = -DWC_E_ABORT;
  43003. + } else {
  43004. + result = 0;
  43005. + }
  43006. +
  43007. + splx(ipl);
  43008. + simple_unlock(&wq->lock);
  43009. + } else {
  43010. + wq->abort = 0;
  43011. + splx(ipl);
  43012. + simple_unlock(&wq->lock);
  43013. +
  43014. + if (result == ERESTART) { // signaled - restart
  43015. + result = -DWC_E_RESTART;
  43016. + } else { // signaled - must be EINTR
  43017. + result = -DWC_E_ABORT;
  43018. + }
  43019. + }
  43020. +
  43021. + return result;
  43022. +}
  43023. +
  43024. +int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  43025. + void *data, int32_t msecs)
  43026. +{
  43027. + struct timeval tv, tv1, tv2;
  43028. + int ipl;
  43029. + int result = 0;
  43030. +
  43031. + tv.tv_sec = msecs / 1000;
  43032. + tv.tv_usec = (msecs - tv.tv_sec * 1000) * 1000;
  43033. +
  43034. + simple_lock(&wq->lock);
  43035. + ipl = splbio();
  43036. +
  43037. + /* Skip the sleep if already aborted or triggered */
  43038. + if (!wq->abort && !cond(data)) {
  43039. + splx(ipl);
  43040. + getmicrouptime(&tv1);
  43041. + result = ltsleep(wq, PCATCH, "dw3wto", tvtohz(&tv), &wq->lock);
  43042. + getmicrouptime(&tv2);
  43043. + ipl = splbio();
  43044. + }
  43045. +
  43046. + if (result == 0) { // awoken
  43047. + if (wq->abort) {
  43048. + wq->abort = 0;
  43049. + splx(ipl);
  43050. + simple_unlock(&wq->lock);
  43051. + result = -DWC_E_ABORT;
  43052. + } else {
  43053. + splx(ipl);
  43054. + simple_unlock(&wq->lock);
  43055. +
  43056. + tv2.tv_usec -= tv1.tv_usec;
  43057. + if (tv2.tv_usec < 0) {
  43058. + tv2.tv_usec += 1000000;
  43059. + tv2.tv_sec--;
  43060. + }
  43061. +
  43062. + tv2.tv_sec -= tv1.tv_sec;
  43063. + result = tv2.tv_sec * 1000 + tv2.tv_usec / 1000;
  43064. + result = msecs - result;
  43065. + if (result <= 0)
  43066. + result = 1;
  43067. + }
  43068. + } else {
  43069. + wq->abort = 0;
  43070. + splx(ipl);
  43071. + simple_unlock(&wq->lock);
  43072. +
  43073. + if (result == ERESTART) { // signaled - restart
  43074. + result = -DWC_E_RESTART;
  43075. +
  43076. + } else if (result == EINTR) { // signaled - interrupt
  43077. + result = -DWC_E_ABORT;
  43078. +
  43079. + } else { // timed out
  43080. + result = -DWC_E_TIMEOUT;
  43081. + }
  43082. + }
  43083. +
  43084. + return result;
  43085. +}
  43086. +
  43087. +void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq)
  43088. +{
  43089. + wakeup(wq);
  43090. +}
  43091. +
  43092. +void DWC_WAITQ_ABORT(dwc_waitq_t *wq)
  43093. +{
  43094. + int ipl;
  43095. +
  43096. + simple_lock(&wq->lock);
  43097. + ipl = splbio();
  43098. + wq->abort = 1;
  43099. + wakeup(wq);
  43100. + splx(ipl);
  43101. + simple_unlock(&wq->lock);
  43102. +}
  43103. +
  43104. +
  43105. +/* Threading */
  43106. +
  43107. +struct dwc_thread {
  43108. + struct proc *proc;
  43109. + int abort;
  43110. +};
  43111. +
  43112. +dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data)
  43113. +{
  43114. + int retval;
  43115. + dwc_thread_t *thread = DWC_ALLOC(sizeof(*thread));
  43116. +
  43117. + if (!thread) {
  43118. + return NULL;
  43119. + }
  43120. +
  43121. + thread->abort = 0;
  43122. + retval = kthread_create1((void (*)(void *))func, data, &thread->proc,
  43123. + "%s", name);
  43124. + if (retval) {
  43125. + DWC_FREE(thread);
  43126. + return NULL;
  43127. + }
  43128. +
  43129. + return thread;
  43130. +}
  43131. +
  43132. +int DWC_THREAD_STOP(dwc_thread_t *thread)
  43133. +{
  43134. + int retval;
  43135. +
  43136. + thread->abort = 1;
  43137. + retval = tsleep(&thread->abort, 0, "dw3stp", 60 * hz);
  43138. +
  43139. + if (retval == 0) {
  43140. + /* DWC_THREAD_EXIT() will free the thread struct */
  43141. + return 0;
  43142. + }
  43143. +
  43144. + /* NOTE: We leak the thread struct if thread doesn't die */
  43145. +
  43146. + if (retval == EWOULDBLOCK) {
  43147. + return -DWC_E_TIMEOUT;
  43148. + }
  43149. +
  43150. + return -DWC_E_UNKNOWN;
  43151. +}
  43152. +
  43153. +dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread)
  43154. +{
  43155. + return thread->abort;
  43156. +}
  43157. +
  43158. +void DWC_THREAD_EXIT(dwc_thread_t *thread)
  43159. +{
  43160. + wakeup(&thread->abort);
  43161. + DWC_FREE(thread);
  43162. + kthread_exit(0);
  43163. +}
  43164. +
  43165. +/* tasklets
  43166. + - Runs in interrupt context (cannot sleep)
  43167. + - Each tasklet runs on a single CPU
  43168. + - Different tasklets can be running simultaneously on different CPUs
  43169. + [ On NetBSD there is no corresponding mechanism, drivers don't have bottom-
  43170. + halves. So we just call the callback directly from DWC_TASK_SCHEDULE() ]
  43171. + */
  43172. +struct dwc_tasklet {
  43173. + dwc_tasklet_callback_t cb;
  43174. + void *data;
  43175. +};
  43176. +
  43177. +static void tasklet_callback(void *data)
  43178. +{
  43179. + dwc_tasklet_t *task = (dwc_tasklet_t *)data;
  43180. +
  43181. + task->cb(task->data);
  43182. +}
  43183. +
  43184. +dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data)
  43185. +{
  43186. + dwc_tasklet_t *task = DWC_ALLOC(sizeof(*task));
  43187. +
  43188. + if (task) {
  43189. + task->cb = cb;
  43190. + task->data = data;
  43191. + } else {
  43192. + DWC_ERROR("Cannot allocate memory for tasklet");
  43193. + }
  43194. +
  43195. + return task;
  43196. +}
  43197. +
  43198. +void DWC_TASK_FREE(dwc_tasklet_t *task)
  43199. +{
  43200. + DWC_FREE(task);
  43201. +}
  43202. +
  43203. +void DWC_TASK_SCHEDULE(dwc_tasklet_t *task)
  43204. +{
  43205. + tasklet_callback(task);
  43206. +}
  43207. +
  43208. +
  43209. +/* workqueues
  43210. + - Runs in process context (can sleep)
  43211. + */
  43212. +typedef struct work_container {
  43213. + dwc_work_callback_t cb;
  43214. + void *data;
  43215. + dwc_workq_t *wq;
  43216. + char *name;
  43217. + int hz;
  43218. + struct work task;
  43219. +} work_container_t;
  43220. +
  43221. +struct dwc_workq {
  43222. + struct workqueue *taskq;
  43223. + dwc_spinlock_t *lock;
  43224. + dwc_waitq_t *waitq;
  43225. + int pending;
  43226. + struct work_container *container;
  43227. +};
  43228. +
  43229. +static void do_work(struct work *task, void *data)
  43230. +{
  43231. + dwc_workq_t *wq = (dwc_workq_t *)data;
  43232. + work_container_t *container = wq->container;
  43233. + dwc_irqflags_t flags;
  43234. +
  43235. + if (container->hz) {
  43236. + tsleep(container, 0, "dw3wrk", container->hz);
  43237. + }
  43238. +
  43239. + container->cb(container->data);
  43240. + DWC_DEBUG("Work done: %s, container=%p", container->name, container);
  43241. +
  43242. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43243. + if (container->name)
  43244. + DWC_FREE(container->name);
  43245. + DWC_FREE(container);
  43246. + wq->pending--;
  43247. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43248. + DWC_WAITQ_TRIGGER(wq->waitq);
  43249. +}
  43250. +
  43251. +static int work_done(void *data)
  43252. +{
  43253. + dwc_workq_t *workq = (dwc_workq_t *)data;
  43254. +
  43255. + return workq->pending == 0;
  43256. +}
  43257. +
  43258. +int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout)
  43259. +{
  43260. + return DWC_WAITQ_WAIT_TIMEOUT(workq->waitq, work_done, workq, timeout);
  43261. +}
  43262. +
  43263. +dwc_workq_t *DWC_WORKQ_ALLOC(char *name)
  43264. +{
  43265. + int result;
  43266. + dwc_workq_t *wq = DWC_ALLOC(sizeof(*wq));
  43267. +
  43268. + if (!wq) {
  43269. + DWC_ERROR("Cannot allocate memory for workqueue");
  43270. + return NULL;
  43271. + }
  43272. +
  43273. + result = workqueue_create(&wq->taskq, name, do_work, wq, 0 /*PWAIT*/,
  43274. + IPL_BIO, 0);
  43275. + if (result) {
  43276. + DWC_ERROR("Cannot create workqueue");
  43277. + goto no_taskq;
  43278. + }
  43279. +
  43280. + wq->pending = 0;
  43281. +
  43282. + wq->lock = DWC_SPINLOCK_ALLOC();
  43283. + if (!wq->lock) {
  43284. + DWC_ERROR("Cannot allocate memory for spinlock");
  43285. + goto no_lock;
  43286. + }
  43287. +
  43288. + wq->waitq = DWC_WAITQ_ALLOC();
  43289. + if (!wq->waitq) {
  43290. + DWC_ERROR("Cannot allocate memory for waitqueue");
  43291. + goto no_waitq;
  43292. + }
  43293. +
  43294. + return wq;
  43295. +
  43296. + no_waitq:
  43297. + DWC_SPINLOCK_FREE(wq->lock);
  43298. + no_lock:
  43299. + workqueue_destroy(wq->taskq);
  43300. + no_taskq:
  43301. + DWC_FREE(wq);
  43302. +
  43303. + return NULL;
  43304. +}
  43305. +
  43306. +void DWC_WORKQ_FREE(dwc_workq_t *wq)
  43307. +{
  43308. +#ifdef DEBUG
  43309. + dwc_irqflags_t flags;
  43310. +
  43311. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43312. +
  43313. + if (wq->pending != 0) {
  43314. + struct work_container *container = wq->container;
  43315. +
  43316. + DWC_ERROR("Destroying work queue with pending work");
  43317. +
  43318. + if (container && container->name) {
  43319. + DWC_ERROR("Work %s still pending", container->name);
  43320. + }
  43321. + }
  43322. +
  43323. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43324. +#endif
  43325. + DWC_WAITQ_FREE(wq->waitq);
  43326. + DWC_SPINLOCK_FREE(wq->lock);
  43327. + workqueue_destroy(wq->taskq);
  43328. + DWC_FREE(wq);
  43329. +}
  43330. +
  43331. +void DWC_WORKQ_SCHEDULE(dwc_workq_t *wq, dwc_work_callback_t cb, void *data,
  43332. + char *format, ...)
  43333. +{
  43334. + dwc_irqflags_t flags;
  43335. + work_container_t *container;
  43336. + static char name[128];
  43337. + va_list args;
  43338. +
  43339. + va_start(args, format);
  43340. + DWC_VSNPRINTF(name, 128, format, args);
  43341. + va_end(args);
  43342. +
  43343. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43344. + wq->pending++;
  43345. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43346. + DWC_WAITQ_TRIGGER(wq->waitq);
  43347. +
  43348. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43349. + if (!container) {
  43350. + DWC_ERROR("Cannot allocate memory for container");
  43351. + return;
  43352. + }
  43353. +
  43354. + container->name = DWC_STRDUP(name);
  43355. + if (!container->name) {
  43356. + DWC_ERROR("Cannot allocate memory for container->name");
  43357. + DWC_FREE(container);
  43358. + return;
  43359. + }
  43360. +
  43361. + container->cb = cb;
  43362. + container->data = data;
  43363. + container->wq = wq;
  43364. + container->hz = 0;
  43365. + wq->container = container;
  43366. +
  43367. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43368. + workqueue_enqueue(wq->taskq, &container->task);
  43369. +}
  43370. +
  43371. +void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *wq, dwc_work_callback_t cb,
  43372. + void *data, uint32_t time, char *format, ...)
  43373. +{
  43374. + dwc_irqflags_t flags;
  43375. + work_container_t *container;
  43376. + static char name[128];
  43377. + struct timeval tv;
  43378. + va_list args;
  43379. +
  43380. + va_start(args, format);
  43381. + DWC_VSNPRINTF(name, 128, format, args);
  43382. + va_end(args);
  43383. +
  43384. + DWC_SPINLOCK_IRQSAVE(wq->lock, &flags);
  43385. + wq->pending++;
  43386. + DWC_SPINUNLOCK_IRQRESTORE(wq->lock, flags);
  43387. + DWC_WAITQ_TRIGGER(wq->waitq);
  43388. +
  43389. + container = DWC_ALLOC_ATOMIC(sizeof(*container));
  43390. + if (!container) {
  43391. + DWC_ERROR("Cannot allocate memory for container");
  43392. + return;
  43393. + }
  43394. +
  43395. + container->name = DWC_STRDUP(name);
  43396. + if (!container->name) {
  43397. + DWC_ERROR("Cannot allocate memory for container->name");
  43398. + DWC_FREE(container);
  43399. + return;
  43400. + }
  43401. +
  43402. + container->cb = cb;
  43403. + container->data = data;
  43404. + container->wq = wq;
  43405. + tv.tv_sec = time / 1000;
  43406. + tv.tv_usec = (time - tv.tv_sec * 1000) * 1000;
  43407. + container->hz = tvtohz(&tv);
  43408. + wq->container = container;
  43409. +
  43410. + DWC_DEBUG("Queueing work: %s, container=%p", container->name, container);
  43411. + workqueue_enqueue(wq->taskq, &container->task);
  43412. +}
  43413. +
  43414. +int DWC_WORKQ_PENDING(dwc_workq_t *wq)
  43415. +{
  43416. + return wq->pending;
  43417. +}
  43418. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_crypto.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c
  43419. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_crypto.c 1970-01-01 01:00:00.000000000 +0100
  43420. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.c 2014-06-11 21:03:43.000000000 +0200
  43421. @@ -0,0 +1,308 @@
  43422. +/* =========================================================================
  43423. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.c $
  43424. + * $Revision: #5 $
  43425. + * $Date: 2010/09/28 $
  43426. + * $Change: 1596182 $
  43427. + *
  43428. + * Synopsys Portability Library Software and documentation
  43429. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43430. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43431. + * between Synopsys and you.
  43432. + *
  43433. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43434. + * under any End User Software License Agreement or Agreement for
  43435. + * Licensed Product with Synopsys or any supplement thereto. You are
  43436. + * permitted to use and redistribute this Software in source and binary
  43437. + * forms, with or without modification, provided that redistributions
  43438. + * of source code must retain this notice. You may not view, use,
  43439. + * disclose, copy or distribute this file or any information contained
  43440. + * herein except pursuant to this license grant from Synopsys. If you
  43441. + * do not agree with this notice, including the disclaimer below, then
  43442. + * you are not authorized to use the Software.
  43443. + *
  43444. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43445. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43446. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43447. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43448. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43449. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43450. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43451. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43452. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43453. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43454. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43455. + * DAMAGE.
  43456. + * ========================================================================= */
  43457. +
  43458. +/** @file
  43459. + * This file contains the WUSB cryptographic routines.
  43460. + */
  43461. +
  43462. +#ifdef DWC_CRYPTOLIB
  43463. +
  43464. +#include "dwc_crypto.h"
  43465. +#include "usb.h"
  43466. +
  43467. +#ifdef DEBUG
  43468. +static inline void dump_bytes(char *name, uint8_t *bytes, int len)
  43469. +{
  43470. + int i;
  43471. + DWC_PRINTF("%s: ", name);
  43472. + for (i=0; i<len; i++) {
  43473. + DWC_PRINTF("%02x ", bytes[i]);
  43474. + }
  43475. + DWC_PRINTF("\n");
  43476. +}
  43477. +#else
  43478. +#define dump_bytes(x...)
  43479. +#endif
  43480. +
  43481. +/* Display a block */
  43482. +void show_block(const u8 *blk, const char *prefix, const char *suffix, int a)
  43483. +{
  43484. +#ifdef DWC_DEBUG_CRYPTO
  43485. + int i, blksize = 16;
  43486. +
  43487. + DWC_DEBUG("%s", prefix);
  43488. +
  43489. + if (suffix == NULL) {
  43490. + suffix = "\n";
  43491. + blksize = a;
  43492. + }
  43493. +
  43494. + for (i = 0; i < blksize; i++)
  43495. + DWC_PRINT("%02x%s", *blk++, ((i & 3) == 3) ? " " : " ");
  43496. + DWC_PRINT(suffix);
  43497. +#endif
  43498. +}
  43499. +
  43500. +/**
  43501. + * Encrypts an array of bytes using the AES encryption engine.
  43502. + * If <code>dst</code> == <code>src</code>, then the bytes will be encrypted
  43503. + * in-place.
  43504. + *
  43505. + * @return 0 on success, negative error code on error.
  43506. + */
  43507. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst)
  43508. +{
  43509. + u8 block_t[16];
  43510. + DWC_MEMSET(block_t, 0, 16);
  43511. +
  43512. + return DWC_AES_CBC(src, 16, key, 16, block_t, dst);
  43513. +}
  43514. +
  43515. +/**
  43516. + * The CCM-MAC-FUNCTION described in section 6.5 of the WUSB spec.
  43517. + * This function takes a data string and returns the encrypted CBC
  43518. + * Counter-mode MIC.
  43519. + *
  43520. + * @param key The 128-bit symmetric key.
  43521. + * @param nonce The CCM nonce.
  43522. + * @param label The unique 14-byte ASCII text label.
  43523. + * @param bytes The byte array to be encrypted.
  43524. + * @param len Length of the byte array.
  43525. + * @param result Byte array to receive the 8-byte encrypted MIC.
  43526. + */
  43527. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43528. + char *label, u8 *bytes, int len, u8 *result)
  43529. +{
  43530. + u8 block_m[16];
  43531. + u8 block_x[16];
  43532. + u8 block_t[8];
  43533. + int idx, blkNum;
  43534. + u16 la = (u16)(len + 14);
  43535. +
  43536. + /* Set the AES-128 key */
  43537. + //dwc_aes_setkey(tfm, key, 16);
  43538. +
  43539. + /* Fill block B0 from flags = 0x59, N, and l(m) = 0 */
  43540. + block_m[0] = 0x59;
  43541. + for (idx = 0; idx < 13; idx++)
  43542. + block_m[idx + 1] = nonce[idx];
  43543. + block_m[14] = 0;
  43544. + block_m[15] = 0;
  43545. +
  43546. + /* Produce the CBC IV */
  43547. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43548. + show_block(block_m, "CBC IV in: ", "\n", 0);
  43549. + show_block(block_x, "CBC IV out:", "\n", 0);
  43550. +
  43551. + /* Fill block B1 from l(a) = Blen + 14, and A */
  43552. + block_x[0] ^= (u8)(la >> 8);
  43553. + block_x[1] ^= (u8)la;
  43554. + for (idx = 0; idx < 14; idx++)
  43555. + block_x[idx + 2] ^= label[idx];
  43556. + show_block(block_x, "After xor: ", "b1\n", 16);
  43557. +
  43558. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43559. + show_block(block_x, "After AES: ", "b1\n", 16);
  43560. +
  43561. + idx = 0;
  43562. + blkNum = 0;
  43563. +
  43564. + /* Fill remaining blocks with B */
  43565. + while (len-- > 0) {
  43566. + block_x[idx] ^= *bytes++;
  43567. + if (++idx >= 16) {
  43568. + idx = 0;
  43569. + show_block(block_x, "After xor: ", "\n", blkNum);
  43570. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43571. + show_block(block_x, "After AES: ", "\n", blkNum);
  43572. + blkNum++;
  43573. + }
  43574. + }
  43575. +
  43576. + /* Handle partial last block */
  43577. + if (idx > 0) {
  43578. + show_block(block_x, "After xor: ", "\n", blkNum);
  43579. + dwc_wusb_aes_encrypt(block_x, key, block_x);
  43580. + show_block(block_x, "After AES: ", "\n", blkNum);
  43581. + }
  43582. +
  43583. + /* Save the MIC tag */
  43584. + DWC_MEMCPY(block_t, block_x, 8);
  43585. + show_block(block_t, "MIC tag : ", NULL, 8);
  43586. +
  43587. + /* Fill block A0 from flags = 0x01, N, and counter = 0 */
  43588. + block_m[0] = 0x01;
  43589. + block_m[14] = 0;
  43590. + block_m[15] = 0;
  43591. +
  43592. + /* Encrypt the counter */
  43593. + dwc_wusb_aes_encrypt(block_m, key, block_x);
  43594. + show_block(block_x, "CTR[MIC] : ", NULL, 8);
  43595. +
  43596. + /* XOR with MIC tag */
  43597. + for (idx = 0; idx < 8; idx++) {
  43598. + block_t[idx] ^= block_x[idx];
  43599. + }
  43600. +
  43601. + /* Return result to caller */
  43602. + DWC_MEMCPY(result, block_t, 8);
  43603. + show_block(result, "CCM-MIC : ", NULL, 8);
  43604. +
  43605. +}
  43606. +
  43607. +/**
  43608. + * The PRF function described in section 6.5 of the WUSB spec. This function
  43609. + * concatenates MIC values returned from dwc_cmf() to create a value of
  43610. + * the requested length.
  43611. + *
  43612. + * @param prf_len Length of the PRF function in bits (64, 128, or 256).
  43613. + * @param key, nonce, label, bytes, len Same as for dwc_cmf().
  43614. + * @param result Byte array to receive the result.
  43615. + */
  43616. +void dwc_wusb_prf(int prf_len, u8 *key,
  43617. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result)
  43618. +{
  43619. + int i;
  43620. +
  43621. + nonce[0] = 0;
  43622. + for (i = 0; i < prf_len >> 6; i++, nonce[0]++) {
  43623. + dwc_wusb_cmf(key, nonce, label, bytes, len, result);
  43624. + result += 8;
  43625. + }
  43626. +}
  43627. +
  43628. +/**
  43629. + * Fills in CCM Nonce per the WUSB spec.
  43630. + *
  43631. + * @param[in] haddr Host address.
  43632. + * @param[in] daddr Device address.
  43633. + * @param[in] tkid Session Key(PTK) identifier.
  43634. + * @param[out] nonce Pointer to where the CCM Nonce output is to be written.
  43635. + */
  43636. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43637. + uint8_t *nonce)
  43638. +{
  43639. +
  43640. + DWC_DEBUG("%s %x %x\n", __func__, daddr, haddr);
  43641. +
  43642. + DWC_MEMSET(&nonce[0], 0, 16);
  43643. +
  43644. + DWC_MEMCPY(&nonce[6], tkid, 3);
  43645. + nonce[9] = daddr & 0xFF;
  43646. + nonce[10] = (daddr >> 8) & 0xFF;
  43647. + nonce[11] = haddr & 0xFF;
  43648. + nonce[12] = (haddr >> 8) & 0xFF;
  43649. +
  43650. + dump_bytes("CCM nonce", nonce, 16);
  43651. +}
  43652. +
  43653. +/**
  43654. + * Generates a 16-byte cryptographic-grade random number for the Host/Device
  43655. + * Nonce.
  43656. + */
  43657. +void dwc_wusb_gen_nonce(uint16_t addr, uint8_t *nonce)
  43658. +{
  43659. + uint8_t inonce[16];
  43660. + uint32_t temp[4];
  43661. +
  43662. + /* Fill in the Nonce */
  43663. + DWC_MEMSET(&inonce[0], 0, sizeof(inonce));
  43664. + inonce[9] = addr & 0xFF;
  43665. + inonce[10] = (addr >> 8) & 0xFF;
  43666. + inonce[11] = inonce[9];
  43667. + inonce[12] = inonce[10];
  43668. +
  43669. + /* Collect "randomness samples" */
  43670. + DWC_RANDOM_BYTES((uint8_t *)temp, 16);
  43671. +
  43672. + dwc_wusb_prf_128((uint8_t *)temp, nonce,
  43673. + "Random Numbers", (uint8_t *)temp, sizeof(temp),
  43674. + nonce);
  43675. +}
  43676. +
  43677. +/**
  43678. + * Generates the Session Key (PTK) and Key Confirmation Key (KCK) per the
  43679. + * WUSB spec.
  43680. + *
  43681. + * @param[in] ccm_nonce Pointer to CCM Nonce.
  43682. + * @param[in] mk Master Key to derive the session from
  43683. + * @param[in] hnonce Pointer to Host Nonce.
  43684. + * @param[in] dnonce Pointer to Device Nonce.
  43685. + * @param[out] kck Pointer to where the KCK output is to be written.
  43686. + * @param[out] ptk Pointer to where the PTK output is to be written.
  43687. + */
  43688. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk, uint8_t *hnonce,
  43689. + uint8_t *dnonce, uint8_t *kck, uint8_t *ptk)
  43690. +{
  43691. + uint8_t idata[32];
  43692. + uint8_t odata[32];
  43693. +
  43694. + dump_bytes("ck", mk, 16);
  43695. + dump_bytes("hnonce", hnonce, 16);
  43696. + dump_bytes("dnonce", dnonce, 16);
  43697. +
  43698. + /* The data is the HNonce and DNonce concatenated */
  43699. + DWC_MEMCPY(&idata[0], hnonce, 16);
  43700. + DWC_MEMCPY(&idata[16], dnonce, 16);
  43701. +
  43702. + dwc_wusb_prf_256(mk, ccm_nonce, "Pair-wise keys", idata, 32, odata);
  43703. +
  43704. + /* Low 16 bytes of the result is the KCK, high 16 is the PTK */
  43705. + DWC_MEMCPY(kck, &odata[0], 16);
  43706. + DWC_MEMCPY(ptk, &odata[16], 16);
  43707. +
  43708. + dump_bytes("kck", kck, 16);
  43709. + dump_bytes("ptk", ptk, 16);
  43710. +}
  43711. +
  43712. +/**
  43713. + * Generates the Message Integrity Code over the Handshake data per the
  43714. + * WUSB spec.
  43715. + *
  43716. + * @param ccm_nonce Pointer to CCM Nonce.
  43717. + * @param kck Pointer to Key Confirmation Key.
  43718. + * @param data Pointer to Handshake data to be checked.
  43719. + * @param mic Pointer to where the MIC output is to be written.
  43720. + */
  43721. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t *kck,
  43722. + uint8_t *data, uint8_t *mic)
  43723. +{
  43724. +
  43725. + dwc_wusb_prf_64(kck, ccm_nonce, "out-of-bandMIC",
  43726. + data, WUSB_HANDSHAKE_LEN_FOR_MIC, mic);
  43727. +}
  43728. +
  43729. +#endif /* DWC_CRYPTOLIB */
  43730. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_crypto.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h
  43731. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_crypto.h 1970-01-01 01:00:00.000000000 +0100
  43732. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_crypto.h 2014-06-11 21:03:43.000000000 +0200
  43733. @@ -0,0 +1,111 @@
  43734. +/* =========================================================================
  43735. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_crypto.h $
  43736. + * $Revision: #3 $
  43737. + * $Date: 2010/09/28 $
  43738. + * $Change: 1596182 $
  43739. + *
  43740. + * Synopsys Portability Library Software and documentation
  43741. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43742. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43743. + * between Synopsys and you.
  43744. + *
  43745. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43746. + * under any End User Software License Agreement or Agreement for
  43747. + * Licensed Product with Synopsys or any supplement thereto. You are
  43748. + * permitted to use and redistribute this Software in source and binary
  43749. + * forms, with or without modification, provided that redistributions
  43750. + * of source code must retain this notice. You may not view, use,
  43751. + * disclose, copy or distribute this file or any information contained
  43752. + * herein except pursuant to this license grant from Synopsys. If you
  43753. + * do not agree with this notice, including the disclaimer below, then
  43754. + * you are not authorized to use the Software.
  43755. + *
  43756. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43757. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43758. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43759. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43760. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43761. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43762. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43763. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43764. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43765. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43766. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43767. + * DAMAGE.
  43768. + * ========================================================================= */
  43769. +
  43770. +#ifndef _DWC_CRYPTO_H_
  43771. +#define _DWC_CRYPTO_H_
  43772. +
  43773. +#ifdef __cplusplus
  43774. +extern "C" {
  43775. +#endif
  43776. +
  43777. +/** @file
  43778. + *
  43779. + * This file contains declarations for the WUSB Cryptographic routines as
  43780. + * defined in the WUSB spec. They are only to be used internally by the DWC UWB
  43781. + * modules.
  43782. + */
  43783. +
  43784. +#include "dwc_os.h"
  43785. +
  43786. +int dwc_wusb_aes_encrypt(u8 *src, u8 *key, u8 *dst);
  43787. +
  43788. +void dwc_wusb_cmf(u8 *key, u8 *nonce,
  43789. + char *label, u8 *bytes, int len, u8 *result);
  43790. +void dwc_wusb_prf(int prf_len, u8 *key,
  43791. + u8 *nonce, char *label, u8 *bytes, int len, u8 *result);
  43792. +
  43793. +/**
  43794. + * The PRF-64 function described in section 6.5 of the WUSB spec.
  43795. + *
  43796. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43797. + */
  43798. +static inline void dwc_wusb_prf_64(u8 *key, u8 *nonce,
  43799. + char *label, u8 *bytes, int len, u8 *result)
  43800. +{
  43801. + dwc_wusb_prf(64, key, nonce, label, bytes, len, result);
  43802. +}
  43803. +
  43804. +/**
  43805. + * The PRF-128 function described in section 6.5 of the WUSB spec.
  43806. + *
  43807. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43808. + */
  43809. +static inline void dwc_wusb_prf_128(u8 *key, u8 *nonce,
  43810. + char *label, u8 *bytes, int len, u8 *result)
  43811. +{
  43812. + dwc_wusb_prf(128, key, nonce, label, bytes, len, result);
  43813. +}
  43814. +
  43815. +/**
  43816. + * The PRF-256 function described in section 6.5 of the WUSB spec.
  43817. + *
  43818. + * @param key, nonce, label, bytes, len, result Same as for dwc_prf().
  43819. + */
  43820. +static inline void dwc_wusb_prf_256(u8 *key, u8 *nonce,
  43821. + char *label, u8 *bytes, int len, u8 *result)
  43822. +{
  43823. + dwc_wusb_prf(256, key, nonce, label, bytes, len, result);
  43824. +}
  43825. +
  43826. +
  43827. +void dwc_wusb_fill_ccm_nonce(uint16_t haddr, uint16_t daddr, uint8_t *tkid,
  43828. + uint8_t *nonce);
  43829. +void dwc_wusb_gen_nonce(uint16_t addr,
  43830. + uint8_t *nonce);
  43831. +
  43832. +void dwc_wusb_gen_key(uint8_t *ccm_nonce, uint8_t *mk,
  43833. + uint8_t *hnonce, uint8_t *dnonce,
  43834. + uint8_t *kck, uint8_t *ptk);
  43835. +
  43836. +
  43837. +void dwc_wusb_gen_mic(uint8_t *ccm_nonce, uint8_t
  43838. + *kck, uint8_t *data, uint8_t *mic);
  43839. +
  43840. +#ifdef __cplusplus
  43841. +}
  43842. +#endif
  43843. +
  43844. +#endif /* _DWC_CRYPTO_H_ */
  43845. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_dh.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c
  43846. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_dh.c 1970-01-01 01:00:00.000000000 +0100
  43847. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.c 2014-06-11 21:03:43.000000000 +0200
  43848. @@ -0,0 +1,291 @@
  43849. +/* =========================================================================
  43850. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.c $
  43851. + * $Revision: #3 $
  43852. + * $Date: 2010/09/28 $
  43853. + * $Change: 1596182 $
  43854. + *
  43855. + * Synopsys Portability Library Software and documentation
  43856. + * (hereinafter, "Software") is an Unsupported proprietary work of
  43857. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  43858. + * between Synopsys and you.
  43859. + *
  43860. + * The Software IS NOT an item of Licensed Software or Licensed Product
  43861. + * under any End User Software License Agreement or Agreement for
  43862. + * Licensed Product with Synopsys or any supplement thereto. You are
  43863. + * permitted to use and redistribute this Software in source and binary
  43864. + * forms, with or without modification, provided that redistributions
  43865. + * of source code must retain this notice. You may not view, use,
  43866. + * disclose, copy or distribute this file or any information contained
  43867. + * herein except pursuant to this license grant from Synopsys. If you
  43868. + * do not agree with this notice, including the disclaimer below, then
  43869. + * you are not authorized to use the Software.
  43870. + *
  43871. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  43872. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  43873. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  43874. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  43875. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  43876. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  43877. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  43878. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  43879. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  43880. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  43881. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  43882. + * DAMAGE.
  43883. + * ========================================================================= */
  43884. +#ifdef DWC_CRYPTOLIB
  43885. +
  43886. +#ifndef CONFIG_MACH_IPMATE
  43887. +
  43888. +#include "dwc_dh.h"
  43889. +#include "dwc_modpow.h"
  43890. +
  43891. +#ifdef DEBUG
  43892. +/* This function prints out a buffer in the format described in the Association
  43893. + * Model specification. */
  43894. +static void dh_dump(char *str, void *_num, int len)
  43895. +{
  43896. + uint8_t *num = _num;
  43897. + int i;
  43898. + DWC_PRINTF("%s\n", str);
  43899. + for (i = 0; i < len; i ++) {
  43900. + DWC_PRINTF("%02x", num[i]);
  43901. + if (((i + 1) % 2) == 0) DWC_PRINTF(" ");
  43902. + if (((i + 1) % 26) == 0) DWC_PRINTF("\n");
  43903. + }
  43904. +
  43905. + DWC_PRINTF("\n");
  43906. +}
  43907. +#else
  43908. +#define dh_dump(_x...) do {; } while(0)
  43909. +#endif
  43910. +
  43911. +/* Constant g value */
  43912. +static __u32 dh_g[] = {
  43913. + 0x02000000,
  43914. +};
  43915. +
  43916. +/* Constant p value */
  43917. +static __u32 dh_p[] = {
  43918. + 0xFFFFFFFF, 0xFFFFFFFF, 0xA2DA0FC9, 0x34C26821, 0x8B62C6C4, 0xD11CDC80, 0x084E0229, 0x74CC678A,
  43919. + 0xA6BE0B02, 0x229B133B, 0x79084A51, 0xDD04348E, 0xB31995EF, 0x1B433ACD, 0x6D0A2B30, 0x37145FF2,
  43920. + 0x6D35E14F, 0x45C2516D, 0x76B585E4, 0xC67E5E62, 0xE9424CF4, 0x6BED37A6, 0xB65CFF0B, 0xEDB706F4,
  43921. + 0xFB6B38EE, 0xA59F895A, 0x11249FAE, 0xE61F4B7C, 0x51662849, 0x3D5BE4EC, 0xB87C00C2, 0x05BF63A1,
  43922. + 0x3648DA98, 0x9AD3551C, 0xA83F1669, 0x5FCF24FD, 0x235D6583, 0x96ADA3DC, 0x56F3621C, 0xBB528520,
  43923. + 0x0729D59E, 0x6D969670, 0x4E350C67, 0x0498BC4A, 0x086C74F1, 0x7C2118CA, 0x465E9032, 0x3BCE362E,
  43924. + 0x2C779EE3, 0x03860E18, 0xA283279B, 0x8FA207EC, 0xF05DC5B5, 0xC9524C6F, 0xF6CB2BDE, 0x18175895,
  43925. + 0x7C499539, 0xE56A95EA, 0x1826D215, 0x1005FA98, 0x5A8E7215, 0x2DC4AA8A, 0x0D1733AD, 0x337A5004,
  43926. + 0xAB2155A8, 0x64BA1CDF, 0x0485FBEC, 0x0AEFDB58, 0x5771EA8A, 0x7D0C065D, 0x850F97B3, 0xC7E4E1A6,
  43927. + 0x8CAEF5AB, 0xD73309DB, 0xE0948C1E, 0x9D61254A, 0x26D2E3CE, 0x6BEED21A, 0x06FA2FF1, 0x64088AD9,
  43928. + 0x730276D8, 0x646AC83E, 0x182B1F52, 0x0C207B17, 0x5717E1BB, 0x6C5D617A, 0xC0880977, 0xE246D9BA,
  43929. + 0xA04FE208, 0x31ABE574, 0xFC5BDB43, 0x8E10FDE0, 0x20D1824B, 0xCAD23AA9, 0xFFFFFFFF, 0xFFFFFFFF,
  43930. +};
  43931. +
  43932. +static void dh_swap_bytes(void *_in, void *_out, uint32_t len)
  43933. +{
  43934. + uint8_t *in = _in;
  43935. + uint8_t *out = _out;
  43936. + int i;
  43937. + for (i=0; i<len; i++) {
  43938. + out[i] = in[len-1-i];
  43939. + }
  43940. +}
  43941. +
  43942. +/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are
  43943. + * big endian numbers of size len, in bytes. Each len value must be a multiple
  43944. + * of 4. */
  43945. +int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  43946. + void *exp, uint32_t exp_len,
  43947. + void *mod, uint32_t mod_len,
  43948. + void *out)
  43949. +{
  43950. + /* modpow() takes little endian numbers. AM uses big-endian. This
  43951. + * function swaps bytes of numbers before passing onto modpow. */
  43952. +
  43953. + int retval = 0;
  43954. + uint32_t *result;
  43955. +
  43956. + uint32_t *bignum_num = dwc_alloc(mem_ctx, num_len + 4);
  43957. + uint32_t *bignum_exp = dwc_alloc(mem_ctx, exp_len + 4);
  43958. + uint32_t *bignum_mod = dwc_alloc(mem_ctx, mod_len + 4);
  43959. +
  43960. + dh_swap_bytes(num, &bignum_num[1], num_len);
  43961. + bignum_num[0] = num_len / 4;
  43962. +
  43963. + dh_swap_bytes(exp, &bignum_exp[1], exp_len);
  43964. + bignum_exp[0] = exp_len / 4;
  43965. +
  43966. + dh_swap_bytes(mod, &bignum_mod[1], mod_len);
  43967. + bignum_mod[0] = mod_len / 4;
  43968. +
  43969. + result = dwc_modpow(mem_ctx, bignum_num, bignum_exp, bignum_mod);
  43970. + if (!result) {
  43971. + retval = -1;
  43972. + goto dh_modpow_nomem;
  43973. + }
  43974. +
  43975. + dh_swap_bytes(&result[1], out, result[0] * 4);
  43976. + dwc_free(mem_ctx, result);
  43977. +
  43978. + dh_modpow_nomem:
  43979. + dwc_free(mem_ctx, bignum_num);
  43980. + dwc_free(mem_ctx, bignum_exp);
  43981. + dwc_free(mem_ctx, bignum_mod);
  43982. + return retval;
  43983. +}
  43984. +
  43985. +
  43986. +int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pk, uint8_t *hash)
  43987. +{
  43988. + int retval;
  43989. + uint8_t m3[385];
  43990. +
  43991. +#ifndef DH_TEST_VECTORS
  43992. + DWC_RANDOM_BYTES(exp, 32);
  43993. +#endif
  43994. +
  43995. + /* Compute the pkd */
  43996. + if ((retval = dwc_dh_modpow(mem_ctx, dh_g, 4,
  43997. + exp, 32,
  43998. + dh_p, 384, pk))) {
  43999. + return retval;
  44000. + }
  44001. +
  44002. + m3[384] = nd;
  44003. + DWC_MEMCPY(&m3[0], pk, 384);
  44004. + DWC_SHA256(m3, 385, hash);
  44005. +
  44006. + dh_dump("PK", pk, 384);
  44007. + dh_dump("SHA-256(M3)", hash, 32);
  44008. + return 0;
  44009. +}
  44010. +
  44011. +int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44012. + uint8_t *exp, int is_host,
  44013. + char *dd, uint8_t *ck, uint8_t *kdk)
  44014. +{
  44015. + int retval;
  44016. + uint8_t mv[784];
  44017. + uint8_t sha_result[32];
  44018. + uint8_t dhkey[384];
  44019. + uint8_t shared_secret[384];
  44020. + char *message;
  44021. + uint32_t vd;
  44022. +
  44023. + uint8_t *pk;
  44024. +
  44025. + if (is_host) {
  44026. + pk = pkd;
  44027. + }
  44028. + else {
  44029. + pk = pkh;
  44030. + }
  44031. +
  44032. + if ((retval = dwc_dh_modpow(mem_ctx, pk, 384,
  44033. + exp, 32,
  44034. + dh_p, 384, shared_secret))) {
  44035. + return retval;
  44036. + }
  44037. + dh_dump("Shared Secret", shared_secret, 384);
  44038. +
  44039. + DWC_SHA256(shared_secret, 384, dhkey);
  44040. + dh_dump("DHKEY", dhkey, 384);
  44041. +
  44042. + DWC_MEMCPY(&mv[0], pkd, 384);
  44043. + DWC_MEMCPY(&mv[384], pkh, 384);
  44044. + DWC_MEMCPY(&mv[768], "displayed digest", 16);
  44045. + dh_dump("MV", mv, 784);
  44046. +
  44047. + DWC_SHA256(mv, 784, sha_result);
  44048. + dh_dump("SHA-256(MV)", sha_result, 32);
  44049. + dh_dump("First 32-bits of SHA-256(MV)", sha_result, 4);
  44050. +
  44051. + dh_swap_bytes(sha_result, &vd, 4);
  44052. +#ifdef DEBUG
  44053. + DWC_PRINTF("Vd (decimal) = %d\n", vd);
  44054. +#endif
  44055. +
  44056. + switch (nd) {
  44057. + case 2:
  44058. + vd = vd % 100;
  44059. + DWC_SPRINTF(dd, "%02d", vd);
  44060. + break;
  44061. + case 3:
  44062. + vd = vd % 1000;
  44063. + DWC_SPRINTF(dd, "%03d", vd);
  44064. + break;
  44065. + case 4:
  44066. + vd = vd % 10000;
  44067. + DWC_SPRINTF(dd, "%04d", vd);
  44068. + break;
  44069. + }
  44070. +#ifdef DEBUG
  44071. + DWC_PRINTF("Display Digits: %s\n", dd);
  44072. +#endif
  44073. +
  44074. + message = "connection key";
  44075. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44076. + dh_dump("HMAC(SHA-256, DHKey, connection key)", sha_result, 32);
  44077. + DWC_MEMCPY(ck, sha_result, 16);
  44078. +
  44079. + message = "key derivation key";
  44080. + DWC_HMAC_SHA256(message, DWC_STRLEN(message), dhkey, 32, sha_result);
  44081. + dh_dump("HMAC(SHA-256, DHKey, key derivation key)", sha_result, 32);
  44082. + DWC_MEMCPY(kdk, sha_result, 32);
  44083. +
  44084. + return 0;
  44085. +}
  44086. +
  44087. +
  44088. +#ifdef DH_TEST_VECTORS
  44089. +
  44090. +static __u8 dh_a[] = {
  44091. + 0x44, 0x00, 0x51, 0xd6,
  44092. + 0xf0, 0xb5, 0x5e, 0xa9,
  44093. + 0x67, 0xab, 0x31, 0xc6,
  44094. + 0x8a, 0x8b, 0x5e, 0x37,
  44095. + 0xd9, 0x10, 0xda, 0xe0,
  44096. + 0xe2, 0xd4, 0x59, 0xa4,
  44097. + 0x86, 0x45, 0x9c, 0xaa,
  44098. + 0xdf, 0x36, 0x75, 0x16,
  44099. +};
  44100. +
  44101. +static __u8 dh_b[] = {
  44102. + 0x5d, 0xae, 0xc7, 0x86,
  44103. + 0x79, 0x80, 0xa3, 0x24,
  44104. + 0x8c, 0xe3, 0x57, 0x8f,
  44105. + 0xc7, 0x5f, 0x1b, 0x0f,
  44106. + 0x2d, 0xf8, 0x9d, 0x30,
  44107. + 0x6f, 0xa4, 0x52, 0xcd,
  44108. + 0xe0, 0x7a, 0x04, 0x8a,
  44109. + 0xde, 0xd9, 0x26, 0x56,
  44110. +};
  44111. +
  44112. +void dwc_run_dh_test_vectors(void *mem_ctx)
  44113. +{
  44114. + uint8_t pkd[384];
  44115. + uint8_t pkh[384];
  44116. + uint8_t hashd[32];
  44117. + uint8_t hashh[32];
  44118. + uint8_t ck[16];
  44119. + uint8_t kdk[32];
  44120. + char dd[5];
  44121. +
  44122. + DWC_PRINTF("\n\n\nDH_TEST_VECTORS\n\n");
  44123. +
  44124. + /* compute the PKd and SHA-256(PKd || Nd) */
  44125. + DWC_PRINTF("Computing PKd\n");
  44126. + dwc_dh_pk(mem_ctx, 2, dh_a, pkd, hashd);
  44127. +
  44128. + /* compute the PKd and SHA-256(PKh || Nd) */
  44129. + DWC_PRINTF("Computing PKh\n");
  44130. + dwc_dh_pk(mem_ctx, 2, dh_b, pkh, hashh);
  44131. +
  44132. + /* compute the dhkey */
  44133. + dwc_dh_derive_keys(mem_ctx, 2, pkh, pkd, dh_a, 0, dd, ck, kdk);
  44134. +}
  44135. +#endif /* DH_TEST_VECTORS */
  44136. +
  44137. +#endif /* !CONFIG_MACH_IPMATE */
  44138. +
  44139. +#endif /* DWC_CRYPTOLIB */
  44140. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_dh.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h
  44141. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_dh.h 1970-01-01 01:00:00.000000000 +0100
  44142. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_dh.h 2014-06-11 21:03:43.000000000 +0200
  44143. @@ -0,0 +1,106 @@
  44144. +/* =========================================================================
  44145. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_dh.h $
  44146. + * $Revision: #4 $
  44147. + * $Date: 2010/09/28 $
  44148. + * $Change: 1596182 $
  44149. + *
  44150. + * Synopsys Portability Library Software and documentation
  44151. + * (hereinafter, "Software") is an Unsupported proprietary work of
  44152. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  44153. + * between Synopsys and you.
  44154. + *
  44155. + * The Software IS NOT an item of Licensed Software or Licensed Product
  44156. + * under any End User Software License Agreement or Agreement for
  44157. + * Licensed Product with Synopsys or any supplement thereto. You are
  44158. + * permitted to use and redistribute this Software in source and binary
  44159. + * forms, with or without modification, provided that redistributions
  44160. + * of source code must retain this notice. You may not view, use,
  44161. + * disclose, copy or distribute this file or any information contained
  44162. + * herein except pursuant to this license grant from Synopsys. If you
  44163. + * do not agree with this notice, including the disclaimer below, then
  44164. + * you are not authorized to use the Software.
  44165. + *
  44166. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  44167. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  44168. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  44169. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  44170. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  44171. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  44172. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  44173. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  44174. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  44175. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  44176. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  44177. + * DAMAGE.
  44178. + * ========================================================================= */
  44179. +#ifndef _DWC_DH_H_
  44180. +#define _DWC_DH_H_
  44181. +
  44182. +#ifdef __cplusplus
  44183. +extern "C" {
  44184. +#endif
  44185. +
  44186. +#include "dwc_os.h"
  44187. +
  44188. +/** @file
  44189. + *
  44190. + * This file defines the common functions on device and host for performing
  44191. + * numeric association as defined in the WUSB spec. They are only to be
  44192. + * used internally by the DWC UWB modules. */
  44193. +
  44194. +extern int dwc_dh_sha256(uint8_t *message, uint32_t len, uint8_t *out);
  44195. +extern int dwc_dh_hmac_sha256(uint8_t *message, uint32_t messagelen,
  44196. + uint8_t *key, uint32_t keylen,
  44197. + uint8_t *out);
  44198. +extern int dwc_dh_modpow(void *mem_ctx, void *num, uint32_t num_len,
  44199. + void *exp, uint32_t exp_len,
  44200. + void *mod, uint32_t mod_len,
  44201. + void *out);
  44202. +
  44203. +/** Computes PKD or PKH, and SHA-256(PKd || Nd)
  44204. + *
  44205. + * PK = g^exp mod p.
  44206. + *
  44207. + * Input:
  44208. + * Nd = Number of digits on the device.
  44209. + *
  44210. + * Output:
  44211. + * exp = A 32-byte buffer to be filled with a randomly generated number.
  44212. + * used as either A or B.
  44213. + * pk = A 384-byte buffer to be filled with the PKH or PKD.
  44214. + * hash = A 32-byte buffer to be filled with SHA-256(PK || ND).
  44215. + */
  44216. +extern int dwc_dh_pk(void *mem_ctx, uint8_t nd, uint8_t *exp, uint8_t *pkd, uint8_t *hash);
  44217. +
  44218. +/** Computes the DHKEY, and VD.
  44219. + *
  44220. + * If called from host, then it will comput DHKEY=PKD^exp % p.
  44221. + * If called from device, then it will comput DHKEY=PKH^exp % p.
  44222. + *
  44223. + * Input:
  44224. + * pkd = The PKD value.
  44225. + * pkh = The PKH value.
  44226. + * exp = The A value (if device) or B value (if host) generated in dwc_wudev_dh_pk.
  44227. + * is_host = Set to non zero if a WUSB host is calling this function.
  44228. + *
  44229. + * Output:
  44230. +
  44231. + * dd = A pointer to an buffer to be set to the displayed digits string to be shown
  44232. + * to the user. This buffer should be at 5 bytes long to hold 4 digits plus a
  44233. + * null termination character. This buffer can be used directly for display.
  44234. + * ck = A 16-byte buffer to be filled with the CK.
  44235. + * kdk = A 32-byte buffer to be filled with the KDK.
  44236. + */
  44237. +extern int dwc_dh_derive_keys(void *mem_ctx, uint8_t nd, uint8_t *pkh, uint8_t *pkd,
  44238. + uint8_t *exp, int is_host,
  44239. + char *dd, uint8_t *ck, uint8_t *kdk);
  44240. +
  44241. +#ifdef DH_TEST_VECTORS
  44242. +extern void dwc_run_dh_test_vectors(void);
  44243. +#endif
  44244. +
  44245. +#ifdef __cplusplus
  44246. +}
  44247. +#endif
  44248. +
  44249. +#endif /* _DWC_DH_H_ */
  44250. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_list.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h
  44251. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_list.h 1970-01-01 01:00:00.000000000 +0100
  44252. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_list.h 2014-06-11 21:03:43.000000000 +0200
  44253. @@ -0,0 +1,594 @@
  44254. +/* $OpenBSD: queue.h,v 1.26 2004/05/04 16:59:32 grange Exp $ */
  44255. +/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
  44256. +
  44257. +/*
  44258. + * Copyright (c) 1991, 1993
  44259. + * The Regents of the University of California. All rights reserved.
  44260. + *
  44261. + * Redistribution and use in source and binary forms, with or without
  44262. + * modification, are permitted provided that the following conditions
  44263. + * are met:
  44264. + * 1. Redistributions of source code must retain the above copyright
  44265. + * notice, this list of conditions and the following disclaimer.
  44266. + * 2. Redistributions in binary form must reproduce the above copyright
  44267. + * notice, this list of conditions and the following disclaimer in the
  44268. + * documentation and/or other materials provided with the distribution.
  44269. + * 3. Neither the name of the University nor the names of its contributors
  44270. + * may be used to endorse or promote products derived from this software
  44271. + * without specific prior written permission.
  44272. + *
  44273. + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  44274. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  44275. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  44276. + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  44277. + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  44278. + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  44279. + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  44280. + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  44281. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  44282. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  44283. + * SUCH DAMAGE.
  44284. + *
  44285. + * @(#)queue.h 8.5 (Berkeley) 8/20/94
  44286. + */
  44287. +
  44288. +#ifndef _DWC_LIST_H_
  44289. +#define _DWC_LIST_H_
  44290. +
  44291. +#ifdef __cplusplus
  44292. +extern "C" {
  44293. +#endif
  44294. +
  44295. +/** @file
  44296. + *
  44297. + * This file defines linked list operations. It is derived from BSD with
  44298. + * only the MACRO names being prefixed with DWC_. This is because a few of
  44299. + * these names conflict with those on Linux. For documentation on use, see the
  44300. + * inline comments in the source code. The original license for this source
  44301. + * code applies and is preserved in the dwc_list.h source file.
  44302. + */
  44303. +
  44304. +/*
  44305. + * This file defines five types of data structures: singly-linked lists,
  44306. + * lists, simple queues, tail queues, and circular queues.
  44307. + *
  44308. + *
  44309. + * A singly-linked list is headed by a single forward pointer. The elements
  44310. + * are singly linked for minimum space and pointer manipulation overhead at
  44311. + * the expense of O(n) removal for arbitrary elements. New elements can be
  44312. + * added to the list after an existing element or at the head of the list.
  44313. + * Elements being removed from the head of the list should use the explicit
  44314. + * macro for this purpose for optimum efficiency. A singly-linked list may
  44315. + * only be traversed in the forward direction. Singly-linked lists are ideal
  44316. + * for applications with large datasets and few or no removals or for
  44317. + * implementing a LIFO queue.
  44318. + *
  44319. + * A list is headed by a single forward pointer (or an array of forward
  44320. + * pointers for a hash table header). The elements are doubly linked
  44321. + * so that an arbitrary element can be removed without a need to
  44322. + * traverse the list. New elements can be added to the list before
  44323. + * or after an existing element or at the head of the list. A list
  44324. + * may only be traversed in the forward direction.
  44325. + *
  44326. + * A simple queue is headed by a pair of pointers, one the head of the
  44327. + * list and the other to the tail of the list. The elements are singly
  44328. + * linked to save space, so elements can only be removed from the
  44329. + * head of the list. New elements can be added to the list before or after
  44330. + * an existing element, at the head of the list, or at the end of the
  44331. + * list. A simple queue may only be traversed in the forward direction.
  44332. + *
  44333. + * A tail queue is headed by a pair of pointers, one to the head of the
  44334. + * list and the other to the tail of the list. The elements are doubly
  44335. + * linked so that an arbitrary element can be removed without a need to
  44336. + * traverse the list. New elements can be added to the list before or
  44337. + * after an existing element, at the head of the list, or at the end of
  44338. + * the list. A tail queue may be traversed in either direction.
  44339. + *
  44340. + * A circle queue is headed by a pair of pointers, one to the head of the
  44341. + * list and the other to the tail of the list. The elements are doubly
  44342. + * linked so that an arbitrary element can be removed without a need to
  44343. + * traverse the list. New elements can be added to the list before or after
  44344. + * an existing element, at the head of the list, or at the end of the list.
  44345. + * A circle queue may be traversed in either direction, but has a more
  44346. + * complex end of list detection.
  44347. + *
  44348. + * For details on the use of these macros, see the queue(3) manual page.
  44349. + */
  44350. +
  44351. +/*
  44352. + * Double-linked List.
  44353. + */
  44354. +
  44355. +typedef struct dwc_list_link {
  44356. + struct dwc_list_link *next;
  44357. + struct dwc_list_link *prev;
  44358. +} dwc_list_link_t;
  44359. +
  44360. +#define DWC_LIST_INIT(link) do { \
  44361. + (link)->next = (link); \
  44362. + (link)->prev = (link); \
  44363. +} while (0)
  44364. +
  44365. +#define DWC_LIST_FIRST(link) ((link)->next)
  44366. +#define DWC_LIST_LAST(link) ((link)->prev)
  44367. +#define DWC_LIST_END(link) (link)
  44368. +#define DWC_LIST_NEXT(link) ((link)->next)
  44369. +#define DWC_LIST_PREV(link) ((link)->prev)
  44370. +#define DWC_LIST_EMPTY(link) \
  44371. + (DWC_LIST_FIRST(link) == DWC_LIST_END(link))
  44372. +#define DWC_LIST_ENTRY(link, type, field) \
  44373. + (type *)((uint8_t *)(link) - (size_t)(&((type *)0)->field))
  44374. +
  44375. +#if 0
  44376. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44377. + (link)->next = (list)->next; \
  44378. + (link)->prev = (list); \
  44379. + (list)->next->prev = (link); \
  44380. + (list)->next = (link); \
  44381. +} while (0)
  44382. +
  44383. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44384. + (link)->next = (list); \
  44385. + (link)->prev = (list)->prev; \
  44386. + (list)->prev->next = (link); \
  44387. + (list)->prev = (link); \
  44388. +} while (0)
  44389. +#else
  44390. +#define DWC_LIST_INSERT_HEAD(list, link) do { \
  44391. + dwc_list_link_t *__next__ = (list)->next; \
  44392. + __next__->prev = (link); \
  44393. + (link)->next = __next__; \
  44394. + (link)->prev = (list); \
  44395. + (list)->next = (link); \
  44396. +} while (0)
  44397. +
  44398. +#define DWC_LIST_INSERT_TAIL(list, link) do { \
  44399. + dwc_list_link_t *__prev__ = (list)->prev; \
  44400. + (list)->prev = (link); \
  44401. + (link)->next = (list); \
  44402. + (link)->prev = __prev__; \
  44403. + __prev__->next = (link); \
  44404. +} while (0)
  44405. +#endif
  44406. +
  44407. +#if 0
  44408. +static inline void __list_add(struct list_head *new,
  44409. + struct list_head *prev,
  44410. + struct list_head *next)
  44411. +{
  44412. + next->prev = new;
  44413. + new->next = next;
  44414. + new->prev = prev;
  44415. + prev->next = new;
  44416. +}
  44417. +
  44418. +static inline void list_add(struct list_head *new, struct list_head *head)
  44419. +{
  44420. + __list_add(new, head, head->next);
  44421. +}
  44422. +
  44423. +static inline void list_add_tail(struct list_head *new, struct list_head *head)
  44424. +{
  44425. + __list_add(new, head->prev, head);
  44426. +}
  44427. +
  44428. +static inline void __list_del(struct list_head * prev, struct list_head * next)
  44429. +{
  44430. + next->prev = prev;
  44431. + prev->next = next;
  44432. +}
  44433. +
  44434. +static inline void list_del(struct list_head *entry)
  44435. +{
  44436. + __list_del(entry->prev, entry->next);
  44437. + entry->next = LIST_POISON1;
  44438. + entry->prev = LIST_POISON2;
  44439. +}
  44440. +#endif
  44441. +
  44442. +#define DWC_LIST_REMOVE(link) do { \
  44443. + (link)->next->prev = (link)->prev; \
  44444. + (link)->prev->next = (link)->next; \
  44445. +} while (0)
  44446. +
  44447. +#define DWC_LIST_REMOVE_INIT(link) do { \
  44448. + DWC_LIST_REMOVE(link); \
  44449. + DWC_LIST_INIT(link); \
  44450. +} while (0)
  44451. +
  44452. +#define DWC_LIST_MOVE_HEAD(list, link) do { \
  44453. + DWC_LIST_REMOVE(link); \
  44454. + DWC_LIST_INSERT_HEAD(list, link); \
  44455. +} while (0)
  44456. +
  44457. +#define DWC_LIST_MOVE_TAIL(list, link) do { \
  44458. + DWC_LIST_REMOVE(link); \
  44459. + DWC_LIST_INSERT_TAIL(list, link); \
  44460. +} while (0)
  44461. +
  44462. +#define DWC_LIST_FOREACH(var, list) \
  44463. + for((var) = DWC_LIST_FIRST(list); \
  44464. + (var) != DWC_LIST_END(list); \
  44465. + (var) = DWC_LIST_NEXT(var))
  44466. +
  44467. +#define DWC_LIST_FOREACH_SAFE(var, var2, list) \
  44468. + for((var) = DWC_LIST_FIRST(list), (var2) = DWC_LIST_NEXT(var); \
  44469. + (var) != DWC_LIST_END(list); \
  44470. + (var) = (var2), (var2) = DWC_LIST_NEXT(var2))
  44471. +
  44472. +#define DWC_LIST_FOREACH_REVERSE(var, list) \
  44473. + for((var) = DWC_LIST_LAST(list); \
  44474. + (var) != DWC_LIST_END(list); \
  44475. + (var) = DWC_LIST_PREV(var))
  44476. +
  44477. +/*
  44478. + * Singly-linked List definitions.
  44479. + */
  44480. +#define DWC_SLIST_HEAD(name, type) \
  44481. +struct name { \
  44482. + struct type *slh_first; /* first element */ \
  44483. +}
  44484. +
  44485. +#define DWC_SLIST_HEAD_INITIALIZER(head) \
  44486. + { NULL }
  44487. +
  44488. +#define DWC_SLIST_ENTRY(type) \
  44489. +struct { \
  44490. + struct type *sle_next; /* next element */ \
  44491. +}
  44492. +
  44493. +/*
  44494. + * Singly-linked List access methods.
  44495. + */
  44496. +#define DWC_SLIST_FIRST(head) ((head)->slh_first)
  44497. +#define DWC_SLIST_END(head) NULL
  44498. +#define DWC_SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
  44499. +#define DWC_SLIST_NEXT(elm, field) ((elm)->field.sle_next)
  44500. +
  44501. +#define DWC_SLIST_FOREACH(var, head, field) \
  44502. + for((var) = SLIST_FIRST(head); \
  44503. + (var) != SLIST_END(head); \
  44504. + (var) = SLIST_NEXT(var, field))
  44505. +
  44506. +#define DWC_SLIST_FOREACH_PREVPTR(var, varp, head, field) \
  44507. + for((varp) = &SLIST_FIRST((head)); \
  44508. + ((var) = *(varp)) != SLIST_END(head); \
  44509. + (varp) = &SLIST_NEXT((var), field))
  44510. +
  44511. +/*
  44512. + * Singly-linked List functions.
  44513. + */
  44514. +#define DWC_SLIST_INIT(head) { \
  44515. + SLIST_FIRST(head) = SLIST_END(head); \
  44516. +}
  44517. +
  44518. +#define DWC_SLIST_INSERT_AFTER(slistelm, elm, field) do { \
  44519. + (elm)->field.sle_next = (slistelm)->field.sle_next; \
  44520. + (slistelm)->field.sle_next = (elm); \
  44521. +} while (0)
  44522. +
  44523. +#define DWC_SLIST_INSERT_HEAD(head, elm, field) do { \
  44524. + (elm)->field.sle_next = (head)->slh_first; \
  44525. + (head)->slh_first = (elm); \
  44526. +} while (0)
  44527. +
  44528. +#define DWC_SLIST_REMOVE_NEXT(head, elm, field) do { \
  44529. + (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
  44530. +} while (0)
  44531. +
  44532. +#define DWC_SLIST_REMOVE_HEAD(head, field) do { \
  44533. + (head)->slh_first = (head)->slh_first->field.sle_next; \
  44534. +} while (0)
  44535. +
  44536. +#define DWC_SLIST_REMOVE(head, elm, type, field) do { \
  44537. + if ((head)->slh_first == (elm)) { \
  44538. + SLIST_REMOVE_HEAD((head), field); \
  44539. + } \
  44540. + else { \
  44541. + struct type *curelm = (head)->slh_first; \
  44542. + while( curelm->field.sle_next != (elm) ) \
  44543. + curelm = curelm->field.sle_next; \
  44544. + curelm->field.sle_next = \
  44545. + curelm->field.sle_next->field.sle_next; \
  44546. + } \
  44547. +} while (0)
  44548. +
  44549. +/*
  44550. + * Simple queue definitions.
  44551. + */
  44552. +#define DWC_SIMPLEQ_HEAD(name, type) \
  44553. +struct name { \
  44554. + struct type *sqh_first; /* first element */ \
  44555. + struct type **sqh_last; /* addr of last next element */ \
  44556. +}
  44557. +
  44558. +#define DWC_SIMPLEQ_HEAD_INITIALIZER(head) \
  44559. + { NULL, &(head).sqh_first }
  44560. +
  44561. +#define DWC_SIMPLEQ_ENTRY(type) \
  44562. +struct { \
  44563. + struct type *sqe_next; /* next element */ \
  44564. +}
  44565. +
  44566. +/*
  44567. + * Simple queue access methods.
  44568. + */
  44569. +#define DWC_SIMPLEQ_FIRST(head) ((head)->sqh_first)
  44570. +#define DWC_SIMPLEQ_END(head) NULL
  44571. +#define DWC_SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
  44572. +#define DWC_SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
  44573. +
  44574. +#define DWC_SIMPLEQ_FOREACH(var, head, field) \
  44575. + for((var) = SIMPLEQ_FIRST(head); \
  44576. + (var) != SIMPLEQ_END(head); \
  44577. + (var) = SIMPLEQ_NEXT(var, field))
  44578. +
  44579. +/*
  44580. + * Simple queue functions.
  44581. + */
  44582. +#define DWC_SIMPLEQ_INIT(head) do { \
  44583. + (head)->sqh_first = NULL; \
  44584. + (head)->sqh_last = &(head)->sqh_first; \
  44585. +} while (0)
  44586. +
  44587. +#define DWC_SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
  44588. + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
  44589. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44590. + (head)->sqh_first = (elm); \
  44591. +} while (0)
  44592. +
  44593. +#define DWC_SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
  44594. + (elm)->field.sqe_next = NULL; \
  44595. + *(head)->sqh_last = (elm); \
  44596. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44597. +} while (0)
  44598. +
  44599. +#define DWC_SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44600. + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
  44601. + (head)->sqh_last = &(elm)->field.sqe_next; \
  44602. + (listelm)->field.sqe_next = (elm); \
  44603. +} while (0)
  44604. +
  44605. +#define DWC_SIMPLEQ_REMOVE_HEAD(head, field) do { \
  44606. + if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
  44607. + (head)->sqh_last = &(head)->sqh_first; \
  44608. +} while (0)
  44609. +
  44610. +/*
  44611. + * Tail queue definitions.
  44612. + */
  44613. +#define DWC_TAILQ_HEAD(name, type) \
  44614. +struct name { \
  44615. + struct type *tqh_first; /* first element */ \
  44616. + struct type **tqh_last; /* addr of last next element */ \
  44617. +}
  44618. +
  44619. +#define DWC_TAILQ_HEAD_INITIALIZER(head) \
  44620. + { NULL, &(head).tqh_first }
  44621. +
  44622. +#define DWC_TAILQ_ENTRY(type) \
  44623. +struct { \
  44624. + struct type *tqe_next; /* next element */ \
  44625. + struct type **tqe_prev; /* address of previous next element */ \
  44626. +}
  44627. +
  44628. +/*
  44629. + * tail queue access methods
  44630. + */
  44631. +#define DWC_TAILQ_FIRST(head) ((head)->tqh_first)
  44632. +#define DWC_TAILQ_END(head) NULL
  44633. +#define DWC_TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
  44634. +#define DWC_TAILQ_LAST(head, headname) \
  44635. + (*(((struct headname *)((head)->tqh_last))->tqh_last))
  44636. +/* XXX */
  44637. +#define DWC_TAILQ_PREV(elm, headname, field) \
  44638. + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
  44639. +#define DWC_TAILQ_EMPTY(head) \
  44640. + (DWC_TAILQ_FIRST(head) == DWC_TAILQ_END(head))
  44641. +
  44642. +#define DWC_TAILQ_FOREACH(var, head, field) \
  44643. + for ((var) = DWC_TAILQ_FIRST(head); \
  44644. + (var) != DWC_TAILQ_END(head); \
  44645. + (var) = DWC_TAILQ_NEXT(var, field))
  44646. +
  44647. +#define DWC_TAILQ_FOREACH_REVERSE(var, head, headname, field) \
  44648. + for ((var) = DWC_TAILQ_LAST(head, headname); \
  44649. + (var) != DWC_TAILQ_END(head); \
  44650. + (var) = DWC_TAILQ_PREV(var, headname, field))
  44651. +
  44652. +/*
  44653. + * Tail queue functions.
  44654. + */
  44655. +#define DWC_TAILQ_INIT(head) do { \
  44656. + (head)->tqh_first = NULL; \
  44657. + (head)->tqh_last = &(head)->tqh_first; \
  44658. +} while (0)
  44659. +
  44660. +#define DWC_TAILQ_INSERT_HEAD(head, elm, field) do { \
  44661. + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
  44662. + (head)->tqh_first->field.tqe_prev = \
  44663. + &(elm)->field.tqe_next; \
  44664. + else \
  44665. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44666. + (head)->tqh_first = (elm); \
  44667. + (elm)->field.tqe_prev = &(head)->tqh_first; \
  44668. +} while (0)
  44669. +
  44670. +#define DWC_TAILQ_INSERT_TAIL(head, elm, field) do { \
  44671. + (elm)->field.tqe_next = NULL; \
  44672. + (elm)->field.tqe_prev = (head)->tqh_last; \
  44673. + *(head)->tqh_last = (elm); \
  44674. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44675. +} while (0)
  44676. +
  44677. +#define DWC_TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44678. + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
  44679. + (elm)->field.tqe_next->field.tqe_prev = \
  44680. + &(elm)->field.tqe_next; \
  44681. + else \
  44682. + (head)->tqh_last = &(elm)->field.tqe_next; \
  44683. + (listelm)->field.tqe_next = (elm); \
  44684. + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
  44685. +} while (0)
  44686. +
  44687. +#define DWC_TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
  44688. + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
  44689. + (elm)->field.tqe_next = (listelm); \
  44690. + *(listelm)->field.tqe_prev = (elm); \
  44691. + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
  44692. +} while (0)
  44693. +
  44694. +#define DWC_TAILQ_REMOVE(head, elm, field) do { \
  44695. + if (((elm)->field.tqe_next) != NULL) \
  44696. + (elm)->field.tqe_next->field.tqe_prev = \
  44697. + (elm)->field.tqe_prev; \
  44698. + else \
  44699. + (head)->tqh_last = (elm)->field.tqe_prev; \
  44700. + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
  44701. +} while (0)
  44702. +
  44703. +#define DWC_TAILQ_REPLACE(head, elm, elm2, field) do { \
  44704. + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
  44705. + (elm2)->field.tqe_next->field.tqe_prev = \
  44706. + &(elm2)->field.tqe_next; \
  44707. + else \
  44708. + (head)->tqh_last = &(elm2)->field.tqe_next; \
  44709. + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
  44710. + *(elm2)->field.tqe_prev = (elm2); \
  44711. +} while (0)
  44712. +
  44713. +/*
  44714. + * Circular queue definitions.
  44715. + */
  44716. +#define DWC_CIRCLEQ_HEAD(name, type) \
  44717. +struct name { \
  44718. + struct type *cqh_first; /* first element */ \
  44719. + struct type *cqh_last; /* last element */ \
  44720. +}
  44721. +
  44722. +#define DWC_CIRCLEQ_HEAD_INITIALIZER(head) \
  44723. + { DWC_CIRCLEQ_END(&head), DWC_CIRCLEQ_END(&head) }
  44724. +
  44725. +#define DWC_CIRCLEQ_ENTRY(type) \
  44726. +struct { \
  44727. + struct type *cqe_next; /* next element */ \
  44728. + struct type *cqe_prev; /* previous element */ \
  44729. +}
  44730. +
  44731. +/*
  44732. + * Circular queue access methods
  44733. + */
  44734. +#define DWC_CIRCLEQ_FIRST(head) ((head)->cqh_first)
  44735. +#define DWC_CIRCLEQ_LAST(head) ((head)->cqh_last)
  44736. +#define DWC_CIRCLEQ_END(head) ((void *)(head))
  44737. +#define DWC_CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
  44738. +#define DWC_CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
  44739. +#define DWC_CIRCLEQ_EMPTY(head) \
  44740. + (DWC_CIRCLEQ_FIRST(head) == DWC_CIRCLEQ_END(head))
  44741. +
  44742. +#define DWC_CIRCLEQ_EMPTY_ENTRY(elm, field) (((elm)->field.cqe_next == NULL) && ((elm)->field.cqe_prev == NULL))
  44743. +
  44744. +#define DWC_CIRCLEQ_FOREACH(var, head, field) \
  44745. + for((var) = DWC_CIRCLEQ_FIRST(head); \
  44746. + (var) != DWC_CIRCLEQ_END(head); \
  44747. + (var) = DWC_CIRCLEQ_NEXT(var, field))
  44748. +
  44749. +#define DWC_CIRCLEQ_FOREACH_SAFE(var, var2, head, field) \
  44750. + for((var) = DWC_CIRCLEQ_FIRST(head), var2 = DWC_CIRCLEQ_NEXT(var, field); \
  44751. + (var) != DWC_CIRCLEQ_END(head); \
  44752. + (var) = var2, var2 = DWC_CIRCLEQ_NEXT(var, field))
  44753. +
  44754. +#define DWC_CIRCLEQ_FOREACH_REVERSE(var, head, field) \
  44755. + for((var) = DWC_CIRCLEQ_LAST(head); \
  44756. + (var) != DWC_CIRCLEQ_END(head); \
  44757. + (var) = DWC_CIRCLEQ_PREV(var, field))
  44758. +
  44759. +/*
  44760. + * Circular queue functions.
  44761. + */
  44762. +#define DWC_CIRCLEQ_INIT(head) do { \
  44763. + (head)->cqh_first = DWC_CIRCLEQ_END(head); \
  44764. + (head)->cqh_last = DWC_CIRCLEQ_END(head); \
  44765. +} while (0)
  44766. +
  44767. +#define DWC_CIRCLEQ_INIT_ENTRY(elm, field) do { \
  44768. + (elm)->field.cqe_next = NULL; \
  44769. + (elm)->field.cqe_prev = NULL; \
  44770. +} while (0)
  44771. +
  44772. +#define DWC_CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
  44773. + (elm)->field.cqe_next = (listelm)->field.cqe_next; \
  44774. + (elm)->field.cqe_prev = (listelm); \
  44775. + if ((listelm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44776. + (head)->cqh_last = (elm); \
  44777. + else \
  44778. + (listelm)->field.cqe_next->field.cqe_prev = (elm); \
  44779. + (listelm)->field.cqe_next = (elm); \
  44780. +} while (0)
  44781. +
  44782. +#define DWC_CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
  44783. + (elm)->field.cqe_next = (listelm); \
  44784. + (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
  44785. + if ((listelm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44786. + (head)->cqh_first = (elm); \
  44787. + else \
  44788. + (listelm)->field.cqe_prev->field.cqe_next = (elm); \
  44789. + (listelm)->field.cqe_prev = (elm); \
  44790. +} while (0)
  44791. +
  44792. +#define DWC_CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
  44793. + (elm)->field.cqe_next = (head)->cqh_first; \
  44794. + (elm)->field.cqe_prev = DWC_CIRCLEQ_END(head); \
  44795. + if ((head)->cqh_last == DWC_CIRCLEQ_END(head)) \
  44796. + (head)->cqh_last = (elm); \
  44797. + else \
  44798. + (head)->cqh_first->field.cqe_prev = (elm); \
  44799. + (head)->cqh_first = (elm); \
  44800. +} while (0)
  44801. +
  44802. +#define DWC_CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
  44803. + (elm)->field.cqe_next = DWC_CIRCLEQ_END(head); \
  44804. + (elm)->field.cqe_prev = (head)->cqh_last; \
  44805. + if ((head)->cqh_first == DWC_CIRCLEQ_END(head)) \
  44806. + (head)->cqh_first = (elm); \
  44807. + else \
  44808. + (head)->cqh_last->field.cqe_next = (elm); \
  44809. + (head)->cqh_last = (elm); \
  44810. +} while (0)
  44811. +
  44812. +#define DWC_CIRCLEQ_REMOVE(head, elm, field) do { \
  44813. + if ((elm)->field.cqe_next == DWC_CIRCLEQ_END(head)) \
  44814. + (head)->cqh_last = (elm)->field.cqe_prev; \
  44815. + else \
  44816. + (elm)->field.cqe_next->field.cqe_prev = \
  44817. + (elm)->field.cqe_prev; \
  44818. + if ((elm)->field.cqe_prev == DWC_CIRCLEQ_END(head)) \
  44819. + (head)->cqh_first = (elm)->field.cqe_next; \
  44820. + else \
  44821. + (elm)->field.cqe_prev->field.cqe_next = \
  44822. + (elm)->field.cqe_next; \
  44823. +} while (0)
  44824. +
  44825. +#define DWC_CIRCLEQ_REMOVE_INIT(head, elm, field) do { \
  44826. + DWC_CIRCLEQ_REMOVE(head, elm, field); \
  44827. + DWC_CIRCLEQ_INIT_ENTRY(elm, field); \
  44828. +} while (0)
  44829. +
  44830. +#define DWC_CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
  44831. + if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
  44832. + DWC_CIRCLEQ_END(head)) \
  44833. + (head).cqh_last = (elm2); \
  44834. + else \
  44835. + (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
  44836. + if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
  44837. + DWC_CIRCLEQ_END(head)) \
  44838. + (head).cqh_first = (elm2); \
  44839. + else \
  44840. + (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
  44841. +} while (0)
  44842. +
  44843. +#ifdef __cplusplus
  44844. +}
  44845. +#endif
  44846. +
  44847. +#endif /* _DWC_LIST_H_ */
  44848. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_mem.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c
  44849. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_mem.c 1970-01-01 01:00:00.000000000 +0100
  44850. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_mem.c 2014-06-11 21:03:43.000000000 +0200
  44851. @@ -0,0 +1,245 @@
  44852. +/* Memory Debugging */
  44853. +#ifdef DWC_DEBUG_MEMORY
  44854. +
  44855. +#include "dwc_os.h"
  44856. +#include "dwc_list.h"
  44857. +
  44858. +struct allocation {
  44859. + void *addr;
  44860. + void *ctx;
  44861. + char *func;
  44862. + int line;
  44863. + uint32_t size;
  44864. + int dma;
  44865. + DWC_CIRCLEQ_ENTRY(allocation) entry;
  44866. +};
  44867. +
  44868. +DWC_CIRCLEQ_HEAD(allocation_queue, allocation);
  44869. +
  44870. +struct allocation_manager {
  44871. + void *mem_ctx;
  44872. + struct allocation_queue allocations;
  44873. +
  44874. + /* statistics */
  44875. + int num;
  44876. + int num_freed;
  44877. + int num_active;
  44878. + uint32_t total;
  44879. + uint32_t cur;
  44880. + uint32_t max;
  44881. +};
  44882. +
  44883. +static struct allocation_manager *manager = NULL;
  44884. +
  44885. +static int add_allocation(void *ctx, uint32_t size, char const *func, int line, void *addr,
  44886. + int dma)
  44887. +{
  44888. + struct allocation *a;
  44889. +
  44890. + DWC_ASSERT(manager != NULL, "manager not allocated");
  44891. +
  44892. + a = __DWC_ALLOC_ATOMIC(manager->mem_ctx, sizeof(*a));
  44893. + if (!a) {
  44894. + return -DWC_E_NO_MEMORY;
  44895. + }
  44896. +
  44897. + a->func = __DWC_ALLOC_ATOMIC(manager->mem_ctx, DWC_STRLEN(func) + 1);
  44898. + if (!a->func) {
  44899. + __DWC_FREE(manager->mem_ctx, a);
  44900. + return -DWC_E_NO_MEMORY;
  44901. + }
  44902. +
  44903. + DWC_MEMCPY(a->func, func, DWC_STRLEN(func) + 1);
  44904. + a->addr = addr;
  44905. + a->ctx = ctx;
  44906. + a->line = line;
  44907. + a->size = size;
  44908. + a->dma = dma;
  44909. + DWC_CIRCLEQ_INSERT_TAIL(&manager->allocations, a, entry);
  44910. +
  44911. + /* Update stats */
  44912. + manager->num++;
  44913. + manager->num_active++;
  44914. + manager->total += size;
  44915. + manager->cur += size;
  44916. +
  44917. + if (manager->max < manager->cur) {
  44918. + manager->max = manager->cur;
  44919. + }
  44920. +
  44921. + return 0;
  44922. +}
  44923. +
  44924. +static struct allocation *find_allocation(void *ctx, void *addr)
  44925. +{
  44926. + struct allocation *a;
  44927. +
  44928. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44929. + if (a->ctx == ctx && a->addr == addr) {
  44930. + return a;
  44931. + }
  44932. + }
  44933. +
  44934. + return NULL;
  44935. +}
  44936. +
  44937. +static void free_allocation(void *ctx, void *addr, char const *func, int line)
  44938. +{
  44939. + struct allocation *a = find_allocation(ctx, addr);
  44940. +
  44941. + if (!a) {
  44942. + DWC_ASSERT(0,
  44943. + "Free of address %p that was never allocated or already freed %s:%d",
  44944. + addr, func, line);
  44945. + return;
  44946. + }
  44947. +
  44948. + DWC_CIRCLEQ_REMOVE(&manager->allocations, a, entry);
  44949. +
  44950. + manager->num_active--;
  44951. + manager->num_freed++;
  44952. + manager->cur -= a->size;
  44953. + __DWC_FREE(manager->mem_ctx, a->func);
  44954. + __DWC_FREE(manager->mem_ctx, a);
  44955. +}
  44956. +
  44957. +int dwc_memory_debug_start(void *mem_ctx)
  44958. +{
  44959. + DWC_ASSERT(manager == NULL, "Memory debugging has already started\n");
  44960. +
  44961. + if (manager) {
  44962. + return -DWC_E_BUSY;
  44963. + }
  44964. +
  44965. + manager = __DWC_ALLOC(mem_ctx, sizeof(*manager));
  44966. + if (!manager) {
  44967. + return -DWC_E_NO_MEMORY;
  44968. + }
  44969. +
  44970. + DWC_CIRCLEQ_INIT(&manager->allocations);
  44971. + manager->mem_ctx = mem_ctx;
  44972. + manager->num = 0;
  44973. + manager->num_freed = 0;
  44974. + manager->num_active = 0;
  44975. + manager->total = 0;
  44976. + manager->cur = 0;
  44977. + manager->max = 0;
  44978. +
  44979. + return 0;
  44980. +}
  44981. +
  44982. +void dwc_memory_debug_stop(void)
  44983. +{
  44984. + struct allocation *a;
  44985. +
  44986. + dwc_memory_debug_report();
  44987. +
  44988. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  44989. + DWC_ERROR("Memory leaked from %s:%d\n", a->func, a->line);
  44990. + free_allocation(a->ctx, a->addr, NULL, -1);
  44991. + }
  44992. +
  44993. + __DWC_FREE(manager->mem_ctx, manager);
  44994. +}
  44995. +
  44996. +void dwc_memory_debug_report(void)
  44997. +{
  44998. + struct allocation *a;
  44999. +
  45000. + DWC_PRINTF("\n\n\n----------------- Memory Debugging Report -----------------\n\n");
  45001. + DWC_PRINTF("Num Allocations = %d\n", manager->num);
  45002. + DWC_PRINTF("Freed = %d\n", manager->num_freed);
  45003. + DWC_PRINTF("Active = %d\n", manager->num_active);
  45004. + DWC_PRINTF("Current Memory Used = %d\n", manager->cur);
  45005. + DWC_PRINTF("Total Memory Used = %d\n", manager->total);
  45006. + DWC_PRINTF("Maximum Memory Used at Once = %d\n", manager->max);
  45007. + DWC_PRINTF("Unfreed allocations:\n");
  45008. +
  45009. + DWC_CIRCLEQ_FOREACH(a, &manager->allocations, entry) {
  45010. + DWC_PRINTF(" addr=%p, size=%d from %s:%d, DMA=%d\n",
  45011. + a->addr, a->size, a->func, a->line, a->dma);
  45012. + }
  45013. +}
  45014. +
  45015. +/* The replacement functions */
  45016. +void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line)
  45017. +{
  45018. + void *addr = __DWC_ALLOC(mem_ctx, size);
  45019. +
  45020. + if (!addr) {
  45021. + return NULL;
  45022. + }
  45023. +
  45024. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45025. + __DWC_FREE(mem_ctx, addr);
  45026. + return NULL;
  45027. + }
  45028. +
  45029. + return addr;
  45030. +}
  45031. +
  45032. +void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func,
  45033. + int line)
  45034. +{
  45035. + void *addr = __DWC_ALLOC_ATOMIC(mem_ctx, size);
  45036. +
  45037. + if (!addr) {
  45038. + return NULL;
  45039. + }
  45040. +
  45041. + if (add_allocation(mem_ctx, size, func, line, addr, 0)) {
  45042. + __DWC_FREE(mem_ctx, addr);
  45043. + return NULL;
  45044. + }
  45045. +
  45046. + return addr;
  45047. +}
  45048. +
  45049. +void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line)
  45050. +{
  45051. + free_allocation(mem_ctx, addr, func, line);
  45052. + __DWC_FREE(mem_ctx, addr);
  45053. +}
  45054. +
  45055. +void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  45056. + char const *func, int line)
  45057. +{
  45058. + void *addr = __DWC_DMA_ALLOC(dma_ctx, size, dma_addr);
  45059. +
  45060. + if (!addr) {
  45061. + return NULL;
  45062. + }
  45063. +
  45064. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45065. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45066. + return NULL;
  45067. + }
  45068. +
  45069. + return addr;
  45070. +}
  45071. +
  45072. +void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size,
  45073. + dwc_dma_t *dma_addr, char const *func, int line)
  45074. +{
  45075. + void *addr = __DWC_DMA_ALLOC_ATOMIC(dma_ctx, size, dma_addr);
  45076. +
  45077. + if (!addr) {
  45078. + return NULL;
  45079. + }
  45080. +
  45081. + if (add_allocation(dma_ctx, size, func, line, addr, 1)) {
  45082. + __DWC_DMA_FREE(dma_ctx, size, addr, *dma_addr);
  45083. + return NULL;
  45084. + }
  45085. +
  45086. + return addr;
  45087. +}
  45088. +
  45089. +void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  45090. + dwc_dma_t dma_addr, char const *func, int line)
  45091. +{
  45092. + free_allocation(dma_ctx, virt_addr, func, line);
  45093. + __DWC_DMA_FREE(dma_ctx, size, virt_addr, dma_addr);
  45094. +}
  45095. +
  45096. +#endif /* DWC_DEBUG_MEMORY */
  45097. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_modpow.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c
  45098. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_modpow.c 1970-01-01 01:00:00.000000000 +0100
  45099. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.c 2014-06-11 21:03:43.000000000 +0200
  45100. @@ -0,0 +1,636 @@
  45101. +/* Bignum routines adapted from PUTTY sources. PuTTY copyright notice follows.
  45102. + *
  45103. + * PuTTY is copyright 1997-2007 Simon Tatham.
  45104. + *
  45105. + * Portions copyright Robert de Bath, Joris van Rantwijk, Delian
  45106. + * Delchev, Andreas Schultz, Jeroen Massar, Wez Furlong, Nicolas Barry,
  45107. + * Justin Bradford, Ben Harris, Malcolm Smith, Ahmad Khalifa, Markus
  45108. + * Kuhn, and CORE SDI S.A.
  45109. + *
  45110. + * Permission is hereby granted, free of charge, to any person
  45111. + * obtaining a copy of this software and associated documentation files
  45112. + * (the "Software"), to deal in the Software without restriction,
  45113. + * including without limitation the rights to use, copy, modify, merge,
  45114. + * publish, distribute, sublicense, and/or sell copies of the Software,
  45115. + * and to permit persons to whom the Software is furnished to do so,
  45116. + * subject to the following conditions:
  45117. + *
  45118. + * The above copyright notice and this permission notice shall be
  45119. + * included in all copies or substantial portions of the Software.
  45120. +
  45121. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  45122. + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  45123. + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  45124. + * NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE
  45125. + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  45126. + * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  45127. + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  45128. + *
  45129. + */
  45130. +#ifdef DWC_CRYPTOLIB
  45131. +
  45132. +#ifndef CONFIG_MACH_IPMATE
  45133. +
  45134. +#include "dwc_modpow.h"
  45135. +
  45136. +#define BIGNUM_INT_MASK 0xFFFFFFFFUL
  45137. +#define BIGNUM_TOP_BIT 0x80000000UL
  45138. +#define BIGNUM_INT_BITS 32
  45139. +
  45140. +
  45141. +static void *snmalloc(void *mem_ctx, size_t n, size_t size)
  45142. +{
  45143. + void *p;
  45144. + size *= n;
  45145. + if (size == 0) size = 1;
  45146. + p = dwc_alloc(mem_ctx, size);
  45147. + return p;
  45148. +}
  45149. +
  45150. +#define snewn(ctx, n, type) ((type *)snmalloc((ctx), (n), sizeof(type)))
  45151. +#define sfree dwc_free
  45152. +
  45153. +/*
  45154. + * Usage notes:
  45155. + * * Do not call the DIVMOD_WORD macro with expressions such as array
  45156. + * subscripts, as some implementations object to this (see below).
  45157. + * * Note that none of the division methods below will cope if the
  45158. + * quotient won't fit into BIGNUM_INT_BITS. Callers should be careful
  45159. + * to avoid this case.
  45160. + * If this condition occurs, in the case of the x86 DIV instruction,
  45161. + * an overflow exception will occur, which (according to a correspondent)
  45162. + * will manifest on Windows as something like
  45163. + * 0xC0000095: Integer overflow
  45164. + * The C variant won't give the right answer, either.
  45165. + */
  45166. +
  45167. +#define MUL_WORD(w1, w2) ((BignumDblInt)w1 * w2)
  45168. +
  45169. +#if defined __GNUC__ && defined __i386__
  45170. +#define DIVMOD_WORD(q, r, hi, lo, w) \
  45171. + __asm__("div %2" : \
  45172. + "=d" (r), "=a" (q) : \
  45173. + "r" (w), "d" (hi), "a" (lo))
  45174. +#else
  45175. +#define DIVMOD_WORD(q, r, hi, lo, w) do { \
  45176. + BignumDblInt n = (((BignumDblInt)hi) << BIGNUM_INT_BITS) | lo; \
  45177. + q = n / w; \
  45178. + r = n % w; \
  45179. +} while (0)
  45180. +#endif
  45181. +
  45182. +// q = n / w;
  45183. +// r = n % w;
  45184. +
  45185. +#define BIGNUM_INT_BYTES (BIGNUM_INT_BITS / 8)
  45186. +
  45187. +#define BIGNUM_INTERNAL
  45188. +
  45189. +static Bignum newbn(void *mem_ctx, int length)
  45190. +{
  45191. + Bignum b = snewn(mem_ctx, length + 1, BignumInt);
  45192. + //if (!b)
  45193. + //abort(); /* FIXME */
  45194. + DWC_MEMSET(b, 0, (length + 1) * sizeof(*b));
  45195. + b[0] = length;
  45196. + return b;
  45197. +}
  45198. +
  45199. +void freebn(void *mem_ctx, Bignum b)
  45200. +{
  45201. + /*
  45202. + * Burn the evidence, just in case.
  45203. + */
  45204. + DWC_MEMSET(b, 0, sizeof(b[0]) * (b[0] + 1));
  45205. + sfree(mem_ctx, b);
  45206. +}
  45207. +
  45208. +/*
  45209. + * Compute c = a * b.
  45210. + * Input is in the first len words of a and b.
  45211. + * Result is returned in the first 2*len words of c.
  45212. + */
  45213. +static void internal_mul(BignumInt *a, BignumInt *b,
  45214. + BignumInt *c, int len)
  45215. +{
  45216. + int i, j;
  45217. + BignumDblInt t;
  45218. +
  45219. + for (j = 0; j < 2 * len; j++)
  45220. + c[j] = 0;
  45221. +
  45222. + for (i = len - 1; i >= 0; i--) {
  45223. + t = 0;
  45224. + for (j = len - 1; j >= 0; j--) {
  45225. + t += MUL_WORD(a[i], (BignumDblInt) b[j]);
  45226. + t += (BignumDblInt) c[i + j + 1];
  45227. + c[i + j + 1] = (BignumInt) t;
  45228. + t = t >> BIGNUM_INT_BITS;
  45229. + }
  45230. + c[i] = (BignumInt) t;
  45231. + }
  45232. +}
  45233. +
  45234. +static void internal_add_shifted(BignumInt *number,
  45235. + unsigned n, int shift)
  45236. +{
  45237. + int word = 1 + (shift / BIGNUM_INT_BITS);
  45238. + int bshift = shift % BIGNUM_INT_BITS;
  45239. + BignumDblInt addend;
  45240. +
  45241. + addend = (BignumDblInt)n << bshift;
  45242. +
  45243. + while (addend) {
  45244. + addend += number[word];
  45245. + number[word] = (BignumInt) addend & BIGNUM_INT_MASK;
  45246. + addend >>= BIGNUM_INT_BITS;
  45247. + word++;
  45248. + }
  45249. +}
  45250. +
  45251. +/*
  45252. + * Compute a = a % m.
  45253. + * Input in first alen words of a and first mlen words of m.
  45254. + * Output in first alen words of a
  45255. + * (of which first alen-mlen words will be zero).
  45256. + * The MSW of m MUST have its high bit set.
  45257. + * Quotient is accumulated in the `quotient' array, which is a Bignum
  45258. + * rather than the internal bigendian format. Quotient parts are shifted
  45259. + * left by `qshift' before adding into quot.
  45260. + */
  45261. +static void internal_mod(BignumInt *a, int alen,
  45262. + BignumInt *m, int mlen,
  45263. + BignumInt *quot, int qshift)
  45264. +{
  45265. + BignumInt m0, m1;
  45266. + unsigned int h;
  45267. + int i, k;
  45268. +
  45269. + m0 = m[0];
  45270. + if (mlen > 1)
  45271. + m1 = m[1];
  45272. + else
  45273. + m1 = 0;
  45274. +
  45275. + for (i = 0; i <= alen - mlen; i++) {
  45276. + BignumDblInt t;
  45277. + unsigned int q, r, c, ai1;
  45278. +
  45279. + if (i == 0) {
  45280. + h = 0;
  45281. + } else {
  45282. + h = a[i - 1];
  45283. + a[i - 1] = 0;
  45284. + }
  45285. +
  45286. + if (i == alen - 1)
  45287. + ai1 = 0;
  45288. + else
  45289. + ai1 = a[i + 1];
  45290. +
  45291. + /* Find q = h:a[i] / m0 */
  45292. + if (h >= m0) {
  45293. + /*
  45294. + * Special case.
  45295. + *
  45296. + * To illustrate it, suppose a BignumInt is 8 bits, and
  45297. + * we are dividing (say) A1:23:45:67 by A1:B2:C3. Then
  45298. + * our initial division will be 0xA123 / 0xA1, which
  45299. + * will give a quotient of 0x100 and a divide overflow.
  45300. + * However, the invariants in this division algorithm
  45301. + * are not violated, since the full number A1:23:... is
  45302. + * _less_ than the quotient prefix A1:B2:... and so the
  45303. + * following correction loop would have sorted it out.
  45304. + *
  45305. + * In this situation we set q to be the largest
  45306. + * quotient we _can_ stomach (0xFF, of course).
  45307. + */
  45308. + q = BIGNUM_INT_MASK;
  45309. + } else {
  45310. + /* Macro doesn't want an array subscript expression passed
  45311. + * into it (see definition), so use a temporary. */
  45312. + BignumInt tmplo = a[i];
  45313. + DIVMOD_WORD(q, r, h, tmplo, m0);
  45314. +
  45315. + /* Refine our estimate of q by looking at
  45316. + h:a[i]:a[i+1] / m0:m1 */
  45317. + t = MUL_WORD(m1, q);
  45318. + if (t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) {
  45319. + q--;
  45320. + t -= m1;
  45321. + r = (r + m0) & BIGNUM_INT_MASK; /* overflow? */
  45322. + if (r >= (BignumDblInt) m0 &&
  45323. + t > ((BignumDblInt) r << BIGNUM_INT_BITS) + ai1) q--;
  45324. + }
  45325. + }
  45326. +
  45327. + /* Subtract q * m from a[i...] */
  45328. + c = 0;
  45329. + for (k = mlen - 1; k >= 0; k--) {
  45330. + t = MUL_WORD(q, m[k]);
  45331. + t += c;
  45332. + c = (unsigned)(t >> BIGNUM_INT_BITS);
  45333. + if ((BignumInt) t > a[i + k])
  45334. + c++;
  45335. + a[i + k] -= (BignumInt) t;
  45336. + }
  45337. +
  45338. + /* Add back m in case of borrow */
  45339. + if (c != h) {
  45340. + t = 0;
  45341. + for (k = mlen - 1; k >= 0; k--) {
  45342. + t += m[k];
  45343. + t += a[i + k];
  45344. + a[i + k] = (BignumInt) t;
  45345. + t = t >> BIGNUM_INT_BITS;
  45346. + }
  45347. + q--;
  45348. + }
  45349. + if (quot)
  45350. + internal_add_shifted(quot, q, qshift + BIGNUM_INT_BITS * (alen - mlen - i));
  45351. + }
  45352. +}
  45353. +
  45354. +/*
  45355. + * Compute p % mod.
  45356. + * The most significant word of mod MUST be non-zero.
  45357. + * We assume that the result array is the same size as the mod array.
  45358. + * We optionally write out a quotient if `quotient' is non-NULL.
  45359. + * We can avoid writing out the result if `result' is NULL.
  45360. + */
  45361. +void bigdivmod(void *mem_ctx, Bignum p, Bignum mod, Bignum result, Bignum quotient)
  45362. +{
  45363. + BignumInt *n, *m;
  45364. + int mshift;
  45365. + int plen, mlen, i, j;
  45366. +
  45367. + /* Allocate m of size mlen, copy mod to m */
  45368. + /* We use big endian internally */
  45369. + mlen = mod[0];
  45370. + m = snewn(mem_ctx, mlen, BignumInt);
  45371. + //if (!m)
  45372. + //abort(); /* FIXME */
  45373. + for (j = 0; j < mlen; j++)
  45374. + m[j] = mod[mod[0] - j];
  45375. +
  45376. + /* Shift m left to make msb bit set */
  45377. + for (mshift = 0; mshift < BIGNUM_INT_BITS-1; mshift++)
  45378. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45379. + break;
  45380. + if (mshift) {
  45381. + for (i = 0; i < mlen - 1; i++)
  45382. + m[i] = (m[i] << mshift) | (m[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45383. + m[mlen - 1] = m[mlen - 1] << mshift;
  45384. + }
  45385. +
  45386. + plen = p[0];
  45387. + /* Ensure plen > mlen */
  45388. + if (plen <= mlen)
  45389. + plen = mlen + 1;
  45390. +
  45391. + /* Allocate n of size plen, copy p to n */
  45392. + n = snewn(mem_ctx, plen, BignumInt);
  45393. + //if (!n)
  45394. + //abort(); /* FIXME */
  45395. + for (j = 0; j < plen; j++)
  45396. + n[j] = 0;
  45397. + for (j = 1; j <= (int)p[0]; j++)
  45398. + n[plen - j] = p[j];
  45399. +
  45400. + /* Main computation */
  45401. + internal_mod(n, plen, m, mlen, quotient, mshift);
  45402. +
  45403. + /* Fixup result in case the modulus was shifted */
  45404. + if (mshift) {
  45405. + for (i = plen - mlen - 1; i < plen - 1; i++)
  45406. + n[i] = (n[i] << mshift) | (n[i + 1] >> (BIGNUM_INT_BITS - mshift));
  45407. + n[plen - 1] = n[plen - 1] << mshift;
  45408. + internal_mod(n, plen, m, mlen, quotient, 0);
  45409. + for (i = plen - 1; i >= plen - mlen; i--)
  45410. + n[i] = (n[i] >> mshift) | (n[i - 1] << (BIGNUM_INT_BITS - mshift));
  45411. + }
  45412. +
  45413. + /* Copy result to buffer */
  45414. + if (result) {
  45415. + for (i = 1; i <= (int)result[0]; i++) {
  45416. + int j = plen - i;
  45417. + result[i] = j >= 0 ? n[j] : 0;
  45418. + }
  45419. + }
  45420. +
  45421. + /* Free temporary arrays */
  45422. + for (i = 0; i < mlen; i++)
  45423. + m[i] = 0;
  45424. + sfree(mem_ctx, m);
  45425. + for (i = 0; i < plen; i++)
  45426. + n[i] = 0;
  45427. + sfree(mem_ctx, n);
  45428. +}
  45429. +
  45430. +/*
  45431. + * Simple remainder.
  45432. + */
  45433. +Bignum bigmod(void *mem_ctx, Bignum a, Bignum b)
  45434. +{
  45435. + Bignum r = newbn(mem_ctx, b[0]);
  45436. + bigdivmod(mem_ctx, a, b, r, NULL);
  45437. + return r;
  45438. +}
  45439. +
  45440. +/*
  45441. + * Compute (base ^ exp) % mod.
  45442. + */
  45443. +Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod)
  45444. +{
  45445. + BignumInt *a, *b, *n, *m;
  45446. + int mshift;
  45447. + int mlen, i, j;
  45448. + Bignum base, result;
  45449. +
  45450. + /*
  45451. + * The most significant word of mod needs to be non-zero. It
  45452. + * should already be, but let's make sure.
  45453. + */
  45454. + //assert(mod[mod[0]] != 0);
  45455. +
  45456. + /*
  45457. + * Make sure the base is smaller than the modulus, by reducing
  45458. + * it modulo the modulus if not.
  45459. + */
  45460. + base = bigmod(mem_ctx, base_in, mod);
  45461. +
  45462. + /* Allocate m of size mlen, copy mod to m */
  45463. + /* We use big endian internally */
  45464. + mlen = mod[0];
  45465. + m = snewn(mem_ctx, mlen, BignumInt);
  45466. + //if (!m)
  45467. + //abort(); /* FIXME */
  45468. + for (j = 0; j < mlen; j++)
  45469. + m[j] = mod[mod[0] - j];
  45470. +
  45471. + /* Shift m left to make msb bit set */
  45472. + for (mshift = 0; mshift < BIGNUM_INT_BITS - 1; mshift++)
  45473. + if ((m[0] << mshift) & BIGNUM_TOP_BIT)
  45474. + break;
  45475. + if (mshift) {
  45476. + for (i = 0; i < mlen - 1; i++)
  45477. + m[i] =
  45478. + (m[i] << mshift) | (m[i + 1] >>
  45479. + (BIGNUM_INT_BITS - mshift));
  45480. + m[mlen - 1] = m[mlen - 1] << mshift;
  45481. + }
  45482. +
  45483. + /* Allocate n of size mlen, copy base to n */
  45484. + n = snewn(mem_ctx, mlen, BignumInt);
  45485. + //if (!n)
  45486. + //abort(); /* FIXME */
  45487. + i = mlen - base[0];
  45488. + for (j = 0; j < i; j++)
  45489. + n[j] = 0;
  45490. + for (j = 0; j < base[0]; j++)
  45491. + n[i + j] = base[base[0] - j];
  45492. +
  45493. + /* Allocate a and b of size 2*mlen. Set a = 1 */
  45494. + a = snewn(mem_ctx, 2 * mlen, BignumInt);
  45495. + //if (!a)
  45496. + //abort(); /* FIXME */
  45497. + b = snewn(mem_ctx, 2 * mlen, BignumInt);
  45498. + //if (!b)
  45499. + //abort(); /* FIXME */
  45500. + for (i = 0; i < 2 * mlen; i++)
  45501. + a[i] = 0;
  45502. + a[2 * mlen - 1] = 1;
  45503. +
  45504. + /* Skip leading zero bits of exp. */
  45505. + i = 0;
  45506. + j = BIGNUM_INT_BITS - 1;
  45507. + while (i < exp[0] && (exp[exp[0] - i] & (1 << j)) == 0) {
  45508. + j--;
  45509. + if (j < 0) {
  45510. + i++;
  45511. + j = BIGNUM_INT_BITS - 1;
  45512. + }
  45513. + }
  45514. +
  45515. + /* Main computation */
  45516. + while (i < exp[0]) {
  45517. + while (j >= 0) {
  45518. + internal_mul(a + mlen, a + mlen, b, mlen);
  45519. + internal_mod(b, mlen * 2, m, mlen, NULL, 0);
  45520. + if ((exp[exp[0] - i] & (1 << j)) != 0) {
  45521. + internal_mul(b + mlen, n, a, mlen);
  45522. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45523. + } else {
  45524. + BignumInt *t;
  45525. + t = a;
  45526. + a = b;
  45527. + b = t;
  45528. + }
  45529. + j--;
  45530. + }
  45531. + i++;
  45532. + j = BIGNUM_INT_BITS - 1;
  45533. + }
  45534. +
  45535. + /* Fixup result in case the modulus was shifted */
  45536. + if (mshift) {
  45537. + for (i = mlen - 1; i < 2 * mlen - 1; i++)
  45538. + a[i] =
  45539. + (a[i] << mshift) | (a[i + 1] >>
  45540. + (BIGNUM_INT_BITS - mshift));
  45541. + a[2 * mlen - 1] = a[2 * mlen - 1] << mshift;
  45542. + internal_mod(a, mlen * 2, m, mlen, NULL, 0);
  45543. + for (i = 2 * mlen - 1; i >= mlen; i--)
  45544. + a[i] =
  45545. + (a[i] >> mshift) | (a[i - 1] <<
  45546. + (BIGNUM_INT_BITS - mshift));
  45547. + }
  45548. +
  45549. + /* Copy result to buffer */
  45550. + result = newbn(mem_ctx, mod[0]);
  45551. + for (i = 0; i < mlen; i++)
  45552. + result[result[0] - i] = a[i + mlen];
  45553. + while (result[0] > 1 && result[result[0]] == 0)
  45554. + result[0]--;
  45555. +
  45556. + /* Free temporary arrays */
  45557. + for (i = 0; i < 2 * mlen; i++)
  45558. + a[i] = 0;
  45559. + sfree(mem_ctx, a);
  45560. + for (i = 0; i < 2 * mlen; i++)
  45561. + b[i] = 0;
  45562. + sfree(mem_ctx, b);
  45563. + for (i = 0; i < mlen; i++)
  45564. + m[i] = 0;
  45565. + sfree(mem_ctx, m);
  45566. + for (i = 0; i < mlen; i++)
  45567. + n[i] = 0;
  45568. + sfree(mem_ctx, n);
  45569. +
  45570. + freebn(mem_ctx, base);
  45571. +
  45572. + return result;
  45573. +}
  45574. +
  45575. +
  45576. +#ifdef UNITTEST
  45577. +
  45578. +static __u32 dh_p[] = {
  45579. + 96,
  45580. + 0xFFFFFFFF,
  45581. + 0xFFFFFFFF,
  45582. + 0xA93AD2CA,
  45583. + 0x4B82D120,
  45584. + 0xE0FD108E,
  45585. + 0x43DB5BFC,
  45586. + 0x74E5AB31,
  45587. + 0x08E24FA0,
  45588. + 0xBAD946E2,
  45589. + 0x770988C0,
  45590. + 0x7A615D6C,
  45591. + 0xBBE11757,
  45592. + 0x177B200C,
  45593. + 0x521F2B18,
  45594. + 0x3EC86A64,
  45595. + 0xD8760273,
  45596. + 0xD98A0864,
  45597. + 0xF12FFA06,
  45598. + 0x1AD2EE6B,
  45599. + 0xCEE3D226,
  45600. + 0x4A25619D,
  45601. + 0x1E8C94E0,
  45602. + 0xDB0933D7,
  45603. + 0xABF5AE8C,
  45604. + 0xA6E1E4C7,
  45605. + 0xB3970F85,
  45606. + 0x5D060C7D,
  45607. + 0x8AEA7157,
  45608. + 0x58DBEF0A,
  45609. + 0xECFB8504,
  45610. + 0xDF1CBA64,
  45611. + 0xA85521AB,
  45612. + 0x04507A33,
  45613. + 0xAD33170D,
  45614. + 0x8AAAC42D,
  45615. + 0x15728E5A,
  45616. + 0x98FA0510,
  45617. + 0x15D22618,
  45618. + 0xEA956AE5,
  45619. + 0x3995497C,
  45620. + 0x95581718,
  45621. + 0xDE2BCBF6,
  45622. + 0x6F4C52C9,
  45623. + 0xB5C55DF0,
  45624. + 0xEC07A28F,
  45625. + 0x9B2783A2,
  45626. + 0x180E8603,
  45627. + 0xE39E772C,
  45628. + 0x2E36CE3B,
  45629. + 0x32905E46,
  45630. + 0xCA18217C,
  45631. + 0xF1746C08,
  45632. + 0x4ABC9804,
  45633. + 0x670C354E,
  45634. + 0x7096966D,
  45635. + 0x9ED52907,
  45636. + 0x208552BB,
  45637. + 0x1C62F356,
  45638. + 0xDCA3AD96,
  45639. + 0x83655D23,
  45640. + 0xFD24CF5F,
  45641. + 0x69163FA8,
  45642. + 0x1C55D39A,
  45643. + 0x98DA4836,
  45644. + 0xA163BF05,
  45645. + 0xC2007CB8,
  45646. + 0xECE45B3D,
  45647. + 0x49286651,
  45648. + 0x7C4B1FE6,
  45649. + 0xAE9F2411,
  45650. + 0x5A899FA5,
  45651. + 0xEE386BFB,
  45652. + 0xF406B7ED,
  45653. + 0x0BFF5CB6,
  45654. + 0xA637ED6B,
  45655. + 0xF44C42E9,
  45656. + 0x625E7EC6,
  45657. + 0xE485B576,
  45658. + 0x6D51C245,
  45659. + 0x4FE1356D,
  45660. + 0xF25F1437,
  45661. + 0x302B0A6D,
  45662. + 0xCD3A431B,
  45663. + 0xEF9519B3,
  45664. + 0x8E3404DD,
  45665. + 0x514A0879,
  45666. + 0x3B139B22,
  45667. + 0x020BBEA6,
  45668. + 0x8A67CC74,
  45669. + 0x29024E08,
  45670. + 0x80DC1CD1,
  45671. + 0xC4C6628B,
  45672. + 0x2168C234,
  45673. + 0xC90FDAA2,
  45674. + 0xFFFFFFFF,
  45675. + 0xFFFFFFFF,
  45676. +};
  45677. +
  45678. +static __u32 dh_a[] = {
  45679. + 8,
  45680. + 0xdf367516,
  45681. + 0x86459caa,
  45682. + 0xe2d459a4,
  45683. + 0xd910dae0,
  45684. + 0x8a8b5e37,
  45685. + 0x67ab31c6,
  45686. + 0xf0b55ea9,
  45687. + 0x440051d6,
  45688. +};
  45689. +
  45690. +static __u32 dh_b[] = {
  45691. + 8,
  45692. + 0xded92656,
  45693. + 0xe07a048a,
  45694. + 0x6fa452cd,
  45695. + 0x2df89d30,
  45696. + 0xc75f1b0f,
  45697. + 0x8ce3578f,
  45698. + 0x7980a324,
  45699. + 0x5daec786,
  45700. +};
  45701. +
  45702. +static __u32 dh_g[] = {
  45703. + 1,
  45704. + 2,
  45705. +};
  45706. +
  45707. +int main(void)
  45708. +{
  45709. + int i;
  45710. + __u32 *k;
  45711. + k = dwc_modpow(NULL, dh_g, dh_a, dh_p);
  45712. +
  45713. + printf("\n\n");
  45714. + for (i=0; i<k[0]; i++) {
  45715. + __u32 word32 = k[k[0] - i];
  45716. + __u16 l = word32 & 0xffff;
  45717. + __u16 m = (word32 & 0xffff0000) >> 16;
  45718. + printf("%04x %04x ", m, l);
  45719. + if (!((i + 1)%13)) printf("\n");
  45720. + }
  45721. + printf("\n\n");
  45722. +
  45723. + if ((k[0] == 0x60) && (k[1] == 0x28e490e5) && (k[0x60] == 0x5a0d3d4e)) {
  45724. + printf("PASS\n\n");
  45725. + }
  45726. + else {
  45727. + printf("FAIL\n\n");
  45728. + }
  45729. +
  45730. +}
  45731. +
  45732. +#endif /* UNITTEST */
  45733. +
  45734. +#endif /* CONFIG_MACH_IPMATE */
  45735. +
  45736. +#endif /*DWC_CRYPTOLIB */
  45737. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_modpow.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h
  45738. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_modpow.h 1970-01-01 01:00:00.000000000 +0100
  45739. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_modpow.h 2014-06-11 21:03:43.000000000 +0200
  45740. @@ -0,0 +1,34 @@
  45741. +/*
  45742. + * dwc_modpow.h
  45743. + * See dwc_modpow.c for license and changes
  45744. + */
  45745. +#ifndef _DWC_MODPOW_H
  45746. +#define _DWC_MODPOW_H
  45747. +
  45748. +#ifdef __cplusplus
  45749. +extern "C" {
  45750. +#endif
  45751. +
  45752. +#include "dwc_os.h"
  45753. +
  45754. +/** @file
  45755. + *
  45756. + * This file defines the module exponentiation function which is only used
  45757. + * internally by the DWC UWB modules for calculation of PKs during numeric
  45758. + * association. The routine is taken from the PUTTY, an open source terminal
  45759. + * emulator. The PUTTY License is preserved in the dwc_modpow.c file.
  45760. + *
  45761. + */
  45762. +
  45763. +typedef uint32_t BignumInt;
  45764. +typedef uint64_t BignumDblInt;
  45765. +typedef BignumInt *Bignum;
  45766. +
  45767. +/* Compute modular exponentiaion */
  45768. +extern Bignum dwc_modpow(void *mem_ctx, Bignum base_in, Bignum exp, Bignum mod);
  45769. +
  45770. +#ifdef __cplusplus
  45771. +}
  45772. +#endif
  45773. +
  45774. +#endif /* _LINUX_BIGNUM_H */
  45775. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_notifier.c linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c
  45776. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_notifier.c 1970-01-01 01:00:00.000000000 +0100
  45777. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.c 2014-06-11 21:03:43.000000000 +0200
  45778. @@ -0,0 +1,319 @@
  45779. +#ifdef DWC_NOTIFYLIB
  45780. +
  45781. +#include "dwc_notifier.h"
  45782. +#include "dwc_list.h"
  45783. +
  45784. +typedef struct dwc_observer {
  45785. + void *observer;
  45786. + dwc_notifier_callback_t callback;
  45787. + void *data;
  45788. + char *notification;
  45789. + DWC_CIRCLEQ_ENTRY(dwc_observer) list_entry;
  45790. +} observer_t;
  45791. +
  45792. +DWC_CIRCLEQ_HEAD(observer_queue, dwc_observer);
  45793. +
  45794. +typedef struct dwc_notifier {
  45795. + void *mem_ctx;
  45796. + void *object;
  45797. + struct observer_queue observers;
  45798. + DWC_CIRCLEQ_ENTRY(dwc_notifier) list_entry;
  45799. +} notifier_t;
  45800. +
  45801. +DWC_CIRCLEQ_HEAD(notifier_queue, dwc_notifier);
  45802. +
  45803. +typedef struct manager {
  45804. + void *mem_ctx;
  45805. + void *wkq_ctx;
  45806. + dwc_workq_t *wq;
  45807. +// dwc_mutex_t *mutex;
  45808. + struct notifier_queue notifiers;
  45809. +} manager_t;
  45810. +
  45811. +static manager_t *manager = NULL;
  45812. +
  45813. +static int create_manager(void *mem_ctx, void *wkq_ctx)
  45814. +{
  45815. + manager = dwc_alloc(mem_ctx, sizeof(manager_t));
  45816. + if (!manager) {
  45817. + return -DWC_E_NO_MEMORY;
  45818. + }
  45819. +
  45820. + DWC_CIRCLEQ_INIT(&manager->notifiers);
  45821. +
  45822. + manager->wq = dwc_workq_alloc(wkq_ctx, "DWC Notification WorkQ");
  45823. + if (!manager->wq) {
  45824. + return -DWC_E_NO_MEMORY;
  45825. + }
  45826. +
  45827. + return 0;
  45828. +}
  45829. +
  45830. +static void free_manager(void)
  45831. +{
  45832. + dwc_workq_free(manager->wq);
  45833. +
  45834. + /* All notifiers must have unregistered themselves before this module
  45835. + * can be removed. Hitting this assertion indicates a programmer
  45836. + * error. */
  45837. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&manager->notifiers),
  45838. + "Notification manager being freed before all notifiers have been removed");
  45839. + dwc_free(manager->mem_ctx, manager);
  45840. +}
  45841. +
  45842. +#ifdef DEBUG
  45843. +static void dump_manager(void)
  45844. +{
  45845. + notifier_t *n;
  45846. + observer_t *o;
  45847. +
  45848. + DWC_ASSERT(manager, "Notification manager not found");
  45849. +
  45850. + DWC_DEBUG("List of all notifiers and observers:\n");
  45851. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  45852. + DWC_DEBUG("Notifier %p has observers:\n", n->object);
  45853. + DWC_CIRCLEQ_FOREACH(o, &n->observers, list_entry) {
  45854. + DWC_DEBUG(" %p watching %s\n", o->observer, o->notification);
  45855. + }
  45856. + }
  45857. +}
  45858. +#else
  45859. +#define dump_manager(...)
  45860. +#endif
  45861. +
  45862. +static observer_t *alloc_observer(void *mem_ctx, void *observer, char *notification,
  45863. + dwc_notifier_callback_t callback, void *data)
  45864. +{
  45865. + observer_t *new_observer = dwc_alloc(mem_ctx, sizeof(observer_t));
  45866. +
  45867. + if (!new_observer) {
  45868. + return NULL;
  45869. + }
  45870. +
  45871. + DWC_CIRCLEQ_INIT_ENTRY(new_observer, list_entry);
  45872. + new_observer->observer = observer;
  45873. + new_observer->notification = notification;
  45874. + new_observer->callback = callback;
  45875. + new_observer->data = data;
  45876. + return new_observer;
  45877. +}
  45878. +
  45879. +static void free_observer(void *mem_ctx, observer_t *observer)
  45880. +{
  45881. + dwc_free(mem_ctx, observer);
  45882. +}
  45883. +
  45884. +static notifier_t *alloc_notifier(void *mem_ctx, void *object)
  45885. +{
  45886. + notifier_t *notifier;
  45887. +
  45888. + if (!object) {
  45889. + return NULL;
  45890. + }
  45891. +
  45892. + notifier = dwc_alloc(mem_ctx, sizeof(notifier_t));
  45893. + if (!notifier) {
  45894. + return NULL;
  45895. + }
  45896. +
  45897. + DWC_CIRCLEQ_INIT(&notifier->observers);
  45898. + DWC_CIRCLEQ_INIT_ENTRY(notifier, list_entry);
  45899. +
  45900. + notifier->mem_ctx = mem_ctx;
  45901. + notifier->object = object;
  45902. + return notifier;
  45903. +}
  45904. +
  45905. +static void free_notifier(notifier_t *notifier)
  45906. +{
  45907. + observer_t *observer;
  45908. +
  45909. + DWC_CIRCLEQ_FOREACH(observer, &notifier->observers, list_entry) {
  45910. + free_observer(notifier->mem_ctx, observer);
  45911. + }
  45912. +
  45913. + dwc_free(notifier->mem_ctx, notifier);
  45914. +}
  45915. +
  45916. +static notifier_t *find_notifier(void *object)
  45917. +{
  45918. + notifier_t *notifier;
  45919. +
  45920. + DWC_ASSERT(manager, "Notification manager not found");
  45921. +
  45922. + if (!object) {
  45923. + return NULL;
  45924. + }
  45925. +
  45926. + DWC_CIRCLEQ_FOREACH(notifier, &manager->notifiers, list_entry) {
  45927. + if (notifier->object == object) {
  45928. + return notifier;
  45929. + }
  45930. + }
  45931. +
  45932. + return NULL;
  45933. +}
  45934. +
  45935. +int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx)
  45936. +{
  45937. + return create_manager(mem_ctx, wkq_ctx);
  45938. +}
  45939. +
  45940. +void dwc_free_notification_manager(void)
  45941. +{
  45942. + free_manager();
  45943. +}
  45944. +
  45945. +dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object)
  45946. +{
  45947. + notifier_t *notifier;
  45948. +
  45949. + DWC_ASSERT(manager, "Notification manager not found");
  45950. +
  45951. + notifier = find_notifier(object);
  45952. + if (notifier) {
  45953. + DWC_ERROR("Notifier %p is already registered\n", object);
  45954. + return NULL;
  45955. + }
  45956. +
  45957. + notifier = alloc_notifier(mem_ctx, object);
  45958. + if (!notifier) {
  45959. + return NULL;
  45960. + }
  45961. +
  45962. + DWC_CIRCLEQ_INSERT_TAIL(&manager->notifiers, notifier, list_entry);
  45963. +
  45964. + DWC_INFO("Notifier %p registered", object);
  45965. + dump_manager();
  45966. +
  45967. + return notifier;
  45968. +}
  45969. +
  45970. +void dwc_unregister_notifier(dwc_notifier_t *notifier)
  45971. +{
  45972. + DWC_ASSERT(manager, "Notification manager not found");
  45973. +
  45974. + if (!DWC_CIRCLEQ_EMPTY(&notifier->observers)) {
  45975. + observer_t *o;
  45976. +
  45977. + DWC_ERROR("Notifier %p has active observers when removing\n", notifier->object);
  45978. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  45979. + DWC_DEBUGC(" %p watching %s\n", o->observer, o->notification);
  45980. + }
  45981. +
  45982. + DWC_ASSERT(DWC_CIRCLEQ_EMPTY(&notifier->observers),
  45983. + "Notifier %p has active observers when removing", notifier);
  45984. + }
  45985. +
  45986. + DWC_CIRCLEQ_REMOVE_INIT(&manager->notifiers, notifier, list_entry);
  45987. + free_notifier(notifier);
  45988. +
  45989. + DWC_INFO("Notifier unregistered");
  45990. + dump_manager();
  45991. +}
  45992. +
  45993. +/* Add an observer to observe the notifier for a particular state, event, or notification. */
  45994. +int dwc_add_observer(void *observer, void *object, char *notification,
  45995. + dwc_notifier_callback_t callback, void *data)
  45996. +{
  45997. + notifier_t *notifier = find_notifier(object);
  45998. + observer_t *new_observer;
  45999. +
  46000. + if (!notifier) {
  46001. + DWC_ERROR("Notifier %p is not found when adding observer\n", object);
  46002. + return -DWC_E_INVALID;
  46003. + }
  46004. +
  46005. + new_observer = alloc_observer(notifier->mem_ctx, observer, notification, callback, data);
  46006. + if (!new_observer) {
  46007. + return -DWC_E_NO_MEMORY;
  46008. + }
  46009. +
  46010. + DWC_CIRCLEQ_INSERT_TAIL(&notifier->observers, new_observer, list_entry);
  46011. +
  46012. + DWC_INFO("Added observer %p to notifier %p observing notification %s, callback=%p, data=%p",
  46013. + observer, object, notification, callback, data);
  46014. +
  46015. + dump_manager();
  46016. + return 0;
  46017. +}
  46018. +
  46019. +int dwc_remove_observer(void *observer)
  46020. +{
  46021. + notifier_t *n;
  46022. +
  46023. + DWC_ASSERT(manager, "Notification manager not found");
  46024. +
  46025. + DWC_CIRCLEQ_FOREACH(n, &manager->notifiers, list_entry) {
  46026. + observer_t *o;
  46027. + observer_t *o2;
  46028. +
  46029. + DWC_CIRCLEQ_FOREACH_SAFE(o, o2, &n->observers, list_entry) {
  46030. + if (o->observer == observer) {
  46031. + DWC_CIRCLEQ_REMOVE_INIT(&n->observers, o, list_entry);
  46032. + DWC_INFO("Removing observer %p from notifier %p watching notification %s:",
  46033. + o->observer, n->object, o->notification);
  46034. + free_observer(n->mem_ctx, o);
  46035. + }
  46036. + }
  46037. + }
  46038. +
  46039. + dump_manager();
  46040. + return 0;
  46041. +}
  46042. +
  46043. +typedef struct callback_data {
  46044. + void *mem_ctx;
  46045. + dwc_notifier_callback_t cb;
  46046. + void *observer;
  46047. + void *data;
  46048. + void *object;
  46049. + char *notification;
  46050. + void *notification_data;
  46051. +} cb_data_t;
  46052. +
  46053. +static void cb_task(void *data)
  46054. +{
  46055. + cb_data_t *cb = (cb_data_t *)data;
  46056. +
  46057. + cb->cb(cb->object, cb->notification, cb->observer, cb->notification_data, cb->data);
  46058. + dwc_free(cb->mem_ctx, cb);
  46059. +}
  46060. +
  46061. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data)
  46062. +{
  46063. + observer_t *o;
  46064. +
  46065. + DWC_ASSERT(manager, "Notification manager not found");
  46066. +
  46067. + DWC_CIRCLEQ_FOREACH(o, &notifier->observers, list_entry) {
  46068. + int len = DWC_STRLEN(notification);
  46069. +
  46070. + if (DWC_STRLEN(o->notification) != len) {
  46071. + continue;
  46072. + }
  46073. +
  46074. + if (DWC_STRNCMP(o->notification, notification, len) == 0) {
  46075. + cb_data_t *cb_data = dwc_alloc(notifier->mem_ctx, sizeof(cb_data_t));
  46076. +
  46077. + if (!cb_data) {
  46078. + DWC_ERROR("Failed to allocate callback data\n");
  46079. + return;
  46080. + }
  46081. +
  46082. + cb_data->mem_ctx = notifier->mem_ctx;
  46083. + cb_data->cb = o->callback;
  46084. + cb_data->observer = o->observer;
  46085. + cb_data->data = o->data;
  46086. + cb_data->object = notifier->object;
  46087. + cb_data->notification = notification;
  46088. + cb_data->notification_data = notification_data;
  46089. + DWC_DEBUGC("Observer found %p for notification %s\n", o->observer, notification);
  46090. + DWC_WORKQ_SCHEDULE(manager->wq, cb_task, cb_data,
  46091. + "Notify callback from %p for Notification %s, to observer %p",
  46092. + cb_data->object, notification, cb_data->observer);
  46093. + }
  46094. + }
  46095. +}
  46096. +
  46097. +#endif /* DWC_NOTIFYLIB */
  46098. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_notifier.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h
  46099. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_notifier.h 1970-01-01 01:00:00.000000000 +0100
  46100. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_notifier.h 2014-06-11 21:03:43.000000000 +0200
  46101. @@ -0,0 +1,122 @@
  46102. +
  46103. +#ifndef __DWC_NOTIFIER_H__
  46104. +#define __DWC_NOTIFIER_H__
  46105. +
  46106. +#ifdef __cplusplus
  46107. +extern "C" {
  46108. +#endif
  46109. +
  46110. +#include "dwc_os.h"
  46111. +
  46112. +/** @file
  46113. + *
  46114. + * A simple implementation of the Observer pattern. Any "module" can
  46115. + * register as an observer or notifier. The notion of "module" is abstract and
  46116. + * can mean anything used to identify either an observer or notifier. Usually
  46117. + * it will be a pointer to a data structure which contains some state, ie an
  46118. + * object.
  46119. + *
  46120. + * Before any notifiers can be added, the global notification manager must be
  46121. + * brought up with dwc_alloc_notification_manager().
  46122. + * dwc_free_notification_manager() will bring it down and free all resources.
  46123. + * These would typically be called upon module load and unload. The
  46124. + * notification manager is a single global instance that handles all registered
  46125. + * observable modules and observers so this should be done only once.
  46126. + *
  46127. + * A module can be observable by using Notifications to publicize some general
  46128. + * information about it's state or operation. It does not care who listens, or
  46129. + * even if anyone listens, or what they do with the information. The observable
  46130. + * modules do not need to know any information about it's observers or their
  46131. + * interface, or their state or data.
  46132. + *
  46133. + * Any module can register to emit Notifications. It should publish a list of
  46134. + * notifications that it can emit and their behavior, such as when they will get
  46135. + * triggered, and what information will be provided to the observer. Then it
  46136. + * should register itself as an observable module. See dwc_register_notifier().
  46137. + *
  46138. + * Any module can observe any observable, registered module, provided it has a
  46139. + * handle to the other module and knows what notifications to observe. See
  46140. + * dwc_add_observer().
  46141. + *
  46142. + * A function of type dwc_notifier_callback_t is called whenever a notification
  46143. + * is triggered with one or more observers observing it. This function is
  46144. + * called in it's own process so it may sleep or block if needed. It is
  46145. + * guaranteed to be called sometime after the notification has occurred and will
  46146. + * be called once per each time the notification is triggered. It will NOT be
  46147. + * called in the same process context used to trigger the notification.
  46148. + *
  46149. + * @section Limitiations
  46150. + *
  46151. + * Keep in mind that Notifications that can be triggered in rapid sucession may
  46152. + * schedule too many processes too handle. Be aware of this limitation when
  46153. + * designing to use notifications, and only add notifications for appropriate
  46154. + * observable information.
  46155. + *
  46156. + * Also Notification callbacks are not synchronous. If you need to synchronize
  46157. + * the behavior between module/observer you must use other means. And perhaps
  46158. + * that will mean Notifications are not the proper solution.
  46159. + */
  46160. +
  46161. +struct dwc_notifier;
  46162. +typedef struct dwc_notifier dwc_notifier_t;
  46163. +
  46164. +/** The callback function must be of this type.
  46165. + *
  46166. + * @param object This is the object that is being observed.
  46167. + * @param notification This is the notification that was triggered.
  46168. + * @param observer This is the observer
  46169. + * @param notification_data This is notification-specific data that the notifier
  46170. + * has included in this notification. The value of this should be published in
  46171. + * the documentation of the observable module with the notifications.
  46172. + * @param user_data This is any custom data that the observer provided when
  46173. + * adding itself as an observer to the notification. */
  46174. +typedef void (*dwc_notifier_callback_t)(void *object, char *notification, void *observer,
  46175. + void *notification_data, void *user_data);
  46176. +
  46177. +/** Brings up the notification manager. */
  46178. +extern int dwc_alloc_notification_manager(void *mem_ctx, void *wkq_ctx);
  46179. +/** Brings down the notification manager. */
  46180. +extern void dwc_free_notification_manager(void);
  46181. +
  46182. +/** This function registers an observable module. A dwc_notifier_t object is
  46183. + * returned to the observable module. This is an opaque object that is used by
  46184. + * the observable module to trigger notifications. This object should only be
  46185. + * accessible to functions that are authorized to trigger notifications for this
  46186. + * module. Observers do not need this object. */
  46187. +extern dwc_notifier_t *dwc_register_notifier(void *mem_ctx, void *object);
  46188. +
  46189. +/** This function unregisters an observable module. All observers have to be
  46190. + * removed prior to unregistration. */
  46191. +extern void dwc_unregister_notifier(dwc_notifier_t *notifier);
  46192. +
  46193. +/** Add a module as an observer to the observable module. The observable module
  46194. + * needs to have previously registered with the notification manager.
  46195. + *
  46196. + * @param observer The observer module
  46197. + * @param object The module to observe
  46198. + * @param notification The notification to observe
  46199. + * @param callback The callback function to call
  46200. + * @param user_data Any additional user data to pass into the callback function */
  46201. +extern int dwc_add_observer(void *observer, void *object, char *notification,
  46202. + dwc_notifier_callback_t callback, void *user_data);
  46203. +
  46204. +/** Removes the specified observer from all notifications that it is currently
  46205. + * observing. */
  46206. +extern int dwc_remove_observer(void *observer);
  46207. +
  46208. +/** This function triggers a Notification. It should be called by the
  46209. + * observable module, or any module or library which the observable module
  46210. + * allows to trigger notification on it's behalf. Such as the dwc_cc_t.
  46211. + *
  46212. + * dwc_notify is a non-blocking function. Callbacks are scheduled called in
  46213. + * their own process context for each trigger. Callbacks can be blocking.
  46214. + * dwc_notify can be called from interrupt context if needed.
  46215. + *
  46216. + */
  46217. +void dwc_notify(dwc_notifier_t *notifier, char *notification, void *notification_data);
  46218. +
  46219. +#ifdef __cplusplus
  46220. +}
  46221. +#endif
  46222. +
  46223. +#endif /* __DWC_NOTIFIER_H__ */
  46224. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/dwc_os.h linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h
  46225. --- linux-3.15/drivers/usb/host/dwc_common_port/dwc_os.h 1970-01-01 01:00:00.000000000 +0100
  46226. +++ linux-rpi/drivers/usb/host/dwc_common_port/dwc_os.h 2014-06-11 21:03:43.000000000 +0200
  46227. @@ -0,0 +1,1262 @@
  46228. +/* =========================================================================
  46229. + * $File: //dwh/usb_iip/dev/software/dwc_common_port_2/dwc_os.h $
  46230. + * $Revision: #14 $
  46231. + * $Date: 2010/11/04 $
  46232. + * $Change: 1621695 $
  46233. + *
  46234. + * Synopsys Portability Library Software and documentation
  46235. + * (hereinafter, "Software") is an Unsupported proprietary work of
  46236. + * Synopsys, Inc. unless otherwise expressly agreed to in writing
  46237. + * between Synopsys and you.
  46238. + *
  46239. + * The Software IS NOT an item of Licensed Software or Licensed Product
  46240. + * under any End User Software License Agreement or Agreement for
  46241. + * Licensed Product with Synopsys or any supplement thereto. You are
  46242. + * permitted to use and redistribute this Software in source and binary
  46243. + * forms, with or without modification, provided that redistributions
  46244. + * of source code must retain this notice. You may not view, use,
  46245. + * disclose, copy or distribute this file or any information contained
  46246. + * herein except pursuant to this license grant from Synopsys. If you
  46247. + * do not agree with this notice, including the disclaimer below, then
  46248. + * you are not authorized to use the Software.
  46249. + *
  46250. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS"
  46251. + * BASIS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  46252. + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  46253. + * FOR A PARTICULAR PURPOSE ARE HEREBY DISCLAIMED. IN NO EVENT SHALL
  46254. + * SYNOPSYS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  46255. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  46256. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  46257. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  46258. + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  46259. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  46260. + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  46261. + * DAMAGE.
  46262. + * ========================================================================= */
  46263. +#ifndef _DWC_OS_H_
  46264. +#define _DWC_OS_H_
  46265. +
  46266. +#ifdef __cplusplus
  46267. +extern "C" {
  46268. +#endif
  46269. +
  46270. +/** @file
  46271. + *
  46272. + * DWC portability library, low level os-wrapper functions
  46273. + *
  46274. + */
  46275. +
  46276. +/* These basic types need to be defined by some OS header file or custom header
  46277. + * file for your specific target architecture.
  46278. + *
  46279. + * uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t, uint64_t, int64_t
  46280. + *
  46281. + * Any custom or alternate header file must be added and enabled here.
  46282. + */
  46283. +
  46284. +#ifdef DWC_LINUX
  46285. +# include <linux/types.h>
  46286. +# ifdef CONFIG_DEBUG_MUTEXES
  46287. +# include <linux/mutex.h>
  46288. +# endif
  46289. +# include <linux/errno.h>
  46290. +# include <stdarg.h>
  46291. +#endif
  46292. +
  46293. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46294. +# include <os_dep.h>
  46295. +#endif
  46296. +
  46297. +
  46298. +/** @name Primitive Types and Values */
  46299. +
  46300. +/** We define a boolean type for consistency. Can be either YES or NO */
  46301. +typedef uint8_t dwc_bool_t;
  46302. +#define YES 1
  46303. +#define NO 0
  46304. +
  46305. +#ifdef DWC_LINUX
  46306. +
  46307. +/** @name Error Codes */
  46308. +#define DWC_E_INVALID EINVAL
  46309. +#define DWC_E_NO_MEMORY ENOMEM
  46310. +#define DWC_E_NO_DEVICE ENODEV
  46311. +#define DWC_E_NOT_SUPPORTED EOPNOTSUPP
  46312. +#define DWC_E_TIMEOUT ETIMEDOUT
  46313. +#define DWC_E_BUSY EBUSY
  46314. +#define DWC_E_AGAIN EAGAIN
  46315. +#define DWC_E_RESTART ERESTART
  46316. +#define DWC_E_ABORT ECONNABORTED
  46317. +#define DWC_E_SHUTDOWN ESHUTDOWN
  46318. +#define DWC_E_NO_DATA ENODATA
  46319. +#define DWC_E_DISCONNECT ECONNRESET
  46320. +#define DWC_E_UNKNOWN EINVAL
  46321. +#define DWC_E_NO_STREAM_RES ENOSR
  46322. +#define DWC_E_COMMUNICATION ECOMM
  46323. +#define DWC_E_OVERFLOW EOVERFLOW
  46324. +#define DWC_E_PROTOCOL EPROTO
  46325. +#define DWC_E_IN_PROGRESS EINPROGRESS
  46326. +#define DWC_E_PIPE EPIPE
  46327. +#define DWC_E_IO EIO
  46328. +#define DWC_E_NO_SPACE ENOSPC
  46329. +
  46330. +#else
  46331. +
  46332. +/** @name Error Codes */
  46333. +#define DWC_E_INVALID 1001
  46334. +#define DWC_E_NO_MEMORY 1002
  46335. +#define DWC_E_NO_DEVICE 1003
  46336. +#define DWC_E_NOT_SUPPORTED 1004
  46337. +#define DWC_E_TIMEOUT 1005
  46338. +#define DWC_E_BUSY 1006
  46339. +#define DWC_E_AGAIN 1007
  46340. +#define DWC_E_RESTART 1008
  46341. +#define DWC_E_ABORT 1009
  46342. +#define DWC_E_SHUTDOWN 1010
  46343. +#define DWC_E_NO_DATA 1011
  46344. +#define DWC_E_DISCONNECT 2000
  46345. +#define DWC_E_UNKNOWN 3000
  46346. +#define DWC_E_NO_STREAM_RES 4001
  46347. +#define DWC_E_COMMUNICATION 4002
  46348. +#define DWC_E_OVERFLOW 4003
  46349. +#define DWC_E_PROTOCOL 4004
  46350. +#define DWC_E_IN_PROGRESS 4005
  46351. +#define DWC_E_PIPE 4006
  46352. +#define DWC_E_IO 4007
  46353. +#define DWC_E_NO_SPACE 4008
  46354. +
  46355. +#endif
  46356. +
  46357. +
  46358. +/** @name Tracing/Logging Functions
  46359. + *
  46360. + * These function provide the capability to add tracing, debugging, and error
  46361. + * messages, as well exceptions as assertions. The WUDEV uses these
  46362. + * extensively. These could be logged to the main console, the serial port, an
  46363. + * internal buffer, etc. These functions could also be no-op if they are too
  46364. + * expensive on your system. By default undefining the DEBUG macro already
  46365. + * no-ops some of these functions. */
  46366. +
  46367. +/** Returns non-zero if in interrupt context. */
  46368. +extern dwc_bool_t DWC_IN_IRQ(void);
  46369. +#define dwc_in_irq DWC_IN_IRQ
  46370. +
  46371. +/** Returns "IRQ" if DWC_IN_IRQ is true. */
  46372. +static inline char *dwc_irq(void) {
  46373. + return DWC_IN_IRQ() ? "IRQ" : "";
  46374. +}
  46375. +
  46376. +/** Returns non-zero if in bottom-half context. */
  46377. +extern dwc_bool_t DWC_IN_BH(void);
  46378. +#define dwc_in_bh DWC_IN_BH
  46379. +
  46380. +/** Returns "BH" if DWC_IN_BH is true. */
  46381. +static inline char *dwc_bh(void) {
  46382. + return DWC_IN_BH() ? "BH" : "";
  46383. +}
  46384. +
  46385. +/**
  46386. + * A vprintf() clone. Just call vprintf if you've got it.
  46387. + */
  46388. +extern void DWC_VPRINTF(char *format, va_list args);
  46389. +#define dwc_vprintf DWC_VPRINTF
  46390. +
  46391. +/**
  46392. + * A vsnprintf() clone. Just call vprintf if you've got it.
  46393. + */
  46394. +extern int DWC_VSNPRINTF(char *str, int size, char *format, va_list args);
  46395. +#define dwc_vsnprintf DWC_VSNPRINTF
  46396. +
  46397. +/**
  46398. + * printf() clone. Just call printf if you've go it.
  46399. + */
  46400. +extern void DWC_PRINTF(char *format, ...)
  46401. +/* This provides compiler level static checking of the parameters if you're
  46402. + * using GCC. */
  46403. +#ifdef __GNUC__
  46404. + __attribute__ ((format(printf, 1, 2)));
  46405. +#else
  46406. + ;
  46407. +#endif
  46408. +#define dwc_printf DWC_PRINTF
  46409. +
  46410. +/**
  46411. + * sprintf() clone. Just call sprintf if you've got it.
  46412. + */
  46413. +extern int DWC_SPRINTF(char *string, char *format, ...)
  46414. +#ifdef __GNUC__
  46415. + __attribute__ ((format(printf, 2, 3)));
  46416. +#else
  46417. + ;
  46418. +#endif
  46419. +#define dwc_sprintf DWC_SPRINTF
  46420. +
  46421. +/**
  46422. + * snprintf() clone. Just call snprintf if you've got it.
  46423. + */
  46424. +extern int DWC_SNPRINTF(char *string, int size, char *format, ...)
  46425. +#ifdef __GNUC__
  46426. + __attribute__ ((format(printf, 3, 4)));
  46427. +#else
  46428. + ;
  46429. +#endif
  46430. +#define dwc_snprintf DWC_SNPRINTF
  46431. +
  46432. +/**
  46433. + * Prints a WARNING message. On systems that don't differentiate between
  46434. + * warnings and regular log messages, just print it. Indicates that something
  46435. + * may be wrong with the driver. Works like printf().
  46436. + *
  46437. + * Use the DWC_WARN macro to call this function.
  46438. + */
  46439. +extern void __DWC_WARN(char *format, ...)
  46440. +#ifdef __GNUC__
  46441. + __attribute__ ((format(printf, 1, 2)));
  46442. +#else
  46443. + ;
  46444. +#endif
  46445. +
  46446. +/**
  46447. + * Prints an error message. On systems that don't differentiate between errors
  46448. + * and regular log messages, just print it. Indicates that something went wrong
  46449. + * with the driver. Works like printf().
  46450. + *
  46451. + * Use the DWC_ERROR macro to call this function.
  46452. + */
  46453. +extern void __DWC_ERROR(char *format, ...)
  46454. +#ifdef __GNUC__
  46455. + __attribute__ ((format(printf, 1, 2)));
  46456. +#else
  46457. + ;
  46458. +#endif
  46459. +
  46460. +/**
  46461. + * Prints an exception error message and takes some user-defined action such as
  46462. + * print out a backtrace or trigger a breakpoint. Indicates that something went
  46463. + * abnormally wrong with the driver such as programmer error, or other
  46464. + * exceptional condition. It should not be ignored so even on systems without
  46465. + * printing capability, some action should be taken to notify the developer of
  46466. + * it. Works like printf().
  46467. + */
  46468. +extern void DWC_EXCEPTION(char *format, ...)
  46469. +#ifdef __GNUC__
  46470. + __attribute__ ((format(printf, 1, 2)));
  46471. +#else
  46472. + ;
  46473. +#endif
  46474. +#define dwc_exception DWC_EXCEPTION
  46475. +
  46476. +#ifndef DWC_OTG_DEBUG_LEV
  46477. +#define DWC_OTG_DEBUG_LEV 0
  46478. +#endif
  46479. +
  46480. +#ifdef DEBUG
  46481. +/**
  46482. + * Prints out a debug message. Used for logging/trace messages.
  46483. + *
  46484. + * Use the DWC_DEBUG macro to call this function
  46485. + */
  46486. +extern void __DWC_DEBUG(char *format, ...)
  46487. +#ifdef __GNUC__
  46488. + __attribute__ ((format(printf, 1, 2)));
  46489. +#else
  46490. + ;
  46491. +#endif
  46492. +#else
  46493. +#define __DWC_DEBUG printk
  46494. +#endif
  46495. +
  46496. +/**
  46497. + * Prints out a Debug message.
  46498. + */
  46499. +#define DWC_DEBUG(_format, _args...) __DWC_DEBUG("DEBUG:%s:%s: " _format "\n", \
  46500. + __func__, dwc_irq(), ## _args)
  46501. +#define dwc_debug DWC_DEBUG
  46502. +/**
  46503. + * Prints out a Debug message if enabled at compile time.
  46504. + */
  46505. +#if DWC_OTG_DEBUG_LEV > 0
  46506. +#define DWC_DEBUGC(_format, _args...) DWC_DEBUG(_format, ##_args )
  46507. +#else
  46508. +#define DWC_DEBUGC(_format, _args...)
  46509. +#endif
  46510. +#define dwc_debugc DWC_DEBUGC
  46511. +/**
  46512. + * Prints out an informative message.
  46513. + */
  46514. +#define DWC_INFO(_format, _args...) DWC_PRINTF("INFO:%s: " _format "\n", \
  46515. + dwc_irq(), ## _args)
  46516. +#define dwc_info DWC_INFO
  46517. +/**
  46518. + * Prints out an informative message if enabled at compile time.
  46519. + */
  46520. +#if DWC_OTG_DEBUG_LEV > 1
  46521. +#define DWC_INFOC(_format, _args...) DWC_INFO(_format, ##_args )
  46522. +#else
  46523. +#define DWC_INFOC(_format, _args...)
  46524. +#endif
  46525. +#define dwc_infoc DWC_INFOC
  46526. +/**
  46527. + * Prints out a warning message.
  46528. + */
  46529. +#define DWC_WARN(_format, _args...) __DWC_WARN("WARN:%s:%s:%d: " _format "\n", \
  46530. + dwc_irq(), __func__, __LINE__, ## _args)
  46531. +#define dwc_warn DWC_WARN
  46532. +/**
  46533. + * Prints out an error message.
  46534. + */
  46535. +#define DWC_ERROR(_format, _args...) __DWC_ERROR("ERROR:%s:%s:%d: " _format "\n", \
  46536. + dwc_irq(), __func__, __LINE__, ## _args)
  46537. +#define dwc_error DWC_ERROR
  46538. +
  46539. +#define DWC_PROTO_ERROR(_format, _args...) __DWC_WARN("ERROR:%s:%s:%d: " _format "\n", \
  46540. + dwc_irq(), __func__, __LINE__, ## _args)
  46541. +#define dwc_proto_error DWC_PROTO_ERROR
  46542. +
  46543. +#ifdef DEBUG
  46544. +/** Prints out a exception error message if the _expr expression fails. Disabled
  46545. + * if DEBUG is not enabled. */
  46546. +#define DWC_ASSERT(_expr, _format, _args...) do { \
  46547. + if (!(_expr)) { DWC_EXCEPTION("%s:%s:%d: " _format "\n", dwc_irq(), \
  46548. + __FILE__, __LINE__, ## _args); } \
  46549. + } while (0)
  46550. +#else
  46551. +#define DWC_ASSERT(_x...)
  46552. +#endif
  46553. +#define dwc_assert DWC_ASSERT
  46554. +
  46555. +
  46556. +/** @name Byte Ordering
  46557. + * The following functions are for conversions between processor's byte ordering
  46558. + * and specific ordering you want.
  46559. + */
  46560. +
  46561. +/** Converts 32 bit data in CPU byte ordering to little endian. */
  46562. +extern uint32_t DWC_CPU_TO_LE32(uint32_t *p);
  46563. +#define dwc_cpu_to_le32 DWC_CPU_TO_LE32
  46564. +
  46565. +/** Converts 32 bit data in CPU byte orderint to big endian. */
  46566. +extern uint32_t DWC_CPU_TO_BE32(uint32_t *p);
  46567. +#define dwc_cpu_to_be32 DWC_CPU_TO_BE32
  46568. +
  46569. +/** Converts 32 bit little endian data to CPU byte ordering. */
  46570. +extern uint32_t DWC_LE32_TO_CPU(uint32_t *p);
  46571. +#define dwc_le32_to_cpu DWC_LE32_TO_CPU
  46572. +
  46573. +/** Converts 32 bit big endian data to CPU byte ordering. */
  46574. +extern uint32_t DWC_BE32_TO_CPU(uint32_t *p);
  46575. +#define dwc_be32_to_cpu DWC_BE32_TO_CPU
  46576. +
  46577. +/** Converts 16 bit data in CPU byte ordering to little endian. */
  46578. +extern uint16_t DWC_CPU_TO_LE16(uint16_t *p);
  46579. +#define dwc_cpu_to_le16 DWC_CPU_TO_LE16
  46580. +
  46581. +/** Converts 16 bit data in CPU byte orderint to big endian. */
  46582. +extern uint16_t DWC_CPU_TO_BE16(uint16_t *p);
  46583. +#define dwc_cpu_to_be16 DWC_CPU_TO_BE16
  46584. +
  46585. +/** Converts 16 bit little endian data to CPU byte ordering. */
  46586. +extern uint16_t DWC_LE16_TO_CPU(uint16_t *p);
  46587. +#define dwc_le16_to_cpu DWC_LE16_TO_CPU
  46588. +
  46589. +/** Converts 16 bit bi endian data to CPU byte ordering. */
  46590. +extern uint16_t DWC_BE16_TO_CPU(uint16_t *p);
  46591. +#define dwc_be16_to_cpu DWC_BE16_TO_CPU
  46592. +
  46593. +
  46594. +/** @name Register Read/Write
  46595. + *
  46596. + * The following six functions should be implemented to read/write registers of
  46597. + * 32-bit and 64-bit sizes. All modules use this to read/write register values.
  46598. + * The reg value is a pointer to the register calculated from the void *base
  46599. + * variable passed into the driver when it is started. */
  46600. +
  46601. +#ifdef DWC_LINUX
  46602. +/* Linux doesn't need any extra parameters for register read/write, so we
  46603. + * just throw away the IO context parameter.
  46604. + */
  46605. +/** Reads the content of a 32-bit register. */
  46606. +extern uint32_t DWC_READ_REG32(uint32_t volatile *reg);
  46607. +#define dwc_read_reg32(_ctx_,_reg_) DWC_READ_REG32(_reg_)
  46608. +
  46609. +/** Reads the content of a 64-bit register. */
  46610. +extern uint64_t DWC_READ_REG64(uint64_t volatile *reg);
  46611. +#define dwc_read_reg64(_ctx_,_reg_) DWC_READ_REG64(_reg_)
  46612. +
  46613. +/** Writes to a 32-bit register. */
  46614. +extern void DWC_WRITE_REG32(uint32_t volatile *reg, uint32_t value);
  46615. +#define dwc_write_reg32(_ctx_,_reg_,_val_) DWC_WRITE_REG32(_reg_, _val_)
  46616. +
  46617. +/** Writes to a 64-bit register. */
  46618. +extern void DWC_WRITE_REG64(uint64_t volatile *reg, uint64_t value);
  46619. +#define dwc_write_reg64(_ctx_,_reg_,_val_) DWC_WRITE_REG64(_reg_, _val_)
  46620. +
  46621. +/**
  46622. + * Modify bit values in a register. Using the
  46623. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46624. + */
  46625. +extern void DWC_MODIFY_REG32(uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46626. +#define dwc_modify_reg32(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG32(_reg_,_cmsk_,_smsk_)
  46627. +extern void DWC_MODIFY_REG64(uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46628. +#define dwc_modify_reg64(_ctx_,_reg_,_cmsk_,_smsk_) DWC_MODIFY_REG64(_reg_,_cmsk_,_smsk_)
  46629. +
  46630. +#endif /* DWC_LINUX */
  46631. +
  46632. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46633. +typedef struct dwc_ioctx {
  46634. + struct device *dev;
  46635. + bus_space_tag_t iot;
  46636. + bus_space_handle_t ioh;
  46637. +} dwc_ioctx_t;
  46638. +
  46639. +/** BSD needs two extra parameters for register read/write, so we pass
  46640. + * them in using the IO context parameter.
  46641. + */
  46642. +/** Reads the content of a 32-bit register. */
  46643. +extern uint32_t DWC_READ_REG32(void *io_ctx, uint32_t volatile *reg);
  46644. +#define dwc_read_reg32 DWC_READ_REG32
  46645. +
  46646. +/** Reads the content of a 64-bit register. */
  46647. +extern uint64_t DWC_READ_REG64(void *io_ctx, uint64_t volatile *reg);
  46648. +#define dwc_read_reg64 DWC_READ_REG64
  46649. +
  46650. +/** Writes to a 32-bit register. */
  46651. +extern void DWC_WRITE_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t value);
  46652. +#define dwc_write_reg32 DWC_WRITE_REG32
  46653. +
  46654. +/** Writes to a 64-bit register. */
  46655. +extern void DWC_WRITE_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t value);
  46656. +#define dwc_write_reg64 DWC_WRITE_REG64
  46657. +
  46658. +/**
  46659. + * Modify bit values in a register. Using the
  46660. + * algorithm: (reg_contents & ~clear_mask) | set_mask.
  46661. + */
  46662. +extern void DWC_MODIFY_REG32(void *io_ctx, uint32_t volatile *reg, uint32_t clear_mask, uint32_t set_mask);
  46663. +#define dwc_modify_reg32 DWC_MODIFY_REG32
  46664. +extern void DWC_MODIFY_REG64(void *io_ctx, uint64_t volatile *reg, uint64_t clear_mask, uint64_t set_mask);
  46665. +#define dwc_modify_reg64 DWC_MODIFY_REG64
  46666. +
  46667. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46668. +
  46669. +/** @cond */
  46670. +
  46671. +/** @name Some convenience MACROS used internally. Define DWC_DEBUG_REGS to log the
  46672. + * register writes. */
  46673. +
  46674. +#ifdef DWC_LINUX
  46675. +
  46676. +# ifdef DWC_DEBUG_REGS
  46677. +
  46678. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46679. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46680. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46681. +} \
  46682. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46683. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46684. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46685. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46686. +}
  46687. +
  46688. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46689. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46690. + return DWC_READ_REG32(&container->regs->_reg); \
  46691. +} \
  46692. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46693. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46694. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46695. +}
  46696. +
  46697. +# else /* DWC_DEBUG_REGS */
  46698. +
  46699. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46700. +static inline uint32_t dwc_read_##_reg##_n(_container_type *container, int num) { \
  46701. + return DWC_READ_REG32(&container->regs->_reg[num]); \
  46702. +} \
  46703. +static inline void dwc_write_##_reg##_n(_container_type *container, int num, uint32_t data) { \
  46704. + DWC_WRITE_REG32(&(((uint32_t*)container->regs->_reg)[num]), data); \
  46705. +}
  46706. +
  46707. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46708. +static inline uint32_t dwc_read_##_reg(_container_type *container) { \
  46709. + return DWC_READ_REG32(&container->regs->_reg); \
  46710. +} \
  46711. +static inline void dwc_write_##_reg(_container_type *container, uint32_t data) { \
  46712. + DWC_WRITE_REG32(&container->regs->_reg, data); \
  46713. +}
  46714. +
  46715. +# endif /* DWC_DEBUG_REGS */
  46716. +
  46717. +#endif /* DWC_LINUX */
  46718. +
  46719. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46720. +
  46721. +# ifdef DWC_DEBUG_REGS
  46722. +
  46723. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46724. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46725. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46726. +} \
  46727. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46728. + DWC_DEBUG("WRITING %8s[%d]: %p: %08x", #_reg, num, \
  46729. + &(((uint32_t*)container->regs->_reg)[num]), data); \
  46730. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46731. +}
  46732. +
  46733. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46734. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46735. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46736. +} \
  46737. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46738. + DWC_DEBUG("WRITING %11s: %p: %08x", #_reg, &container->regs->_reg, data); \
  46739. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46740. +}
  46741. +
  46742. +# else /* DWC_DEBUG_REGS */
  46743. +
  46744. +#define dwc_define_read_write_reg_n(_reg,_container_type) \
  46745. +static inline uint32_t dwc_read_##_reg##_n(void *io_ctx, _container_type *container, int num) { \
  46746. + return DWC_READ_REG32(io_ctx, &container->regs->_reg[num]); \
  46747. +} \
  46748. +static inline void dwc_write_##_reg##_n(void *io_ctx, _container_type *container, int num, uint32_t data) { \
  46749. + DWC_WRITE_REG32(io_ctx, &(((uint32_t*)container->regs->_reg)[num]), data); \
  46750. +}
  46751. +
  46752. +#define dwc_define_read_write_reg(_reg,_container_type) \
  46753. +static inline uint32_t dwc_read_##_reg(void *io_ctx, _container_type *container) { \
  46754. + return DWC_READ_REG32(io_ctx, &container->regs->_reg); \
  46755. +} \
  46756. +static inline void dwc_write_##_reg(void *io_ctx, _container_type *container, uint32_t data) { \
  46757. + DWC_WRITE_REG32(io_ctx, &container->regs->_reg, data); \
  46758. +}
  46759. +
  46760. +# endif /* DWC_DEBUG_REGS */
  46761. +
  46762. +#endif /* DWC_FREEBSD || DWC_NETBSD */
  46763. +
  46764. +/** @endcond */
  46765. +
  46766. +
  46767. +#ifdef DWC_CRYPTOLIB
  46768. +/** @name Crypto Functions
  46769. + *
  46770. + * These are the low-level cryptographic functions used by the driver. */
  46771. +
  46772. +/** Perform AES CBC */
  46773. +extern int DWC_AES_CBC(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t iv[16], uint8_t *out);
  46774. +#define dwc_aes_cbc DWC_AES_CBC
  46775. +
  46776. +/** Fill the provided buffer with random bytes. These should be cryptographic grade random numbers. */
  46777. +extern void DWC_RANDOM_BYTES(uint8_t *buffer, uint32_t length);
  46778. +#define dwc_random_bytes DWC_RANDOM_BYTES
  46779. +
  46780. +/** Perform the SHA-256 hash function */
  46781. +extern int DWC_SHA256(uint8_t *message, uint32_t len, uint8_t *out);
  46782. +#define dwc_sha256 DWC_SHA256
  46783. +
  46784. +/** Calculated the HMAC-SHA256 */
  46785. +extern int DWC_HMAC_SHA256(uint8_t *message, uint32_t messagelen, uint8_t *key, uint32_t keylen, uint8_t *out);
  46786. +#define dwc_hmac_sha256 DWC_HMAC_SHA256
  46787. +
  46788. +#endif /* DWC_CRYPTOLIB */
  46789. +
  46790. +
  46791. +/** @name Memory Allocation
  46792. + *
  46793. + * These function provide access to memory allocation. There are only 2 DMA
  46794. + * functions and 3 Regular memory functions that need to be implemented. None
  46795. + * of the memory debugging routines need to be implemented. The allocation
  46796. + * routines all ZERO the contents of the memory.
  46797. + *
  46798. + * Defining DWC_DEBUG_MEMORY turns on memory debugging and statistic gathering.
  46799. + * This checks for memory leaks, keeping track of alloc/free pairs. It also
  46800. + * keeps track of how much memory the driver is using at any given time. */
  46801. +
  46802. +#define DWC_PAGE_SIZE 4096
  46803. +#define DWC_PAGE_OFFSET(addr) (((uint32_t)addr) & 0xfff)
  46804. +#define DWC_PAGE_ALIGNED(addr) ((((uint32_t)addr) & 0xfff) == 0)
  46805. +
  46806. +#define DWC_INVALID_DMA_ADDR 0x0
  46807. +
  46808. +#ifdef DWC_LINUX
  46809. +/** Type for a DMA address */
  46810. +typedef dma_addr_t dwc_dma_t;
  46811. +#endif
  46812. +
  46813. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46814. +typedef bus_addr_t dwc_dma_t;
  46815. +#endif
  46816. +
  46817. +#ifdef DWC_FREEBSD
  46818. +typedef struct dwc_dmactx {
  46819. + struct device *dev;
  46820. + bus_dma_tag_t dma_tag;
  46821. + bus_dmamap_t dma_map;
  46822. + bus_addr_t dma_paddr;
  46823. + void *dma_vaddr;
  46824. +} dwc_dmactx_t;
  46825. +#endif
  46826. +
  46827. +#ifdef DWC_NETBSD
  46828. +typedef struct dwc_dmactx {
  46829. + struct device *dev;
  46830. + bus_dma_tag_t dma_tag;
  46831. + bus_dmamap_t dma_map;
  46832. + bus_dma_segment_t segs[1];
  46833. + int nsegs;
  46834. + bus_addr_t dma_paddr;
  46835. + void *dma_vaddr;
  46836. +} dwc_dmactx_t;
  46837. +#endif
  46838. +
  46839. +/* @todo these functions will be added in the future */
  46840. +#if 0
  46841. +/**
  46842. + * Creates a DMA pool from which you can allocate DMA buffers. Buffers
  46843. + * allocated from this pool will be guaranteed to meet the size, alignment, and
  46844. + * boundary requirements specified.
  46845. + *
  46846. + * @param[in] size Specifies the size of the buffers that will be allocated from
  46847. + * this pool.
  46848. + * @param[in] align Specifies the byte alignment requirements of the buffers
  46849. + * allocated from this pool. Must be a power of 2.
  46850. + * @param[in] boundary Specifies the N-byte boundary that buffers allocated from
  46851. + * this pool must not cross.
  46852. + *
  46853. + * @returns A pointer to an internal opaque structure which is not to be
  46854. + * accessed outside of these library functions. Use this handle to specify
  46855. + * which pools to allocate/free DMA buffers from and also to destroy the pool,
  46856. + * when you are done with it.
  46857. + */
  46858. +extern dwc_pool_t *DWC_DMA_POOL_CREATE(uint32_t size, uint32_t align, uint32_t boundary);
  46859. +
  46860. +/**
  46861. + * Destroy a DMA pool. All buffers allocated from that pool must be freed first.
  46862. + */
  46863. +extern void DWC_DMA_POOL_DESTROY(dwc_pool_t *pool);
  46864. +
  46865. +/**
  46866. + * Allocate a buffer from the specified DMA pool and zeros its contents.
  46867. + */
  46868. +extern void *DWC_DMA_POOL_ALLOC(dwc_pool_t *pool, uint64_t *dma_addr);
  46869. +
  46870. +/**
  46871. + * Free a previously allocated buffer from the DMA pool.
  46872. + */
  46873. +extern void DWC_DMA_POOL_FREE(dwc_pool_t *pool, void *vaddr, void *daddr);
  46874. +#endif
  46875. +
  46876. +/** Allocates a DMA capable buffer and zeroes its contents. */
  46877. +extern void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46878. +
  46879. +/** Allocates a DMA capable buffer and zeroes its contents in atomic contest */
  46880. +extern void *__DWC_DMA_ALLOC_ATOMIC(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr);
  46881. +
  46882. +/** Frees a previously allocated buffer. */
  46883. +extern void __DWC_DMA_FREE(void *dma_ctx, uint32_t size, void *virt_addr, dwc_dma_t dma_addr);
  46884. +
  46885. +/** Allocates a block of memory and zeroes its contents. */
  46886. +extern void *__DWC_ALLOC(void *mem_ctx, uint32_t size);
  46887. +
  46888. +/** Allocates a block of memory and zeroes its contents, in an atomic manner
  46889. + * which can be used inside interrupt context. The size should be sufficiently
  46890. + * small, a few KB at most, such that failures are not likely to occur. Can just call
  46891. + * __DWC_ALLOC if it is atomic. */
  46892. +extern void *__DWC_ALLOC_ATOMIC(void *mem_ctx, uint32_t size);
  46893. +
  46894. +/** Frees a previously allocated buffer. */
  46895. +extern void __DWC_FREE(void *mem_ctx, void *addr);
  46896. +
  46897. +#ifndef DWC_DEBUG_MEMORY
  46898. +
  46899. +#define DWC_ALLOC(_size_) __DWC_ALLOC(NULL, _size_)
  46900. +#define DWC_ALLOC_ATOMIC(_size_) __DWC_ALLOC_ATOMIC(NULL, _size_)
  46901. +#define DWC_FREE(_addr_) __DWC_FREE(NULL, _addr_)
  46902. +
  46903. +# ifdef DWC_LINUX
  46904. +#define DWC_DMA_ALLOC(_size_,_dma_) __DWC_DMA_ALLOC(NULL, _size_, _dma_)
  46905. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) __DWC_DMA_ALLOC_ATOMIC(NULL, _size_,_dma_)
  46906. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) __DWC_DMA_FREE(NULL, _size_, _virt_, _dma_)
  46907. +# endif
  46908. +
  46909. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46910. +#define DWC_DMA_ALLOC __DWC_DMA_ALLOC
  46911. +#define DWC_DMA_FREE __DWC_DMA_FREE
  46912. +# endif
  46913. +extern void *dwc_dma_alloc_atomic_debug(uint32_t size, dwc_dma_t *dma_addr, char const *func, int line);
  46914. +
  46915. +#else /* DWC_DEBUG_MEMORY */
  46916. +
  46917. +extern void *dwc_alloc_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46918. +extern void *dwc_alloc_atomic_debug(void *mem_ctx, uint32_t size, char const *func, int line);
  46919. +extern void dwc_free_debug(void *mem_ctx, void *addr, char const *func, int line);
  46920. +extern void *dwc_dma_alloc_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46921. + char const *func, int line);
  46922. +extern void *dwc_dma_alloc_atomic_debug(void *dma_ctx, uint32_t size, dwc_dma_t *dma_addr,
  46923. + char const *func, int line);
  46924. +extern void dwc_dma_free_debug(void *dma_ctx, uint32_t size, void *virt_addr,
  46925. + dwc_dma_t dma_addr, char const *func, int line);
  46926. +
  46927. +extern int dwc_memory_debug_start(void *mem_ctx);
  46928. +extern void dwc_memory_debug_stop(void);
  46929. +extern void dwc_memory_debug_report(void);
  46930. +
  46931. +#define DWC_ALLOC(_size_) dwc_alloc_debug(NULL, _size_, __func__, __LINE__)
  46932. +#define DWC_ALLOC_ATOMIC(_size_) dwc_alloc_atomic_debug(NULL, _size_, \
  46933. + __func__, __LINE__)
  46934. +#define DWC_FREE(_addr_) dwc_free_debug(NULL, _addr_, __func__, __LINE__)
  46935. +
  46936. +# ifdef DWC_LINUX
  46937. +#define DWC_DMA_ALLOC(_size_,_dma_) dwc_dma_alloc_debug(NULL, _size_, \
  46938. + _dma_, __func__, __LINE__)
  46939. +#define DWC_DMA_ALLOC_ATOMIC(_size_,_dma_) dwc_dma_alloc_atomic_debug(NULL, _size_, \
  46940. + _dma_, __func__, __LINE__)
  46941. +#define DWC_DMA_FREE(_size_,_virt_,_dma_) dwc_dma_free_debug(NULL, _size_, \
  46942. + _virt_, _dma_, __func__, __LINE__)
  46943. +# endif
  46944. +
  46945. +# if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46946. +#define DWC_DMA_ALLOC(_ctx_,_size_,_dma_) dwc_dma_alloc_debug(_ctx_, _size_, \
  46947. + _dma_, __func__, __LINE__)
  46948. +#define DWC_DMA_FREE(_ctx_,_size_,_virt_,_dma_) dwc_dma_free_debug(_ctx_, _size_, \
  46949. + _virt_, _dma_, __func__, __LINE__)
  46950. +# endif
  46951. +
  46952. +#endif /* DWC_DEBUG_MEMORY */
  46953. +
  46954. +#define dwc_alloc(_ctx_,_size_) DWC_ALLOC(_size_)
  46955. +#define dwc_alloc_atomic(_ctx_,_size_) DWC_ALLOC_ATOMIC(_size_)
  46956. +#define dwc_free(_ctx_,_addr_) DWC_FREE(_addr_)
  46957. +
  46958. +#ifdef DWC_LINUX
  46959. +/* Linux doesn't need any extra parameters for DMA buffer allocation, so we
  46960. + * just throw away the DMA context parameter.
  46961. + */
  46962. +#define dwc_dma_alloc(_ctx_,_size_,_dma_) DWC_DMA_ALLOC(_size_, _dma_)
  46963. +#define dwc_dma_alloc_atomic(_ctx_,_size_,_dma_) DWC_DMA_ALLOC_ATOMIC(_size_, _dma_)
  46964. +#define dwc_dma_free(_ctx_,_size_,_virt_,_dma_) DWC_DMA_FREE(_size_, _virt_, _dma_)
  46965. +#endif
  46966. +
  46967. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  46968. +/** BSD needs several extra parameters for DMA buffer allocation, so we pass
  46969. + * them in using the DMA context parameter.
  46970. + */
  46971. +#define dwc_dma_alloc DWC_DMA_ALLOC
  46972. +#define dwc_dma_free DWC_DMA_FREE
  46973. +#endif
  46974. +
  46975. +
  46976. +/** @name Memory and String Processing */
  46977. +
  46978. +/** memset() clone */
  46979. +extern void *DWC_MEMSET(void *dest, uint8_t byte, uint32_t size);
  46980. +#define dwc_memset DWC_MEMSET
  46981. +
  46982. +/** memcpy() clone */
  46983. +extern void *DWC_MEMCPY(void *dest, void const *src, uint32_t size);
  46984. +#define dwc_memcpy DWC_MEMCPY
  46985. +
  46986. +/** memmove() clone */
  46987. +extern void *DWC_MEMMOVE(void *dest, void *src, uint32_t size);
  46988. +#define dwc_memmove DWC_MEMMOVE
  46989. +
  46990. +/** memcmp() clone */
  46991. +extern int DWC_MEMCMP(void *m1, void *m2, uint32_t size);
  46992. +#define dwc_memcmp DWC_MEMCMP
  46993. +
  46994. +/** strcmp() clone */
  46995. +extern int DWC_STRCMP(void *s1, void *s2);
  46996. +#define dwc_strcmp DWC_STRCMP
  46997. +
  46998. +/** strncmp() clone */
  46999. +extern int DWC_STRNCMP(void *s1, void *s2, uint32_t size);
  47000. +#define dwc_strncmp DWC_STRNCMP
  47001. +
  47002. +/** strlen() clone, for NULL terminated ASCII strings */
  47003. +extern int DWC_STRLEN(char const *str);
  47004. +#define dwc_strlen DWC_STRLEN
  47005. +
  47006. +/** strcpy() clone, for NULL terminated ASCII strings */
  47007. +extern char *DWC_STRCPY(char *to, const char *from);
  47008. +#define dwc_strcpy DWC_STRCPY
  47009. +
  47010. +/** strdup() clone. If you wish to use memory allocation debugging, this
  47011. + * implementation of strdup should use the DWC_* memory routines instead of
  47012. + * calling a predefined strdup. Otherwise the memory allocated by this routine
  47013. + * will not be seen by the debugging routines. */
  47014. +extern char *DWC_STRDUP(char const *str);
  47015. +#define dwc_strdup(_ctx_,_str_) DWC_STRDUP(_str_)
  47016. +
  47017. +/** NOT an atoi() clone. Read the description carefully. Returns an integer
  47018. + * converted from the string str in base 10 unless the string begins with a "0x"
  47019. + * in which case it is base 16. String must be a NULL terminated sequence of
  47020. + * ASCII characters and may optionally begin with whitespace, a + or -, and a
  47021. + * "0x" prefix if base 16. The remaining characters must be valid digits for
  47022. + * the number and end with a NULL character. If any invalid characters are
  47023. + * encountered or it returns with a negative error code and the results of the
  47024. + * conversion are undefined. On sucess it returns 0. Overflow conditions are
  47025. + * undefined. An example implementation using atoi() can be referenced from the
  47026. + * Linux implementation. */
  47027. +extern int DWC_ATOI(const char *str, int32_t *value);
  47028. +#define dwc_atoi DWC_ATOI
  47029. +
  47030. +/** Same as above but for unsigned. */
  47031. +extern int DWC_ATOUI(const char *str, uint32_t *value);
  47032. +#define dwc_atoui DWC_ATOUI
  47033. +
  47034. +#ifdef DWC_UTFLIB
  47035. +/** This routine returns a UTF16LE unicode encoded string from a UTF8 string. */
  47036. +extern int DWC_UTF8_TO_UTF16LE(uint8_t const *utf8string, uint16_t *utf16string, unsigned len);
  47037. +#define dwc_utf8_to_utf16le DWC_UTF8_TO_UTF16LE
  47038. +#endif
  47039. +
  47040. +
  47041. +/** @name Wait queues
  47042. + *
  47043. + * Wait queues provide a means of synchronizing between threads or processes. A
  47044. + * process can block on a waitq if some condition is not true, waiting for it to
  47045. + * become true. When the waitq is triggered all waiting process will get
  47046. + * unblocked and the condition will be check again. Waitqs should be triggered
  47047. + * every time a condition can potentially change.*/
  47048. +struct dwc_waitq;
  47049. +
  47050. +/** Type for a waitq */
  47051. +typedef struct dwc_waitq dwc_waitq_t;
  47052. +
  47053. +/** The type of waitq condition callback function. This is called every time
  47054. + * condition is evaluated. */
  47055. +typedef int (*dwc_waitq_condition_t)(void *data);
  47056. +
  47057. +/** Allocate a waitq */
  47058. +extern dwc_waitq_t *DWC_WAITQ_ALLOC(void);
  47059. +#define dwc_waitq_alloc(_ctx_) DWC_WAITQ_ALLOC()
  47060. +
  47061. +/** Free a waitq */
  47062. +extern void DWC_WAITQ_FREE(dwc_waitq_t *wq);
  47063. +#define dwc_waitq_free DWC_WAITQ_FREE
  47064. +
  47065. +/** Check the condition and if it is false, block on the waitq. When unblocked, check the
  47066. + * condition again. The function returns when the condition becomes true. The return value
  47067. + * is 0 on condition true, DWC_WAITQ_ABORTED on abort or killed, or DWC_WAITQ_UNKNOWN on error. */
  47068. +extern int32_t DWC_WAITQ_WAIT(dwc_waitq_t *wq, dwc_waitq_condition_t cond, void *data);
  47069. +#define dwc_waitq_wait DWC_WAITQ_WAIT
  47070. +
  47071. +/** Check the condition and if it is false, block on the waitq. When unblocked,
  47072. + * check the condition again. The function returns when the condition become
  47073. + * true or the timeout has passed. The return value is 0 on condition true or
  47074. + * DWC_TIMED_OUT on timeout, or DWC_WAITQ_ABORTED, or DWC_WAITQ_UNKNOWN on
  47075. + * error. */
  47076. +extern int32_t DWC_WAITQ_WAIT_TIMEOUT(dwc_waitq_t *wq, dwc_waitq_condition_t cond,
  47077. + void *data, int32_t msecs);
  47078. +#define dwc_waitq_wait_timeout DWC_WAITQ_WAIT_TIMEOUT
  47079. +
  47080. +/** Trigger a waitq, unblocking all processes. This should be called whenever a condition
  47081. + * has potentially changed. */
  47082. +extern void DWC_WAITQ_TRIGGER(dwc_waitq_t *wq);
  47083. +#define dwc_waitq_trigger DWC_WAITQ_TRIGGER
  47084. +
  47085. +/** Unblock all processes waiting on the waitq with an ABORTED result. */
  47086. +extern void DWC_WAITQ_ABORT(dwc_waitq_t *wq);
  47087. +#define dwc_waitq_abort DWC_WAITQ_ABORT
  47088. +
  47089. +
  47090. +/** @name Threads
  47091. + *
  47092. + * A thread must be explicitly stopped. It must check DWC_THREAD_SHOULD_STOP
  47093. + * whenever it is woken up, and then return. The DWC_THREAD_STOP function
  47094. + * returns the value from the thread.
  47095. + */
  47096. +
  47097. +struct dwc_thread;
  47098. +
  47099. +/** Type for a thread */
  47100. +typedef struct dwc_thread dwc_thread_t;
  47101. +
  47102. +/** The thread function */
  47103. +typedef int (*dwc_thread_function_t)(void *data);
  47104. +
  47105. +/** Create a thread and start it running the thread_function. Returns a handle
  47106. + * to the thread */
  47107. +extern dwc_thread_t *DWC_THREAD_RUN(dwc_thread_function_t func, char *name, void *data);
  47108. +#define dwc_thread_run(_ctx_,_func_,_name_,_data_) DWC_THREAD_RUN(_func_, _name_, _data_)
  47109. +
  47110. +/** Stops a thread. Return the value returned by the thread. Or will return
  47111. + * DWC_ABORT if the thread never started. */
  47112. +extern int DWC_THREAD_STOP(dwc_thread_t *thread);
  47113. +#define dwc_thread_stop DWC_THREAD_STOP
  47114. +
  47115. +/** Signifies to the thread that it must stop. */
  47116. +#ifdef DWC_LINUX
  47117. +/* Linux doesn't need any parameters for kthread_should_stop() */
  47118. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(void);
  47119. +#define dwc_thread_should_stop(_thrd_) DWC_THREAD_SHOULD_STOP()
  47120. +
  47121. +/* No thread_exit function in Linux */
  47122. +#define dwc_thread_exit(_thrd_)
  47123. +#endif
  47124. +
  47125. +#if defined(DWC_FREEBSD) || defined(DWC_NETBSD)
  47126. +/** BSD needs the thread pointer for kthread_suspend_check() */
  47127. +extern dwc_bool_t DWC_THREAD_SHOULD_STOP(dwc_thread_t *thread);
  47128. +#define dwc_thread_should_stop DWC_THREAD_SHOULD_STOP
  47129. +
  47130. +/** The thread must call this to exit. */
  47131. +extern void DWC_THREAD_EXIT(dwc_thread_t *thread);
  47132. +#define dwc_thread_exit DWC_THREAD_EXIT
  47133. +#endif
  47134. +
  47135. +
  47136. +/** @name Work queues
  47137. + *
  47138. + * Workqs are used to queue a callback function to be called at some later time,
  47139. + * in another thread. */
  47140. +struct dwc_workq;
  47141. +
  47142. +/** Type for a workq */
  47143. +typedef struct dwc_workq dwc_workq_t;
  47144. +
  47145. +/** The type of the callback function to be called. */
  47146. +typedef void (*dwc_work_callback_t)(void *data);
  47147. +
  47148. +/** Allocate a workq */
  47149. +extern dwc_workq_t *DWC_WORKQ_ALLOC(char *name);
  47150. +#define dwc_workq_alloc(_ctx_,_name_) DWC_WORKQ_ALLOC(_name_)
  47151. +
  47152. +/** Free a workq. All work must be completed before being freed. */
  47153. +extern void DWC_WORKQ_FREE(dwc_workq_t *workq);
  47154. +#define dwc_workq_free DWC_WORKQ_FREE
  47155. +
  47156. +/** Schedule a callback on the workq, passing in data. The function will be
  47157. + * scheduled at some later time. */
  47158. +extern void DWC_WORKQ_SCHEDULE(dwc_workq_t *workq, dwc_work_callback_t cb,
  47159. + void *data, char *format, ...)
  47160. +#ifdef __GNUC__
  47161. + __attribute__ ((format(printf, 4, 5)));
  47162. +#else
  47163. + ;
  47164. +#endif
  47165. +#define dwc_workq_schedule DWC_WORKQ_SCHEDULE
  47166. +
  47167. +/** Schedule a callback on the workq, that will be called until at least
  47168. + * given number miliseconds have passed. */
  47169. +extern void DWC_WORKQ_SCHEDULE_DELAYED(dwc_workq_t *workq, dwc_work_callback_t cb,
  47170. + void *data, uint32_t time, char *format, ...)
  47171. +#ifdef __GNUC__
  47172. + __attribute__ ((format(printf, 5, 6)));
  47173. +#else
  47174. + ;
  47175. +#endif
  47176. +#define dwc_workq_schedule_delayed DWC_WORKQ_SCHEDULE_DELAYED
  47177. +
  47178. +/** The number of processes in the workq */
  47179. +extern int DWC_WORKQ_PENDING(dwc_workq_t *workq);
  47180. +#define dwc_workq_pending DWC_WORKQ_PENDING
  47181. +
  47182. +/** Blocks until all the work in the workq is complete or timed out. Returns <
  47183. + * 0 on timeout. */
  47184. +extern int DWC_WORKQ_WAIT_WORK_DONE(dwc_workq_t *workq, int timeout);
  47185. +#define dwc_workq_wait_work_done DWC_WORKQ_WAIT_WORK_DONE
  47186. +
  47187. +
  47188. +/** @name Tasklets
  47189. + *
  47190. + */
  47191. +struct dwc_tasklet;
  47192. +
  47193. +/** Type for a tasklet */
  47194. +typedef struct dwc_tasklet dwc_tasklet_t;
  47195. +
  47196. +/** The type of the callback function to be called */
  47197. +typedef void (*dwc_tasklet_callback_t)(void *data);
  47198. +
  47199. +/** Allocates a tasklet */
  47200. +extern dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data);
  47201. +#define dwc_task_alloc(_ctx_,_name_,_cb_,_data_) DWC_TASK_ALLOC(_name_, _cb_, _data_)
  47202. +
  47203. +/** Frees a tasklet */
  47204. +extern void DWC_TASK_FREE(dwc_tasklet_t *task);
  47205. +#define dwc_task_free DWC_TASK_FREE
  47206. +
  47207. +/** Schedules a tasklet to run */
  47208. +extern void DWC_TASK_SCHEDULE(dwc_tasklet_t *task);
  47209. +#define dwc_task_schedule DWC_TASK_SCHEDULE
  47210. +
  47211. +extern void DWC_TASK_HI_SCHEDULE(dwc_tasklet_t *task);
  47212. +#define dwc_task_hi_schedule DWC_TASK_HI_SCHEDULE
  47213. +
  47214. +/** @name Timer
  47215. + *
  47216. + * Callbacks must be small and atomic.
  47217. + */
  47218. +struct dwc_timer;
  47219. +
  47220. +/** Type for a timer */
  47221. +typedef struct dwc_timer dwc_timer_t;
  47222. +
  47223. +/** The type of the callback function to be called */
  47224. +typedef void (*dwc_timer_callback_t)(void *data);
  47225. +
  47226. +/** Allocates a timer */
  47227. +extern dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data);
  47228. +#define dwc_timer_alloc(_ctx_,_name_,_cb_,_data_) DWC_TIMER_ALLOC(_name_,_cb_,_data_)
  47229. +
  47230. +/** Frees a timer */
  47231. +extern void DWC_TIMER_FREE(dwc_timer_t *timer);
  47232. +#define dwc_timer_free DWC_TIMER_FREE
  47233. +
  47234. +/** Schedules the timer to run at time ms from now. And will repeat at every
  47235. + * repeat_interval msec therafter
  47236. + *
  47237. + * Modifies a timer that is still awaiting execution to a new expiration time.
  47238. + * The mod_time is added to the old time. */
  47239. +extern void DWC_TIMER_SCHEDULE(dwc_timer_t *timer, uint32_t time);
  47240. +#define dwc_timer_schedule DWC_TIMER_SCHEDULE
  47241. +
  47242. +/** Disables the timer from execution. */
  47243. +extern void DWC_TIMER_CANCEL(dwc_timer_t *timer);
  47244. +#define dwc_timer_cancel DWC_TIMER_CANCEL
  47245. +
  47246. +
  47247. +/** @name Spinlocks
  47248. + *
  47249. + * These locks are used when the work between the lock/unlock is atomic and
  47250. + * short. Interrupts are also disabled during the lock/unlock and thus they are
  47251. + * suitable to lock between interrupt/non-interrupt context. They also lock
  47252. + * between processes if you have multiple CPUs or Preemption. If you don't have
  47253. + * multiple CPUS or Preemption, then the you can simply implement the
  47254. + * DWC_SPINLOCK and DWC_SPINUNLOCK to disable and enable interrupts. Because
  47255. + * the work between the lock/unlock is atomic, the process context will never
  47256. + * change, and so you never have to lock between processes. */
  47257. +
  47258. +struct dwc_spinlock;
  47259. +
  47260. +/** Type for a spinlock */
  47261. +typedef struct dwc_spinlock dwc_spinlock_t;
  47262. +
  47263. +/** Type for the 'flags' argument to spinlock funtions */
  47264. +typedef unsigned long dwc_irqflags_t;
  47265. +
  47266. +/** Returns an initialized lock variable. This function should allocate and
  47267. + * initialize the OS-specific data structure used for locking. This data
  47268. + * structure is to be used for the DWC_LOCK and DWC_UNLOCK functions and should
  47269. + * be freed by the DWC_FREE_LOCK when it is no longer used. */
  47270. +extern dwc_spinlock_t *DWC_SPINLOCK_ALLOC(void);
  47271. +#define dwc_spinlock_alloc(_ctx_) DWC_SPINLOCK_ALLOC()
  47272. +
  47273. +/** Frees an initialized lock variable. */
  47274. +extern void DWC_SPINLOCK_FREE(dwc_spinlock_t *lock);
  47275. +#define dwc_spinlock_free(_ctx_,_lock_) DWC_SPINLOCK_FREE(_lock_)
  47276. +
  47277. +/** Disables interrupts and blocks until it acquires the lock.
  47278. + *
  47279. + * @param lock Pointer to the spinlock.
  47280. + * @param flags Unsigned long for irq flags storage.
  47281. + */
  47282. +extern void DWC_SPINLOCK_IRQSAVE(dwc_spinlock_t *lock, dwc_irqflags_t *flags);
  47283. +#define dwc_spinlock_irqsave DWC_SPINLOCK_IRQSAVE
  47284. +
  47285. +/** Re-enables the interrupt and releases the lock.
  47286. + *
  47287. + * @param lock Pointer to the spinlock.
  47288. + * @param flags Unsigned long for irq flags storage. Must be the same as was
  47289. + * passed into DWC_LOCK.
  47290. + */
  47291. +extern void DWC_SPINUNLOCK_IRQRESTORE(dwc_spinlock_t *lock, dwc_irqflags_t flags);
  47292. +#define dwc_spinunlock_irqrestore DWC_SPINUNLOCK_IRQRESTORE
  47293. +
  47294. +/** Blocks until it acquires the lock.
  47295. + *
  47296. + * @param lock Pointer to the spinlock.
  47297. + */
  47298. +extern void DWC_SPINLOCK(dwc_spinlock_t *lock);
  47299. +#define dwc_spinlock DWC_SPINLOCK
  47300. +
  47301. +/** Releases the lock.
  47302. + *
  47303. + * @param lock Pointer to the spinlock.
  47304. + */
  47305. +extern void DWC_SPINUNLOCK(dwc_spinlock_t *lock);
  47306. +#define dwc_spinunlock DWC_SPINUNLOCK
  47307. +
  47308. +
  47309. +/** @name Mutexes
  47310. + *
  47311. + * Unlike spinlocks Mutexes lock only between processes and the work between the
  47312. + * lock/unlock CAN block, therefore it CANNOT be called from interrupt context.
  47313. + */
  47314. +
  47315. +struct dwc_mutex;
  47316. +
  47317. +/** Type for a mutex */
  47318. +typedef struct dwc_mutex dwc_mutex_t;
  47319. +
  47320. +/* For Linux Mutex Debugging make it inline because the debugging routines use
  47321. + * the symbol to determine recursive locking. This makes it falsely think
  47322. + * recursive locking occurs. */
  47323. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47324. +#define DWC_MUTEX_ALLOC_LINUX_DEBUG(__mutexp) ({ \
  47325. + __mutexp = (dwc_mutex_t *)DWC_ALLOC(sizeof(struct mutex)); \
  47326. + mutex_init((struct mutex *)__mutexp); \
  47327. +})
  47328. +#endif
  47329. +
  47330. +/** Allocate a mutex */
  47331. +extern dwc_mutex_t *DWC_MUTEX_ALLOC(void);
  47332. +#define dwc_mutex_alloc(_ctx_) DWC_MUTEX_ALLOC()
  47333. +
  47334. +/* For memory leak debugging when using Linux Mutex Debugging */
  47335. +#if defined(DWC_LINUX) && defined(CONFIG_DEBUG_MUTEXES)
  47336. +#define DWC_MUTEX_FREE(__mutexp) do { \
  47337. + mutex_destroy((struct mutex *)__mutexp); \
  47338. + DWC_FREE(__mutexp); \
  47339. +} while(0)
  47340. +#else
  47341. +/** Free a mutex */
  47342. +extern void DWC_MUTEX_FREE(dwc_mutex_t *mutex);
  47343. +#define dwc_mutex_free(_ctx_,_mutex_) DWC_MUTEX_FREE(_mutex_)
  47344. +#endif
  47345. +
  47346. +/** Lock a mutex */
  47347. +extern void DWC_MUTEX_LOCK(dwc_mutex_t *mutex);
  47348. +#define dwc_mutex_lock DWC_MUTEX_LOCK
  47349. +
  47350. +/** Non-blocking lock returns 1 on successful lock. */
  47351. +extern int DWC_MUTEX_TRYLOCK(dwc_mutex_t *mutex);
  47352. +#define dwc_mutex_trylock DWC_MUTEX_TRYLOCK
  47353. +
  47354. +/** Unlock a mutex */
  47355. +extern void DWC_MUTEX_UNLOCK(dwc_mutex_t *mutex);
  47356. +#define dwc_mutex_unlock DWC_MUTEX_UNLOCK
  47357. +
  47358. +
  47359. +/** @name Time */
  47360. +
  47361. +/** Microsecond delay.
  47362. + *
  47363. + * @param usecs Microseconds to delay.
  47364. + */
  47365. +extern void DWC_UDELAY(uint32_t usecs);
  47366. +#define dwc_udelay DWC_UDELAY
  47367. +
  47368. +/** Millisecond delay.
  47369. + *
  47370. + * @param msecs Milliseconds to delay.
  47371. + */
  47372. +extern void DWC_MDELAY(uint32_t msecs);
  47373. +#define dwc_mdelay DWC_MDELAY
  47374. +
  47375. +/** Non-busy waiting.
  47376. + * Sleeps for specified number of milliseconds.
  47377. + *
  47378. + * @param msecs Milliseconds to sleep.
  47379. + */
  47380. +extern void DWC_MSLEEP(uint32_t msecs);
  47381. +#define dwc_msleep DWC_MSLEEP
  47382. +
  47383. +/**
  47384. + * Returns number of milliseconds since boot.
  47385. + */
  47386. +extern uint32_t DWC_TIME(void);
  47387. +#define dwc_time DWC_TIME
  47388. +
  47389. +
  47390. +
  47391. +
  47392. +/* @mainpage DWC Portability and Common Library
  47393. + *
  47394. + * This is the documentation for the DWC Portability and Common Library.
  47395. + *
  47396. + * @section intro Introduction
  47397. + *
  47398. + * The DWC Portability library consists of wrapper calls and data structures to
  47399. + * all low-level functions which are typically provided by the OS. The WUDEV
  47400. + * driver uses only these functions. In order to port the WUDEV driver, only
  47401. + * the functions in this library need to be re-implemented, with the same
  47402. + * behavior as documented here.
  47403. + *
  47404. + * The Common library consists of higher level functions, which rely only on
  47405. + * calling the functions from the DWC Portability library. These common
  47406. + * routines are shared across modules. Some of the common libraries need to be
  47407. + * used directly by the driver programmer when porting WUDEV. Such as the
  47408. + * parameter and notification libraries.
  47409. + *
  47410. + * @section low Portability Library OS Wrapper Functions
  47411. + *
  47412. + * Any function starting with DWC and in all CAPS is a low-level OS-wrapper that
  47413. + * needs to be implemented when porting, for example DWC_MUTEX_ALLOC(). All of
  47414. + * these functions are included in the dwc_os.h file.
  47415. + *
  47416. + * There are many functions here covering a wide array of OS services. Please
  47417. + * see dwc_os.h for details, and implementation notes for each function.
  47418. + *
  47419. + * @section common Common Library Functions
  47420. + *
  47421. + * Any function starting with dwc and in all lowercase is a common library
  47422. + * routine. These functions have a portable implementation and do not need to
  47423. + * be reimplemented when porting. The common routines can be used by any
  47424. + * driver, and some must be used by the end user to control the drivers. For
  47425. + * example, you must use the Parameter common library in order to set the
  47426. + * parameters in the WUDEV module.
  47427. + *
  47428. + * The common libraries consist of the following:
  47429. + *
  47430. + * - Connection Contexts - Used internally and can be used by end-user. See dwc_cc.h
  47431. + * - Parameters - Used internally and can be used by end-user. See dwc_params.h
  47432. + * - Notifications - Used internally and can be used by end-user. See dwc_notifier.h
  47433. + * - Lists - Used internally and can be used by end-user. See dwc_list.h
  47434. + * - Memory Debugging - Used internally and can be used by end-user. See dwc_os.h
  47435. + * - Modpow - Used internally only. See dwc_modpow.h
  47436. + * - DH - Used internally only. See dwc_dh.h
  47437. + * - Crypto - Used internally only. See dwc_crypto.h
  47438. + *
  47439. + *
  47440. + * @section prereq Prerequistes For dwc_os.h
  47441. + * @subsection types Data Types
  47442. + *
  47443. + * The dwc_os.h file assumes that several low-level data types are pre defined for the
  47444. + * compilation environment. These data types are:
  47445. + *
  47446. + * - uint8_t - unsigned 8-bit data type
  47447. + * - int8_t - signed 8-bit data type
  47448. + * - uint16_t - unsigned 16-bit data type
  47449. + * - int16_t - signed 16-bit data type
  47450. + * - uint32_t - unsigned 32-bit data type
  47451. + * - int32_t - signed 32-bit data type
  47452. + * - uint64_t - unsigned 64-bit data type
  47453. + * - int64_t - signed 64-bit data type
  47454. + *
  47455. + * Ensure that these are defined before using dwc_os.h. The easiest way to do
  47456. + * that is to modify the top of the file to include the appropriate header.
  47457. + * This is already done for the Linux environment. If the DWC_LINUX macro is
  47458. + * defined, the correct header will be added. A standard header <stdint.h> is
  47459. + * also used for environments where standard C headers are available.
  47460. + *
  47461. + * @subsection stdarg Variable Arguments
  47462. + *
  47463. + * Variable arguments are provided by a standard C header <stdarg.h>. it is
  47464. + * available in Both the Linux and ANSI C enviornment. An equivalent must be
  47465. + * provided in your enviornment in order to use dwc_os.h with the debug and
  47466. + * tracing message functionality.
  47467. + *
  47468. + * @subsection thread Threading
  47469. + *
  47470. + * WUDEV Core must be run on an operating system that provides for multiple
  47471. + * threads/processes. Threading can be implemented in many ways, even in
  47472. + * embedded systems without an operating system. At the bare minimum, the
  47473. + * system should be able to start any number of processes at any time to handle
  47474. + * special work. It need not be a pre-emptive system. Process context can
  47475. + * change upon a call to a blocking function. The hardware interrupt context
  47476. + * that calls the module's ISR() function must be differentiable from process
  47477. + * context, even if your processes are impemented via a hardware interrupt.
  47478. + * Further locking mechanism between process must exist (or be implemented), and
  47479. + * process context must have a way to disable interrupts for a period of time to
  47480. + * lock them out. If all of this exists, the functions in dwc_os.h related to
  47481. + * threading should be able to be implemented with the defined behavior.
  47482. + *
  47483. + */
  47484. +
  47485. +#ifdef __cplusplus
  47486. +}
  47487. +#endif
  47488. +
  47489. +#endif /* _DWC_OS_H_ */
  47490. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/Makefile linux-rpi/drivers/usb/host/dwc_common_port/Makefile
  47491. --- linux-3.15/drivers/usb/host/dwc_common_port/Makefile 1970-01-01 01:00:00.000000000 +0100
  47492. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile 2014-06-11 21:03:43.000000000 +0200
  47493. @@ -0,0 +1,58 @@
  47494. +#
  47495. +# Makefile for DWC_common library
  47496. +#
  47497. +
  47498. +ifneq ($(KERNELRELEASE),)
  47499. +
  47500. +ccflags-y += -DDWC_LINUX
  47501. +#ccflags-y += -DDEBUG
  47502. +#ccflags-y += -DDWC_DEBUG_REGS
  47503. +#ccflags-y += -DDWC_DEBUG_MEMORY
  47504. +
  47505. +ccflags-y += -DDWC_LIBMODULE
  47506. +ccflags-y += -DDWC_CCLIB
  47507. +#ccflags-y += -DDWC_CRYPTOLIB
  47508. +ccflags-y += -DDWC_NOTIFYLIB
  47509. +ccflags-y += -DDWC_UTFLIB
  47510. +
  47511. +obj-$(CONFIG_USB_DWCOTG) += dwc_common_port_lib.o
  47512. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47513. + dwc_crypto.o dwc_notifier.o \
  47514. + dwc_common_linux.o dwc_mem.o
  47515. +
  47516. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  47517. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  47518. +
  47519. +ifneq ($(kernrel3),2.6.20)
  47520. +# grayg - I only know that we use ccflags-y in 2.6.31 actually
  47521. +ccflags-y += $(CPPFLAGS)
  47522. +endif
  47523. +
  47524. +else
  47525. +
  47526. +#ifeq ($(KDIR),)
  47527. +#$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47528. +#endif
  47529. +
  47530. +ifeq ($(ARCH),)
  47531. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47532. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47533. +endif
  47534. +
  47535. +ifeq ($(DOXYGEN),)
  47536. +DOXYGEN := doxygen
  47537. +endif
  47538. +
  47539. +default:
  47540. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47541. +
  47542. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47543. + $(DOXYGEN) doc/doxygen.cfg
  47544. +
  47545. +tags: $(wildcard *.[hc])
  47546. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47547. +
  47548. +endif
  47549. +
  47550. +clean:
  47551. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47552. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/Makefile.fbsd linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd
  47553. --- linux-3.15/drivers/usb/host/dwc_common_port/Makefile.fbsd 1970-01-01 01:00:00.000000000 +0100
  47554. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.fbsd 2014-06-11 21:03:43.000000000 +0200
  47555. @@ -0,0 +1,17 @@
  47556. +CFLAGS += -I/sys/i386/compile/GENERIC -I/sys/i386/include -I/usr/include
  47557. +CFLAGS += -DDWC_FREEBSD
  47558. +CFLAGS += -DDEBUG
  47559. +#CFLAGS += -DDWC_DEBUG_REGS
  47560. +#CFLAGS += -DDWC_DEBUG_MEMORY
  47561. +
  47562. +#CFLAGS += -DDWC_LIBMODULE
  47563. +#CFLAGS += -DDWC_CCLIB
  47564. +#CFLAGS += -DDWC_CRYPTOLIB
  47565. +#CFLAGS += -DDWC_NOTIFYLIB
  47566. +#CFLAGS += -DDWC_UTFLIB
  47567. +
  47568. +KMOD = dwc_common_port_lib
  47569. +SRCS = dwc_cc.c dwc_modpow.c dwc_dh.c dwc_crypto.c dwc_notifier.c \
  47570. + dwc_common_fbsd.c dwc_mem.c
  47571. +
  47572. +.include <bsd.kmod.mk>
  47573. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/Makefile.linux linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux
  47574. --- linux-3.15/drivers/usb/host/dwc_common_port/Makefile.linux 1970-01-01 01:00:00.000000000 +0100
  47575. +++ linux-rpi/drivers/usb/host/dwc_common_port/Makefile.linux 2014-06-11 21:03:43.000000000 +0200
  47576. @@ -0,0 +1,49 @@
  47577. +#
  47578. +# Makefile for DWC_common library
  47579. +#
  47580. +ifneq ($(KERNELRELEASE),)
  47581. +
  47582. +ccflags-y += -DDWC_LINUX
  47583. +#ccflags-y += -DDEBUG
  47584. +#ccflags-y += -DDWC_DEBUG_REGS
  47585. +#ccflags-y += -DDWC_DEBUG_MEMORY
  47586. +
  47587. +ccflags-y += -DDWC_LIBMODULE
  47588. +ccflags-y += -DDWC_CCLIB
  47589. +ccflags-y += -DDWC_CRYPTOLIB
  47590. +ccflags-y += -DDWC_NOTIFYLIB
  47591. +ccflags-y += -DDWC_UTFLIB
  47592. +
  47593. +obj-m := dwc_common_port_lib.o
  47594. +dwc_common_port_lib-objs := dwc_cc.o dwc_modpow.o dwc_dh.o \
  47595. + dwc_crypto.o dwc_notifier.o \
  47596. + dwc_common_linux.o dwc_mem.o
  47597. +
  47598. +else
  47599. +
  47600. +ifeq ($(KDIR),)
  47601. +$(error Must give "KDIR=/path/to/kernel/source" on command line or in environment)
  47602. +endif
  47603. +
  47604. +ifeq ($(ARCH),)
  47605. +$(error Must give "ARCH=<arch>" on command line or in environment. Also, if \
  47606. + cross-compiling, must give "CROSS_COMPILE=/path/to/compiler/plus/tool-prefix-")
  47607. +endif
  47608. +
  47609. +ifeq ($(DOXYGEN),)
  47610. +DOXYGEN := doxygen
  47611. +endif
  47612. +
  47613. +default:
  47614. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  47615. +
  47616. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  47617. + $(DOXYGEN) doc/doxygen.cfg
  47618. +
  47619. +tags: $(wildcard *.[hc])
  47620. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  47621. +
  47622. +endif
  47623. +
  47624. +clean:
  47625. + rm -rf *.o *.ko .*.cmd *.mod.c .*.o.d .*.o.tmp modules.order Module.markers Module.symvers .tmp_versions/
  47626. diff -Nur linux-3.15/drivers/usb/host/dwc_common_port/usb.h linux-rpi/drivers/usb/host/dwc_common_port/usb.h
  47627. --- linux-3.15/drivers/usb/host/dwc_common_port/usb.h 1970-01-01 01:00:00.000000000 +0100
  47628. +++ linux-rpi/drivers/usb/host/dwc_common_port/usb.h 2014-06-11 21:03:43.000000000 +0200
  47629. @@ -0,0 +1,946 @@
  47630. +/*
  47631. + * Copyright (c) 1998 The NetBSD Foundation, Inc.
  47632. + * All rights reserved.
  47633. + *
  47634. + * This code is derived from software contributed to The NetBSD Foundation
  47635. + * by Lennart Augustsson (lennart@augustsson.net) at
  47636. + * Carlstedt Research & Technology.
  47637. + *
  47638. + * Redistribution and use in source and binary forms, with or without
  47639. + * modification, are permitted provided that the following conditions
  47640. + * are met:
  47641. + * 1. Redistributions of source code must retain the above copyright
  47642. + * notice, this list of conditions and the following disclaimer.
  47643. + * 2. Redistributions in binary form must reproduce the above copyright
  47644. + * notice, this list of conditions and the following disclaimer in the
  47645. + * documentation and/or other materials provided with the distribution.
  47646. + * 3. All advertising materials mentioning features or use of this software
  47647. + * must display the following acknowledgement:
  47648. + * This product includes software developed by the NetBSD
  47649. + * Foundation, Inc. and its contributors.
  47650. + * 4. Neither the name of The NetBSD Foundation nor the names of its
  47651. + * contributors may be used to endorse or promote products derived
  47652. + * from this software without specific prior written permission.
  47653. + *
  47654. + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  47655. + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  47656. + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  47657. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
  47658. + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  47659. + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  47660. + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  47661. + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  47662. + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  47663. + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  47664. + * POSSIBILITY OF SUCH DAMAGE.
  47665. + */
  47666. +
  47667. +/* Modified by Synopsys, Inc, 12/12/2007 */
  47668. +
  47669. +
  47670. +#ifndef _USB_H_
  47671. +#define _USB_H_
  47672. +
  47673. +#ifdef __cplusplus
  47674. +extern "C" {
  47675. +#endif
  47676. +
  47677. +/*
  47678. + * The USB records contain some unaligned little-endian word
  47679. + * components. The U[SG]ETW macros take care of both the alignment
  47680. + * and endian problem and should always be used to access non-byte
  47681. + * values.
  47682. + */
  47683. +typedef u_int8_t uByte;
  47684. +typedef u_int8_t uWord[2];
  47685. +typedef u_int8_t uDWord[4];
  47686. +
  47687. +#define USETW2(w,h,l) ((w)[0] = (u_int8_t)(l), (w)[1] = (u_int8_t)(h))
  47688. +#define UCONSTW(x) { (x) & 0xff, ((x) >> 8) & 0xff }
  47689. +#define UCONSTDW(x) { (x) & 0xff, ((x) >> 8) & 0xff, \
  47690. + ((x) >> 16) & 0xff, ((x) >> 24) & 0xff }
  47691. +
  47692. +#if 1
  47693. +#define UGETW(w) ((w)[0] | ((w)[1] << 8))
  47694. +#define USETW(w,v) ((w)[0] = (u_int8_t)(v), (w)[1] = (u_int8_t)((v) >> 8))
  47695. +#define UGETDW(w) ((w)[0] | ((w)[1] << 8) | ((w)[2] << 16) | ((w)[3] << 24))
  47696. +#define USETDW(w,v) ((w)[0] = (u_int8_t)(v), \
  47697. + (w)[1] = (u_int8_t)((v) >> 8), \
  47698. + (w)[2] = (u_int8_t)((v) >> 16), \
  47699. + (w)[3] = (u_int8_t)((v) >> 24))
  47700. +#else
  47701. +/*
  47702. + * On little-endian machines that can handle unanliged accesses
  47703. + * (e.g. i386) these macros can be replaced by the following.
  47704. + */
  47705. +#define UGETW(w) (*(u_int16_t *)(w))
  47706. +#define USETW(w,v) (*(u_int16_t *)(w) = (v))
  47707. +#define UGETDW(w) (*(u_int32_t *)(w))
  47708. +#define USETDW(w,v) (*(u_int32_t *)(w) = (v))
  47709. +#endif
  47710. +
  47711. +/*
  47712. + * Macros for accessing UAS IU fields, which are big-endian
  47713. + */
  47714. +#define IUSETW2(w,h,l) ((w)[0] = (u_int8_t)(h), (w)[1] = (u_int8_t)(l))
  47715. +#define IUCONSTW(x) { ((x) >> 8) & 0xff, (x) & 0xff }
  47716. +#define IUCONSTDW(x) { ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \
  47717. + ((x) >> 8) & 0xff, (x) & 0xff }
  47718. +#define IUGETW(w) (((w)[0] << 8) | (w)[1])
  47719. +#define IUSETW(w,v) ((w)[0] = (u_int8_t)((v) >> 8), (w)[1] = (u_int8_t)(v))
  47720. +#define IUGETDW(w) (((w)[0] << 24) | ((w)[1] << 16) | ((w)[2] << 8) | (w)[3])
  47721. +#define IUSETDW(w,v) ((w)[0] = (u_int8_t)((v) >> 24), \
  47722. + (w)[1] = (u_int8_t)((v) >> 16), \
  47723. + (w)[2] = (u_int8_t)((v) >> 8), \
  47724. + (w)[3] = (u_int8_t)(v))
  47725. +
  47726. +#define UPACKED __attribute__((__packed__))
  47727. +
  47728. +typedef struct {
  47729. + uByte bmRequestType;
  47730. + uByte bRequest;
  47731. + uWord wValue;
  47732. + uWord wIndex;
  47733. + uWord wLength;
  47734. +} UPACKED usb_device_request_t;
  47735. +
  47736. +#define UT_GET_DIR(a) ((a) & 0x80)
  47737. +#define UT_WRITE 0x00
  47738. +#define UT_READ 0x80
  47739. +
  47740. +#define UT_GET_TYPE(a) ((a) & 0x60)
  47741. +#define UT_STANDARD 0x00
  47742. +#define UT_CLASS 0x20
  47743. +#define UT_VENDOR 0x40
  47744. +
  47745. +#define UT_GET_RECIPIENT(a) ((a) & 0x1f)
  47746. +#define UT_DEVICE 0x00
  47747. +#define UT_INTERFACE 0x01
  47748. +#define UT_ENDPOINT 0x02
  47749. +#define UT_OTHER 0x03
  47750. +
  47751. +#define UT_READ_DEVICE (UT_READ | UT_STANDARD | UT_DEVICE)
  47752. +#define UT_READ_INTERFACE (UT_READ | UT_STANDARD | UT_INTERFACE)
  47753. +#define UT_READ_ENDPOINT (UT_READ | UT_STANDARD | UT_ENDPOINT)
  47754. +#define UT_WRITE_DEVICE (UT_WRITE | UT_STANDARD | UT_DEVICE)
  47755. +#define UT_WRITE_INTERFACE (UT_WRITE | UT_STANDARD | UT_INTERFACE)
  47756. +#define UT_WRITE_ENDPOINT (UT_WRITE | UT_STANDARD | UT_ENDPOINT)
  47757. +#define UT_READ_CLASS_DEVICE (UT_READ | UT_CLASS | UT_DEVICE)
  47758. +#define UT_READ_CLASS_INTERFACE (UT_READ | UT_CLASS | UT_INTERFACE)
  47759. +#define UT_READ_CLASS_OTHER (UT_READ | UT_CLASS | UT_OTHER)
  47760. +#define UT_READ_CLASS_ENDPOINT (UT_READ | UT_CLASS | UT_ENDPOINT)
  47761. +#define UT_WRITE_CLASS_DEVICE (UT_WRITE | UT_CLASS | UT_DEVICE)
  47762. +#define UT_WRITE_CLASS_INTERFACE (UT_WRITE | UT_CLASS | UT_INTERFACE)
  47763. +#define UT_WRITE_CLASS_OTHER (UT_WRITE | UT_CLASS | UT_OTHER)
  47764. +#define UT_WRITE_CLASS_ENDPOINT (UT_WRITE | UT_CLASS | UT_ENDPOINT)
  47765. +#define UT_READ_VENDOR_DEVICE (UT_READ | UT_VENDOR | UT_DEVICE)
  47766. +#define UT_READ_VENDOR_INTERFACE (UT_READ | UT_VENDOR | UT_INTERFACE)
  47767. +#define UT_READ_VENDOR_OTHER (UT_READ | UT_VENDOR | UT_OTHER)
  47768. +#define UT_READ_VENDOR_ENDPOINT (UT_READ | UT_VENDOR | UT_ENDPOINT)
  47769. +#define UT_WRITE_VENDOR_DEVICE (UT_WRITE | UT_VENDOR | UT_DEVICE)
  47770. +#define UT_WRITE_VENDOR_INTERFACE (UT_WRITE | UT_VENDOR | UT_INTERFACE)
  47771. +#define UT_WRITE_VENDOR_OTHER (UT_WRITE | UT_VENDOR | UT_OTHER)
  47772. +#define UT_WRITE_VENDOR_ENDPOINT (UT_WRITE | UT_VENDOR | UT_ENDPOINT)
  47773. +
  47774. +/* Requests */
  47775. +#define UR_GET_STATUS 0x00
  47776. +#define USTAT_STANDARD_STATUS 0x00
  47777. +#define WUSTAT_WUSB_FEATURE 0x01
  47778. +#define WUSTAT_CHANNEL_INFO 0x02
  47779. +#define WUSTAT_RECEIVED_DATA 0x03
  47780. +#define WUSTAT_MAS_AVAILABILITY 0x04
  47781. +#define WUSTAT_CURRENT_TRANSMIT_POWER 0x05
  47782. +#define UR_CLEAR_FEATURE 0x01
  47783. +#define UR_SET_FEATURE 0x03
  47784. +#define UR_SET_AND_TEST_FEATURE 0x0c
  47785. +#define UR_SET_ADDRESS 0x05
  47786. +#define UR_GET_DESCRIPTOR 0x06
  47787. +#define UDESC_DEVICE 0x01
  47788. +#define UDESC_CONFIG 0x02
  47789. +#define UDESC_STRING 0x03
  47790. +#define UDESC_INTERFACE 0x04
  47791. +#define UDESC_ENDPOINT 0x05
  47792. +#define UDESC_SS_USB_COMPANION 0x30
  47793. +#define UDESC_DEVICE_QUALIFIER 0x06
  47794. +#define UDESC_OTHER_SPEED_CONFIGURATION 0x07
  47795. +#define UDESC_INTERFACE_POWER 0x08
  47796. +#define UDESC_OTG 0x09
  47797. +#define WUDESC_SECURITY 0x0c
  47798. +#define WUDESC_KEY 0x0d
  47799. +#define WUD_GET_KEY_INDEX(_wValue_) ((_wValue_) & 0xf)
  47800. +#define WUD_GET_KEY_TYPE(_wValue_) (((_wValue_) & 0x30) >> 4)
  47801. +#define WUD_KEY_TYPE_ASSOC 0x01
  47802. +#define WUD_KEY_TYPE_GTK 0x02
  47803. +#define WUD_GET_KEY_ORIGIN(_wValue_) (((_wValue_) & 0x40) >> 6)
  47804. +#define WUD_KEY_ORIGIN_HOST 0x00
  47805. +#define WUD_KEY_ORIGIN_DEVICE 0x01
  47806. +#define WUDESC_ENCRYPTION_TYPE 0x0e
  47807. +#define WUDESC_BOS 0x0f
  47808. +#define WUDESC_DEVICE_CAPABILITY 0x10
  47809. +#define WUDESC_WIRELESS_ENDPOINT_COMPANION 0x11
  47810. +#define UDESC_BOS 0x0f
  47811. +#define UDESC_DEVICE_CAPABILITY 0x10
  47812. +#define UDESC_CS_DEVICE 0x21 /* class specific */
  47813. +#define UDESC_CS_CONFIG 0x22
  47814. +#define UDESC_CS_STRING 0x23
  47815. +#define UDESC_CS_INTERFACE 0x24
  47816. +#define UDESC_CS_ENDPOINT 0x25
  47817. +#define UDESC_HUB 0x29
  47818. +#define UR_SET_DESCRIPTOR 0x07
  47819. +#define UR_GET_CONFIG 0x08
  47820. +#define UR_SET_CONFIG 0x09
  47821. +#define UR_GET_INTERFACE 0x0a
  47822. +#define UR_SET_INTERFACE 0x0b
  47823. +#define UR_SYNCH_FRAME 0x0c
  47824. +#define WUR_SET_ENCRYPTION 0x0d
  47825. +#define WUR_GET_ENCRYPTION 0x0e
  47826. +#define WUR_SET_HANDSHAKE 0x0f
  47827. +#define WUR_GET_HANDSHAKE 0x10
  47828. +#define WUR_SET_CONNECTION 0x11
  47829. +#define WUR_SET_SECURITY_DATA 0x12
  47830. +#define WUR_GET_SECURITY_DATA 0x13
  47831. +#define WUR_SET_WUSB_DATA 0x14
  47832. +#define WUDATA_DRPIE_INFO 0x01
  47833. +#define WUDATA_TRANSMIT_DATA 0x02
  47834. +#define WUDATA_TRANSMIT_PARAMS 0x03
  47835. +#define WUDATA_RECEIVE_PARAMS 0x04
  47836. +#define WUDATA_TRANSMIT_POWER 0x05
  47837. +#define WUR_LOOPBACK_DATA_WRITE 0x15
  47838. +#define WUR_LOOPBACK_DATA_READ 0x16
  47839. +#define WUR_SET_INTERFACE_DS 0x17
  47840. +
  47841. +/* Feature numbers */
  47842. +#define UF_ENDPOINT_HALT 0
  47843. +#define UF_DEVICE_REMOTE_WAKEUP 1
  47844. +#define UF_TEST_MODE 2
  47845. +#define UF_DEVICE_B_HNP_ENABLE 3
  47846. +#define UF_DEVICE_A_HNP_SUPPORT 4
  47847. +#define UF_DEVICE_A_ALT_HNP_SUPPORT 5
  47848. +#define WUF_WUSB 3
  47849. +#define WUF_TX_DRPIE 0x0
  47850. +#define WUF_DEV_XMIT_PACKET 0x1
  47851. +#define WUF_COUNT_PACKETS 0x2
  47852. +#define WUF_CAPTURE_PACKETS 0x3
  47853. +#define UF_FUNCTION_SUSPEND 0
  47854. +#define UF_U1_ENABLE 48
  47855. +#define UF_U2_ENABLE 49
  47856. +#define UF_LTM_ENABLE 50
  47857. +
  47858. +/* Class requests from the USB 2.0 hub spec, table 11-15 */
  47859. +#define UCR_CLEAR_HUB_FEATURE (0x2000 | UR_CLEAR_FEATURE)
  47860. +#define UCR_CLEAR_PORT_FEATURE (0x2300 | UR_CLEAR_FEATURE)
  47861. +#define UCR_GET_HUB_DESCRIPTOR (0xa000 | UR_GET_DESCRIPTOR)
  47862. +#define UCR_GET_HUB_STATUS (0xa000 | UR_GET_STATUS)
  47863. +#define UCR_GET_PORT_STATUS (0xa300 | UR_GET_STATUS)
  47864. +#define UCR_SET_HUB_FEATURE (0x2000 | UR_SET_FEATURE)
  47865. +#define UCR_SET_PORT_FEATURE (0x2300 | UR_SET_FEATURE)
  47866. +#define UCR_SET_AND_TEST_PORT_FEATURE (0xa300 | UR_SET_AND_TEST_FEATURE)
  47867. +
  47868. +#ifdef _MSC_VER
  47869. +#include <pshpack1.h>
  47870. +#endif
  47871. +
  47872. +typedef struct {
  47873. + uByte bLength;
  47874. + uByte bDescriptorType;
  47875. + uByte bDescriptorSubtype;
  47876. +} UPACKED usb_descriptor_t;
  47877. +
  47878. +typedef struct {
  47879. + uByte bLength;
  47880. + uByte bDescriptorType;
  47881. +} UPACKED usb_descriptor_header_t;
  47882. +
  47883. +typedef struct {
  47884. + uByte bLength;
  47885. + uByte bDescriptorType;
  47886. + uWord bcdUSB;
  47887. +#define UD_USB_2_0 0x0200
  47888. +#define UD_IS_USB2(d) (UGETW((d)->bcdUSB) >= UD_USB_2_0)
  47889. + uByte bDeviceClass;
  47890. + uByte bDeviceSubClass;
  47891. + uByte bDeviceProtocol;
  47892. + uByte bMaxPacketSize;
  47893. + /* The fields below are not part of the initial descriptor. */
  47894. + uWord idVendor;
  47895. + uWord idProduct;
  47896. + uWord bcdDevice;
  47897. + uByte iManufacturer;
  47898. + uByte iProduct;
  47899. + uByte iSerialNumber;
  47900. + uByte bNumConfigurations;
  47901. +} UPACKED usb_device_descriptor_t;
  47902. +#define USB_DEVICE_DESCRIPTOR_SIZE 18
  47903. +
  47904. +typedef struct {
  47905. + uByte bLength;
  47906. + uByte bDescriptorType;
  47907. + uWord wTotalLength;
  47908. + uByte bNumInterface;
  47909. + uByte bConfigurationValue;
  47910. + uByte iConfiguration;
  47911. +#define UC_ATT_ONE (1 << 7) /* must be set */
  47912. +#define UC_ATT_SELFPOWER (1 << 6) /* self powered */
  47913. +#define UC_ATT_WAKEUP (1 << 5) /* can wakeup */
  47914. +#define UC_ATT_BATTERY (1 << 4) /* battery powered */
  47915. + uByte bmAttributes;
  47916. +#define UC_BUS_POWERED 0x80
  47917. +#define UC_SELF_POWERED 0x40
  47918. +#define UC_REMOTE_WAKEUP 0x20
  47919. + uByte bMaxPower; /* max current in 2 mA units */
  47920. +#define UC_POWER_FACTOR 2
  47921. +} UPACKED usb_config_descriptor_t;
  47922. +#define USB_CONFIG_DESCRIPTOR_SIZE 9
  47923. +
  47924. +typedef struct {
  47925. + uByte bLength;
  47926. + uByte bDescriptorType;
  47927. + uByte bInterfaceNumber;
  47928. + uByte bAlternateSetting;
  47929. + uByte bNumEndpoints;
  47930. + uByte bInterfaceClass;
  47931. + uByte bInterfaceSubClass;
  47932. + uByte bInterfaceProtocol;
  47933. + uByte iInterface;
  47934. +} UPACKED usb_interface_descriptor_t;
  47935. +#define USB_INTERFACE_DESCRIPTOR_SIZE 9
  47936. +
  47937. +typedef struct {
  47938. + uByte bLength;
  47939. + uByte bDescriptorType;
  47940. + uByte bEndpointAddress;
  47941. +#define UE_GET_DIR(a) ((a) & 0x80)
  47942. +#define UE_SET_DIR(a,d) ((a) | (((d)&1) << 7))
  47943. +#define UE_DIR_IN 0x80
  47944. +#define UE_DIR_OUT 0x00
  47945. +#define UE_ADDR 0x0f
  47946. +#define UE_GET_ADDR(a) ((a) & UE_ADDR)
  47947. + uByte bmAttributes;
  47948. +#define UE_XFERTYPE 0x03
  47949. +#define UE_CONTROL 0x00
  47950. +#define UE_ISOCHRONOUS 0x01
  47951. +#define UE_BULK 0x02
  47952. +#define UE_INTERRUPT 0x03
  47953. +#define UE_GET_XFERTYPE(a) ((a) & UE_XFERTYPE)
  47954. +#define UE_ISO_TYPE 0x0c
  47955. +#define UE_ISO_ASYNC 0x04
  47956. +#define UE_ISO_ADAPT 0x08
  47957. +#define UE_ISO_SYNC 0x0c
  47958. +#define UE_GET_ISO_TYPE(a) ((a) & UE_ISO_TYPE)
  47959. + uWord wMaxPacketSize;
  47960. + uByte bInterval;
  47961. +} UPACKED usb_endpoint_descriptor_t;
  47962. +#define USB_ENDPOINT_DESCRIPTOR_SIZE 7
  47963. +
  47964. +typedef struct ss_endpoint_companion_descriptor {
  47965. + uByte bLength;
  47966. + uByte bDescriptorType;
  47967. + uByte bMaxBurst;
  47968. +#define USSE_GET_MAX_STREAMS(a) ((a) & 0x1f)
  47969. +#define USSE_SET_MAX_STREAMS(a, b) ((a) | ((b) & 0x1f))
  47970. +#define USSE_GET_MAX_PACKET_NUM(a) ((a) & 0x03)
  47971. +#define USSE_SET_MAX_PACKET_NUM(a, b) ((a) | ((b) & 0x03))
  47972. + uByte bmAttributes;
  47973. + uWord wBytesPerInterval;
  47974. +} UPACKED ss_endpoint_companion_descriptor_t;
  47975. +#define USB_SS_ENDPOINT_COMPANION_DESCRIPTOR_SIZE 6
  47976. +
  47977. +typedef struct {
  47978. + uByte bLength;
  47979. + uByte bDescriptorType;
  47980. + uWord bString[127];
  47981. +} UPACKED usb_string_descriptor_t;
  47982. +#define USB_MAX_STRING_LEN 128
  47983. +#define USB_LANGUAGE_TABLE 0 /* # of the string language id table */
  47984. +
  47985. +/* Hub specific request */
  47986. +#define UR_GET_BUS_STATE 0x02
  47987. +#define UR_CLEAR_TT_BUFFER 0x08
  47988. +#define UR_RESET_TT 0x09
  47989. +#define UR_GET_TT_STATE 0x0a
  47990. +#define UR_STOP_TT 0x0b
  47991. +
  47992. +/* Hub features */
  47993. +#define UHF_C_HUB_LOCAL_POWER 0
  47994. +#define UHF_C_HUB_OVER_CURRENT 1
  47995. +#define UHF_PORT_CONNECTION 0
  47996. +#define UHF_PORT_ENABLE 1
  47997. +#define UHF_PORT_SUSPEND 2
  47998. +#define UHF_PORT_OVER_CURRENT 3
  47999. +#define UHF_PORT_RESET 4
  48000. +#define UHF_PORT_L1 5
  48001. +#define UHF_PORT_POWER 8
  48002. +#define UHF_PORT_LOW_SPEED 9
  48003. +#define UHF_PORT_HIGH_SPEED 10
  48004. +#define UHF_C_PORT_CONNECTION 16
  48005. +#define UHF_C_PORT_ENABLE 17
  48006. +#define UHF_C_PORT_SUSPEND 18
  48007. +#define UHF_C_PORT_OVER_CURRENT 19
  48008. +#define UHF_C_PORT_RESET 20
  48009. +#define UHF_C_PORT_L1 23
  48010. +#define UHF_PORT_TEST 21
  48011. +#define UHF_PORT_INDICATOR 22
  48012. +
  48013. +typedef struct {
  48014. + uByte bDescLength;
  48015. + uByte bDescriptorType;
  48016. + uByte bNbrPorts;
  48017. + uWord wHubCharacteristics;
  48018. +#define UHD_PWR 0x0003
  48019. +#define UHD_PWR_GANGED 0x0000
  48020. +#define UHD_PWR_INDIVIDUAL 0x0001
  48021. +#define UHD_PWR_NO_SWITCH 0x0002
  48022. +#define UHD_COMPOUND 0x0004
  48023. +#define UHD_OC 0x0018
  48024. +#define UHD_OC_GLOBAL 0x0000
  48025. +#define UHD_OC_INDIVIDUAL 0x0008
  48026. +#define UHD_OC_NONE 0x0010
  48027. +#define UHD_TT_THINK 0x0060
  48028. +#define UHD_TT_THINK_8 0x0000
  48029. +#define UHD_TT_THINK_16 0x0020
  48030. +#define UHD_TT_THINK_24 0x0040
  48031. +#define UHD_TT_THINK_32 0x0060
  48032. +#define UHD_PORT_IND 0x0080
  48033. + uByte bPwrOn2PwrGood; /* delay in 2 ms units */
  48034. +#define UHD_PWRON_FACTOR 2
  48035. + uByte bHubContrCurrent;
  48036. + uByte DeviceRemovable[32]; /* max 255 ports */
  48037. +#define UHD_NOT_REMOV(desc, i) \
  48038. + (((desc)->DeviceRemovable[(i)/8] >> ((i) % 8)) & 1)
  48039. + /* deprecated */ uByte PortPowerCtrlMask[1];
  48040. +} UPACKED usb_hub_descriptor_t;
  48041. +#define USB_HUB_DESCRIPTOR_SIZE 9 /* includes deprecated PortPowerCtrlMask */
  48042. +
  48043. +typedef struct {
  48044. + uByte bLength;
  48045. + uByte bDescriptorType;
  48046. + uWord bcdUSB;
  48047. + uByte bDeviceClass;
  48048. + uByte bDeviceSubClass;
  48049. + uByte bDeviceProtocol;
  48050. + uByte bMaxPacketSize0;
  48051. + uByte bNumConfigurations;
  48052. + uByte bReserved;
  48053. +} UPACKED usb_device_qualifier_t;
  48054. +#define USB_DEVICE_QUALIFIER_SIZE 10
  48055. +
  48056. +typedef struct {
  48057. + uByte bLength;
  48058. + uByte bDescriptorType;
  48059. + uByte bmAttributes;
  48060. +#define UOTG_SRP 0x01
  48061. +#define UOTG_HNP 0x02
  48062. +} UPACKED usb_otg_descriptor_t;
  48063. +
  48064. +/* OTG feature selectors */
  48065. +#define UOTG_B_HNP_ENABLE 3
  48066. +#define UOTG_A_HNP_SUPPORT 4
  48067. +#define UOTG_A_ALT_HNP_SUPPORT 5
  48068. +
  48069. +typedef struct {
  48070. + uWord wStatus;
  48071. +/* Device status flags */
  48072. +#define UDS_SELF_POWERED 0x0001
  48073. +#define UDS_REMOTE_WAKEUP 0x0002
  48074. +/* Endpoint status flags */
  48075. +#define UES_HALT 0x0001
  48076. +} UPACKED usb_status_t;
  48077. +
  48078. +typedef struct {
  48079. + uWord wHubStatus;
  48080. +#define UHS_LOCAL_POWER 0x0001
  48081. +#define UHS_OVER_CURRENT 0x0002
  48082. + uWord wHubChange;
  48083. +} UPACKED usb_hub_status_t;
  48084. +
  48085. +typedef struct {
  48086. + uWord wPortStatus;
  48087. +#define UPS_CURRENT_CONNECT_STATUS 0x0001
  48088. +#define UPS_PORT_ENABLED 0x0002
  48089. +#define UPS_SUSPEND 0x0004
  48090. +#define UPS_OVERCURRENT_INDICATOR 0x0008
  48091. +#define UPS_RESET 0x0010
  48092. +#define UPS_PORT_POWER 0x0100
  48093. +#define UPS_LOW_SPEED 0x0200
  48094. +#define UPS_HIGH_SPEED 0x0400
  48095. +#define UPS_PORT_TEST 0x0800
  48096. +#define UPS_PORT_INDICATOR 0x1000
  48097. + uWord wPortChange;
  48098. +#define UPS_C_CONNECT_STATUS 0x0001
  48099. +#define UPS_C_PORT_ENABLED 0x0002
  48100. +#define UPS_C_SUSPEND 0x0004
  48101. +#define UPS_C_OVERCURRENT_INDICATOR 0x0008
  48102. +#define UPS_C_PORT_RESET 0x0010
  48103. +} UPACKED usb_port_status_t;
  48104. +
  48105. +#ifdef _MSC_VER
  48106. +#include <poppack.h>
  48107. +#endif
  48108. +
  48109. +/* Device class codes */
  48110. +#define UDCLASS_IN_INTERFACE 0x00
  48111. +#define UDCLASS_COMM 0x02
  48112. +#define UDCLASS_HUB 0x09
  48113. +#define UDSUBCLASS_HUB 0x00
  48114. +#define UDPROTO_FSHUB 0x00
  48115. +#define UDPROTO_HSHUBSTT 0x01
  48116. +#define UDPROTO_HSHUBMTT 0x02
  48117. +#define UDCLASS_DIAGNOSTIC 0xdc
  48118. +#define UDCLASS_WIRELESS 0xe0
  48119. +#define UDSUBCLASS_RF 0x01
  48120. +#define UDPROTO_BLUETOOTH 0x01
  48121. +#define UDCLASS_VENDOR 0xff
  48122. +
  48123. +/* Interface class codes */
  48124. +#define UICLASS_UNSPEC 0x00
  48125. +
  48126. +#define UICLASS_AUDIO 0x01
  48127. +#define UISUBCLASS_AUDIOCONTROL 1
  48128. +#define UISUBCLASS_AUDIOSTREAM 2
  48129. +#define UISUBCLASS_MIDISTREAM 3
  48130. +
  48131. +#define UICLASS_CDC 0x02 /* communication */
  48132. +#define UISUBCLASS_DIRECT_LINE_CONTROL_MODEL 1
  48133. +#define UISUBCLASS_ABSTRACT_CONTROL_MODEL 2
  48134. +#define UISUBCLASS_TELEPHONE_CONTROL_MODEL 3
  48135. +#define UISUBCLASS_MULTICHANNEL_CONTROL_MODEL 4
  48136. +#define UISUBCLASS_CAPI_CONTROLMODEL 5
  48137. +#define UISUBCLASS_ETHERNET_NETWORKING_CONTROL_MODEL 6
  48138. +#define UISUBCLASS_ATM_NETWORKING_CONTROL_MODEL 7
  48139. +#define UIPROTO_CDC_AT 1
  48140. +
  48141. +#define UICLASS_HID 0x03
  48142. +#define UISUBCLASS_BOOT 1
  48143. +#define UIPROTO_BOOT_KEYBOARD 1
  48144. +
  48145. +#define UICLASS_PHYSICAL 0x05
  48146. +
  48147. +#define UICLASS_IMAGE 0x06
  48148. +
  48149. +#define UICLASS_PRINTER 0x07
  48150. +#define UISUBCLASS_PRINTER 1
  48151. +#define UIPROTO_PRINTER_UNI 1
  48152. +#define UIPROTO_PRINTER_BI 2
  48153. +#define UIPROTO_PRINTER_1284 3
  48154. +
  48155. +#define UICLASS_MASS 0x08
  48156. +#define UISUBCLASS_RBC 1
  48157. +#define UISUBCLASS_SFF8020I 2
  48158. +#define UISUBCLASS_QIC157 3
  48159. +#define UISUBCLASS_UFI 4
  48160. +#define UISUBCLASS_SFF8070I 5
  48161. +#define UISUBCLASS_SCSI 6
  48162. +#define UIPROTO_MASS_CBI_I 0
  48163. +#define UIPROTO_MASS_CBI 1
  48164. +#define UIPROTO_MASS_BBB_OLD 2 /* Not in the spec anymore */
  48165. +#define UIPROTO_MASS_BBB 80 /* 'P' for the Iomega Zip drive */
  48166. +
  48167. +#define UICLASS_HUB 0x09
  48168. +#define UISUBCLASS_HUB 0
  48169. +#define UIPROTO_FSHUB 0
  48170. +#define UIPROTO_HSHUBSTT 0 /* Yes, same as previous */
  48171. +#define UIPROTO_HSHUBMTT 1
  48172. +
  48173. +#define UICLASS_CDC_DATA 0x0a
  48174. +#define UISUBCLASS_DATA 0
  48175. +#define UIPROTO_DATA_ISDNBRI 0x30 /* Physical iface */
  48176. +#define UIPROTO_DATA_HDLC 0x31 /* HDLC */
  48177. +#define UIPROTO_DATA_TRANSPARENT 0x32 /* Transparent */
  48178. +#define UIPROTO_DATA_Q921M 0x50 /* Management for Q921 */
  48179. +#define UIPROTO_DATA_Q921 0x51 /* Data for Q921 */
  48180. +#define UIPROTO_DATA_Q921TM 0x52 /* TEI multiplexer for Q921 */
  48181. +#define UIPROTO_DATA_V42BIS 0x90 /* Data compression */
  48182. +#define UIPROTO_DATA_Q931 0x91 /* Euro-ISDN */
  48183. +#define UIPROTO_DATA_V120 0x92 /* V.24 rate adaption */
  48184. +#define UIPROTO_DATA_CAPI 0x93 /* CAPI 2.0 commands */
  48185. +#define UIPROTO_DATA_HOST_BASED 0xfd /* Host based driver */
  48186. +#define UIPROTO_DATA_PUF 0xfe /* see Prot. Unit Func. Desc.*/
  48187. +#define UIPROTO_DATA_VENDOR 0xff /* Vendor specific */
  48188. +
  48189. +#define UICLASS_SMARTCARD 0x0b
  48190. +
  48191. +/*#define UICLASS_FIRM_UPD 0x0c*/
  48192. +
  48193. +#define UICLASS_SECURITY 0x0d
  48194. +
  48195. +#define UICLASS_DIAGNOSTIC 0xdc
  48196. +
  48197. +#define UICLASS_WIRELESS 0xe0
  48198. +#define UISUBCLASS_RF 0x01
  48199. +#define UIPROTO_BLUETOOTH 0x01
  48200. +
  48201. +#define UICLASS_APPL_SPEC 0xfe
  48202. +#define UISUBCLASS_FIRMWARE_DOWNLOAD 1
  48203. +#define UISUBCLASS_IRDA 2
  48204. +#define UIPROTO_IRDA 0
  48205. +
  48206. +#define UICLASS_VENDOR 0xff
  48207. +
  48208. +#define USB_HUB_MAX_DEPTH 5
  48209. +
  48210. +/*
  48211. + * Minimum time a device needs to be powered down to go through
  48212. + * a power cycle. XXX Are these time in the spec?
  48213. + */
  48214. +#define USB_POWER_DOWN_TIME 200 /* ms */
  48215. +#define USB_PORT_POWER_DOWN_TIME 100 /* ms */
  48216. +
  48217. +#if 0
  48218. +/* These are the values from the spec. */
  48219. +#define USB_PORT_RESET_DELAY 10 /* ms */
  48220. +#define USB_PORT_ROOT_RESET_DELAY 50 /* ms */
  48221. +#define USB_PORT_RESET_RECOVERY 10 /* ms */
  48222. +#define USB_PORT_POWERUP_DELAY 100 /* ms */
  48223. +#define USB_SET_ADDRESS_SETTLE 2 /* ms */
  48224. +#define USB_RESUME_DELAY (20*5) /* ms */
  48225. +#define USB_RESUME_WAIT 10 /* ms */
  48226. +#define USB_RESUME_RECOVERY 10 /* ms */
  48227. +#define USB_EXTRA_POWER_UP_TIME 0 /* ms */
  48228. +#else
  48229. +/* Allow for marginal (i.e. non-conforming) devices. */
  48230. +#define USB_PORT_RESET_DELAY 50 /* ms */
  48231. +#define USB_PORT_ROOT_RESET_DELAY 250 /* ms */
  48232. +#define USB_PORT_RESET_RECOVERY 250 /* ms */
  48233. +#define USB_PORT_POWERUP_DELAY 300 /* ms */
  48234. +#define USB_SET_ADDRESS_SETTLE 10 /* ms */
  48235. +#define USB_RESUME_DELAY (50*5) /* ms */
  48236. +#define USB_RESUME_WAIT 50 /* ms */
  48237. +#define USB_RESUME_RECOVERY 50 /* ms */
  48238. +#define USB_EXTRA_POWER_UP_TIME 20 /* ms */
  48239. +#endif
  48240. +
  48241. +#define USB_MIN_POWER 100 /* mA */
  48242. +#define USB_MAX_POWER 500 /* mA */
  48243. +
  48244. +#define USB_BUS_RESET_DELAY 100 /* ms XXX?*/
  48245. +
  48246. +#define USB_UNCONFIG_NO 0
  48247. +#define USB_UNCONFIG_INDEX (-1)
  48248. +
  48249. +/*** ioctl() related stuff ***/
  48250. +
  48251. +struct usb_ctl_request {
  48252. + int ucr_addr;
  48253. + usb_device_request_t ucr_request;
  48254. + void *ucr_data;
  48255. + int ucr_flags;
  48256. +#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */
  48257. + int ucr_actlen; /* actual length transferred */
  48258. +};
  48259. +
  48260. +struct usb_alt_interface {
  48261. + int uai_config_index;
  48262. + int uai_interface_index;
  48263. + int uai_alt_no;
  48264. +};
  48265. +
  48266. +#define USB_CURRENT_CONFIG_INDEX (-1)
  48267. +#define USB_CURRENT_ALT_INDEX (-1)
  48268. +
  48269. +struct usb_config_desc {
  48270. + int ucd_config_index;
  48271. + usb_config_descriptor_t ucd_desc;
  48272. +};
  48273. +
  48274. +struct usb_interface_desc {
  48275. + int uid_config_index;
  48276. + int uid_interface_index;
  48277. + int uid_alt_index;
  48278. + usb_interface_descriptor_t uid_desc;
  48279. +};
  48280. +
  48281. +struct usb_endpoint_desc {
  48282. + int ued_config_index;
  48283. + int ued_interface_index;
  48284. + int ued_alt_index;
  48285. + int ued_endpoint_index;
  48286. + usb_endpoint_descriptor_t ued_desc;
  48287. +};
  48288. +
  48289. +struct usb_full_desc {
  48290. + int ufd_config_index;
  48291. + u_int ufd_size;
  48292. + u_char *ufd_data;
  48293. +};
  48294. +
  48295. +struct usb_string_desc {
  48296. + int usd_string_index;
  48297. + int usd_language_id;
  48298. + usb_string_descriptor_t usd_desc;
  48299. +};
  48300. +
  48301. +struct usb_ctl_report_desc {
  48302. + int ucrd_size;
  48303. + u_char ucrd_data[1024]; /* filled data size will vary */
  48304. +};
  48305. +
  48306. +typedef struct { u_int32_t cookie; } usb_event_cookie_t;
  48307. +
  48308. +#define USB_MAX_DEVNAMES 4
  48309. +#define USB_MAX_DEVNAMELEN 16
  48310. +struct usb_device_info {
  48311. + u_int8_t udi_bus;
  48312. + u_int8_t udi_addr; /* device address */
  48313. + usb_event_cookie_t udi_cookie;
  48314. + char udi_product[USB_MAX_STRING_LEN];
  48315. + char udi_vendor[USB_MAX_STRING_LEN];
  48316. + char udi_release[8];
  48317. + u_int16_t udi_productNo;
  48318. + u_int16_t udi_vendorNo;
  48319. + u_int16_t udi_releaseNo;
  48320. + u_int8_t udi_class;
  48321. + u_int8_t udi_subclass;
  48322. + u_int8_t udi_protocol;
  48323. + u_int8_t udi_config;
  48324. + u_int8_t udi_speed;
  48325. +#define USB_SPEED_UNKNOWN 0
  48326. +#define USB_SPEED_LOW 1
  48327. +#define USB_SPEED_FULL 2
  48328. +#define USB_SPEED_HIGH 3
  48329. +#define USB_SPEED_VARIABLE 4
  48330. +#define USB_SPEED_SUPER 5
  48331. + int udi_power; /* power consumption in mA, 0 if selfpowered */
  48332. + int udi_nports;
  48333. + char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
  48334. + u_int8_t udi_ports[16];/* hub only: addresses of devices on ports */
  48335. +#define USB_PORT_ENABLED 0xff
  48336. +#define USB_PORT_SUSPENDED 0xfe
  48337. +#define USB_PORT_POWERED 0xfd
  48338. +#define USB_PORT_DISABLED 0xfc
  48339. +};
  48340. +
  48341. +struct usb_ctl_report {
  48342. + int ucr_report;
  48343. + u_char ucr_data[1024]; /* filled data size will vary */
  48344. +};
  48345. +
  48346. +struct usb_device_stats {
  48347. + u_long uds_requests[4]; /* indexed by transfer type UE_* */
  48348. +};
  48349. +
  48350. +#define WUSB_MIN_IE 0x80
  48351. +#define WUSB_WCTA_IE 0x80
  48352. +#define WUSB_WCONNECTACK_IE 0x81
  48353. +#define WUSB_WHOSTINFO_IE 0x82
  48354. +#define WUHI_GET_CA(_bmAttributes_) ((_bmAttributes_) & 0x3)
  48355. +#define WUHI_CA_RECONN 0x00
  48356. +#define WUHI_CA_LIMITED 0x01
  48357. +#define WUHI_CA_ALL 0x03
  48358. +#define WUHI_GET_MLSI(_bmAttributes_) (((_bmAttributes_) & 0x38) >> 3)
  48359. +#define WUSB_WCHCHANGEANNOUNCE_IE 0x83
  48360. +#define WUSB_WDEV_DISCONNECT_IE 0x84
  48361. +#define WUSB_WHOST_DISCONNECT_IE 0x85
  48362. +#define WUSB_WRELEASE_CHANNEL_IE 0x86
  48363. +#define WUSB_WWORK_IE 0x87
  48364. +#define WUSB_WCHANNEL_STOP_IE 0x88
  48365. +#define WUSB_WDEV_KEEPALIVE_IE 0x89
  48366. +#define WUSB_WISOCH_DISCARD_IE 0x8A
  48367. +#define WUSB_WRESETDEVICE_IE 0x8B
  48368. +#define WUSB_WXMIT_PACKET_ADJUST_IE 0x8C
  48369. +#define WUSB_MAX_IE 0x8C
  48370. +
  48371. +/* Device Notification Types */
  48372. +
  48373. +#define WUSB_DN_MIN 0x01
  48374. +#define WUSB_DN_CONNECT 0x01
  48375. +# define WUSB_DA_OLDCONN 0x00
  48376. +# define WUSB_DA_NEWCONN 0x01
  48377. +# define WUSB_DA_SELF_BEACON 0x02
  48378. +# define WUSB_DA_DIR_BEACON 0x04
  48379. +# define WUSB_DA_NO_BEACON 0x06
  48380. +#define WUSB_DN_DISCONNECT 0x02
  48381. +#define WUSB_DN_EPRDY 0x03
  48382. +#define WUSB_DN_MASAVAILCHANGED 0x04
  48383. +#define WUSB_DN_REMOTEWAKEUP 0x05
  48384. +#define WUSB_DN_SLEEP 0x06
  48385. +#define WUSB_DN_ALIVE 0x07
  48386. +#define WUSB_DN_MAX 0x07
  48387. +
  48388. +#ifdef _MSC_VER
  48389. +#include <pshpack1.h>
  48390. +#endif
  48391. +
  48392. +/* WUSB Handshake Data. Used during the SET/GET HANDSHAKE requests */
  48393. +typedef struct wusb_hndshk_data {
  48394. + uByte bMessageNumber;
  48395. + uByte bStatus;
  48396. + uByte tTKID[3];
  48397. + uByte bReserved;
  48398. + uByte CDID[16];
  48399. + uByte Nonce[16];
  48400. + uByte MIC[8];
  48401. +} UPACKED wusb_hndshk_data_t;
  48402. +#define WUSB_HANDSHAKE_LEN_FOR_MIC 38
  48403. +
  48404. +/* WUSB Connection Context */
  48405. +typedef struct wusb_conn_context {
  48406. + uByte CHID [16];
  48407. + uByte CDID [16];
  48408. + uByte CK [16];
  48409. +} UPACKED wusb_conn_context_t;
  48410. +
  48411. +/* WUSB Security Descriptor */
  48412. +typedef struct wusb_security_desc {
  48413. + uByte bLength;
  48414. + uByte bDescriptorType;
  48415. + uWord wTotalLength;
  48416. + uByte bNumEncryptionTypes;
  48417. +} UPACKED wusb_security_desc_t;
  48418. +
  48419. +/* WUSB Encryption Type Descriptor */
  48420. +typedef struct wusb_encrypt_type_desc {
  48421. + uByte bLength;
  48422. + uByte bDescriptorType;
  48423. +
  48424. + uByte bEncryptionType;
  48425. +#define WUETD_UNSECURE 0
  48426. +#define WUETD_WIRED 1
  48427. +#define WUETD_CCM_1 2
  48428. +#define WUETD_RSA_1 3
  48429. +
  48430. + uByte bEncryptionValue;
  48431. + uByte bAuthKeyIndex;
  48432. +} UPACKED wusb_encrypt_type_desc_t;
  48433. +
  48434. +/* WUSB Key Descriptor */
  48435. +typedef struct wusb_key_desc {
  48436. + uByte bLength;
  48437. + uByte bDescriptorType;
  48438. + uByte tTKID[3];
  48439. + uByte bReserved;
  48440. + uByte KeyData[1]; /* variable length */
  48441. +} UPACKED wusb_key_desc_t;
  48442. +
  48443. +/* WUSB BOS Descriptor (Binary device Object Store) */
  48444. +typedef struct wusb_bos_desc {
  48445. + uByte bLength;
  48446. + uByte bDescriptorType;
  48447. + uWord wTotalLength;
  48448. + uByte bNumDeviceCaps;
  48449. +} UPACKED wusb_bos_desc_t;
  48450. +
  48451. +#define USB_DEVICE_CAPABILITY_20_EXTENSION 0x02
  48452. +typedef struct usb_dev_cap_20_ext_desc {
  48453. + uByte bLength;
  48454. + uByte bDescriptorType;
  48455. + uByte bDevCapabilityType;
  48456. +#define USB_20_EXT_LPM 0x02
  48457. + uDWord bmAttributes;
  48458. +} UPACKED usb_dev_cap_20_ext_desc_t;
  48459. +
  48460. +#define USB_DEVICE_CAPABILITY_SS_USB 0x03
  48461. +typedef struct usb_dev_cap_ss_usb {
  48462. + uByte bLength;
  48463. + uByte bDescriptorType;
  48464. + uByte bDevCapabilityType;
  48465. +#define USB_DC_SS_USB_LTM_CAPABLE 0x02
  48466. + uByte bmAttributes;
  48467. +#define USB_DC_SS_USB_SPEED_SUPPORT_LOW 0x01
  48468. +#define USB_DC_SS_USB_SPEED_SUPPORT_FULL 0x02
  48469. +#define USB_DC_SS_USB_SPEED_SUPPORT_HIGH 0x04
  48470. +#define USB_DC_SS_USB_SPEED_SUPPORT_SS 0x08
  48471. + uWord wSpeedsSupported;
  48472. + uByte bFunctionalitySupport;
  48473. + uByte bU1DevExitLat;
  48474. + uWord wU2DevExitLat;
  48475. +} UPACKED usb_dev_cap_ss_usb_t;
  48476. +
  48477. +#define USB_DEVICE_CAPABILITY_CONTAINER_ID 0x04
  48478. +typedef struct usb_dev_cap_container_id {
  48479. + uByte bLength;
  48480. + uByte bDescriptorType;
  48481. + uByte bDevCapabilityType;
  48482. + uByte bReserved;
  48483. + uByte containerID[16];
  48484. +} UPACKED usb_dev_cap_container_id_t;
  48485. +
  48486. +/* Device Capability Type Codes */
  48487. +#define WUSB_DEVICE_CAPABILITY_WIRELESS_USB 0x01
  48488. +
  48489. +/* Device Capability Descriptor */
  48490. +typedef struct wusb_dev_cap_desc {
  48491. + uByte bLength;
  48492. + uByte bDescriptorType;
  48493. + uByte bDevCapabilityType;
  48494. + uByte caps[1]; /* Variable length */
  48495. +} UPACKED wusb_dev_cap_desc_t;
  48496. +
  48497. +/* Device Capability Descriptor */
  48498. +typedef struct wusb_dev_cap_uwb_desc {
  48499. + uByte bLength;
  48500. + uByte bDescriptorType;
  48501. + uByte bDevCapabilityType;
  48502. + uByte bmAttributes;
  48503. + uWord wPHYRates; /* Bitmap */
  48504. + uByte bmTFITXPowerInfo;
  48505. + uByte bmFFITXPowerInfo;
  48506. + uWord bmBandGroup;
  48507. + uByte bReserved;
  48508. +} UPACKED wusb_dev_cap_uwb_desc_t;
  48509. +
  48510. +/* Wireless USB Endpoint Companion Descriptor */
  48511. +typedef struct wusb_endpoint_companion_desc {
  48512. + uByte bLength;
  48513. + uByte bDescriptorType;
  48514. + uByte bMaxBurst;
  48515. + uByte bMaxSequence;
  48516. + uWord wMaxStreamDelay;
  48517. + uWord wOverTheAirPacketSize;
  48518. + uByte bOverTheAirInterval;
  48519. + uByte bmCompAttributes;
  48520. +} UPACKED wusb_endpoint_companion_desc_t;
  48521. +
  48522. +/* Wireless USB Numeric Association M1 Data Structure */
  48523. +typedef struct wusb_m1_data {
  48524. + uByte version;
  48525. + uWord langId;
  48526. + uByte deviceFriendlyNameLength;
  48527. + uByte sha_256_m3[32];
  48528. + uByte deviceFriendlyName[256];
  48529. +} UPACKED wusb_m1_data_t;
  48530. +
  48531. +typedef struct wusb_m2_data {
  48532. + uByte version;
  48533. + uWord langId;
  48534. + uByte hostFriendlyNameLength;
  48535. + uByte pkh[384];
  48536. + uByte hostFriendlyName[256];
  48537. +} UPACKED wusb_m2_data_t;
  48538. +
  48539. +typedef struct wusb_m3_data {
  48540. + uByte pkd[384];
  48541. + uByte nd;
  48542. +} UPACKED wusb_m3_data_t;
  48543. +
  48544. +typedef struct wusb_m4_data {
  48545. + uDWord _attributeTypeIdAndLength_1;
  48546. + uWord associationTypeId;
  48547. +
  48548. + uDWord _attributeTypeIdAndLength_2;
  48549. + uWord associationSubTypeId;
  48550. +
  48551. + uDWord _attributeTypeIdAndLength_3;
  48552. + uDWord length;
  48553. +
  48554. + uDWord _attributeTypeIdAndLength_4;
  48555. + uDWord associationStatus;
  48556. +
  48557. + uDWord _attributeTypeIdAndLength_5;
  48558. + uByte chid[16];
  48559. +
  48560. + uDWord _attributeTypeIdAndLength_6;
  48561. + uByte cdid[16];
  48562. +
  48563. + uDWord _attributeTypeIdAndLength_7;
  48564. + uByte bandGroups[2];
  48565. +} UPACKED wusb_m4_data_t;
  48566. +
  48567. +#ifdef _MSC_VER
  48568. +#include <poppack.h>
  48569. +#endif
  48570. +
  48571. +#ifdef __cplusplus
  48572. +}
  48573. +#endif
  48574. +
  48575. +#endif /* _USB_H_ */
  48576. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/doc/doxygen.cfg linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg
  48577. --- linux-3.15/drivers/usb/host/dwc_otg/doc/doxygen.cfg 1970-01-01 01:00:00.000000000 +0100
  48578. +++ linux-rpi/drivers/usb/host/dwc_otg/doc/doxygen.cfg 2014-06-11 21:03:43.000000000 +0200
  48579. @@ -0,0 +1,224 @@
  48580. +# Doxyfile 1.3.9.1
  48581. +
  48582. +#---------------------------------------------------------------------------
  48583. +# Project related configuration options
  48584. +#---------------------------------------------------------------------------
  48585. +PROJECT_NAME = "DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver"
  48586. +PROJECT_NUMBER = v3.00a
  48587. +OUTPUT_DIRECTORY = ./doc/
  48588. +CREATE_SUBDIRS = NO
  48589. +OUTPUT_LANGUAGE = English
  48590. +BRIEF_MEMBER_DESC = YES
  48591. +REPEAT_BRIEF = YES
  48592. +ABBREVIATE_BRIEF = "The $name class" \
  48593. + "The $name widget" \
  48594. + "The $name file" \
  48595. + is \
  48596. + provides \
  48597. + specifies \
  48598. + contains \
  48599. + represents \
  48600. + a \
  48601. + an \
  48602. + the
  48603. +ALWAYS_DETAILED_SEC = NO
  48604. +INLINE_INHERITED_MEMB = NO
  48605. +FULL_PATH_NAMES = NO
  48606. +STRIP_FROM_PATH =
  48607. +STRIP_FROM_INC_PATH =
  48608. +SHORT_NAMES = NO
  48609. +JAVADOC_AUTOBRIEF = YES
  48610. +MULTILINE_CPP_IS_BRIEF = NO
  48611. +INHERIT_DOCS = YES
  48612. +DISTRIBUTE_GROUP_DOC = NO
  48613. +TAB_SIZE = 8
  48614. +ALIASES =
  48615. +OPTIMIZE_OUTPUT_FOR_C = YES
  48616. +OPTIMIZE_OUTPUT_JAVA = NO
  48617. +SUBGROUPING = YES
  48618. +#---------------------------------------------------------------------------
  48619. +# Build related configuration options
  48620. +#---------------------------------------------------------------------------
  48621. +EXTRACT_ALL = NO
  48622. +EXTRACT_PRIVATE = YES
  48623. +EXTRACT_STATIC = YES
  48624. +EXTRACT_LOCAL_CLASSES = YES
  48625. +EXTRACT_LOCAL_METHODS = NO
  48626. +HIDE_UNDOC_MEMBERS = NO
  48627. +HIDE_UNDOC_CLASSES = NO
  48628. +HIDE_FRIEND_COMPOUNDS = NO
  48629. +HIDE_IN_BODY_DOCS = NO
  48630. +INTERNAL_DOCS = NO
  48631. +CASE_SENSE_NAMES = NO
  48632. +HIDE_SCOPE_NAMES = NO
  48633. +SHOW_INCLUDE_FILES = YES
  48634. +INLINE_INFO = YES
  48635. +SORT_MEMBER_DOCS = NO
  48636. +SORT_BRIEF_DOCS = NO
  48637. +SORT_BY_SCOPE_NAME = NO
  48638. +GENERATE_TODOLIST = YES
  48639. +GENERATE_TESTLIST = YES
  48640. +GENERATE_BUGLIST = YES
  48641. +GENERATE_DEPRECATEDLIST= YES
  48642. +ENABLED_SECTIONS =
  48643. +MAX_INITIALIZER_LINES = 30
  48644. +SHOW_USED_FILES = YES
  48645. +SHOW_DIRECTORIES = YES
  48646. +#---------------------------------------------------------------------------
  48647. +# configuration options related to warning and progress messages
  48648. +#---------------------------------------------------------------------------
  48649. +QUIET = YES
  48650. +WARNINGS = YES
  48651. +WARN_IF_UNDOCUMENTED = NO
  48652. +WARN_IF_DOC_ERROR = YES
  48653. +WARN_FORMAT = "$file:$line: $text"
  48654. +WARN_LOGFILE =
  48655. +#---------------------------------------------------------------------------
  48656. +# configuration options related to the input files
  48657. +#---------------------------------------------------------------------------
  48658. +INPUT = .
  48659. +FILE_PATTERNS = *.c \
  48660. + *.h \
  48661. + ./linux/*.c \
  48662. + ./linux/*.h
  48663. +RECURSIVE = NO
  48664. +EXCLUDE = ./test/ \
  48665. + ./dwc_otg/.AppleDouble/
  48666. +EXCLUDE_SYMLINKS = YES
  48667. +EXCLUDE_PATTERNS = *.mod.*
  48668. +EXAMPLE_PATH =
  48669. +EXAMPLE_PATTERNS = *
  48670. +EXAMPLE_RECURSIVE = NO
  48671. +IMAGE_PATH =
  48672. +INPUT_FILTER =
  48673. +FILTER_PATTERNS =
  48674. +FILTER_SOURCE_FILES = NO
  48675. +#---------------------------------------------------------------------------
  48676. +# configuration options related to source browsing
  48677. +#---------------------------------------------------------------------------
  48678. +SOURCE_BROWSER = YES
  48679. +INLINE_SOURCES = NO
  48680. +STRIP_CODE_COMMENTS = YES
  48681. +REFERENCED_BY_RELATION = NO
  48682. +REFERENCES_RELATION = NO
  48683. +VERBATIM_HEADERS = NO
  48684. +#---------------------------------------------------------------------------
  48685. +# configuration options related to the alphabetical class index
  48686. +#---------------------------------------------------------------------------
  48687. +ALPHABETICAL_INDEX = NO
  48688. +COLS_IN_ALPHA_INDEX = 5
  48689. +IGNORE_PREFIX =
  48690. +#---------------------------------------------------------------------------
  48691. +# configuration options related to the HTML output
  48692. +#---------------------------------------------------------------------------
  48693. +GENERATE_HTML = YES
  48694. +HTML_OUTPUT = html
  48695. +HTML_FILE_EXTENSION = .html
  48696. +HTML_HEADER =
  48697. +HTML_FOOTER =
  48698. +HTML_STYLESHEET =
  48699. +HTML_ALIGN_MEMBERS = YES
  48700. +GENERATE_HTMLHELP = NO
  48701. +CHM_FILE =
  48702. +HHC_LOCATION =
  48703. +GENERATE_CHI = NO
  48704. +BINARY_TOC = NO
  48705. +TOC_EXPAND = NO
  48706. +DISABLE_INDEX = NO
  48707. +ENUM_VALUES_PER_LINE = 4
  48708. +GENERATE_TREEVIEW = YES
  48709. +TREEVIEW_WIDTH = 250
  48710. +#---------------------------------------------------------------------------
  48711. +# configuration options related to the LaTeX output
  48712. +#---------------------------------------------------------------------------
  48713. +GENERATE_LATEX = NO
  48714. +LATEX_OUTPUT = latex
  48715. +LATEX_CMD_NAME = latex
  48716. +MAKEINDEX_CMD_NAME = makeindex
  48717. +COMPACT_LATEX = NO
  48718. +PAPER_TYPE = a4wide
  48719. +EXTRA_PACKAGES =
  48720. +LATEX_HEADER =
  48721. +PDF_HYPERLINKS = NO
  48722. +USE_PDFLATEX = NO
  48723. +LATEX_BATCHMODE = NO
  48724. +LATEX_HIDE_INDICES = NO
  48725. +#---------------------------------------------------------------------------
  48726. +# configuration options related to the RTF output
  48727. +#---------------------------------------------------------------------------
  48728. +GENERATE_RTF = NO
  48729. +RTF_OUTPUT = rtf
  48730. +COMPACT_RTF = NO
  48731. +RTF_HYPERLINKS = NO
  48732. +RTF_STYLESHEET_FILE =
  48733. +RTF_EXTENSIONS_FILE =
  48734. +#---------------------------------------------------------------------------
  48735. +# configuration options related to the man page output
  48736. +#---------------------------------------------------------------------------
  48737. +GENERATE_MAN = NO
  48738. +MAN_OUTPUT = man
  48739. +MAN_EXTENSION = .3
  48740. +MAN_LINKS = NO
  48741. +#---------------------------------------------------------------------------
  48742. +# configuration options related to the XML output
  48743. +#---------------------------------------------------------------------------
  48744. +GENERATE_XML = NO
  48745. +XML_OUTPUT = xml
  48746. +XML_SCHEMA =
  48747. +XML_DTD =
  48748. +XML_PROGRAMLISTING = YES
  48749. +#---------------------------------------------------------------------------
  48750. +# configuration options for the AutoGen Definitions output
  48751. +#---------------------------------------------------------------------------
  48752. +GENERATE_AUTOGEN_DEF = NO
  48753. +#---------------------------------------------------------------------------
  48754. +# configuration options related to the Perl module output
  48755. +#---------------------------------------------------------------------------
  48756. +GENERATE_PERLMOD = NO
  48757. +PERLMOD_LATEX = NO
  48758. +PERLMOD_PRETTY = YES
  48759. +PERLMOD_MAKEVAR_PREFIX =
  48760. +#---------------------------------------------------------------------------
  48761. +# Configuration options related to the preprocessor
  48762. +#---------------------------------------------------------------------------
  48763. +ENABLE_PREPROCESSING = YES
  48764. +MACRO_EXPANSION = YES
  48765. +EXPAND_ONLY_PREDEF = YES
  48766. +SEARCH_INCLUDES = YES
  48767. +INCLUDE_PATH =
  48768. +INCLUDE_FILE_PATTERNS =
  48769. +PREDEFINED = DEVICE_ATTR DWC_EN_ISOC
  48770. +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
  48771. +SKIP_FUNCTION_MACROS = NO
  48772. +#---------------------------------------------------------------------------
  48773. +# Configuration::additions related to external references
  48774. +#---------------------------------------------------------------------------
  48775. +TAGFILES =
  48776. +GENERATE_TAGFILE =
  48777. +ALLEXTERNALS = NO
  48778. +EXTERNAL_GROUPS = YES
  48779. +PERL_PATH = /usr/bin/perl
  48780. +#---------------------------------------------------------------------------
  48781. +# Configuration options related to the dot tool
  48782. +#---------------------------------------------------------------------------
  48783. +CLASS_DIAGRAMS = YES
  48784. +HIDE_UNDOC_RELATIONS = YES
  48785. +HAVE_DOT = NO
  48786. +CLASS_GRAPH = YES
  48787. +COLLABORATION_GRAPH = YES
  48788. +UML_LOOK = NO
  48789. +TEMPLATE_RELATIONS = NO
  48790. +INCLUDE_GRAPH = YES
  48791. +INCLUDED_BY_GRAPH = YES
  48792. +CALL_GRAPH = NO
  48793. +GRAPHICAL_HIERARCHY = YES
  48794. +DOT_IMAGE_FORMAT = png
  48795. +DOT_PATH =
  48796. +DOTFILE_DIRS =
  48797. +MAX_DOT_GRAPH_DEPTH = 1000
  48798. +GENERATE_LEGEND = YES
  48799. +DOT_CLEANUP = YES
  48800. +#---------------------------------------------------------------------------
  48801. +# Configuration::additions related to the search engine
  48802. +#---------------------------------------------------------------------------
  48803. +SEARCHENGINE = NO
  48804. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dummy_audio.c linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c
  48805. --- linux-3.15/drivers/usb/host/dwc_otg/dummy_audio.c 1970-01-01 01:00:00.000000000 +0100
  48806. +++ linux-rpi/drivers/usb/host/dwc_otg/dummy_audio.c 2014-06-11 21:03:43.000000000 +0200
  48807. @@ -0,0 +1,1575 @@
  48808. +/*
  48809. + * zero.c -- Gadget Zero, for USB development
  48810. + *
  48811. + * Copyright (C) 2003-2004 David Brownell
  48812. + * All rights reserved.
  48813. + *
  48814. + * Redistribution and use in source and binary forms, with or without
  48815. + * modification, are permitted provided that the following conditions
  48816. + * are met:
  48817. + * 1. Redistributions of source code must retain the above copyright
  48818. + * notice, this list of conditions, and the following disclaimer,
  48819. + * without modification.
  48820. + * 2. Redistributions in binary form must reproduce the above copyright
  48821. + * notice, this list of conditions and the following disclaimer in the
  48822. + * documentation and/or other materials provided with the distribution.
  48823. + * 3. The names of the above-listed copyright holders may not be used
  48824. + * to endorse or promote products derived from this software without
  48825. + * specific prior written permission.
  48826. + *
  48827. + * ALTERNATIVELY, this software may be distributed under the terms of the
  48828. + * GNU General Public License ("GPL") as published by the Free Software
  48829. + * Foundation, either version 2 of that License or (at your option) any
  48830. + * later version.
  48831. + *
  48832. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  48833. + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  48834. + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  48835. + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  48836. + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  48837. + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  48838. + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  48839. + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  48840. + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  48841. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48842. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  48843. + */
  48844. +
  48845. +
  48846. +/*
  48847. + * Gadget Zero only needs two bulk endpoints, and is an example of how you
  48848. + * can write a hardware-agnostic gadget driver running inside a USB device.
  48849. + *
  48850. + * Hardware details are visible (see CONFIG_USB_ZERO_* below) but don't
  48851. + * affect most of the driver.
  48852. + *
  48853. + * Use it with the Linux host/master side "usbtest" driver to get a basic
  48854. + * functional test of your device-side usb stack, or with "usb-skeleton".
  48855. + *
  48856. + * It supports two similar configurations. One sinks whatever the usb host
  48857. + * writes, and in return sources zeroes. The other loops whatever the host
  48858. + * writes back, so the host can read it. Module options include:
  48859. + *
  48860. + * buflen=N default N=4096, buffer size used
  48861. + * qlen=N default N=32, how many buffers in the loopback queue
  48862. + * loopdefault default false, list loopback config first
  48863. + *
  48864. + * Many drivers will only have one configuration, letting them be much
  48865. + * simpler if they also don't support high speed operation (like this
  48866. + * driver does).
  48867. + */
  48868. +
  48869. +#include <linux/config.h>
  48870. +#include <linux/module.h>
  48871. +#include <linux/kernel.h>
  48872. +#include <linux/delay.h>
  48873. +#include <linux/ioport.h>
  48874. +#include <linux/sched.h>
  48875. +#include <linux/slab.h>
  48876. +#include <linux/smp_lock.h>
  48877. +#include <linux/errno.h>
  48878. +#include <linux/init.h>
  48879. +#include <linux/timer.h>
  48880. +#include <linux/list.h>
  48881. +#include <linux/interrupt.h>
  48882. +#include <linux/uts.h>
  48883. +#include <linux/version.h>
  48884. +#include <linux/device.h>
  48885. +#include <linux/moduleparam.h>
  48886. +#include <linux/proc_fs.h>
  48887. +
  48888. +#include <asm/byteorder.h>
  48889. +#include <asm/io.h>
  48890. +#include <asm/irq.h>
  48891. +#include <asm/system.h>
  48892. +#include <asm/unaligned.h>
  48893. +
  48894. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  48895. +# include <linux/usb/ch9.h>
  48896. +#else
  48897. +# include <linux/usb_ch9.h>
  48898. +#endif
  48899. +
  48900. +#include <linux/usb_gadget.h>
  48901. +
  48902. +
  48903. +/*-------------------------------------------------------------------------*/
  48904. +/*-------------------------------------------------------------------------*/
  48905. +
  48906. +
  48907. +static int utf8_to_utf16le(const char *s, u16 *cp, unsigned len)
  48908. +{
  48909. + int count = 0;
  48910. + u8 c;
  48911. + u16 uchar;
  48912. +
  48913. + /* this insists on correct encodings, though not minimal ones.
  48914. + * BUT it currently rejects legit 4-byte UTF-8 code points,
  48915. + * which need surrogate pairs. (Unicode 3.1 can use them.)
  48916. + */
  48917. + while (len != 0 && (c = (u8) *s++) != 0) {
  48918. + if (unlikely(c & 0x80)) {
  48919. + // 2-byte sequence:
  48920. + // 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
  48921. + if ((c & 0xe0) == 0xc0) {
  48922. + uchar = (c & 0x1f) << 6;
  48923. +
  48924. + c = (u8) *s++;
  48925. + if ((c & 0xc0) != 0xc0)
  48926. + goto fail;
  48927. + c &= 0x3f;
  48928. + uchar |= c;
  48929. +
  48930. + // 3-byte sequence (most CJKV characters):
  48931. + // zzzzyyyyyyxxxxxx = 1110zzzz 10yyyyyy 10xxxxxx
  48932. + } else if ((c & 0xf0) == 0xe0) {
  48933. + uchar = (c & 0x0f) << 12;
  48934. +
  48935. + c = (u8) *s++;
  48936. + if ((c & 0xc0) != 0xc0)
  48937. + goto fail;
  48938. + c &= 0x3f;
  48939. + uchar |= c << 6;
  48940. +
  48941. + c = (u8) *s++;
  48942. + if ((c & 0xc0) != 0xc0)
  48943. + goto fail;
  48944. + c &= 0x3f;
  48945. + uchar |= c;
  48946. +
  48947. + /* no bogus surrogates */
  48948. + if (0xd800 <= uchar && uchar <= 0xdfff)
  48949. + goto fail;
  48950. +
  48951. + // 4-byte sequence (surrogate pairs, currently rare):
  48952. + // 11101110wwwwzzzzyy + 110111yyyyxxxxxx
  48953. + // = 11110uuu 10uuzzzz 10yyyyyy 10xxxxxx
  48954. + // (uuuuu = wwww + 1)
  48955. + // FIXME accept the surrogate code points (only)
  48956. +
  48957. + } else
  48958. + goto fail;
  48959. + } else
  48960. + uchar = c;
  48961. + put_unaligned (cpu_to_le16 (uchar), cp++);
  48962. + count++;
  48963. + len--;
  48964. + }
  48965. + return count;
  48966. +fail:
  48967. + return -1;
  48968. +}
  48969. +
  48970. +
  48971. +/**
  48972. + * usb_gadget_get_string - fill out a string descriptor
  48973. + * @table: of c strings encoded using UTF-8
  48974. + * @id: string id, from low byte of wValue in get string descriptor
  48975. + * @buf: at least 256 bytes
  48976. + *
  48977. + * Finds the UTF-8 string matching the ID, and converts it into a
  48978. + * string descriptor in utf16-le.
  48979. + * Returns length of descriptor (always even) or negative errno
  48980. + *
  48981. + * If your driver needs stings in multiple languages, you'll probably
  48982. + * "switch (wIndex) { ... }" in your ep0 string descriptor logic,
  48983. + * using this routine after choosing which set of UTF-8 strings to use.
  48984. + * Note that US-ASCII is a strict subset of UTF-8; any string bytes with
  48985. + * the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1
  48986. + * characters (which are also widely used in C strings).
  48987. + */
  48988. +int
  48989. +usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
  48990. +{
  48991. + struct usb_string *s;
  48992. + int len;
  48993. +
  48994. + /* descriptor 0 has the language id */
  48995. + if (id == 0) {
  48996. + buf [0] = 4;
  48997. + buf [1] = USB_DT_STRING;
  48998. + buf [2] = (u8) table->language;
  48999. + buf [3] = (u8) (table->language >> 8);
  49000. + return 4;
  49001. + }
  49002. + for (s = table->strings; s && s->s; s++)
  49003. + if (s->id == id)
  49004. + break;
  49005. +
  49006. + /* unrecognized: stall. */
  49007. + if (!s || !s->s)
  49008. + return -EINVAL;
  49009. +
  49010. + /* string descriptors have length, tag, then UTF16-LE text */
  49011. + len = min ((size_t) 126, strlen (s->s));
  49012. + memset (buf + 2, 0, 2 * len); /* zero all the bytes */
  49013. + len = utf8_to_utf16le(s->s, (u16 *)&buf[2], len);
  49014. + if (len < 0)
  49015. + return -EINVAL;
  49016. + buf [0] = (len + 1) * 2;
  49017. + buf [1] = USB_DT_STRING;
  49018. + return buf [0];
  49019. +}
  49020. +
  49021. +
  49022. +/*-------------------------------------------------------------------------*/
  49023. +/*-------------------------------------------------------------------------*/
  49024. +
  49025. +
  49026. +/**
  49027. + * usb_descriptor_fillbuf - fill buffer with descriptors
  49028. + * @buf: Buffer to be filled
  49029. + * @buflen: Size of buf
  49030. + * @src: Array of descriptor pointers, terminated by null pointer.
  49031. + *
  49032. + * Copies descriptors into the buffer, returning the length or a
  49033. + * negative error code if they can't all be copied. Useful when
  49034. + * assembling descriptors for an associated set of interfaces used
  49035. + * as part of configuring a composite device; or in other cases where
  49036. + * sets of descriptors need to be marshaled.
  49037. + */
  49038. +int
  49039. +usb_descriptor_fillbuf(void *buf, unsigned buflen,
  49040. + const struct usb_descriptor_header **src)
  49041. +{
  49042. + u8 *dest = buf;
  49043. +
  49044. + if (!src)
  49045. + return -EINVAL;
  49046. +
  49047. + /* fill buffer from src[] until null descriptor ptr */
  49048. + for (; 0 != *src; src++) {
  49049. + unsigned len = (*src)->bLength;
  49050. +
  49051. + if (len > buflen)
  49052. + return -EINVAL;
  49053. + memcpy(dest, *src, len);
  49054. + buflen -= len;
  49055. + dest += len;
  49056. + }
  49057. + return dest - (u8 *)buf;
  49058. +}
  49059. +
  49060. +
  49061. +/**
  49062. + * usb_gadget_config_buf - builts a complete configuration descriptor
  49063. + * @config: Header for the descriptor, including characteristics such
  49064. + * as power requirements and number of interfaces.
  49065. + * @desc: Null-terminated vector of pointers to the descriptors (interface,
  49066. + * endpoint, etc) defining all functions in this device configuration.
  49067. + * @buf: Buffer for the resulting configuration descriptor.
  49068. + * @length: Length of buffer. If this is not big enough to hold the
  49069. + * entire configuration descriptor, an error code will be returned.
  49070. + *
  49071. + * This copies descriptors into the response buffer, building a descriptor
  49072. + * for that configuration. It returns the buffer length or a negative
  49073. + * status code. The config.wTotalLength field is set to match the length
  49074. + * of the result, but other descriptor fields (including power usage and
  49075. + * interface count) must be set by the caller.
  49076. + *
  49077. + * Gadget drivers could use this when constructing a config descriptor
  49078. + * in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the
  49079. + * resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.
  49080. + */
  49081. +int usb_gadget_config_buf(
  49082. + const struct usb_config_descriptor *config,
  49083. + void *buf,
  49084. + unsigned length,
  49085. + const struct usb_descriptor_header **desc
  49086. +)
  49087. +{
  49088. + struct usb_config_descriptor *cp = buf;
  49089. + int len;
  49090. +
  49091. + /* config descriptor first */
  49092. + if (length < USB_DT_CONFIG_SIZE || !desc)
  49093. + return -EINVAL;
  49094. + *cp = *config;
  49095. +
  49096. + /* then interface/endpoint/class/vendor/... */
  49097. + len = usb_descriptor_fillbuf(USB_DT_CONFIG_SIZE + (u8*)buf,
  49098. + length - USB_DT_CONFIG_SIZE, desc);
  49099. + if (len < 0)
  49100. + return len;
  49101. + len += USB_DT_CONFIG_SIZE;
  49102. + if (len > 0xffff)
  49103. + return -EINVAL;
  49104. +
  49105. + /* patch up the config descriptor */
  49106. + cp->bLength = USB_DT_CONFIG_SIZE;
  49107. + cp->bDescriptorType = USB_DT_CONFIG;
  49108. + cp->wTotalLength = cpu_to_le16(len);
  49109. + cp->bmAttributes |= USB_CONFIG_ATT_ONE;
  49110. + return len;
  49111. +}
  49112. +
  49113. +/*-------------------------------------------------------------------------*/
  49114. +/*-------------------------------------------------------------------------*/
  49115. +
  49116. +
  49117. +#define RBUF_LEN (1024*1024)
  49118. +static int rbuf_start;
  49119. +static int rbuf_len;
  49120. +static __u8 rbuf[RBUF_LEN];
  49121. +
  49122. +/*-------------------------------------------------------------------------*/
  49123. +
  49124. +#define DRIVER_VERSION "St Patrick's Day 2004"
  49125. +
  49126. +static const char shortname [] = "zero";
  49127. +static const char longname [] = "YAMAHA YST-MS35D USB Speaker ";
  49128. +
  49129. +static const char source_sink [] = "source and sink data";
  49130. +static const char loopback [] = "loop input to output";
  49131. +
  49132. +/*-------------------------------------------------------------------------*/
  49133. +
  49134. +/*
  49135. + * driver assumes self-powered hardware, and
  49136. + * has no way for users to trigger remote wakeup.
  49137. + *
  49138. + * this version autoconfigures as much as possible,
  49139. + * which is reasonable for most "bulk-only" drivers.
  49140. + */
  49141. +static const char *EP_IN_NAME; /* source */
  49142. +static const char *EP_OUT_NAME; /* sink */
  49143. +
  49144. +/*-------------------------------------------------------------------------*/
  49145. +
  49146. +/* big enough to hold our biggest descriptor */
  49147. +#define USB_BUFSIZ 512
  49148. +
  49149. +struct zero_dev {
  49150. + spinlock_t lock;
  49151. + struct usb_gadget *gadget;
  49152. + struct usb_request *req; /* for control responses */
  49153. +
  49154. + /* when configured, we have one of two configs:
  49155. + * - source data (in to host) and sink it (out from host)
  49156. + * - or loop it back (out from host back in to host)
  49157. + */
  49158. + u8 config;
  49159. + struct usb_ep *in_ep, *out_ep;
  49160. +
  49161. + /* autoresume timer */
  49162. + struct timer_list resume;
  49163. +};
  49164. +
  49165. +#define xprintk(d,level,fmt,args...) \
  49166. + dev_printk(level , &(d)->gadget->dev , fmt , ## args)
  49167. +
  49168. +#ifdef DEBUG
  49169. +#define DBG(dev,fmt,args...) \
  49170. + xprintk(dev , KERN_DEBUG , fmt , ## args)
  49171. +#else
  49172. +#define DBG(dev,fmt,args...) \
  49173. + do { } while (0)
  49174. +#endif /* DEBUG */
  49175. +
  49176. +#ifdef VERBOSE
  49177. +#define VDBG DBG
  49178. +#else
  49179. +#define VDBG(dev,fmt,args...) \
  49180. + do { } while (0)
  49181. +#endif /* VERBOSE */
  49182. +
  49183. +#define ERROR(dev,fmt,args...) \
  49184. + xprintk(dev , KERN_ERR , fmt , ## args)
  49185. +#define WARN(dev,fmt,args...) \
  49186. + xprintk(dev , KERN_WARNING , fmt , ## args)
  49187. +#define INFO(dev,fmt,args...) \
  49188. + xprintk(dev , KERN_INFO , fmt , ## args)
  49189. +
  49190. +/*-------------------------------------------------------------------------*/
  49191. +
  49192. +static unsigned buflen = 4096;
  49193. +static unsigned qlen = 32;
  49194. +static unsigned pattern = 0;
  49195. +
  49196. +module_param (buflen, uint, S_IRUGO|S_IWUSR);
  49197. +module_param (qlen, uint, S_IRUGO|S_IWUSR);
  49198. +module_param (pattern, uint, S_IRUGO|S_IWUSR);
  49199. +
  49200. +/*
  49201. + * if it's nonzero, autoresume says how many seconds to wait
  49202. + * before trying to wake up the host after suspend.
  49203. + */
  49204. +static unsigned autoresume = 0;
  49205. +module_param (autoresume, uint, 0);
  49206. +
  49207. +/*
  49208. + * Normally the "loopback" configuration is second (index 1) so
  49209. + * it's not the default. Here's where to change that order, to
  49210. + * work better with hosts where config changes are problematic.
  49211. + * Or controllers (like superh) that only support one config.
  49212. + */
  49213. +static int loopdefault = 0;
  49214. +
  49215. +module_param (loopdefault, bool, S_IRUGO|S_IWUSR);
  49216. +
  49217. +/*-------------------------------------------------------------------------*/
  49218. +
  49219. +/* Thanks to NetChip Technologies for donating this product ID.
  49220. + *
  49221. + * DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
  49222. + * Instead: allocate your own, using normal USB-IF procedures.
  49223. + */
  49224. +#ifndef CONFIG_USB_ZERO_HNPTEST
  49225. +#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
  49226. +#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
  49227. +#else
  49228. +#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
  49229. +#define DRIVER_PRODUCT_NUM 0xbadd
  49230. +#endif
  49231. +
  49232. +/*-------------------------------------------------------------------------*/
  49233. +
  49234. +/*
  49235. + * DESCRIPTORS ... most are static, but strings and (full)
  49236. + * configuration descriptors are built on demand.
  49237. + */
  49238. +
  49239. +/*
  49240. +#define STRING_MANUFACTURER 25
  49241. +#define STRING_PRODUCT 42
  49242. +#define STRING_SERIAL 101
  49243. +*/
  49244. +#define STRING_MANUFACTURER 1
  49245. +#define STRING_PRODUCT 2
  49246. +#define STRING_SERIAL 3
  49247. +
  49248. +#define STRING_SOURCE_SINK 250
  49249. +#define STRING_LOOPBACK 251
  49250. +
  49251. +/*
  49252. + * This device advertises two configurations; these numbers work
  49253. + * on a pxa250 as well as more flexible hardware.
  49254. + */
  49255. +#define CONFIG_SOURCE_SINK 3
  49256. +#define CONFIG_LOOPBACK 2
  49257. +
  49258. +/*
  49259. +static struct usb_device_descriptor
  49260. +device_desc = {
  49261. + .bLength = sizeof device_desc,
  49262. + .bDescriptorType = USB_DT_DEVICE,
  49263. +
  49264. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49265. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49266. +
  49267. + .idVendor = __constant_cpu_to_le16 (DRIVER_VENDOR_NUM),
  49268. + .idProduct = __constant_cpu_to_le16 (DRIVER_PRODUCT_NUM),
  49269. + .iManufacturer = STRING_MANUFACTURER,
  49270. + .iProduct = STRING_PRODUCT,
  49271. + .iSerialNumber = STRING_SERIAL,
  49272. + .bNumConfigurations = 2,
  49273. +};
  49274. +*/
  49275. +static struct usb_device_descriptor
  49276. +device_desc = {
  49277. + .bLength = sizeof device_desc,
  49278. + .bDescriptorType = USB_DT_DEVICE,
  49279. + .bcdUSB = __constant_cpu_to_le16 (0x0100),
  49280. + .bDeviceClass = USB_CLASS_PER_INTERFACE,
  49281. + .bDeviceSubClass = 0,
  49282. + .bDeviceProtocol = 0,
  49283. + .bMaxPacketSize0 = 64,
  49284. + .bcdDevice = __constant_cpu_to_le16 (0x0100),
  49285. + .idVendor = __constant_cpu_to_le16 (0x0499),
  49286. + .idProduct = __constant_cpu_to_le16 (0x3002),
  49287. + .iManufacturer = STRING_MANUFACTURER,
  49288. + .iProduct = STRING_PRODUCT,
  49289. + .iSerialNumber = STRING_SERIAL,
  49290. + .bNumConfigurations = 1,
  49291. +};
  49292. +
  49293. +static struct usb_config_descriptor
  49294. +z_config = {
  49295. + .bLength = sizeof z_config,
  49296. + .bDescriptorType = USB_DT_CONFIG,
  49297. +
  49298. + /* compute wTotalLength on the fly */
  49299. + .bNumInterfaces = 2,
  49300. + .bConfigurationValue = 1,
  49301. + .iConfiguration = 0,
  49302. + .bmAttributes = 0x40,
  49303. + .bMaxPower = 0, /* self-powered */
  49304. +};
  49305. +
  49306. +
  49307. +static struct usb_otg_descriptor
  49308. +otg_descriptor = {
  49309. + .bLength = sizeof otg_descriptor,
  49310. + .bDescriptorType = USB_DT_OTG,
  49311. +
  49312. + .bmAttributes = USB_OTG_SRP,
  49313. +};
  49314. +
  49315. +/* one interface in each configuration */
  49316. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49317. +
  49318. +/*
  49319. + * usb 2.0 devices need to expose both high speed and full speed
  49320. + * descriptors, unless they only run at full speed.
  49321. + *
  49322. + * that means alternate endpoint descriptors (bigger packets)
  49323. + * and a "device qualifier" ... plus more construction options
  49324. + * for the config descriptor.
  49325. + */
  49326. +
  49327. +static struct usb_qualifier_descriptor
  49328. +dev_qualifier = {
  49329. + .bLength = sizeof dev_qualifier,
  49330. + .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
  49331. +
  49332. + .bcdUSB = __constant_cpu_to_le16 (0x0200),
  49333. + .bDeviceClass = USB_CLASS_VENDOR_SPEC,
  49334. +
  49335. + .bNumConfigurations = 2,
  49336. +};
  49337. +
  49338. +
  49339. +struct usb_cs_as_general_descriptor {
  49340. + __u8 bLength;
  49341. + __u8 bDescriptorType;
  49342. +
  49343. + __u8 bDescriptorSubType;
  49344. + __u8 bTerminalLink;
  49345. + __u8 bDelay;
  49346. + __u16 wFormatTag;
  49347. +} __attribute__ ((packed));
  49348. +
  49349. +struct usb_cs_as_format_descriptor {
  49350. + __u8 bLength;
  49351. + __u8 bDescriptorType;
  49352. +
  49353. + __u8 bDescriptorSubType;
  49354. + __u8 bFormatType;
  49355. + __u8 bNrChannels;
  49356. + __u8 bSubframeSize;
  49357. + __u8 bBitResolution;
  49358. + __u8 bSamfreqType;
  49359. + __u8 tLowerSamFreq[3];
  49360. + __u8 tUpperSamFreq[3];
  49361. +} __attribute__ ((packed));
  49362. +
  49363. +static const struct usb_interface_descriptor
  49364. +z_audio_control_if_desc = {
  49365. + .bLength = sizeof z_audio_control_if_desc,
  49366. + .bDescriptorType = USB_DT_INTERFACE,
  49367. + .bInterfaceNumber = 0,
  49368. + .bAlternateSetting = 0,
  49369. + .bNumEndpoints = 0,
  49370. + .bInterfaceClass = USB_CLASS_AUDIO,
  49371. + .bInterfaceSubClass = 0x1,
  49372. + .bInterfaceProtocol = 0,
  49373. + .iInterface = 0,
  49374. +};
  49375. +
  49376. +static const struct usb_interface_descriptor
  49377. +z_audio_if_desc = {
  49378. + .bLength = sizeof z_audio_if_desc,
  49379. + .bDescriptorType = USB_DT_INTERFACE,
  49380. + .bInterfaceNumber = 1,
  49381. + .bAlternateSetting = 0,
  49382. + .bNumEndpoints = 0,
  49383. + .bInterfaceClass = USB_CLASS_AUDIO,
  49384. + .bInterfaceSubClass = 0x2,
  49385. + .bInterfaceProtocol = 0,
  49386. + .iInterface = 0,
  49387. +};
  49388. +
  49389. +static const struct usb_interface_descriptor
  49390. +z_audio_if_desc2 = {
  49391. + .bLength = sizeof z_audio_if_desc,
  49392. + .bDescriptorType = USB_DT_INTERFACE,
  49393. + .bInterfaceNumber = 1,
  49394. + .bAlternateSetting = 1,
  49395. + .bNumEndpoints = 1,
  49396. + .bInterfaceClass = USB_CLASS_AUDIO,
  49397. + .bInterfaceSubClass = 0x2,
  49398. + .bInterfaceProtocol = 0,
  49399. + .iInterface = 0,
  49400. +};
  49401. +
  49402. +static const struct usb_cs_as_general_descriptor
  49403. +z_audio_cs_as_if_desc = {
  49404. + .bLength = 7,
  49405. + .bDescriptorType = 0x24,
  49406. +
  49407. + .bDescriptorSubType = 0x01,
  49408. + .bTerminalLink = 0x01,
  49409. + .bDelay = 0x0,
  49410. + .wFormatTag = __constant_cpu_to_le16 (0x0001)
  49411. +};
  49412. +
  49413. +
  49414. +static const struct usb_cs_as_format_descriptor
  49415. +z_audio_cs_as_format_desc = {
  49416. + .bLength = 0xe,
  49417. + .bDescriptorType = 0x24,
  49418. +
  49419. + .bDescriptorSubType = 2,
  49420. + .bFormatType = 1,
  49421. + .bNrChannels = 1,
  49422. + .bSubframeSize = 1,
  49423. + .bBitResolution = 8,
  49424. + .bSamfreqType = 0,
  49425. + .tLowerSamFreq = {0x7e, 0x13, 0x00},
  49426. + .tUpperSamFreq = {0xe2, 0xd6, 0x00},
  49427. +};
  49428. +
  49429. +static const struct usb_endpoint_descriptor
  49430. +z_iso_ep = {
  49431. + .bLength = 0x09,
  49432. + .bDescriptorType = 0x05,
  49433. + .bEndpointAddress = 0x04,
  49434. + .bmAttributes = 0x09,
  49435. + .wMaxPacketSize = 0x0038,
  49436. + .bInterval = 0x01,
  49437. + .bRefresh = 0x00,
  49438. + .bSynchAddress = 0x00,
  49439. +};
  49440. +
  49441. +static char z_iso_ep2[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49442. +
  49443. +// 9 bytes
  49444. +static char z_ac_interface_header_desc[] =
  49445. +{ 0x09, 0x24, 0x01, 0x00, 0x01, 0x2b, 0x00, 0x01, 0x01 };
  49446. +
  49447. +// 12 bytes
  49448. +static char z_0[] = {0x0c, 0x24, 0x02, 0x01, 0x01, 0x01, 0x00, 0x02,
  49449. + 0x03, 0x00, 0x00, 0x00};
  49450. +// 13 bytes
  49451. +static char z_1[] = {0x0d, 0x24, 0x06, 0x02, 0x01, 0x02, 0x15, 0x00,
  49452. + 0x02, 0x00, 0x02, 0x00, 0x00};
  49453. +// 9 bytes
  49454. +static char z_2[] = {0x09, 0x24, 0x03, 0x03, 0x01, 0x03, 0x00, 0x02,
  49455. + 0x00};
  49456. +
  49457. +static char za_0[] = {0x09, 0x04, 0x01, 0x02, 0x01, 0x01, 0x02, 0x00,
  49458. + 0x00};
  49459. +
  49460. +static char za_1[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49461. +
  49462. +static char za_2[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x01, 0x08, 0x00,
  49463. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49464. +
  49465. +static char za_3[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49466. + 0x00};
  49467. +
  49468. +static char za_4[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49469. +
  49470. +static char za_5[] = {0x09, 0x04, 0x01, 0x03, 0x01, 0x01, 0x02, 0x00,
  49471. + 0x00};
  49472. +
  49473. +static char za_6[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49474. +
  49475. +static char za_7[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x02, 0x10, 0x00,
  49476. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49477. +
  49478. +static char za_8[] = {0x09, 0x05, 0x04, 0x09, 0x70, 0x00, 0x01, 0x00,
  49479. + 0x00};
  49480. +
  49481. +static char za_9[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49482. +
  49483. +static char za_10[] = {0x09, 0x04, 0x01, 0x04, 0x01, 0x01, 0x02, 0x00,
  49484. + 0x00};
  49485. +
  49486. +static char za_11[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49487. +
  49488. +static char za_12[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x02, 0x10, 0x00,
  49489. + 0x73, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49490. +
  49491. +static char za_13[] = {0x09, 0x05, 0x04, 0x09, 0xe0, 0x00, 0x01, 0x00,
  49492. + 0x00};
  49493. +
  49494. +static char za_14[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49495. +
  49496. +static char za_15[] = {0x09, 0x04, 0x01, 0x05, 0x01, 0x01, 0x02, 0x00,
  49497. + 0x00};
  49498. +
  49499. +static char za_16[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49500. +
  49501. +static char za_17[] = {0x0e, 0x24, 0x02, 0x01, 0x01, 0x03, 0x14, 0x00,
  49502. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49503. +
  49504. +static char za_18[] = {0x09, 0x05, 0x04, 0x09, 0xa8, 0x00, 0x01, 0x00,
  49505. + 0x00};
  49506. +
  49507. +static char za_19[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49508. +
  49509. +static char za_20[] = {0x09, 0x04, 0x01, 0x06, 0x01, 0x01, 0x02, 0x00,
  49510. + 0x00};
  49511. +
  49512. +static char za_21[] = {0x07, 0x24, 0x01, 0x01, 0x00, 0x01, 0x00};
  49513. +
  49514. +static char za_22[] = {0x0e, 0x24, 0x02, 0x01, 0x02, 0x03, 0x14, 0x00,
  49515. + 0x7e, 0x13, 0x00, 0xe2, 0xd6, 0x00};
  49516. +
  49517. +static char za_23[] = {0x09, 0x05, 0x04, 0x09, 0x50, 0x01, 0x01, 0x00,
  49518. + 0x00};
  49519. +
  49520. +static char za_24[] = {0x07, 0x25, 0x01, 0x00, 0x02, 0x00, 0x02};
  49521. +
  49522. +
  49523. +
  49524. +static const struct usb_descriptor_header *z_function [] = {
  49525. + (struct usb_descriptor_header *) &z_audio_control_if_desc,
  49526. + (struct usb_descriptor_header *) &z_ac_interface_header_desc,
  49527. + (struct usb_descriptor_header *) &z_0,
  49528. + (struct usb_descriptor_header *) &z_1,
  49529. + (struct usb_descriptor_header *) &z_2,
  49530. + (struct usb_descriptor_header *) &z_audio_if_desc,
  49531. + (struct usb_descriptor_header *) &z_audio_if_desc2,
  49532. + (struct usb_descriptor_header *) &z_audio_cs_as_if_desc,
  49533. + (struct usb_descriptor_header *) &z_audio_cs_as_format_desc,
  49534. + (struct usb_descriptor_header *) &z_iso_ep,
  49535. + (struct usb_descriptor_header *) &z_iso_ep2,
  49536. + (struct usb_descriptor_header *) &za_0,
  49537. + (struct usb_descriptor_header *) &za_1,
  49538. + (struct usb_descriptor_header *) &za_2,
  49539. + (struct usb_descriptor_header *) &za_3,
  49540. + (struct usb_descriptor_header *) &za_4,
  49541. + (struct usb_descriptor_header *) &za_5,
  49542. + (struct usb_descriptor_header *) &za_6,
  49543. + (struct usb_descriptor_header *) &za_7,
  49544. + (struct usb_descriptor_header *) &za_8,
  49545. + (struct usb_descriptor_header *) &za_9,
  49546. + (struct usb_descriptor_header *) &za_10,
  49547. + (struct usb_descriptor_header *) &za_11,
  49548. + (struct usb_descriptor_header *) &za_12,
  49549. + (struct usb_descriptor_header *) &za_13,
  49550. + (struct usb_descriptor_header *) &za_14,
  49551. + (struct usb_descriptor_header *) &za_15,
  49552. + (struct usb_descriptor_header *) &za_16,
  49553. + (struct usb_descriptor_header *) &za_17,
  49554. + (struct usb_descriptor_header *) &za_18,
  49555. + (struct usb_descriptor_header *) &za_19,
  49556. + (struct usb_descriptor_header *) &za_20,
  49557. + (struct usb_descriptor_header *) &za_21,
  49558. + (struct usb_descriptor_header *) &za_22,
  49559. + (struct usb_descriptor_header *) &za_23,
  49560. + (struct usb_descriptor_header *) &za_24,
  49561. + NULL,
  49562. +};
  49563. +
  49564. +/* maxpacket and other transfer characteristics vary by speed. */
  49565. +#define ep_desc(g,hs,fs) (((g)->speed==USB_SPEED_HIGH)?(hs):(fs))
  49566. +
  49567. +#else
  49568. +
  49569. +/* if there's no high speed support, maxpacket doesn't change. */
  49570. +#define ep_desc(g,hs,fs) fs
  49571. +
  49572. +#endif /* !CONFIG_USB_GADGET_DUALSPEED */
  49573. +
  49574. +static char manufacturer [40];
  49575. +//static char serial [40];
  49576. +static char serial [] = "Ser 00 em";
  49577. +
  49578. +/* static strings, in UTF-8 */
  49579. +static struct usb_string strings [] = {
  49580. + { STRING_MANUFACTURER, manufacturer, },
  49581. + { STRING_PRODUCT, longname, },
  49582. + { STRING_SERIAL, serial, },
  49583. + { STRING_LOOPBACK, loopback, },
  49584. + { STRING_SOURCE_SINK, source_sink, },
  49585. + { } /* end of list */
  49586. +};
  49587. +
  49588. +static struct usb_gadget_strings stringtab = {
  49589. + .language = 0x0409, /* en-us */
  49590. + .strings = strings,
  49591. +};
  49592. +
  49593. +/*
  49594. + * config descriptors are also handcrafted. these must agree with code
  49595. + * that sets configurations, and with code managing interfaces and their
  49596. + * altsettings. other complexity may come from:
  49597. + *
  49598. + * - high speed support, including "other speed config" rules
  49599. + * - multiple configurations
  49600. + * - interfaces with alternate settings
  49601. + * - embedded class or vendor-specific descriptors
  49602. + *
  49603. + * this handles high speed, and has a second config that could as easily
  49604. + * have been an alternate interface setting (on most hardware).
  49605. + *
  49606. + * NOTE: to demonstrate (and test) more USB capabilities, this driver
  49607. + * should include an altsetting to test interrupt transfers, including
  49608. + * high bandwidth modes at high speed. (Maybe work like Intel's test
  49609. + * device?)
  49610. + */
  49611. +static int
  49612. +config_buf (struct usb_gadget *gadget, u8 *buf, u8 type, unsigned index)
  49613. +{
  49614. + int len;
  49615. + const struct usb_descriptor_header **function;
  49616. +
  49617. + function = z_function;
  49618. + len = usb_gadget_config_buf (&z_config, buf, USB_BUFSIZ, function);
  49619. + if (len < 0)
  49620. + return len;
  49621. + ((struct usb_config_descriptor *) buf)->bDescriptorType = type;
  49622. + return len;
  49623. +}
  49624. +
  49625. +/*-------------------------------------------------------------------------*/
  49626. +
  49627. +static struct usb_request *
  49628. +alloc_ep_req (struct usb_ep *ep, unsigned length)
  49629. +{
  49630. + struct usb_request *req;
  49631. +
  49632. + req = usb_ep_alloc_request (ep, GFP_ATOMIC);
  49633. + if (req) {
  49634. + req->length = length;
  49635. + req->buf = usb_ep_alloc_buffer (ep, length,
  49636. + &req->dma, GFP_ATOMIC);
  49637. + if (!req->buf) {
  49638. + usb_ep_free_request (ep, req);
  49639. + req = NULL;
  49640. + }
  49641. + }
  49642. + return req;
  49643. +}
  49644. +
  49645. +static void free_ep_req (struct usb_ep *ep, struct usb_request *req)
  49646. +{
  49647. + if (req->buf)
  49648. + usb_ep_free_buffer (ep, req->buf, req->dma, req->length);
  49649. + usb_ep_free_request (ep, req);
  49650. +}
  49651. +
  49652. +/*-------------------------------------------------------------------------*/
  49653. +
  49654. +/* optionally require specific source/sink data patterns */
  49655. +
  49656. +static int
  49657. +check_read_data (
  49658. + struct zero_dev *dev,
  49659. + struct usb_ep *ep,
  49660. + struct usb_request *req
  49661. +)
  49662. +{
  49663. + unsigned i;
  49664. + u8 *buf = req->buf;
  49665. +
  49666. + for (i = 0; i < req->actual; i++, buf++) {
  49667. + switch (pattern) {
  49668. + /* all-zeroes has no synchronization issues */
  49669. + case 0:
  49670. + if (*buf == 0)
  49671. + continue;
  49672. + break;
  49673. + /* mod63 stays in sync with short-terminated transfers,
  49674. + * or otherwise when host and gadget agree on how large
  49675. + * each usb transfer request should be. resync is done
  49676. + * with set_interface or set_config.
  49677. + */
  49678. + case 1:
  49679. + if (*buf == (u8)(i % 63))
  49680. + continue;
  49681. + break;
  49682. + }
  49683. + ERROR (dev, "bad OUT byte, buf [%d] = %d\n", i, *buf);
  49684. + usb_ep_set_halt (ep);
  49685. + return -EINVAL;
  49686. + }
  49687. + return 0;
  49688. +}
  49689. +
  49690. +/*-------------------------------------------------------------------------*/
  49691. +
  49692. +static void zero_reset_config (struct zero_dev *dev)
  49693. +{
  49694. + if (dev->config == 0)
  49695. + return;
  49696. +
  49697. + DBG (dev, "reset config\n");
  49698. +
  49699. + /* just disable endpoints, forcing completion of pending i/o.
  49700. + * all our completion handlers free their requests in this case.
  49701. + */
  49702. + if (dev->in_ep) {
  49703. + usb_ep_disable (dev->in_ep);
  49704. + dev->in_ep = NULL;
  49705. + }
  49706. + if (dev->out_ep) {
  49707. + usb_ep_disable (dev->out_ep);
  49708. + dev->out_ep = NULL;
  49709. + }
  49710. + dev->config = 0;
  49711. + del_timer (&dev->resume);
  49712. +}
  49713. +
  49714. +#define _write(f, buf, sz) (f->f_op->write(f, buf, sz, &f->f_pos))
  49715. +
  49716. +static void
  49717. +zero_isoc_complete (struct usb_ep *ep, struct usb_request *req)
  49718. +{
  49719. + struct zero_dev *dev = ep->driver_data;
  49720. + int status = req->status;
  49721. + int i, j;
  49722. +
  49723. + switch (status) {
  49724. +
  49725. + case 0: /* normal completion? */
  49726. + //printk ("\nzero ---------------> isoc normal completion %d bytes\n", req->actual);
  49727. + for (i=0, j=rbuf_start; i<req->actual; i++) {
  49728. + //printk ("%02x ", ((__u8*)req->buf)[i]);
  49729. + rbuf[j] = ((__u8*)req->buf)[i];
  49730. + j++;
  49731. + if (j >= RBUF_LEN) j=0;
  49732. + }
  49733. + rbuf_start = j;
  49734. + //printk ("\n\n");
  49735. +
  49736. + if (rbuf_len < RBUF_LEN) {
  49737. + rbuf_len += req->actual;
  49738. + if (rbuf_len > RBUF_LEN) {
  49739. + rbuf_len = RBUF_LEN;
  49740. + }
  49741. + }
  49742. +
  49743. + break;
  49744. +
  49745. + /* this endpoint is normally active while we're configured */
  49746. + case -ECONNABORTED: /* hardware forced ep reset */
  49747. + case -ECONNRESET: /* request dequeued */
  49748. + case -ESHUTDOWN: /* disconnect from host */
  49749. + VDBG (dev, "%s gone (%d), %d/%d\n", ep->name, status,
  49750. + req->actual, req->length);
  49751. + if (ep == dev->out_ep)
  49752. + check_read_data (dev, ep, req);
  49753. + free_ep_req (ep, req);
  49754. + return;
  49755. +
  49756. + case -EOVERFLOW: /* buffer overrun on read means that
  49757. + * we didn't provide a big enough
  49758. + * buffer.
  49759. + */
  49760. + default:
  49761. +#if 1
  49762. + DBG (dev, "%s complete --> %d, %d/%d\n", ep->name,
  49763. + status, req->actual, req->length);
  49764. +#endif
  49765. + case -EREMOTEIO: /* short read */
  49766. + break;
  49767. + }
  49768. +
  49769. + status = usb_ep_queue (ep, req, GFP_ATOMIC);
  49770. + if (status) {
  49771. + ERROR (dev, "kill %s: resubmit %d bytes --> %d\n",
  49772. + ep->name, req->length, status);
  49773. + usb_ep_set_halt (ep);
  49774. + /* FIXME recover later ... somehow */
  49775. + }
  49776. +}
  49777. +
  49778. +static struct usb_request *
  49779. +zero_start_isoc_ep (struct usb_ep *ep, int gfp_flags)
  49780. +{
  49781. + struct usb_request *req;
  49782. + int status;
  49783. +
  49784. + req = alloc_ep_req (ep, 512);
  49785. + if (!req)
  49786. + return NULL;
  49787. +
  49788. + req->complete = zero_isoc_complete;
  49789. +
  49790. + status = usb_ep_queue (ep, req, gfp_flags);
  49791. + if (status) {
  49792. + struct zero_dev *dev = ep->driver_data;
  49793. +
  49794. + ERROR (dev, "start %s --> %d\n", ep->name, status);
  49795. + free_ep_req (ep, req);
  49796. + req = NULL;
  49797. + }
  49798. +
  49799. + return req;
  49800. +}
  49801. +
  49802. +/* change our operational config. this code must agree with the code
  49803. + * that returns config descriptors, and altsetting code.
  49804. + *
  49805. + * it's also responsible for power management interactions. some
  49806. + * configurations might not work with our current power sources.
  49807. + *
  49808. + * note that some device controller hardware will constrain what this
  49809. + * code can do, perhaps by disallowing more than one configuration or
  49810. + * by limiting configuration choices (like the pxa2xx).
  49811. + */
  49812. +static int
  49813. +zero_set_config (struct zero_dev *dev, unsigned number, int gfp_flags)
  49814. +{
  49815. + int result = 0;
  49816. + struct usb_gadget *gadget = dev->gadget;
  49817. + const struct usb_endpoint_descriptor *d;
  49818. + struct usb_ep *ep;
  49819. +
  49820. + if (number == dev->config)
  49821. + return 0;
  49822. +
  49823. + zero_reset_config (dev);
  49824. +
  49825. + gadget_for_each_ep (ep, gadget) {
  49826. +
  49827. + if (strcmp (ep->name, "ep4") == 0) {
  49828. +
  49829. + d = (struct usb_endpoint_descripter *)&za_23; // isoc ep desc for audio i/f alt setting 6
  49830. + result = usb_ep_enable (ep, d);
  49831. +
  49832. + if (result == 0) {
  49833. + ep->driver_data = dev;
  49834. + dev->in_ep = ep;
  49835. +
  49836. + if (zero_start_isoc_ep (ep, gfp_flags) != 0) {
  49837. +
  49838. + dev->in_ep = ep;
  49839. + continue;
  49840. + }
  49841. +
  49842. + usb_ep_disable (ep);
  49843. + result = -EIO;
  49844. + }
  49845. + }
  49846. +
  49847. + }
  49848. +
  49849. + dev->config = number;
  49850. + return result;
  49851. +}
  49852. +
  49853. +/*-------------------------------------------------------------------------*/
  49854. +
  49855. +static void zero_setup_complete (struct usb_ep *ep, struct usb_request *req)
  49856. +{
  49857. + if (req->status || req->actual != req->length)
  49858. + DBG ((struct zero_dev *) ep->driver_data,
  49859. + "setup complete --> %d, %d/%d\n",
  49860. + req->status, req->actual, req->length);
  49861. +}
  49862. +
  49863. +/*
  49864. + * The setup() callback implements all the ep0 functionality that's
  49865. + * not handled lower down, in hardware or the hardware driver (like
  49866. + * device and endpoint feature flags, and their status). It's all
  49867. + * housekeeping for the gadget function we're implementing. Most of
  49868. + * the work is in config-specific setup.
  49869. + */
  49870. +static int
  49871. +zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
  49872. +{
  49873. + struct zero_dev *dev = get_gadget_data (gadget);
  49874. + struct usb_request *req = dev->req;
  49875. + int value = -EOPNOTSUPP;
  49876. +
  49877. + /* usually this stores reply data in the pre-allocated ep0 buffer,
  49878. + * but config change events will reconfigure hardware.
  49879. + */
  49880. + req->zero = 0;
  49881. + switch (ctrl->bRequest) {
  49882. +
  49883. + case USB_REQ_GET_DESCRIPTOR:
  49884. +
  49885. + switch (ctrl->wValue >> 8) {
  49886. +
  49887. + case USB_DT_DEVICE:
  49888. + value = min (ctrl->wLength, (u16) sizeof device_desc);
  49889. + memcpy (req->buf, &device_desc, value);
  49890. + break;
  49891. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  49892. + case USB_DT_DEVICE_QUALIFIER:
  49893. + if (!gadget->is_dualspeed)
  49894. + break;
  49895. + value = min (ctrl->wLength, (u16) sizeof dev_qualifier);
  49896. + memcpy (req->buf, &dev_qualifier, value);
  49897. + break;
  49898. +
  49899. + case USB_DT_OTHER_SPEED_CONFIG:
  49900. + if (!gadget->is_dualspeed)
  49901. + break;
  49902. + // FALLTHROUGH
  49903. +#endif /* CONFIG_USB_GADGET_DUALSPEED */
  49904. + case USB_DT_CONFIG:
  49905. + value = config_buf (gadget, req->buf,
  49906. + ctrl->wValue >> 8,
  49907. + ctrl->wValue & 0xff);
  49908. + if (value >= 0)
  49909. + value = min (ctrl->wLength, (u16) value);
  49910. + break;
  49911. +
  49912. + case USB_DT_STRING:
  49913. + /* wIndex == language code.
  49914. + * this driver only handles one language, you can
  49915. + * add string tables for other languages, using
  49916. + * any UTF-8 characters
  49917. + */
  49918. + value = usb_gadget_get_string (&stringtab,
  49919. + ctrl->wValue & 0xff, req->buf);
  49920. + if (value >= 0) {
  49921. + value = min (ctrl->wLength, (u16) value);
  49922. + }
  49923. + break;
  49924. + }
  49925. + break;
  49926. +
  49927. + /* currently two configs, two speeds */
  49928. + case USB_REQ_SET_CONFIGURATION:
  49929. + if (ctrl->bRequestType != 0)
  49930. + goto unknown;
  49931. +
  49932. + spin_lock (&dev->lock);
  49933. + value = zero_set_config (dev, ctrl->wValue, GFP_ATOMIC);
  49934. + spin_unlock (&dev->lock);
  49935. + break;
  49936. + case USB_REQ_GET_CONFIGURATION:
  49937. + if (ctrl->bRequestType != USB_DIR_IN)
  49938. + goto unknown;
  49939. + *(u8 *)req->buf = dev->config;
  49940. + value = min (ctrl->wLength, (u16) 1);
  49941. + break;
  49942. +
  49943. + /* until we add altsetting support, or other interfaces,
  49944. + * only 0/0 are possible. pxa2xx only supports 0/0 (poorly)
  49945. + * and already killed pending endpoint I/O.
  49946. + */
  49947. + case USB_REQ_SET_INTERFACE:
  49948. +
  49949. + if (ctrl->bRequestType != USB_RECIP_INTERFACE)
  49950. + goto unknown;
  49951. + spin_lock (&dev->lock);
  49952. + if (dev->config) {
  49953. + u8 config = dev->config;
  49954. +
  49955. + /* resets interface configuration, forgets about
  49956. + * previous transaction state (queued bufs, etc)
  49957. + * and re-inits endpoint state (toggle etc)
  49958. + * no response queued, just zero status == success.
  49959. + * if we had more than one interface we couldn't
  49960. + * use this "reset the config" shortcut.
  49961. + */
  49962. + zero_reset_config (dev);
  49963. + zero_set_config (dev, config, GFP_ATOMIC);
  49964. + value = 0;
  49965. + }
  49966. + spin_unlock (&dev->lock);
  49967. + break;
  49968. + case USB_REQ_GET_INTERFACE:
  49969. + if ((ctrl->bRequestType == 0x21) && (ctrl->wIndex == 0x02)) {
  49970. + value = ctrl->wLength;
  49971. + break;
  49972. + }
  49973. + else {
  49974. + if (ctrl->bRequestType != (USB_DIR_IN|USB_RECIP_INTERFACE))
  49975. + goto unknown;
  49976. + if (!dev->config)
  49977. + break;
  49978. + if (ctrl->wIndex != 0) {
  49979. + value = -EDOM;
  49980. + break;
  49981. + }
  49982. + *(u8 *)req->buf = 0;
  49983. + value = min (ctrl->wLength, (u16) 1);
  49984. + }
  49985. + break;
  49986. +
  49987. + /*
  49988. + * These are the same vendor-specific requests supported by
  49989. + * Intel's USB 2.0 compliance test devices. We exceed that
  49990. + * device spec by allowing multiple-packet requests.
  49991. + */
  49992. + case 0x5b: /* control WRITE test -- fill the buffer */
  49993. + if (ctrl->bRequestType != (USB_DIR_OUT|USB_TYPE_VENDOR))
  49994. + goto unknown;
  49995. + if (ctrl->wValue || ctrl->wIndex)
  49996. + break;
  49997. + /* just read that many bytes into the buffer */
  49998. + if (ctrl->wLength > USB_BUFSIZ)
  49999. + break;
  50000. + value = ctrl->wLength;
  50001. + break;
  50002. + case 0x5c: /* control READ test -- return the buffer */
  50003. + if (ctrl->bRequestType != (USB_DIR_IN|USB_TYPE_VENDOR))
  50004. + goto unknown;
  50005. + if (ctrl->wValue || ctrl->wIndex)
  50006. + break;
  50007. + /* expect those bytes are still in the buffer; send back */
  50008. + if (ctrl->wLength > USB_BUFSIZ
  50009. + || ctrl->wLength != req->length)
  50010. + break;
  50011. + value = ctrl->wLength;
  50012. + break;
  50013. +
  50014. + case 0x01: // SET_CUR
  50015. + case 0x02:
  50016. + case 0x03:
  50017. + case 0x04:
  50018. + case 0x05:
  50019. + value = ctrl->wLength;
  50020. + break;
  50021. + case 0x81:
  50022. + switch (ctrl->wValue) {
  50023. + case 0x0201:
  50024. + case 0x0202:
  50025. + ((u8*)req->buf)[0] = 0x00;
  50026. + ((u8*)req->buf)[1] = 0xe3;
  50027. + break;
  50028. + case 0x0300:
  50029. + case 0x0500:
  50030. + ((u8*)req->buf)[0] = 0x00;
  50031. + break;
  50032. + }
  50033. + //((u8*)req->buf)[0] = 0x81;
  50034. + //((u8*)req->buf)[1] = 0x81;
  50035. + value = ctrl->wLength;
  50036. + break;
  50037. + case 0x82:
  50038. + switch (ctrl->wValue) {
  50039. + case 0x0201:
  50040. + case 0x0202:
  50041. + ((u8*)req->buf)[0] = 0x00;
  50042. + ((u8*)req->buf)[1] = 0xc3;
  50043. + break;
  50044. + case 0x0300:
  50045. + case 0x0500:
  50046. + ((u8*)req->buf)[0] = 0x00;
  50047. + break;
  50048. + }
  50049. + //((u8*)req->buf)[0] = 0x82;
  50050. + //((u8*)req->buf)[1] = 0x82;
  50051. + value = ctrl->wLength;
  50052. + break;
  50053. + case 0x83:
  50054. + switch (ctrl->wValue) {
  50055. + case 0x0201:
  50056. + case 0x0202:
  50057. + ((u8*)req->buf)[0] = 0x00;
  50058. + ((u8*)req->buf)[1] = 0x00;
  50059. + break;
  50060. + case 0x0300:
  50061. + ((u8*)req->buf)[0] = 0x60;
  50062. + break;
  50063. + case 0x0500:
  50064. + ((u8*)req->buf)[0] = 0x18;
  50065. + break;
  50066. + }
  50067. + //((u8*)req->buf)[0] = 0x83;
  50068. + //((u8*)req->buf)[1] = 0x83;
  50069. + value = ctrl->wLength;
  50070. + break;
  50071. + case 0x84:
  50072. + switch (ctrl->wValue) {
  50073. + case 0x0201:
  50074. + case 0x0202:
  50075. + ((u8*)req->buf)[0] = 0x00;
  50076. + ((u8*)req->buf)[1] = 0x01;
  50077. + break;
  50078. + case 0x0300:
  50079. + case 0x0500:
  50080. + ((u8*)req->buf)[0] = 0x08;
  50081. + break;
  50082. + }
  50083. + //((u8*)req->buf)[0] = 0x84;
  50084. + //((u8*)req->buf)[1] = 0x84;
  50085. + value = ctrl->wLength;
  50086. + break;
  50087. + case 0x85:
  50088. + ((u8*)req->buf)[0] = 0x85;
  50089. + ((u8*)req->buf)[1] = 0x85;
  50090. + value = ctrl->wLength;
  50091. + break;
  50092. +
  50093. +
  50094. + default:
  50095. +unknown:
  50096. + printk("unknown control req%02x.%02x v%04x i%04x l%d\n",
  50097. + ctrl->bRequestType, ctrl->bRequest,
  50098. + ctrl->wValue, ctrl->wIndex, ctrl->wLength);
  50099. + }
  50100. +
  50101. + /* respond with data transfer before status phase? */
  50102. + if (value >= 0) {
  50103. + req->length = value;
  50104. + req->zero = value < ctrl->wLength
  50105. + && (value % gadget->ep0->maxpacket) == 0;
  50106. + value = usb_ep_queue (gadget->ep0, req, GFP_ATOMIC);
  50107. + if (value < 0) {
  50108. + DBG (dev, "ep_queue < 0 --> %d\n", value);
  50109. + req->status = 0;
  50110. + zero_setup_complete (gadget->ep0, req);
  50111. + }
  50112. + }
  50113. +
  50114. + /* device either stalls (value < 0) or reports success */
  50115. + return value;
  50116. +}
  50117. +
  50118. +static void
  50119. +zero_disconnect (struct usb_gadget *gadget)
  50120. +{
  50121. + struct zero_dev *dev = get_gadget_data (gadget);
  50122. + unsigned long flags;
  50123. +
  50124. + spin_lock_irqsave (&dev->lock, flags);
  50125. + zero_reset_config (dev);
  50126. +
  50127. + /* a more significant application might have some non-usb
  50128. + * activities to quiesce here, saving resources like power
  50129. + * or pushing the notification up a network stack.
  50130. + */
  50131. + spin_unlock_irqrestore (&dev->lock, flags);
  50132. +
  50133. + /* next we may get setup() calls to enumerate new connections;
  50134. + * or an unbind() during shutdown (including removing module).
  50135. + */
  50136. +}
  50137. +
  50138. +static void
  50139. +zero_autoresume (unsigned long _dev)
  50140. +{
  50141. + struct zero_dev *dev = (struct zero_dev *) _dev;
  50142. + int status;
  50143. +
  50144. + /* normally the host would be woken up for something
  50145. + * more significant than just a timer firing...
  50146. + */
  50147. + if (dev->gadget->speed != USB_SPEED_UNKNOWN) {
  50148. + status = usb_gadget_wakeup (dev->gadget);
  50149. + DBG (dev, "wakeup --> %d\n", status);
  50150. + }
  50151. +}
  50152. +
  50153. +/*-------------------------------------------------------------------------*/
  50154. +
  50155. +static void
  50156. +zero_unbind (struct usb_gadget *gadget)
  50157. +{
  50158. + struct zero_dev *dev = get_gadget_data (gadget);
  50159. +
  50160. + DBG (dev, "unbind\n");
  50161. +
  50162. + /* we've already been disconnected ... no i/o is active */
  50163. + if (dev->req)
  50164. + free_ep_req (gadget->ep0, dev->req);
  50165. + del_timer_sync (&dev->resume);
  50166. + kfree (dev);
  50167. + set_gadget_data (gadget, NULL);
  50168. +}
  50169. +
  50170. +static int
  50171. +zero_bind (struct usb_gadget *gadget)
  50172. +{
  50173. + struct zero_dev *dev;
  50174. + //struct usb_ep *ep;
  50175. +
  50176. + printk("binding\n");
  50177. + /*
  50178. + * DRIVER POLICY CHOICE: you may want to do this differently.
  50179. + * One thing to avoid is reusing a bcdDevice revision code
  50180. + * with different host-visible configurations or behavior
  50181. + * restrictions -- using ep1in/ep2out vs ep1out/ep3in, etc
  50182. + */
  50183. + //device_desc.bcdDevice = __constant_cpu_to_le16 (0x0201);
  50184. +
  50185. +
  50186. + /* ok, we made sense of the hardware ... */
  50187. + dev = kmalloc (sizeof *dev, SLAB_KERNEL);
  50188. + if (!dev)
  50189. + return -ENOMEM;
  50190. + memset (dev, 0, sizeof *dev);
  50191. + spin_lock_init (&dev->lock);
  50192. + dev->gadget = gadget;
  50193. + set_gadget_data (gadget, dev);
  50194. +
  50195. + /* preallocate control response and buffer */
  50196. + dev->req = usb_ep_alloc_request (gadget->ep0, GFP_KERNEL);
  50197. + if (!dev->req)
  50198. + goto enomem;
  50199. + dev->req->buf = usb_ep_alloc_buffer (gadget->ep0, USB_BUFSIZ,
  50200. + &dev->req->dma, GFP_KERNEL);
  50201. + if (!dev->req->buf)
  50202. + goto enomem;
  50203. +
  50204. + dev->req->complete = zero_setup_complete;
  50205. +
  50206. + device_desc.bMaxPacketSize0 = gadget->ep0->maxpacket;
  50207. +
  50208. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50209. + /* assume ep0 uses the same value for both speeds ... */
  50210. + dev_qualifier.bMaxPacketSize0 = device_desc.bMaxPacketSize0;
  50211. +
  50212. + /* and that all endpoints are dual-speed */
  50213. + //hs_source_desc.bEndpointAddress = fs_source_desc.bEndpointAddress;
  50214. + //hs_sink_desc.bEndpointAddress = fs_sink_desc.bEndpointAddress;
  50215. +#endif
  50216. +
  50217. + usb_gadget_set_selfpowered (gadget);
  50218. +
  50219. + init_timer (&dev->resume);
  50220. + dev->resume.function = zero_autoresume;
  50221. + dev->resume.data = (unsigned long) dev;
  50222. +
  50223. + gadget->ep0->driver_data = dev;
  50224. +
  50225. + INFO (dev, "%s, version: " DRIVER_VERSION "\n", longname);
  50226. + INFO (dev, "using %s, OUT %s IN %s\n", gadget->name,
  50227. + EP_OUT_NAME, EP_IN_NAME);
  50228. +
  50229. + snprintf (manufacturer, sizeof manufacturer,
  50230. + UTS_SYSNAME " " UTS_RELEASE " with %s",
  50231. + gadget->name);
  50232. +
  50233. + return 0;
  50234. +
  50235. +enomem:
  50236. + zero_unbind (gadget);
  50237. + return -ENOMEM;
  50238. +}
  50239. +
  50240. +/*-------------------------------------------------------------------------*/
  50241. +
  50242. +static void
  50243. +zero_suspend (struct usb_gadget *gadget)
  50244. +{
  50245. + struct zero_dev *dev = get_gadget_data (gadget);
  50246. +
  50247. + if (gadget->speed == USB_SPEED_UNKNOWN)
  50248. + return;
  50249. +
  50250. + if (autoresume) {
  50251. + mod_timer (&dev->resume, jiffies + (HZ * autoresume));
  50252. + DBG (dev, "suspend, wakeup in %d seconds\n", autoresume);
  50253. + } else
  50254. + DBG (dev, "suspend\n");
  50255. +}
  50256. +
  50257. +static void
  50258. +zero_resume (struct usb_gadget *gadget)
  50259. +{
  50260. + struct zero_dev *dev = get_gadget_data (gadget);
  50261. +
  50262. + DBG (dev, "resume\n");
  50263. + del_timer (&dev->resume);
  50264. +}
  50265. +
  50266. +
  50267. +/*-------------------------------------------------------------------------*/
  50268. +
  50269. +static struct usb_gadget_driver zero_driver = {
  50270. +#ifdef CONFIG_USB_GADGET_DUALSPEED
  50271. + .speed = USB_SPEED_HIGH,
  50272. +#else
  50273. + .speed = USB_SPEED_FULL,
  50274. +#endif
  50275. + .function = (char *) longname,
  50276. + .bind = zero_bind,
  50277. + .unbind = zero_unbind,
  50278. +
  50279. + .setup = zero_setup,
  50280. + .disconnect = zero_disconnect,
  50281. +
  50282. + .suspend = zero_suspend,
  50283. + .resume = zero_resume,
  50284. +
  50285. + .driver = {
  50286. + .name = (char *) shortname,
  50287. + // .shutdown = ...
  50288. + // .suspend = ...
  50289. + // .resume = ...
  50290. + },
  50291. +};
  50292. +
  50293. +MODULE_AUTHOR ("David Brownell");
  50294. +MODULE_LICENSE ("Dual BSD/GPL");
  50295. +
  50296. +static struct proc_dir_entry *pdir, *pfile;
  50297. +
  50298. +static int isoc_read_data (char *page, char **start,
  50299. + off_t off, int count,
  50300. + int *eof, void *data)
  50301. +{
  50302. + int i;
  50303. + static int c = 0;
  50304. + static int done = 0;
  50305. + static int s = 0;
  50306. +
  50307. +/*
  50308. + printk ("\ncount: %d\n", count);
  50309. + printk ("rbuf_start: %d\n", rbuf_start);
  50310. + printk ("rbuf_len: %d\n", rbuf_len);
  50311. + printk ("off: %d\n", off);
  50312. + printk ("start: %p\n\n", *start);
  50313. +*/
  50314. + if (done) {
  50315. + c = 0;
  50316. + done = 0;
  50317. + *eof = 1;
  50318. + return 0;
  50319. + }
  50320. +
  50321. + if (c == 0) {
  50322. + if (rbuf_len == RBUF_LEN)
  50323. + s = rbuf_start;
  50324. + else s = 0;
  50325. + }
  50326. +
  50327. + for (i=0; i<count && c<rbuf_len; i++, c++) {
  50328. + page[i] = rbuf[(c+s) % RBUF_LEN];
  50329. + }
  50330. + *start = page;
  50331. +
  50332. + if (c >= rbuf_len) {
  50333. + *eof = 1;
  50334. + done = 1;
  50335. + }
  50336. +
  50337. +
  50338. + return i;
  50339. +}
  50340. +
  50341. +static int __init init (void)
  50342. +{
  50343. +
  50344. + int retval = 0;
  50345. +
  50346. + pdir = proc_mkdir("isoc_test", NULL);
  50347. + if(pdir == NULL) {
  50348. + retval = -ENOMEM;
  50349. + printk("Error creating dir\n");
  50350. + goto done;
  50351. + }
  50352. + pdir->owner = THIS_MODULE;
  50353. +
  50354. + pfile = create_proc_read_entry("isoc_data",
  50355. + 0444, pdir,
  50356. + isoc_read_data,
  50357. + NULL);
  50358. + if (pfile == NULL) {
  50359. + retval = -ENOMEM;
  50360. + printk("Error creating file\n");
  50361. + goto no_file;
  50362. + }
  50363. + pfile->owner = THIS_MODULE;
  50364. +
  50365. + return usb_gadget_register_driver (&zero_driver);
  50366. +
  50367. + no_file:
  50368. + remove_proc_entry("isoc_data", NULL);
  50369. + done:
  50370. + return retval;
  50371. +}
  50372. +module_init (init);
  50373. +
  50374. +static void __exit cleanup (void)
  50375. +{
  50376. +
  50377. + usb_gadget_unregister_driver (&zero_driver);
  50378. +
  50379. + remove_proc_entry("isoc_data", pdir);
  50380. + remove_proc_entry("isoc_test", NULL);
  50381. +}
  50382. +module_exit (cleanup);
  50383. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_cfi_common.h linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h
  50384. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_cfi_common.h 1970-01-01 01:00:00.000000000 +0100
  50385. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_cfi_common.h 2014-06-11 21:03:43.000000000 +0200
  50386. @@ -0,0 +1,142 @@
  50387. +/* ==========================================================================
  50388. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50389. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50390. + * otherwise expressly agreed to in writing between Synopsys and you.
  50391. + *
  50392. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50393. + * any End User Software License Agreement or Agreement for Licensed Product
  50394. + * with Synopsys or any supplement thereto. You are permitted to use and
  50395. + * redistribute this Software in source and binary forms, with or without
  50396. + * modification, provided that redistributions of source code must retain this
  50397. + * notice. You may not view, use, disclose, copy or distribute this file or
  50398. + * any information contained herein except pursuant to this license grant from
  50399. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50400. + * below, then you are not authorized to use the Software.
  50401. + *
  50402. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50403. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50404. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50405. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50406. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50407. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50408. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50409. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50410. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50411. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50412. + * DAMAGE.
  50413. + * ========================================================================== */
  50414. +
  50415. +#if !defined(__DWC_CFI_COMMON_H__)
  50416. +#define __DWC_CFI_COMMON_H__
  50417. +
  50418. +//#include <linux/types.h>
  50419. +
  50420. +/**
  50421. + * @file
  50422. + *
  50423. + * This file contains the CFI specific common constants, interfaces
  50424. + * (functions and macros) and structures for Linux. No PCD specific
  50425. + * data structure or definition is to be included in this file.
  50426. + *
  50427. + */
  50428. +
  50429. +/** This is a request for all Core Features */
  50430. +#define VEN_CORE_GET_FEATURES 0xB1
  50431. +
  50432. +/** This is a request to get the value of a specific Core Feature */
  50433. +#define VEN_CORE_GET_FEATURE 0xB2
  50434. +
  50435. +/** This command allows the host to set the value of a specific Core Feature */
  50436. +#define VEN_CORE_SET_FEATURE 0xB3
  50437. +
  50438. +/** This command allows the host to set the default values of
  50439. + * either all or any specific Core Feature
  50440. + */
  50441. +#define VEN_CORE_RESET_FEATURES 0xB4
  50442. +
  50443. +/** This command forces the PCD to write the deferred values of a Core Features */
  50444. +#define VEN_CORE_ACTIVATE_FEATURES 0xB5
  50445. +
  50446. +/** This request reads a DWORD value from a register at the specified offset */
  50447. +#define VEN_CORE_READ_REGISTER 0xB6
  50448. +
  50449. +/** This request writes a DWORD value into a register at the specified offset */
  50450. +#define VEN_CORE_WRITE_REGISTER 0xB7
  50451. +
  50452. +/** This structure is the header of the Core Features dataset returned to
  50453. + * the Host
  50454. + */
  50455. +struct cfi_all_features_header {
  50456. +/** The features header structure length is */
  50457. +#define CFI_ALL_FEATURES_HDR_LEN 8
  50458. + /**
  50459. + * The total length of the features dataset returned to the Host
  50460. + */
  50461. + uint16_t wTotalLen;
  50462. +
  50463. + /**
  50464. + * CFI version number inBinary-Coded Decimal (i.e., 1.00 is 100H).
  50465. + * This field identifies the version of the CFI Specification with which
  50466. + * the device is compliant.
  50467. + */
  50468. + uint16_t wVersion;
  50469. +
  50470. + /** The ID of the Core */
  50471. + uint16_t wCoreID;
  50472. +#define CFI_CORE_ID_UDC 1
  50473. +#define CFI_CORE_ID_OTG 2
  50474. +#define CFI_CORE_ID_WUDEV 3
  50475. +
  50476. + /** Number of features returned by VEN_CORE_GET_FEATURES request */
  50477. + uint16_t wNumFeatures;
  50478. +} UPACKED;
  50479. +
  50480. +typedef struct cfi_all_features_header cfi_all_features_header_t;
  50481. +
  50482. +/** This structure is a header of the Core Feature descriptor dataset returned to
  50483. + * the Host after the VEN_CORE_GET_FEATURES request
  50484. + */
  50485. +struct cfi_feature_desc_header {
  50486. +#define CFI_FEATURE_DESC_HDR_LEN 8
  50487. +
  50488. + /** The feature ID */
  50489. + uint16_t wFeatureID;
  50490. +
  50491. + /** Length of this feature descriptor in bytes - including the
  50492. + * length of the feature name string
  50493. + */
  50494. + uint16_t wLength;
  50495. +
  50496. + /** The data length of this feature in bytes */
  50497. + uint16_t wDataLength;
  50498. +
  50499. + /**
  50500. + * Attributes of this features
  50501. + * D0: Access rights
  50502. + * 0 - Read/Write
  50503. + * 1 - Read only
  50504. + */
  50505. + uint8_t bmAttributes;
  50506. +#define CFI_FEATURE_ATTR_RO 1
  50507. +#define CFI_FEATURE_ATTR_RW 0
  50508. +
  50509. + /** Length of the feature name in bytes */
  50510. + uint8_t bNameLen;
  50511. +
  50512. + /** The feature name buffer */
  50513. + //uint8_t *name;
  50514. +} UPACKED;
  50515. +
  50516. +typedef struct cfi_feature_desc_header cfi_feature_desc_header_t;
  50517. +
  50518. +/**
  50519. + * This structure describes a NULL terminated string referenced by its id field.
  50520. + * It is very similar to usb_string structure but has the id field type set to 16-bit.
  50521. + */
  50522. +struct cfi_string {
  50523. + uint16_t id;
  50524. + const uint8_t *s;
  50525. +};
  50526. +typedef struct cfi_string cfi_string_t;
  50527. +
  50528. +#endif
  50529. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_adp.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c
  50530. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_adp.c 1970-01-01 01:00:00.000000000 +0100
  50531. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.c 2014-06-11 21:03:43.000000000 +0200
  50532. @@ -0,0 +1,854 @@
  50533. +/* ==========================================================================
  50534. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.c $
  50535. + * $Revision: #12 $
  50536. + * $Date: 2011/10/26 $
  50537. + * $Change: 1873028 $
  50538. + *
  50539. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  50540. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  50541. + * otherwise expressly agreed to in writing between Synopsys and you.
  50542. + *
  50543. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  50544. + * any End User Software License Agreement or Agreement for Licensed Product
  50545. + * with Synopsys or any supplement thereto. You are permitted to use and
  50546. + * redistribute this Software in source and binary forms, with or without
  50547. + * modification, provided that redistributions of source code must retain this
  50548. + * notice. You may not view, use, disclose, copy or distribute this file or
  50549. + * any information contained herein except pursuant to this license grant from
  50550. + * Synopsys. If you do not agree with this notice, including the disclaimer
  50551. + * below, then you are not authorized to use the Software.
  50552. + *
  50553. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  50554. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50555. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  50556. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  50557. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  50558. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  50559. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  50560. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  50561. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  50562. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  50563. + * DAMAGE.
  50564. + * ========================================================================== */
  50565. +
  50566. +#include "dwc_os.h"
  50567. +#include "dwc_otg_regs.h"
  50568. +#include "dwc_otg_cil.h"
  50569. +#include "dwc_otg_adp.h"
  50570. +
  50571. +/** @file
  50572. + *
  50573. + * This file contains the most of the Attach Detect Protocol implementation for
  50574. + * the driver to support OTG Rev2.0.
  50575. + *
  50576. + */
  50577. +
  50578. +void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value)
  50579. +{
  50580. + adpctl_data_t adpctl;
  50581. +
  50582. + adpctl.d32 = value;
  50583. + adpctl.b.ar = 0x2;
  50584. +
  50585. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50586. +
  50587. + while (adpctl.b.ar) {
  50588. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50589. + }
  50590. +
  50591. +}
  50592. +
  50593. +/**
  50594. + * Function is called to read ADP registers
  50595. + */
  50596. +uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if)
  50597. +{
  50598. + adpctl_data_t adpctl;
  50599. +
  50600. + adpctl.d32 = 0;
  50601. + adpctl.b.ar = 0x1;
  50602. +
  50603. + DWC_WRITE_REG32(&core_if->core_global_regs->adpctl, adpctl.d32);
  50604. +
  50605. + while (adpctl.b.ar) {
  50606. + adpctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->adpctl);
  50607. + }
  50608. +
  50609. + return adpctl.d32;
  50610. +}
  50611. +
  50612. +/**
  50613. + * Function is called to read ADPCTL register and filter Write-clear bits
  50614. + */
  50615. +uint32_t dwc_otg_adp_read_reg_filter(dwc_otg_core_if_t * core_if)
  50616. +{
  50617. + adpctl_data_t adpctl;
  50618. +
  50619. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50620. + adpctl.b.adp_tmout_int = 0;
  50621. + adpctl.b.adp_prb_int = 0;
  50622. + adpctl.b.adp_tmout_int = 0;
  50623. +
  50624. + return adpctl.d32;
  50625. +}
  50626. +
  50627. +/**
  50628. + * Function is called to write ADP registers
  50629. + */
  50630. +void dwc_otg_adp_modify_reg(dwc_otg_core_if_t * core_if, uint32_t clr,
  50631. + uint32_t set)
  50632. +{
  50633. + dwc_otg_adp_write_reg(core_if,
  50634. + (dwc_otg_adp_read_reg(core_if) & (~clr)) | set);
  50635. +}
  50636. +
  50637. +static void adp_sense_timeout(void *ptr)
  50638. +{
  50639. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50640. + core_if->adp.sense_timer_started = 0;
  50641. + DWC_PRINTF("ADP SENSE TIMEOUT\n");
  50642. + if (core_if->adp_enable) {
  50643. + dwc_otg_adp_sense_stop(core_if);
  50644. + dwc_otg_adp_probe_start(core_if);
  50645. + }
  50646. +}
  50647. +
  50648. +/**
  50649. + * This function is called when the ADP vbus timer expires. Timeout is 1.1s.
  50650. + */
  50651. +static void adp_vbuson_timeout(void *ptr)
  50652. +{
  50653. + gpwrdn_data_t gpwrdn;
  50654. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  50655. + hprt0_data_t hprt0 = {.d32 = 0 };
  50656. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  50657. + DWC_PRINTF("%s: 1.1 seconds expire after turning on VBUS\n",__FUNCTION__);
  50658. + if (core_if) {
  50659. + core_if->adp.vbuson_timer_started = 0;
  50660. + /* Turn off vbus */
  50661. + hprt0.b.prtpwr = 1;
  50662. + DWC_MODIFY_REG32(core_if->host_if->hprt0, hprt0.d32, 0);
  50663. + gpwrdn.d32 = 0;
  50664. +
  50665. + /* Power off the core */
  50666. + if (core_if->power_down == 2) {
  50667. + /* Enable Wakeup Logic */
  50668. +// gpwrdn.b.wkupactiv = 1;
  50669. + gpwrdn.b.pmuactv = 0;
  50670. + gpwrdn.b.pwrdnrstn = 1;
  50671. + gpwrdn.b.pwrdnclmp = 1;
  50672. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50673. + gpwrdn.d32);
  50674. +
  50675. + /* Suspend the Phy Clock */
  50676. + pcgcctl.b.stoppclk = 1;
  50677. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  50678. +
  50679. + /* Switch on VDD */
  50680. +// gpwrdn.b.wkupactiv = 1;
  50681. + gpwrdn.b.pmuactv = 1;
  50682. + gpwrdn.b.pwrdnrstn = 1;
  50683. + gpwrdn.b.pwrdnclmp = 1;
  50684. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  50685. + gpwrdn.d32);
  50686. + } else {
  50687. + /* Enable Power Down Logic */
  50688. + gpwrdn.b.pmuintsel = 1;
  50689. + gpwrdn.b.pmuactv = 1;
  50690. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50691. + }
  50692. +
  50693. + /* Power off the core */
  50694. + if (core_if->power_down == 2) {
  50695. + gpwrdn.d32 = 0;
  50696. + gpwrdn.b.pwrdnswtch = 1;
  50697. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn,
  50698. + gpwrdn.d32, 0);
  50699. + }
  50700. +
  50701. + /* Unmask SRP detected interrupt from Power Down Logic */
  50702. + gpwrdn.d32 = 0;
  50703. + gpwrdn.b.srp_det_msk = 1;
  50704. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50705. +
  50706. + dwc_otg_adp_probe_start(core_if);
  50707. + dwc_otg_dump_global_registers(core_if);
  50708. + dwc_otg_dump_host_registers(core_if);
  50709. + }
  50710. +
  50711. +}
  50712. +
  50713. +/**
  50714. + * Start the ADP Initial Probe timer to detect if Port Connected interrupt is
  50715. + * not asserted within 1.1 seconds.
  50716. + *
  50717. + * @param core_if the pointer to core_if strucure.
  50718. + */
  50719. +void dwc_otg_adp_vbuson_timer_start(dwc_otg_core_if_t * core_if)
  50720. +{
  50721. + core_if->adp.vbuson_timer_started = 1;
  50722. + if (core_if->adp.vbuson_timer)
  50723. + {
  50724. + DWC_PRINTF("SCHEDULING VBUSON TIMER\n");
  50725. + /* 1.1 secs + 60ms necessary for cil_hcd_start*/
  50726. + DWC_TIMER_SCHEDULE(core_if->adp.vbuson_timer, 1160);
  50727. + } else {
  50728. + DWC_WARN("VBUSON_TIMER = %p\n",core_if->adp.vbuson_timer);
  50729. + }
  50730. +}
  50731. +
  50732. +#if 0
  50733. +/**
  50734. + * Masks all DWC OTG core interrupts
  50735. + *
  50736. + */
  50737. +static void mask_all_interrupts(dwc_otg_core_if_t * core_if)
  50738. +{
  50739. + int i;
  50740. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  50741. +
  50742. + /* Mask Host Interrupts */
  50743. +
  50744. + /* Clear and disable HCINTs */
  50745. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  50746. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk, 0);
  50747. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcint, 0xFFFFFFFF);
  50748. +
  50749. + }
  50750. +
  50751. + /* Clear and disable HAINT */
  50752. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk, 0x0000);
  50753. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haint, 0xFFFFFFFF);
  50754. +
  50755. + /* Mask Device Interrupts */
  50756. + if (!core_if->multiproc_int_enable) {
  50757. + /* Clear and disable IN Endpoint interrupts */
  50758. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, 0);
  50759. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  50760. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50761. + diepint, 0xFFFFFFFF);
  50762. + }
  50763. +
  50764. + /* Clear and disable OUT Endpoint interrupts */
  50765. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, 0);
  50766. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  50767. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50768. + doepint, 0xFFFFFFFF);
  50769. + }
  50770. +
  50771. + /* Clear and disable DAINT */
  50772. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daint,
  50773. + 0xFFFFFFFF);
  50774. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, 0);
  50775. + } else {
  50776. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  50777. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50778. + diepeachintmsk[i], 0);
  50779. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->
  50780. + diepint, 0xFFFFFFFF);
  50781. + }
  50782. +
  50783. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  50784. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  50785. + doepeachintmsk[i], 0);
  50786. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->
  50787. + doepint, 0xFFFFFFFF);
  50788. + }
  50789. +
  50790. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  50791. + 0);
  50792. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->deachint,
  50793. + 0xFFFFFFFF);
  50794. +
  50795. + }
  50796. +
  50797. + /* Disable interrupts */
  50798. + ahbcfg.b.glblintrmsk = 1;
  50799. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  50800. +
  50801. + /* Disable all interrupts. */
  50802. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  50803. +
  50804. + /* Clear any pending interrupts */
  50805. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50806. +
  50807. + /* Clear any pending OTG Interrupts */
  50808. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, 0xFFFFFFFF);
  50809. +}
  50810. +
  50811. +/**
  50812. + * Unmask Port Connection Detected interrupt
  50813. + *
  50814. + */
  50815. +static void unmask_conn_det_intr(dwc_otg_core_if_t * core_if)
  50816. +{
  50817. + gintmsk_data_t gintmsk = {.d32 = 0,.b.portintr = 1 };
  50818. +
  50819. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  50820. +}
  50821. +#endif
  50822. +
  50823. +/**
  50824. + * Starts the ADP Probing
  50825. + *
  50826. + * @param core_if the pointer to core_if structure.
  50827. + */
  50828. +uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if)
  50829. +{
  50830. +
  50831. + adpctl_data_t adpctl = {.d32 = 0};
  50832. + gpwrdn_data_t gpwrdn;
  50833. +#if 0
  50834. + adpctl_data_t adpctl_int = {.d32 = 0, .b.adp_prb_int = 1,
  50835. + .b.adp_sns_int = 1, b.adp_tmout_int};
  50836. +#endif
  50837. + dwc_otg_disable_global_interrupts(core_if);
  50838. + DWC_PRINTF("ADP Probe Start\n");
  50839. + core_if->adp.probe_enabled = 1;
  50840. +
  50841. + adpctl.b.adpres = 1;
  50842. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50843. +
  50844. + while (adpctl.b.adpres) {
  50845. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50846. + }
  50847. +
  50848. + adpctl.d32 = 0;
  50849. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  50850. +
  50851. + /* In Host mode unmask SRP detected interrupt */
  50852. + gpwrdn.d32 = 0;
  50853. + gpwrdn.b.sts_chngint_msk = 1;
  50854. + if (!gpwrdn.b.idsts) {
  50855. + gpwrdn.b.srp_det_msk = 1;
  50856. + }
  50857. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  50858. +
  50859. + adpctl.b.adp_tmout_int_msk = 1;
  50860. + adpctl.b.adp_prb_int_msk = 1;
  50861. + adpctl.b.prb_dschg = 1;
  50862. + adpctl.b.prb_delta = 1;
  50863. + adpctl.b.prb_per = 1;
  50864. + adpctl.b.adpen = 1;
  50865. + adpctl.b.enaprb = 1;
  50866. +
  50867. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50868. + DWC_PRINTF("ADP Probe Finish\n");
  50869. + return 0;
  50870. +}
  50871. +
  50872. +/**
  50873. + * Starts the ADP Sense timer to detect if ADP Sense interrupt is not asserted
  50874. + * within 3 seconds.
  50875. + *
  50876. + * @param core_if the pointer to core_if strucure.
  50877. + */
  50878. +void dwc_otg_adp_sense_timer_start(dwc_otg_core_if_t * core_if)
  50879. +{
  50880. + core_if->adp.sense_timer_started = 1;
  50881. + DWC_TIMER_SCHEDULE(core_if->adp.sense_timer, 3000 /* 3 secs */ );
  50882. +}
  50883. +
  50884. +/**
  50885. + * Starts the ADP Sense
  50886. + *
  50887. + * @param core_if the pointer to core_if strucure.
  50888. + */
  50889. +uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if)
  50890. +{
  50891. + adpctl_data_t adpctl;
  50892. +
  50893. + DWC_PRINTF("ADP Sense Start\n");
  50894. +
  50895. + /* Unmask ADP sense interrupt and mask all other from the core */
  50896. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50897. + adpctl.b.adp_sns_int_msk = 1;
  50898. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50899. + dwc_otg_disable_global_interrupts(core_if); // vahrama
  50900. +
  50901. + /* Set ADP reset bit*/
  50902. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50903. + adpctl.b.adpres = 1;
  50904. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50905. +
  50906. + while (adpctl.b.adpres) {
  50907. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50908. + }
  50909. +
  50910. + adpctl.b.adpres = 0;
  50911. + adpctl.b.adpen = 1;
  50912. + adpctl.b.enasns = 1;
  50913. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50914. +
  50915. + dwc_otg_adp_sense_timer_start(core_if);
  50916. +
  50917. + return 0;
  50918. +}
  50919. +
  50920. +/**
  50921. + * Stops the ADP Probing
  50922. + *
  50923. + * @param core_if the pointer to core_if strucure.
  50924. + */
  50925. +uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if)
  50926. +{
  50927. +
  50928. + adpctl_data_t adpctl;
  50929. + DWC_PRINTF("Stop ADP probe\n");
  50930. + core_if->adp.probe_enabled = 0;
  50931. + core_if->adp.probe_counter = 0;
  50932. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  50933. +
  50934. + adpctl.b.adpen = 0;
  50935. + adpctl.b.adp_prb_int = 1;
  50936. + adpctl.b.adp_tmout_int = 1;
  50937. + adpctl.b.adp_sns_int = 1;
  50938. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50939. +
  50940. + return 0;
  50941. +}
  50942. +
  50943. +/**
  50944. + * Stops the ADP Sensing
  50945. + *
  50946. + * @param core_if the pointer to core_if strucure.
  50947. + */
  50948. +uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if)
  50949. +{
  50950. + adpctl_data_t adpctl;
  50951. +
  50952. + core_if->adp.sense_enabled = 0;
  50953. +
  50954. + adpctl.d32 = dwc_otg_adp_read_reg_filter(core_if);
  50955. + adpctl.b.enasns = 0;
  50956. + adpctl.b.adp_sns_int = 1;
  50957. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  50958. +
  50959. + return 0;
  50960. +}
  50961. +
  50962. +/**
  50963. + * Called to turn on the VBUS after initial ADP probe in host mode.
  50964. + * If port power was already enabled in cil_hcd_start function then
  50965. + * only schedule a timer.
  50966. + *
  50967. + * @param core_if the pointer to core_if structure.
  50968. + */
  50969. +void dwc_otg_adp_turnon_vbus(dwc_otg_core_if_t * core_if)
  50970. +{
  50971. + hprt0_data_t hprt0 = {.d32 = 0 };
  50972. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  50973. + DWC_PRINTF("Turn on VBUS for 1.1s, port power is %d\n", hprt0.b.prtpwr);
  50974. +
  50975. + if (hprt0.b.prtpwr == 0) {
  50976. + hprt0.b.prtpwr = 1;
  50977. + //DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  50978. + }
  50979. +
  50980. + dwc_otg_adp_vbuson_timer_start(core_if);
  50981. +}
  50982. +
  50983. +/**
  50984. + * Called right after driver is loaded
  50985. + * to perform initial actions for ADP
  50986. + *
  50987. + * @param core_if the pointer to core_if structure.
  50988. + * @param is_host - flag for current mode of operation either from GINTSTS or GPWRDN
  50989. + */
  50990. +void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host)
  50991. +{
  50992. + gpwrdn_data_t gpwrdn;
  50993. +
  50994. + DWC_PRINTF("ADP Initial Start\n");
  50995. + core_if->adp.adp_started = 1;
  50996. +
  50997. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  50998. + dwc_otg_disable_global_interrupts(core_if);
  50999. + if (is_host) {
  51000. + DWC_PRINTF("HOST MODE\n");
  51001. + /* Enable Power Down Logic Interrupt*/
  51002. + gpwrdn.d32 = 0;
  51003. + gpwrdn.b.pmuintsel = 1;
  51004. + gpwrdn.b.pmuactv = 1;
  51005. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51006. + /* Initialize first ADP probe to obtain Ramp Time value */
  51007. + core_if->adp.initial_probe = 1;
  51008. + dwc_otg_adp_probe_start(core_if);
  51009. + } else {
  51010. + gotgctl_data_t gotgctl;
  51011. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51012. + DWC_PRINTF("DEVICE MODE\n");
  51013. + if (gotgctl.b.bsesvld == 0) {
  51014. + /* Enable Power Down Logic Interrupt*/
  51015. + gpwrdn.d32 = 0;
  51016. + DWC_PRINTF("VBUS is not valid - start ADP probe\n");
  51017. + gpwrdn.b.pmuintsel = 1;
  51018. + gpwrdn.b.pmuactv = 1;
  51019. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  51020. + core_if->adp.initial_probe = 1;
  51021. + dwc_otg_adp_probe_start(core_if);
  51022. + } else {
  51023. + DWC_PRINTF("VBUS is valid - initialize core as a Device\n");
  51024. + core_if->op_state = B_PERIPHERAL;
  51025. + dwc_otg_core_init(core_if);
  51026. + dwc_otg_enable_global_interrupts(core_if);
  51027. + cil_pcd_start(core_if);
  51028. + dwc_otg_dump_global_registers(core_if);
  51029. + dwc_otg_dump_dev_registers(core_if);
  51030. + }
  51031. + }
  51032. +}
  51033. +
  51034. +void dwc_otg_adp_init(dwc_otg_core_if_t * core_if)
  51035. +{
  51036. + core_if->adp.adp_started = 0;
  51037. + core_if->adp.initial_probe = 0;
  51038. + core_if->adp.probe_timer_values[0] = -1;
  51039. + core_if->adp.probe_timer_values[1] = -1;
  51040. + core_if->adp.probe_enabled = 0;
  51041. + core_if->adp.sense_enabled = 0;
  51042. + core_if->adp.sense_timer_started = 0;
  51043. + core_if->adp.vbuson_timer_started = 0;
  51044. + core_if->adp.probe_counter = 0;
  51045. + core_if->adp.gpwrdn = 0;
  51046. + core_if->adp.attached = DWC_OTG_ADP_UNKOWN;
  51047. + /* Initialize timers */
  51048. + core_if->adp.sense_timer =
  51049. + DWC_TIMER_ALLOC("ADP SENSE TIMER", adp_sense_timeout, core_if);
  51050. + core_if->adp.vbuson_timer =
  51051. + DWC_TIMER_ALLOC("ADP VBUS ON TIMER", adp_vbuson_timeout, core_if);
  51052. + if (!core_if->adp.sense_timer || !core_if->adp.vbuson_timer)
  51053. + {
  51054. + DWC_ERROR("Could not allocate memory for ADP timers\n");
  51055. + }
  51056. +}
  51057. +
  51058. +void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if)
  51059. +{
  51060. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  51061. + gpwrdn.b.pmuintsel = 1;
  51062. + gpwrdn.b.pmuactv = 1;
  51063. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51064. +
  51065. + if (core_if->adp.probe_enabled)
  51066. + dwc_otg_adp_probe_stop(core_if);
  51067. + if (core_if->adp.sense_enabled)
  51068. + dwc_otg_adp_sense_stop(core_if);
  51069. + if (core_if->adp.sense_timer_started)
  51070. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51071. + if (core_if->adp.vbuson_timer_started)
  51072. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  51073. + DWC_TIMER_FREE(core_if->adp.sense_timer);
  51074. + DWC_TIMER_FREE(core_if->adp.vbuson_timer);
  51075. +}
  51076. +
  51077. +/////////////////////////////////////////////////////////////////////
  51078. +////////////// ADP Interrupt Handlers ///////////////////////////////
  51079. +/////////////////////////////////////////////////////////////////////
  51080. +/**
  51081. + * This function sets Ramp Timer values
  51082. + */
  51083. +static uint32_t set_timer_value(dwc_otg_core_if_t * core_if, uint32_t val)
  51084. +{
  51085. + if (core_if->adp.probe_timer_values[0] == -1) {
  51086. + core_if->adp.probe_timer_values[0] = val;
  51087. + core_if->adp.probe_timer_values[1] = -1;
  51088. + return 1;
  51089. + } else {
  51090. + core_if->adp.probe_timer_values[1] =
  51091. + core_if->adp.probe_timer_values[0];
  51092. + core_if->adp.probe_timer_values[0] = val;
  51093. + return 0;
  51094. + }
  51095. +}
  51096. +
  51097. +/**
  51098. + * This function compares Ramp Timer values
  51099. + */
  51100. +static uint32_t compare_timer_values(dwc_otg_core_if_t * core_if)
  51101. +{
  51102. + uint32_t diff;
  51103. + if (core_if->adp.probe_timer_values[0]>=core_if->adp.probe_timer_values[1])
  51104. + diff = core_if->adp.probe_timer_values[0]-core_if->adp.probe_timer_values[1];
  51105. + else
  51106. + diff = core_if->adp.probe_timer_values[1]-core_if->adp.probe_timer_values[0];
  51107. + if(diff < 2) {
  51108. + return 0;
  51109. + } else {
  51110. + return 1;
  51111. + }
  51112. +}
  51113. +
  51114. +/**
  51115. + * This function handles ADP Probe Interrupts
  51116. + */
  51117. +static int32_t dwc_otg_adp_handle_prb_intr(dwc_otg_core_if_t * core_if,
  51118. + uint32_t val)
  51119. +{
  51120. + adpctl_data_t adpctl = {.d32 = 0 };
  51121. + gpwrdn_data_t gpwrdn, temp;
  51122. + adpctl.d32 = val;
  51123. +
  51124. + temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51125. + core_if->adp.probe_counter++;
  51126. + core_if->adp.gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51127. + if (adpctl.b.rtim == 0 && !temp.b.idsts){
  51128. + DWC_PRINTF("RTIM value is 0\n");
  51129. + goto exit;
  51130. + }
  51131. + if (set_timer_value(core_if, adpctl.b.rtim) &&
  51132. + core_if->adp.initial_probe) {
  51133. + core_if->adp.initial_probe = 0;
  51134. + dwc_otg_adp_probe_stop(core_if);
  51135. + gpwrdn.d32 = 0;
  51136. + gpwrdn.b.pmuactv = 1;
  51137. + gpwrdn.b.pmuintsel = 1;
  51138. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51139. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  51140. +
  51141. + /* check which value is for device mode and which for Host mode */
  51142. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51143. + /*
  51144. + * Turn on VBUS after initial ADP probe.
  51145. + */
  51146. + core_if->op_state = A_HOST;
  51147. + dwc_otg_enable_global_interrupts(core_if);
  51148. + DWC_SPINUNLOCK(core_if->lock);
  51149. + cil_hcd_start(core_if);
  51150. + dwc_otg_adp_turnon_vbus(core_if);
  51151. + DWC_SPINLOCK(core_if->lock);
  51152. + } else {
  51153. + /*
  51154. + * Initiate SRP after initial ADP probe.
  51155. + */
  51156. + dwc_otg_enable_global_interrupts(core_if);
  51157. + dwc_otg_initiate_srp(core_if);
  51158. + }
  51159. + } else if (core_if->adp.probe_counter > 2){
  51160. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51161. + if (compare_timer_values(core_if)) {
  51162. + DWC_PRINTF("Difference in timer values !!! \n");
  51163. +// core_if->adp.attached = DWC_OTG_ADP_ATTACHED;
  51164. + dwc_otg_adp_probe_stop(core_if);
  51165. +
  51166. + /* Power on the core */
  51167. + if (core_if->power_down == 2) {
  51168. + gpwrdn.b.pwrdnswtch = 1;
  51169. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51170. + gpwrdn, 0, gpwrdn.d32);
  51171. + }
  51172. +
  51173. + /* check which value is for device mode and which for Host mode */
  51174. + if (!temp.b.idsts) { /* considered host mode value is 0 */
  51175. + /* Disable Interrupt from Power Down Logic */
  51176. + gpwrdn.d32 = 0;
  51177. + gpwrdn.b.pmuintsel = 1;
  51178. + gpwrdn.b.pmuactv = 1;
  51179. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51180. + gpwrdn, gpwrdn.d32, 0);
  51181. +
  51182. + /*
  51183. + * Initialize the Core for Host mode.
  51184. + */
  51185. + core_if->op_state = A_HOST;
  51186. + dwc_otg_core_init(core_if);
  51187. + dwc_otg_enable_global_interrupts(core_if);
  51188. + cil_hcd_start(core_if);
  51189. + } else {
  51190. + gotgctl_data_t gotgctl;
  51191. + /* Mask SRP detected interrupt from Power Down Logic */
  51192. + gpwrdn.d32 = 0;
  51193. + gpwrdn.b.srp_det_msk = 1;
  51194. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51195. + gpwrdn, gpwrdn.d32, 0);
  51196. +
  51197. + /* Disable Power Down Logic */
  51198. + gpwrdn.d32 = 0;
  51199. + gpwrdn.b.pmuintsel = 1;
  51200. + gpwrdn.b.pmuactv = 1;
  51201. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51202. + gpwrdn, gpwrdn.d32, 0);
  51203. +
  51204. + /*
  51205. + * Initialize the Core for Device mode.
  51206. + */
  51207. + core_if->op_state = B_PERIPHERAL;
  51208. + dwc_otg_core_init(core_if);
  51209. + dwc_otg_enable_global_interrupts(core_if);
  51210. + cil_pcd_start(core_if);
  51211. +
  51212. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  51213. + if (!gotgctl.b.bsesvld) {
  51214. + dwc_otg_initiate_srp(core_if);
  51215. + }
  51216. + }
  51217. + }
  51218. + if (core_if->power_down == 2) {
  51219. + if (gpwrdn.b.bsessvld) {
  51220. + /* Mask SRP detected interrupt from Power Down Logic */
  51221. + gpwrdn.d32 = 0;
  51222. + gpwrdn.b.srp_det_msk = 1;
  51223. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51224. +
  51225. + /* Disable Power Down Logic */
  51226. + gpwrdn.d32 = 0;
  51227. + gpwrdn.b.pmuactv = 1;
  51228. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  51229. +
  51230. + /*
  51231. + * Initialize the Core for Device mode.
  51232. + */
  51233. + core_if->op_state = B_PERIPHERAL;
  51234. + dwc_otg_core_init(core_if);
  51235. + dwc_otg_enable_global_interrupts(core_if);
  51236. + cil_pcd_start(core_if);
  51237. + }
  51238. + }
  51239. + }
  51240. +exit:
  51241. + /* Clear interrupt */
  51242. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51243. + adpctl.b.adp_prb_int = 1;
  51244. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51245. +
  51246. + return 0;
  51247. +}
  51248. +
  51249. +/**
  51250. + * This function hadles ADP Sense Interrupt
  51251. + */
  51252. +static int32_t dwc_otg_adp_handle_sns_intr(dwc_otg_core_if_t * core_if)
  51253. +{
  51254. + adpctl_data_t adpctl;
  51255. + /* Stop ADP Sense timer */
  51256. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  51257. +
  51258. + /* Restart ADP Sense timer */
  51259. + dwc_otg_adp_sense_timer_start(core_if);
  51260. +
  51261. + /* Clear interrupt */
  51262. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51263. + adpctl.b.adp_sns_int = 1;
  51264. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51265. +
  51266. + return 0;
  51267. +}
  51268. +
  51269. +/**
  51270. + * This function handles ADP Probe Interrupts
  51271. + */
  51272. +static int32_t dwc_otg_adp_handle_prb_tmout_intr(dwc_otg_core_if_t * core_if,
  51273. + uint32_t val)
  51274. +{
  51275. + adpctl_data_t adpctl = {.d32 = 0 };
  51276. + adpctl.d32 = val;
  51277. + set_timer_value(core_if, adpctl.b.rtim);
  51278. +
  51279. + /* Clear interrupt */
  51280. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51281. + adpctl.b.adp_tmout_int = 1;
  51282. + dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51283. +
  51284. + return 0;
  51285. +}
  51286. +
  51287. +/**
  51288. + * ADP Interrupt handler.
  51289. + *
  51290. + */
  51291. +int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if)
  51292. +{
  51293. + int retval = 0;
  51294. + adpctl_data_t adpctl = {.d32 = 0};
  51295. +
  51296. + adpctl.d32 = dwc_otg_adp_read_reg(core_if);
  51297. + DWC_PRINTF("ADPCTL = %08x\n",adpctl.d32);
  51298. +
  51299. + if (adpctl.b.adp_sns_int & adpctl.b.adp_sns_int_msk) {
  51300. + DWC_PRINTF("ADP Sense interrupt\n");
  51301. + retval |= dwc_otg_adp_handle_sns_intr(core_if);
  51302. + }
  51303. + if (adpctl.b.adp_tmout_int & adpctl.b.adp_tmout_int_msk) {
  51304. + DWC_PRINTF("ADP timeout interrupt\n");
  51305. + retval |= dwc_otg_adp_handle_prb_tmout_intr(core_if, adpctl.d32);
  51306. + }
  51307. + if (adpctl.b.adp_prb_int & adpctl.b.adp_prb_int_msk) {
  51308. + DWC_PRINTF("ADP Probe interrupt\n");
  51309. + adpctl.b.adp_prb_int = 1;
  51310. + retval |= dwc_otg_adp_handle_prb_intr(core_if, adpctl.d32);
  51311. + }
  51312. +
  51313. +// dwc_otg_adp_modify_reg(core_if, adpctl.d32, 0);
  51314. + //dwc_otg_adp_write_reg(core_if, adpctl.d32);
  51315. + DWC_PRINTF("RETURN FROM ADP ISR\n");
  51316. +
  51317. + return retval;
  51318. +}
  51319. +
  51320. +/**
  51321. + *
  51322. + * @param core_if Programming view of DWC_otg controller.
  51323. + */
  51324. +int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if)
  51325. +{
  51326. +
  51327. +#ifndef DWC_HOST_ONLY
  51328. + hprt0_data_t hprt0;
  51329. + gpwrdn_data_t gpwrdn;
  51330. + DWC_DEBUGPL(DBG_ANY, "++ Power Down Logic Session Request Interrupt++\n");
  51331. +
  51332. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  51333. + /* check which value is for device mode and which for Host mode */
  51334. + if (!gpwrdn.b.idsts) { /* considered host mode value is 0 */
  51335. + DWC_PRINTF("SRP: Host mode\n");
  51336. +
  51337. + if (core_if->adp_enable) {
  51338. + dwc_otg_adp_probe_stop(core_if);
  51339. +
  51340. + /* Power on the core */
  51341. + if (core_if->power_down == 2) {
  51342. + gpwrdn.b.pwrdnswtch = 1;
  51343. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51344. + gpwrdn, 0, gpwrdn.d32);
  51345. + }
  51346. +
  51347. + core_if->op_state = A_HOST;
  51348. + dwc_otg_core_init(core_if);
  51349. + dwc_otg_enable_global_interrupts(core_if);
  51350. + cil_hcd_start(core_if);
  51351. + }
  51352. +
  51353. + /* Turn on the port power bit. */
  51354. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  51355. + hprt0.b.prtpwr = 1;
  51356. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  51357. +
  51358. + /* Start the Connection timer. So a message can be displayed
  51359. + * if connect does not occur within 10 seconds. */
  51360. + cil_hcd_session_start(core_if);
  51361. + } else {
  51362. + DWC_PRINTF("SRP: Device mode %s\n", __FUNCTION__);
  51363. + if (core_if->adp_enable) {
  51364. + dwc_otg_adp_probe_stop(core_if);
  51365. +
  51366. + /* Power on the core */
  51367. + if (core_if->power_down == 2) {
  51368. + gpwrdn.b.pwrdnswtch = 1;
  51369. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  51370. + gpwrdn, 0, gpwrdn.d32);
  51371. + }
  51372. +
  51373. + gpwrdn.d32 = 0;
  51374. + gpwrdn.b.pmuactv = 0;
  51375. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  51376. + gpwrdn.d32);
  51377. +
  51378. + core_if->op_state = B_PERIPHERAL;
  51379. + dwc_otg_core_init(core_if);
  51380. + dwc_otg_enable_global_interrupts(core_if);
  51381. + cil_pcd_start(core_if);
  51382. + }
  51383. + }
  51384. +#endif
  51385. + return 1;
  51386. +}
  51387. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_adp.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h
  51388. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_adp.h 1970-01-01 01:00:00.000000000 +0100
  51389. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_adp.h 2014-06-11 21:03:43.000000000 +0200
  51390. @@ -0,0 +1,80 @@
  51391. +/* ==========================================================================
  51392. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_adp.h $
  51393. + * $Revision: #7 $
  51394. + * $Date: 2011/10/24 $
  51395. + * $Change: 1871159 $
  51396. + *
  51397. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51398. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51399. + * otherwise expressly agreed to in writing between Synopsys and you.
  51400. + *
  51401. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51402. + * any End User Software License Agreement or Agreement for Licensed Product
  51403. + * with Synopsys or any supplement thereto. You are permitted to use and
  51404. + * redistribute this Software in source and binary forms, with or without
  51405. + * modification, provided that redistributions of source code must retain this
  51406. + * notice. You may not view, use, disclose, copy or distribute this file or
  51407. + * any information contained herein except pursuant to this license grant from
  51408. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51409. + * below, then you are not authorized to use the Software.
  51410. + *
  51411. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51412. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51413. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51414. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51415. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51416. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51417. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51418. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51419. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51420. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51421. + * DAMAGE.
  51422. + * ========================================================================== */
  51423. +
  51424. +#ifndef __DWC_OTG_ADP_H__
  51425. +#define __DWC_OTG_ADP_H__
  51426. +
  51427. +/**
  51428. + * @file
  51429. + *
  51430. + * This file contains the Attach Detect Protocol interfaces and defines
  51431. + * (functions) and structures for Linux.
  51432. + *
  51433. + */
  51434. +
  51435. +#define DWC_OTG_ADP_UNATTACHED 0
  51436. +#define DWC_OTG_ADP_ATTACHED 1
  51437. +#define DWC_OTG_ADP_UNKOWN 2
  51438. +
  51439. +typedef struct dwc_otg_adp {
  51440. + uint32_t adp_started;
  51441. + uint32_t initial_probe;
  51442. + int32_t probe_timer_values[2];
  51443. + uint32_t probe_enabled;
  51444. + uint32_t sense_enabled;
  51445. + dwc_timer_t *sense_timer;
  51446. + uint32_t sense_timer_started;
  51447. + dwc_timer_t *vbuson_timer;
  51448. + uint32_t vbuson_timer_started;
  51449. + uint32_t attached;
  51450. + uint32_t probe_counter;
  51451. + uint32_t gpwrdn;
  51452. +} dwc_otg_adp_t;
  51453. +
  51454. +/**
  51455. + * Attach Detect Protocol functions
  51456. + */
  51457. +
  51458. +extern void dwc_otg_adp_write_reg(dwc_otg_core_if_t * core_if, uint32_t value);
  51459. +extern uint32_t dwc_otg_adp_read_reg(dwc_otg_core_if_t * core_if);
  51460. +extern uint32_t dwc_otg_adp_probe_start(dwc_otg_core_if_t * core_if);
  51461. +extern uint32_t dwc_otg_adp_sense_start(dwc_otg_core_if_t * core_if);
  51462. +extern uint32_t dwc_otg_adp_probe_stop(dwc_otg_core_if_t * core_if);
  51463. +extern uint32_t dwc_otg_adp_sense_stop(dwc_otg_core_if_t * core_if);
  51464. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  51465. +extern void dwc_otg_adp_init(dwc_otg_core_if_t * core_if);
  51466. +extern void dwc_otg_adp_remove(dwc_otg_core_if_t * core_if);
  51467. +extern int32_t dwc_otg_adp_handle_intr(dwc_otg_core_if_t * core_if);
  51468. +extern int32_t dwc_otg_adp_handle_srp_intr(dwc_otg_core_if_t * core_if);
  51469. +
  51470. +#endif //__DWC_OTG_ADP_H__
  51471. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_attr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c
  51472. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_attr.c 1970-01-01 01:00:00.000000000 +0100
  51473. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.c 2014-06-11 21:03:43.000000000 +0200
  51474. @@ -0,0 +1,1210 @@
  51475. +/* ==========================================================================
  51476. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.c $
  51477. + * $Revision: #44 $
  51478. + * $Date: 2010/11/29 $
  51479. + * $Change: 1636033 $
  51480. + *
  51481. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  51482. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  51483. + * otherwise expressly agreed to in writing between Synopsys and you.
  51484. + *
  51485. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  51486. + * any End User Software License Agreement or Agreement for Licensed Product
  51487. + * with Synopsys or any supplement thereto. You are permitted to use and
  51488. + * redistribute this Software in source and binary forms, with or without
  51489. + * modification, provided that redistributions of source code must retain this
  51490. + * notice. You may not view, use, disclose, copy or distribute this file or
  51491. + * any information contained herein except pursuant to this license grant from
  51492. + * Synopsys. If you do not agree with this notice, including the disclaimer
  51493. + * below, then you are not authorized to use the Software.
  51494. + *
  51495. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  51496. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51497. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  51498. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  51499. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  51500. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  51501. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  51502. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  51503. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  51504. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  51505. + * DAMAGE.
  51506. + * ========================================================================== */
  51507. +
  51508. +/** @file
  51509. + *
  51510. + * The diagnostic interface will provide access to the controller for
  51511. + * bringing up the hardware and testing. The Linux driver attributes
  51512. + * feature will be used to provide the Linux Diagnostic
  51513. + * Interface. These attributes are accessed through sysfs.
  51514. + */
  51515. +
  51516. +/** @page "Linux Module Attributes"
  51517. + *
  51518. + * The Linux module attributes feature is used to provide the Linux
  51519. + * Diagnostic Interface. These attributes are accessed through sysfs.
  51520. + * The diagnostic interface will provide access to the controller for
  51521. + * bringing up the hardware and testing.
  51522. +
  51523. + The following table shows the attributes.
  51524. + <table>
  51525. + <tr>
  51526. + <td><b> Name</b></td>
  51527. + <td><b> Description</b></td>
  51528. + <td><b> Access</b></td>
  51529. + </tr>
  51530. +
  51531. + <tr>
  51532. + <td> mode </td>
  51533. + <td> Returns the current mode: 0 for device mode, 1 for host mode</td>
  51534. + <td> Read</td>
  51535. + </tr>
  51536. +
  51537. + <tr>
  51538. + <td> hnpcapable </td>
  51539. + <td> Gets or sets the "HNP-capable" bit in the Core USB Configuraton Register.
  51540. + Read returns the current value.</td>
  51541. + <td> Read/Write</td>
  51542. + </tr>
  51543. +
  51544. + <tr>
  51545. + <td> srpcapable </td>
  51546. + <td> Gets or sets the "SRP-capable" bit in the Core USB Configuraton Register.
  51547. + Read returns the current value.</td>
  51548. + <td> Read/Write</td>
  51549. + </tr>
  51550. +
  51551. + <tr>
  51552. + <td> hsic_connect </td>
  51553. + <td> Gets or sets the "HSIC-Connect" bit in the GLPMCFG Register.
  51554. + Read returns the current value.</td>
  51555. + <td> Read/Write</td>
  51556. + </tr>
  51557. +
  51558. + <tr>
  51559. + <td> inv_sel_hsic </td>
  51560. + <td> Gets or sets the "Invert Select HSIC" bit in the GLPMFG Register.
  51561. + Read returns the current value.</td>
  51562. + <td> Read/Write</td>
  51563. + </tr>
  51564. +
  51565. + <tr>
  51566. + <td> hnp </td>
  51567. + <td> Initiates the Host Negotiation Protocol. Read returns the status.</td>
  51568. + <td> Read/Write</td>
  51569. + </tr>
  51570. +
  51571. + <tr>
  51572. + <td> srp </td>
  51573. + <td> Initiates the Session Request Protocol. Read returns the status.</td>
  51574. + <td> Read/Write</td>
  51575. + </tr>
  51576. +
  51577. + <tr>
  51578. + <td> buspower </td>
  51579. + <td> Gets or sets the Power State of the bus (0 - Off or 1 - On)</td>
  51580. + <td> Read/Write</td>
  51581. + </tr>
  51582. +
  51583. + <tr>
  51584. + <td> bussuspend </td>
  51585. + <td> Suspends the USB bus.</td>
  51586. + <td> Read/Write</td>
  51587. + </tr>
  51588. +
  51589. + <tr>
  51590. + <td> busconnected </td>
  51591. + <td> Gets the connection status of the bus</td>
  51592. + <td> Read</td>
  51593. + </tr>
  51594. +
  51595. + <tr>
  51596. + <td> gotgctl </td>
  51597. + <td> Gets or sets the Core Control Status Register.</td>
  51598. + <td> Read/Write</td>
  51599. + </tr>
  51600. +
  51601. + <tr>
  51602. + <td> gusbcfg </td>
  51603. + <td> Gets or sets the Core USB Configuration Register</td>
  51604. + <td> Read/Write</td>
  51605. + </tr>
  51606. +
  51607. + <tr>
  51608. + <td> grxfsiz </td>
  51609. + <td> Gets or sets the Receive FIFO Size Register</td>
  51610. + <td> Read/Write</td>
  51611. + </tr>
  51612. +
  51613. + <tr>
  51614. + <td> gnptxfsiz </td>
  51615. + <td> Gets or sets the non-periodic Transmit Size Register</td>
  51616. + <td> Read/Write</td>
  51617. + </tr>
  51618. +
  51619. + <tr>
  51620. + <td> gpvndctl </td>
  51621. + <td> Gets or sets the PHY Vendor Control Register</td>
  51622. + <td> Read/Write</td>
  51623. + </tr>
  51624. +
  51625. + <tr>
  51626. + <td> ggpio </td>
  51627. + <td> Gets the value in the lower 16-bits of the General Purpose IO Register
  51628. + or sets the upper 16 bits.</td>
  51629. + <td> Read/Write</td>
  51630. + </tr>
  51631. +
  51632. + <tr>
  51633. + <td> guid </td>
  51634. + <td> Gets or sets the value of the User ID Register</td>
  51635. + <td> Read/Write</td>
  51636. + </tr>
  51637. +
  51638. + <tr>
  51639. + <td> gsnpsid </td>
  51640. + <td> Gets the value of the Synopsys ID Regester</td>
  51641. + <td> Read</td>
  51642. + </tr>
  51643. +
  51644. + <tr>
  51645. + <td> devspeed </td>
  51646. + <td> Gets or sets the device speed setting in the DCFG register</td>
  51647. + <td> Read/Write</td>
  51648. + </tr>
  51649. +
  51650. + <tr>
  51651. + <td> enumspeed </td>
  51652. + <td> Gets the device enumeration Speed.</td>
  51653. + <td> Read</td>
  51654. + </tr>
  51655. +
  51656. + <tr>
  51657. + <td> hptxfsiz </td>
  51658. + <td> Gets the value of the Host Periodic Transmit FIFO</td>
  51659. + <td> Read</td>
  51660. + </tr>
  51661. +
  51662. + <tr>
  51663. + <td> hprt0 </td>
  51664. + <td> Gets or sets the value in the Host Port Control and Status Register</td>
  51665. + <td> Read/Write</td>
  51666. + </tr>
  51667. +
  51668. + <tr>
  51669. + <td> regoffset </td>
  51670. + <td> Sets the register offset for the next Register Access</td>
  51671. + <td> Read/Write</td>
  51672. + </tr>
  51673. +
  51674. + <tr>
  51675. + <td> regvalue </td>
  51676. + <td> Gets or sets the value of the register at the offset in the regoffset attribute.</td>
  51677. + <td> Read/Write</td>
  51678. + </tr>
  51679. +
  51680. + <tr>
  51681. + <td> remote_wakeup </td>
  51682. + <td> On read, shows the status of Remote Wakeup. On write, initiates a remote
  51683. + wakeup of the host. When bit 0 is 1 and Remote Wakeup is enabled, the Remote
  51684. + Wakeup signalling bit in the Device Control Register is set for 1
  51685. + milli-second.</td>
  51686. + <td> Read/Write</td>
  51687. + </tr>
  51688. +
  51689. + <tr>
  51690. + <td> rem_wakeup_pwrdn </td>
  51691. + <td> On read, shows the status core - hibernated or not. On write, initiates
  51692. + a remote wakeup of the device from Hibernation. </td>
  51693. + <td> Read/Write</td>
  51694. + </tr>
  51695. +
  51696. + <tr>
  51697. + <td> mode_ch_tim_en </td>
  51698. + <td> This bit is used to enable or disable the host core to wait for 200 PHY
  51699. + clock cycles at the end of Resume to change the opmode signal to the PHY to 00
  51700. + after Suspend or LPM. </td>
  51701. + <td> Read/Write</td>
  51702. + </tr>
  51703. +
  51704. + <tr>
  51705. + <td> fr_interval </td>
  51706. + <td> On read, shows the value of HFIR Frame Interval. On write, dynamically
  51707. + reload HFIR register during runtime. The application can write a value to this
  51708. + register only after the Port Enable bit of the Host Port Control and Status
  51709. + register (HPRT.PrtEnaPort) has been set </td>
  51710. + <td> Read/Write</td>
  51711. + </tr>
  51712. +
  51713. + <tr>
  51714. + <td> disconnect_us </td>
  51715. + <td> On read, shows the status of disconnect_device_us. On write, sets disconnect_us
  51716. + which causes soft disconnect for 100us. Applicable only for device mode of operation.</td>
  51717. + <td> Read/Write</td>
  51718. + </tr>
  51719. +
  51720. + <tr>
  51721. + <td> regdump </td>
  51722. + <td> Dumps the contents of core registers.</td>
  51723. + <td> Read</td>
  51724. + </tr>
  51725. +
  51726. + <tr>
  51727. + <td> spramdump </td>
  51728. + <td> Dumps the contents of core registers.</td>
  51729. + <td> Read</td>
  51730. + </tr>
  51731. +
  51732. + <tr>
  51733. + <td> hcddump </td>
  51734. + <td> Dumps the current HCD state.</td>
  51735. + <td> Read</td>
  51736. + </tr>
  51737. +
  51738. + <tr>
  51739. + <td> hcd_frrem </td>
  51740. + <td> Shows the average value of the Frame Remaining
  51741. + field in the Host Frame Number/Frame Remaining register when an SOF interrupt
  51742. + occurs. This can be used to determine the average interrupt latency. Also
  51743. + shows the average Frame Remaining value for start_transfer and the "a" and
  51744. + "b" sample points. The "a" and "b" sample points may be used during debugging
  51745. + bto determine how long it takes to execute a section of the HCD code.</td>
  51746. + <td> Read</td>
  51747. + </tr>
  51748. +
  51749. + <tr>
  51750. + <td> rd_reg_test </td>
  51751. + <td> Displays the time required to read the GNPTXFSIZ register many times
  51752. + (the output shows the number of times the register is read).
  51753. + <td> Read</td>
  51754. + </tr>
  51755. +
  51756. + <tr>
  51757. + <td> wr_reg_test </td>
  51758. + <td> Displays the time required to write the GNPTXFSIZ register many times
  51759. + (the output shows the number of times the register is written).
  51760. + <td> Read</td>
  51761. + </tr>
  51762. +
  51763. + <tr>
  51764. + <td> lpm_response </td>
  51765. + <td> Gets or sets lpm_response mode. Applicable only in device mode.
  51766. + <td> Write</td>
  51767. + </tr>
  51768. +
  51769. + <tr>
  51770. + <td> sleep_status </td>
  51771. + <td> Shows sleep status of device.
  51772. + <td> Read</td>
  51773. + </tr>
  51774. +
  51775. + </table>
  51776. +
  51777. + Example usage:
  51778. + To get the current mode:
  51779. + cat /sys/devices/lm0/mode
  51780. +
  51781. + To power down the USB:
  51782. + echo 0 > /sys/devices/lm0/buspower
  51783. + */
  51784. +
  51785. +#include "dwc_otg_os_dep.h"
  51786. +#include "dwc_os.h"
  51787. +#include "dwc_otg_driver.h"
  51788. +#include "dwc_otg_attr.h"
  51789. +#include "dwc_otg_core_if.h"
  51790. +#include "dwc_otg_pcd_if.h"
  51791. +#include "dwc_otg_hcd_if.h"
  51792. +
  51793. +/*
  51794. + * MACROs for defining sysfs attribute
  51795. + */
  51796. +#ifdef LM_INTERFACE
  51797. +
  51798. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51799. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51800. +{ \
  51801. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51802. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51803. + uint32_t val; \
  51804. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51805. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51806. +}
  51807. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51808. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51809. + const char *buf, size_t count) \
  51810. +{ \
  51811. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51812. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51813. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51814. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51815. + return count; \
  51816. +}
  51817. +
  51818. +#elif defined(PCI_INTERFACE)
  51819. +
  51820. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51821. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51822. +{ \
  51823. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51824. + uint32_t val; \
  51825. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51826. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51827. +}
  51828. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51829. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51830. + const char *buf, size_t count) \
  51831. +{ \
  51832. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51833. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51834. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51835. + return count; \
  51836. +}
  51837. +
  51838. +#elif defined(PLATFORM_INTERFACE)
  51839. +
  51840. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51841. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51842. +{ \
  51843. + struct platform_device *platform_dev = \
  51844. + container_of(_dev, struct platform_device, dev); \
  51845. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51846. + uint32_t val; \
  51847. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51848. + __func__, _dev, platform_dev, otg_dev); \
  51849. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51850. + return sprintf (buf, "%s = 0x%x\n", _string_, val); \
  51851. +}
  51852. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51853. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51854. + const char *buf, size_t count) \
  51855. +{ \
  51856. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51857. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51858. + uint32_t set = simple_strtoul(buf, NULL, 16); \
  51859. + dwc_otg_set_##_otg_attr_name_(otg_dev->core_if, set);\
  51860. + return count; \
  51861. +}
  51862. +#endif
  51863. +
  51864. +/*
  51865. + * MACROs for defining sysfs attribute for 32-bit registers
  51866. + */
  51867. +#ifdef LM_INTERFACE
  51868. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51869. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51870. +{ \
  51871. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51872. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51873. + uint32_t val; \
  51874. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51875. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51876. +}
  51877. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51878. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51879. + const char *buf, size_t count) \
  51880. +{ \
  51881. + struct lm_device *lm_dev = container_of(_dev, struct lm_device, dev); \
  51882. + dwc_otg_device_t *otg_dev = lm_get_drvdata(lm_dev); \
  51883. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51884. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51885. + return count; \
  51886. +}
  51887. +#elif defined(PCI_INTERFACE)
  51888. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51889. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51890. +{ \
  51891. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51892. + uint32_t val; \
  51893. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51894. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51895. +}
  51896. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51897. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51898. + const char *buf, size_t count) \
  51899. +{ \
  51900. + dwc_otg_device_t *otg_dev = dev_get_drvdata(_dev); \
  51901. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51902. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51903. + return count; \
  51904. +}
  51905. +
  51906. +#elif defined(PLATFORM_INTERFACE)
  51907. +#include "dwc_otg_dbg.h"
  51908. +#define DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51909. +static ssize_t _otg_attr_name_##_show (struct device *_dev, struct device_attribute *attr, char *buf) \
  51910. +{ \
  51911. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51912. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51913. + uint32_t val; \
  51914. + DWC_PRINTF("%s(%p) -> platform_dev %p, otg_dev %p\n", \
  51915. + __func__, _dev, platform_dev, otg_dev); \
  51916. + val = dwc_otg_get_##_otg_attr_name_ (otg_dev->core_if); \
  51917. + return sprintf (buf, "%s = 0x%08x\n", _string_, val); \
  51918. +}
  51919. +#define DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51920. +static ssize_t _otg_attr_name_##_store (struct device *_dev, struct device_attribute *attr, \
  51921. + const char *buf, size_t count) \
  51922. +{ \
  51923. + struct platform_device *platform_dev = container_of(_dev, struct platform_device, dev); \
  51924. + dwc_otg_device_t *otg_dev = platform_get_drvdata(platform_dev); \
  51925. + uint32_t val = simple_strtoul(buf, NULL, 16); \
  51926. + dwc_otg_set_##_otg_attr_name_ (otg_dev->core_if, val); \
  51927. + return count; \
  51928. +}
  51929. +
  51930. +#endif
  51931. +
  51932. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RW(_otg_attr_name_,_string_) \
  51933. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51934. +DWC_OTG_DEVICE_ATTR_BITFIELD_STORE(_otg_attr_name_,_string_) \
  51935. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51936. +
  51937. +#define DWC_OTG_DEVICE_ATTR_BITFIELD_RO(_otg_attr_name_,_string_) \
  51938. +DWC_OTG_DEVICE_ATTR_BITFIELD_SHOW(_otg_attr_name_,_string_) \
  51939. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51940. +
  51941. +#define DWC_OTG_DEVICE_ATTR_REG32_RW(_otg_attr_name_,_addr_,_string_) \
  51942. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51943. +DWC_OTG_DEVICE_ATTR_REG_STORE(_otg_attr_name_,_string_) \
  51944. +DEVICE_ATTR(_otg_attr_name_,0644,_otg_attr_name_##_show,_otg_attr_name_##_store);
  51945. +
  51946. +#define DWC_OTG_DEVICE_ATTR_REG32_RO(_otg_attr_name_,_addr_,_string_) \
  51947. +DWC_OTG_DEVICE_ATTR_REG_SHOW(_otg_attr_name_,_string_) \
  51948. +DEVICE_ATTR(_otg_attr_name_,0444,_otg_attr_name_##_show,NULL);
  51949. +
  51950. +/** @name Functions for Show/Store of Attributes */
  51951. +/**@{*/
  51952. +
  51953. +/**
  51954. + * Helper function returning the otg_device structure of the given device
  51955. + */
  51956. +static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  51957. +{
  51958. + dwc_otg_device_t *otg_dev;
  51959. + DWC_OTG_GETDRVDEV(otg_dev, _dev);
  51960. + return otg_dev;
  51961. +}
  51962. +
  51963. +/**
  51964. + * Show the register offset of the Register Access.
  51965. + */
  51966. +static ssize_t regoffset_show(struct device *_dev,
  51967. + struct device_attribute *attr, char *buf)
  51968. +{
  51969. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51970. + return snprintf(buf, sizeof("0xFFFFFFFF\n") + 1, "0x%08x\n",
  51971. + otg_dev->os_dep.reg_offset);
  51972. +}
  51973. +
  51974. +/**
  51975. + * Set the register offset for the next Register Access Read/Write
  51976. + */
  51977. +static ssize_t regoffset_store(struct device *_dev,
  51978. + struct device_attribute *attr,
  51979. + const char *buf, size_t count)
  51980. +{
  51981. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  51982. + uint32_t offset = simple_strtoul(buf, NULL, 16);
  51983. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  51984. + if (offset < SZ_256K) {
  51985. +#elif defined(PCI_INTERFACE)
  51986. + if (offset < 0x00040000) {
  51987. +#endif
  51988. + otg_dev->os_dep.reg_offset = offset;
  51989. + } else {
  51990. + dev_err(_dev, "invalid offset\n");
  51991. + }
  51992. +
  51993. + return count;
  51994. +}
  51995. +
  51996. +DEVICE_ATTR(regoffset, S_IRUGO | S_IWUSR, regoffset_show, regoffset_store);
  51997. +
  51998. +/**
  51999. + * Show the value of the register at the offset in the reg_offset
  52000. + * attribute.
  52001. + */
  52002. +static ssize_t regvalue_show(struct device *_dev,
  52003. + struct device_attribute *attr, char *buf)
  52004. +{
  52005. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52006. + uint32_t val;
  52007. + volatile uint32_t *addr;
  52008. +
  52009. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52010. + /* Calculate the address */
  52011. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52012. + (uint8_t *) otg_dev->os_dep.base);
  52013. + val = DWC_READ_REG32(addr);
  52014. + return snprintf(buf,
  52015. + sizeof("Reg@0xFFFFFFFF = 0xFFFFFFFF\n") + 1,
  52016. + "Reg@0x%06x = 0x%08x\n", otg_dev->os_dep.reg_offset,
  52017. + val);
  52018. + } else {
  52019. + dev_err(_dev, "Invalid offset (0x%0x)\n", otg_dev->os_dep.reg_offset);
  52020. + return sprintf(buf, "invalid offset\n");
  52021. + }
  52022. +}
  52023. +
  52024. +/**
  52025. + * Store the value in the register at the offset in the reg_offset
  52026. + * attribute.
  52027. + *
  52028. + */
  52029. +static ssize_t regvalue_store(struct device *_dev,
  52030. + struct device_attribute *attr,
  52031. + const char *buf, size_t count)
  52032. +{
  52033. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52034. + volatile uint32_t *addr;
  52035. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52036. + //dev_dbg(_dev, "Offset=0x%08x Val=0x%08x\n", otg_dev->reg_offset, val);
  52037. + if (otg_dev->os_dep.reg_offset != 0xFFFFFFFF && 0 != otg_dev->os_dep.base) {
  52038. + /* Calculate the address */
  52039. + addr = (uint32_t *) (otg_dev->os_dep.reg_offset +
  52040. + (uint8_t *) otg_dev->os_dep.base);
  52041. + DWC_WRITE_REG32(addr, val);
  52042. + } else {
  52043. + dev_err(_dev, "Invalid Register Offset (0x%08x)\n",
  52044. + otg_dev->os_dep.reg_offset);
  52045. + }
  52046. + return count;
  52047. +}
  52048. +
  52049. +DEVICE_ATTR(regvalue, S_IRUGO | S_IWUSR, regvalue_show, regvalue_store);
  52050. +
  52051. +/*
  52052. + * Attributes
  52053. + */
  52054. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(mode, "Mode");
  52055. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hnpcapable, "HNPCapable");
  52056. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(srpcapable, "SRPCapable");
  52057. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(hsic_connect, "HSIC Connect");
  52058. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(inv_sel_hsic, "Invert Select HSIC");
  52059. +
  52060. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(buspower,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52061. +//DWC_OTG_DEVICE_ATTR_BITFIELD_RW(bussuspend,&(otg_dev->core_if->core_global_regs->gotgctl),(1<<8),8,"Mode");
  52062. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(busconnected, "Bus Connected");
  52063. +
  52064. +DWC_OTG_DEVICE_ATTR_REG32_RW(gotgctl, 0, "GOTGCTL");
  52065. +DWC_OTG_DEVICE_ATTR_REG32_RW(gusbcfg,
  52066. + &(otg_dev->core_if->core_global_regs->gusbcfg),
  52067. + "GUSBCFG");
  52068. +DWC_OTG_DEVICE_ATTR_REG32_RW(grxfsiz,
  52069. + &(otg_dev->core_if->core_global_regs->grxfsiz),
  52070. + "GRXFSIZ");
  52071. +DWC_OTG_DEVICE_ATTR_REG32_RW(gnptxfsiz,
  52072. + &(otg_dev->core_if->core_global_regs->gnptxfsiz),
  52073. + "GNPTXFSIZ");
  52074. +DWC_OTG_DEVICE_ATTR_REG32_RW(gpvndctl,
  52075. + &(otg_dev->core_if->core_global_regs->gpvndctl),
  52076. + "GPVNDCTL");
  52077. +DWC_OTG_DEVICE_ATTR_REG32_RW(ggpio,
  52078. + &(otg_dev->core_if->core_global_regs->ggpio),
  52079. + "GGPIO");
  52080. +DWC_OTG_DEVICE_ATTR_REG32_RW(guid, &(otg_dev->core_if->core_global_regs->guid),
  52081. + "GUID");
  52082. +DWC_OTG_DEVICE_ATTR_REG32_RO(gsnpsid,
  52083. + &(otg_dev->core_if->core_global_regs->gsnpsid),
  52084. + "GSNPSID");
  52085. +DWC_OTG_DEVICE_ATTR_BITFIELD_RW(devspeed, "Device Speed");
  52086. +DWC_OTG_DEVICE_ATTR_BITFIELD_RO(enumspeed, "Device Enumeration Speed");
  52087. +
  52088. +DWC_OTG_DEVICE_ATTR_REG32_RO(hptxfsiz,
  52089. + &(otg_dev->core_if->core_global_regs->hptxfsiz),
  52090. + "HPTXFSIZ");
  52091. +DWC_OTG_DEVICE_ATTR_REG32_RW(hprt0, otg_dev->core_if->host_if->hprt0, "HPRT0");
  52092. +
  52093. +/**
  52094. + * @todo Add code to initiate the HNP.
  52095. + */
  52096. +/**
  52097. + * Show the HNP status bit
  52098. + */
  52099. +static ssize_t hnp_show(struct device *_dev,
  52100. + struct device_attribute *attr, char *buf)
  52101. +{
  52102. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52103. + return sprintf(buf, "HstNegScs = 0x%x\n",
  52104. + dwc_otg_get_hnpstatus(otg_dev->core_if));
  52105. +}
  52106. +
  52107. +/**
  52108. + * Set the HNP Request bit
  52109. + */
  52110. +static ssize_t hnp_store(struct device *_dev,
  52111. + struct device_attribute *attr,
  52112. + const char *buf, size_t count)
  52113. +{
  52114. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52115. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52116. + dwc_otg_set_hnpreq(otg_dev->core_if, in);
  52117. + return count;
  52118. +}
  52119. +
  52120. +DEVICE_ATTR(hnp, 0644, hnp_show, hnp_store);
  52121. +
  52122. +/**
  52123. + * @todo Add code to initiate the SRP.
  52124. + */
  52125. +/**
  52126. + * Show the SRP status bit
  52127. + */
  52128. +static ssize_t srp_show(struct device *_dev,
  52129. + struct device_attribute *attr, char *buf)
  52130. +{
  52131. +#ifndef DWC_HOST_ONLY
  52132. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52133. + return sprintf(buf, "SesReqScs = 0x%x\n",
  52134. + dwc_otg_get_srpstatus(otg_dev->core_if));
  52135. +#else
  52136. + return sprintf(buf, "Host Only Mode!\n");
  52137. +#endif
  52138. +}
  52139. +
  52140. +/**
  52141. + * Set the SRP Request bit
  52142. + */
  52143. +static ssize_t srp_store(struct device *_dev,
  52144. + struct device_attribute *attr,
  52145. + const char *buf, size_t count)
  52146. +{
  52147. +#ifndef DWC_HOST_ONLY
  52148. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52149. + dwc_otg_pcd_initiate_srp(otg_dev->pcd);
  52150. +#endif
  52151. + return count;
  52152. +}
  52153. +
  52154. +DEVICE_ATTR(srp, 0644, srp_show, srp_store);
  52155. +
  52156. +/**
  52157. + * @todo Need to do more for power on/off?
  52158. + */
  52159. +/**
  52160. + * Show the Bus Power status
  52161. + */
  52162. +static ssize_t buspower_show(struct device *_dev,
  52163. + struct device_attribute *attr, char *buf)
  52164. +{
  52165. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52166. + return sprintf(buf, "Bus Power = 0x%x\n",
  52167. + dwc_otg_get_prtpower(otg_dev->core_if));
  52168. +}
  52169. +
  52170. +/**
  52171. + * Set the Bus Power status
  52172. + */
  52173. +static ssize_t buspower_store(struct device *_dev,
  52174. + struct device_attribute *attr,
  52175. + const char *buf, size_t count)
  52176. +{
  52177. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52178. + uint32_t on = simple_strtoul(buf, NULL, 16);
  52179. + dwc_otg_set_prtpower(otg_dev->core_if, on);
  52180. + return count;
  52181. +}
  52182. +
  52183. +DEVICE_ATTR(buspower, 0644, buspower_show, buspower_store);
  52184. +
  52185. +/**
  52186. + * @todo Need to do more for suspend?
  52187. + */
  52188. +/**
  52189. + * Show the Bus Suspend status
  52190. + */
  52191. +static ssize_t bussuspend_show(struct device *_dev,
  52192. + struct device_attribute *attr, char *buf)
  52193. +{
  52194. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52195. + return sprintf(buf, "Bus Suspend = 0x%x\n",
  52196. + dwc_otg_get_prtsuspend(otg_dev->core_if));
  52197. +}
  52198. +
  52199. +/**
  52200. + * Set the Bus Suspend status
  52201. + */
  52202. +static ssize_t bussuspend_store(struct device *_dev,
  52203. + struct device_attribute *attr,
  52204. + const char *buf, size_t count)
  52205. +{
  52206. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52207. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52208. + dwc_otg_set_prtsuspend(otg_dev->core_if, in);
  52209. + return count;
  52210. +}
  52211. +
  52212. +DEVICE_ATTR(bussuspend, 0644, bussuspend_show, bussuspend_store);
  52213. +
  52214. +/**
  52215. + * Show the Mode Change Ready Timer status
  52216. + */
  52217. +static ssize_t mode_ch_tim_en_show(struct device *_dev,
  52218. + struct device_attribute *attr, char *buf)
  52219. +{
  52220. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52221. + return sprintf(buf, "Mode Change Ready Timer Enable = 0x%x\n",
  52222. + dwc_otg_get_mode_ch_tim(otg_dev->core_if));
  52223. +}
  52224. +
  52225. +/**
  52226. + * Set the Mode Change Ready Timer status
  52227. + */
  52228. +static ssize_t mode_ch_tim_en_store(struct device *_dev,
  52229. + struct device_attribute *attr,
  52230. + const char *buf, size_t count)
  52231. +{
  52232. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52233. + uint32_t in = simple_strtoul(buf, NULL, 16);
  52234. + dwc_otg_set_mode_ch_tim(otg_dev->core_if, in);
  52235. + return count;
  52236. +}
  52237. +
  52238. +DEVICE_ATTR(mode_ch_tim_en, 0644, mode_ch_tim_en_show, mode_ch_tim_en_store);
  52239. +
  52240. +/**
  52241. + * Show the value of HFIR Frame Interval bitfield
  52242. + */
  52243. +static ssize_t fr_interval_show(struct device *_dev,
  52244. + struct device_attribute *attr, char *buf)
  52245. +{
  52246. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52247. + return sprintf(buf, "Frame Interval = 0x%x\n",
  52248. + dwc_otg_get_fr_interval(otg_dev->core_if));
  52249. +}
  52250. +
  52251. +/**
  52252. + * Set the HFIR Frame Interval value
  52253. + */
  52254. +static ssize_t fr_interval_store(struct device *_dev,
  52255. + struct device_attribute *attr,
  52256. + const char *buf, size_t count)
  52257. +{
  52258. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52259. + uint32_t in = simple_strtoul(buf, NULL, 10);
  52260. + dwc_otg_set_fr_interval(otg_dev->core_if, in);
  52261. + return count;
  52262. +}
  52263. +
  52264. +DEVICE_ATTR(fr_interval, 0644, fr_interval_show, fr_interval_store);
  52265. +
  52266. +/**
  52267. + * Show the status of Remote Wakeup.
  52268. + */
  52269. +static ssize_t remote_wakeup_show(struct device *_dev,
  52270. + struct device_attribute *attr, char *buf)
  52271. +{
  52272. +#ifndef DWC_HOST_ONLY
  52273. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52274. +
  52275. + return sprintf(buf,
  52276. + "Remote Wakeup Sig = %d Enabled = %d LPM Remote Wakeup = %d\n",
  52277. + dwc_otg_get_remotewakesig(otg_dev->core_if),
  52278. + dwc_otg_pcd_get_rmwkup_enable(otg_dev->pcd),
  52279. + dwc_otg_get_lpm_remotewakeenabled(otg_dev->core_if));
  52280. +#else
  52281. + return sprintf(buf, "Host Only Mode!\n");
  52282. +#endif /* DWC_HOST_ONLY */
  52283. +}
  52284. +
  52285. +/**
  52286. + * Initiate a remote wakeup of the host. The Device control register
  52287. + * Remote Wakeup Signal bit is written if the PCD Remote wakeup enable
  52288. + * flag is set.
  52289. + *
  52290. + */
  52291. +static ssize_t remote_wakeup_store(struct device *_dev,
  52292. + struct device_attribute *attr,
  52293. + const char *buf, size_t count)
  52294. +{
  52295. +#ifndef DWC_HOST_ONLY
  52296. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52297. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52298. +
  52299. + if (val & 1) {
  52300. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 1);
  52301. + } else {
  52302. + dwc_otg_pcd_remote_wakeup(otg_dev->pcd, 0);
  52303. + }
  52304. +#endif /* DWC_HOST_ONLY */
  52305. + return count;
  52306. +}
  52307. +
  52308. +DEVICE_ATTR(remote_wakeup, S_IRUGO | S_IWUSR, remote_wakeup_show,
  52309. + remote_wakeup_store);
  52310. +
  52311. +/**
  52312. + * Show the whether core is hibernated or not.
  52313. + */
  52314. +static ssize_t rem_wakeup_pwrdn_show(struct device *_dev,
  52315. + struct device_attribute *attr, char *buf)
  52316. +{
  52317. +#ifndef DWC_HOST_ONLY
  52318. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52319. +
  52320. + if (dwc_otg_get_core_state(otg_dev->core_if)) {
  52321. + DWC_PRINTF("Core is in hibernation\n");
  52322. + } else {
  52323. + DWC_PRINTF("Core is not in hibernation\n");
  52324. + }
  52325. +#endif /* DWC_HOST_ONLY */
  52326. + return 0;
  52327. +}
  52328. +
  52329. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  52330. + int rem_wakeup, int reset);
  52331. +
  52332. +/**
  52333. + * Initiate a remote wakeup of the device to exit from hibernation.
  52334. + */
  52335. +static ssize_t rem_wakeup_pwrdn_store(struct device *_dev,
  52336. + struct device_attribute *attr,
  52337. + const char *buf, size_t count)
  52338. +{
  52339. +#ifndef DWC_HOST_ONLY
  52340. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52341. + dwc_otg_device_hibernation_restore(otg_dev->core_if, 1, 0);
  52342. +#endif
  52343. + return count;
  52344. +}
  52345. +
  52346. +DEVICE_ATTR(rem_wakeup_pwrdn, S_IRUGO | S_IWUSR, rem_wakeup_pwrdn_show,
  52347. + rem_wakeup_pwrdn_store);
  52348. +
  52349. +static ssize_t disconnect_us(struct device *_dev,
  52350. + struct device_attribute *attr,
  52351. + const char *buf, size_t count)
  52352. +{
  52353. +
  52354. +#ifndef DWC_HOST_ONLY
  52355. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52356. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52357. + DWC_PRINTF("The Passed value is %04x\n", val);
  52358. +
  52359. + dwc_otg_pcd_disconnect_us(otg_dev->pcd, 50);
  52360. +
  52361. +#endif /* DWC_HOST_ONLY */
  52362. + return count;
  52363. +}
  52364. +
  52365. +DEVICE_ATTR(disconnect_us, S_IWUSR, 0, disconnect_us);
  52366. +
  52367. +/**
  52368. + * Dump global registers and either host or device registers (depending on the
  52369. + * current mode of the core).
  52370. + */
  52371. +static ssize_t regdump_show(struct device *_dev,
  52372. + struct device_attribute *attr, char *buf)
  52373. +{
  52374. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52375. +
  52376. + dwc_otg_dump_global_registers(otg_dev->core_if);
  52377. + if (dwc_otg_is_host_mode(otg_dev->core_if)) {
  52378. + dwc_otg_dump_host_registers(otg_dev->core_if);
  52379. + } else {
  52380. + dwc_otg_dump_dev_registers(otg_dev->core_if);
  52381. +
  52382. + }
  52383. + return sprintf(buf, "Register Dump\n");
  52384. +}
  52385. +
  52386. +DEVICE_ATTR(regdump, S_IRUGO, regdump_show, 0);
  52387. +
  52388. +/**
  52389. + * Dump global registers and either host or device registers (depending on the
  52390. + * current mode of the core).
  52391. + */
  52392. +static ssize_t spramdump_show(struct device *_dev,
  52393. + struct device_attribute *attr, char *buf)
  52394. +{
  52395. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52396. +
  52397. + //dwc_otg_dump_spram(otg_dev->core_if);
  52398. +
  52399. + return sprintf(buf, "SPRAM Dump\n");
  52400. +}
  52401. +
  52402. +DEVICE_ATTR(spramdump, S_IRUGO, spramdump_show, 0);
  52403. +
  52404. +/**
  52405. + * Dump the current hcd state.
  52406. + */
  52407. +static ssize_t hcddump_show(struct device *_dev,
  52408. + struct device_attribute *attr, char *buf)
  52409. +{
  52410. +#ifndef DWC_DEVICE_ONLY
  52411. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52412. + dwc_otg_hcd_dump_state(otg_dev->hcd);
  52413. +#endif /* DWC_DEVICE_ONLY */
  52414. + return sprintf(buf, "HCD Dump\n");
  52415. +}
  52416. +
  52417. +DEVICE_ATTR(hcddump, S_IRUGO, hcddump_show, 0);
  52418. +
  52419. +/**
  52420. + * Dump the average frame remaining at SOF. This can be used to
  52421. + * determine average interrupt latency. Frame remaining is also shown for
  52422. + * start transfer and two additional sample points.
  52423. + */
  52424. +static ssize_t hcd_frrem_show(struct device *_dev,
  52425. + struct device_attribute *attr, char *buf)
  52426. +{
  52427. +#ifndef DWC_DEVICE_ONLY
  52428. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52429. +
  52430. + dwc_otg_hcd_dump_frrem(otg_dev->hcd);
  52431. +#endif /* DWC_DEVICE_ONLY */
  52432. + return sprintf(buf, "HCD Dump Frame Remaining\n");
  52433. +}
  52434. +
  52435. +DEVICE_ATTR(hcd_frrem, S_IRUGO, hcd_frrem_show, 0);
  52436. +
  52437. +/**
  52438. + * Displays the time required to read the GNPTXFSIZ register many times (the
  52439. + * output shows the number of times the register is read).
  52440. + */
  52441. +#define RW_REG_COUNT 10000000
  52442. +#define MSEC_PER_JIFFIE 1000/HZ
  52443. +static ssize_t rd_reg_test_show(struct device *_dev,
  52444. + struct device_attribute *attr, char *buf)
  52445. +{
  52446. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52447. + int i;
  52448. + int time;
  52449. + int start_jiffies;
  52450. +
  52451. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52452. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52453. + start_jiffies = jiffies;
  52454. + for (i = 0; i < RW_REG_COUNT; i++) {
  52455. + dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52456. + }
  52457. + time = jiffies - start_jiffies;
  52458. + return sprintf(buf,
  52459. + "Time to read GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52460. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52461. +}
  52462. +
  52463. +DEVICE_ATTR(rd_reg_test, S_IRUGO, rd_reg_test_show, 0);
  52464. +
  52465. +/**
  52466. + * Displays the time required to write the GNPTXFSIZ register many times (the
  52467. + * output shows the number of times the register is written).
  52468. + */
  52469. +static ssize_t wr_reg_test_show(struct device *_dev,
  52470. + struct device_attribute *attr, char *buf)
  52471. +{
  52472. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52473. + uint32_t reg_val;
  52474. + int i;
  52475. + int time;
  52476. + int start_jiffies;
  52477. +
  52478. + printk("HZ %d, MSEC_PER_JIFFIE %d, loops_per_jiffy %lu\n",
  52479. + HZ, MSEC_PER_JIFFIE, loops_per_jiffy);
  52480. + reg_val = dwc_otg_get_gnptxfsiz(otg_dev->core_if);
  52481. + start_jiffies = jiffies;
  52482. + for (i = 0; i < RW_REG_COUNT; i++) {
  52483. + dwc_otg_set_gnptxfsiz(otg_dev->core_if, reg_val);
  52484. + }
  52485. + time = jiffies - start_jiffies;
  52486. + return sprintf(buf,
  52487. + "Time to write GNPTXFSIZ reg %d times: %d msecs (%d jiffies)\n",
  52488. + RW_REG_COUNT, time * MSEC_PER_JIFFIE, time);
  52489. +}
  52490. +
  52491. +DEVICE_ATTR(wr_reg_test, S_IRUGO, wr_reg_test_show, 0);
  52492. +
  52493. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52494. +
  52495. +/**
  52496. +* Show the lpm_response attribute.
  52497. +*/
  52498. +static ssize_t lpmresp_show(struct device *_dev,
  52499. + struct device_attribute *attr, char *buf)
  52500. +{
  52501. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52502. +
  52503. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if))
  52504. + return sprintf(buf, "** LPM is DISABLED **\n");
  52505. +
  52506. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52507. + return sprintf(buf, "** Current mode is not device mode\n");
  52508. + }
  52509. + return sprintf(buf, "lpm_response = %d\n",
  52510. + dwc_otg_get_lpmresponse(otg_dev->core_if));
  52511. +}
  52512. +
  52513. +/**
  52514. +* Store the lpm_response attribute.
  52515. +*/
  52516. +static ssize_t lpmresp_store(struct device *_dev,
  52517. + struct device_attribute *attr,
  52518. + const char *buf, size_t count)
  52519. +{
  52520. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52521. + uint32_t val = simple_strtoul(buf, NULL, 16);
  52522. +
  52523. + if (!dwc_otg_get_param_lpm_enable(otg_dev->core_if)) {
  52524. + return 0;
  52525. + }
  52526. +
  52527. + if (!dwc_otg_is_device_mode(otg_dev->core_if)) {
  52528. + return 0;
  52529. + }
  52530. +
  52531. + dwc_otg_set_lpmresponse(otg_dev->core_if, val);
  52532. + return count;
  52533. +}
  52534. +
  52535. +DEVICE_ATTR(lpm_response, S_IRUGO | S_IWUSR, lpmresp_show, lpmresp_store);
  52536. +
  52537. +/**
  52538. +* Show the sleep_status attribute.
  52539. +*/
  52540. +static ssize_t sleepstatus_show(struct device *_dev,
  52541. + struct device_attribute *attr, char *buf)
  52542. +{
  52543. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52544. + return sprintf(buf, "Sleep Status = %d\n",
  52545. + dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if));
  52546. +}
  52547. +
  52548. +/**
  52549. + * Store the sleep_status attribure.
  52550. + */
  52551. +static ssize_t sleepstatus_store(struct device *_dev,
  52552. + struct device_attribute *attr,
  52553. + const char *buf, size_t count)
  52554. +{
  52555. + dwc_otg_device_t *otg_dev = dwc_otg_drvdev(_dev);
  52556. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  52557. +
  52558. + if (dwc_otg_get_lpm_portsleepstatus(otg_dev->core_if)) {
  52559. + if (dwc_otg_is_host_mode(core_if)) {
  52560. +
  52561. + DWC_PRINTF("Host initiated resume\n");
  52562. + dwc_otg_set_prtresume(otg_dev->core_if, 1);
  52563. + }
  52564. + }
  52565. +
  52566. + return count;
  52567. +}
  52568. +
  52569. +DEVICE_ATTR(sleep_status, S_IRUGO | S_IWUSR, sleepstatus_show,
  52570. + sleepstatus_store);
  52571. +
  52572. +#endif /* CONFIG_USB_DWC_OTG_LPM_ENABLE */
  52573. +
  52574. +/**@}*/
  52575. +
  52576. +/**
  52577. + * Create the device files
  52578. + */
  52579. +void dwc_otg_attr_create(
  52580. +#ifdef LM_INTERFACE
  52581. + struct lm_device *dev
  52582. +#elif defined(PCI_INTERFACE)
  52583. + struct pci_dev *dev
  52584. +#elif defined(PLATFORM_INTERFACE)
  52585. + struct platform_device *dev
  52586. +#endif
  52587. + )
  52588. +{
  52589. + int error;
  52590. +
  52591. + error = device_create_file(&dev->dev, &dev_attr_regoffset);
  52592. + error = device_create_file(&dev->dev, &dev_attr_regvalue);
  52593. + error = device_create_file(&dev->dev, &dev_attr_mode);
  52594. + error = device_create_file(&dev->dev, &dev_attr_hnpcapable);
  52595. + error = device_create_file(&dev->dev, &dev_attr_srpcapable);
  52596. + error = device_create_file(&dev->dev, &dev_attr_hsic_connect);
  52597. + error = device_create_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52598. + error = device_create_file(&dev->dev, &dev_attr_hnp);
  52599. + error = device_create_file(&dev->dev, &dev_attr_srp);
  52600. + error = device_create_file(&dev->dev, &dev_attr_buspower);
  52601. + error = device_create_file(&dev->dev, &dev_attr_bussuspend);
  52602. + error = device_create_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52603. + error = device_create_file(&dev->dev, &dev_attr_fr_interval);
  52604. + error = device_create_file(&dev->dev, &dev_attr_busconnected);
  52605. + error = device_create_file(&dev->dev, &dev_attr_gotgctl);
  52606. + error = device_create_file(&dev->dev, &dev_attr_gusbcfg);
  52607. + error = device_create_file(&dev->dev, &dev_attr_grxfsiz);
  52608. + error = device_create_file(&dev->dev, &dev_attr_gnptxfsiz);
  52609. + error = device_create_file(&dev->dev, &dev_attr_gpvndctl);
  52610. + error = device_create_file(&dev->dev, &dev_attr_ggpio);
  52611. + error = device_create_file(&dev->dev, &dev_attr_guid);
  52612. + error = device_create_file(&dev->dev, &dev_attr_gsnpsid);
  52613. + error = device_create_file(&dev->dev, &dev_attr_devspeed);
  52614. + error = device_create_file(&dev->dev, &dev_attr_enumspeed);
  52615. + error = device_create_file(&dev->dev, &dev_attr_hptxfsiz);
  52616. + error = device_create_file(&dev->dev, &dev_attr_hprt0);
  52617. + error = device_create_file(&dev->dev, &dev_attr_remote_wakeup);
  52618. + error = device_create_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52619. + error = device_create_file(&dev->dev, &dev_attr_disconnect_us);
  52620. + error = device_create_file(&dev->dev, &dev_attr_regdump);
  52621. + error = device_create_file(&dev->dev, &dev_attr_spramdump);
  52622. + error = device_create_file(&dev->dev, &dev_attr_hcddump);
  52623. + error = device_create_file(&dev->dev, &dev_attr_hcd_frrem);
  52624. + error = device_create_file(&dev->dev, &dev_attr_rd_reg_test);
  52625. + error = device_create_file(&dev->dev, &dev_attr_wr_reg_test);
  52626. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52627. + error = device_create_file(&dev->dev, &dev_attr_lpm_response);
  52628. + error = device_create_file(&dev->dev, &dev_attr_sleep_status);
  52629. +#endif
  52630. +}
  52631. +
  52632. +/**
  52633. + * Remove the device files
  52634. + */
  52635. +void dwc_otg_attr_remove(
  52636. +#ifdef LM_INTERFACE
  52637. + struct lm_device *dev
  52638. +#elif defined(PCI_INTERFACE)
  52639. + struct pci_dev *dev
  52640. +#elif defined(PLATFORM_INTERFACE)
  52641. + struct platform_device *dev
  52642. +#endif
  52643. + )
  52644. +{
  52645. + device_remove_file(&dev->dev, &dev_attr_regoffset);
  52646. + device_remove_file(&dev->dev, &dev_attr_regvalue);
  52647. + device_remove_file(&dev->dev, &dev_attr_mode);
  52648. + device_remove_file(&dev->dev, &dev_attr_hnpcapable);
  52649. + device_remove_file(&dev->dev, &dev_attr_srpcapable);
  52650. + device_remove_file(&dev->dev, &dev_attr_hsic_connect);
  52651. + device_remove_file(&dev->dev, &dev_attr_inv_sel_hsic);
  52652. + device_remove_file(&dev->dev, &dev_attr_hnp);
  52653. + device_remove_file(&dev->dev, &dev_attr_srp);
  52654. + device_remove_file(&dev->dev, &dev_attr_buspower);
  52655. + device_remove_file(&dev->dev, &dev_attr_bussuspend);
  52656. + device_remove_file(&dev->dev, &dev_attr_mode_ch_tim_en);
  52657. + device_remove_file(&dev->dev, &dev_attr_fr_interval);
  52658. + device_remove_file(&dev->dev, &dev_attr_busconnected);
  52659. + device_remove_file(&dev->dev, &dev_attr_gotgctl);
  52660. + device_remove_file(&dev->dev, &dev_attr_gusbcfg);
  52661. + device_remove_file(&dev->dev, &dev_attr_grxfsiz);
  52662. + device_remove_file(&dev->dev, &dev_attr_gnptxfsiz);
  52663. + device_remove_file(&dev->dev, &dev_attr_gpvndctl);
  52664. + device_remove_file(&dev->dev, &dev_attr_ggpio);
  52665. + device_remove_file(&dev->dev, &dev_attr_guid);
  52666. + device_remove_file(&dev->dev, &dev_attr_gsnpsid);
  52667. + device_remove_file(&dev->dev, &dev_attr_devspeed);
  52668. + device_remove_file(&dev->dev, &dev_attr_enumspeed);
  52669. + device_remove_file(&dev->dev, &dev_attr_hptxfsiz);
  52670. + device_remove_file(&dev->dev, &dev_attr_hprt0);
  52671. + device_remove_file(&dev->dev, &dev_attr_remote_wakeup);
  52672. + device_remove_file(&dev->dev, &dev_attr_rem_wakeup_pwrdn);
  52673. + device_remove_file(&dev->dev, &dev_attr_disconnect_us);
  52674. + device_remove_file(&dev->dev, &dev_attr_regdump);
  52675. + device_remove_file(&dev->dev, &dev_attr_spramdump);
  52676. + device_remove_file(&dev->dev, &dev_attr_hcddump);
  52677. + device_remove_file(&dev->dev, &dev_attr_hcd_frrem);
  52678. + device_remove_file(&dev->dev, &dev_attr_rd_reg_test);
  52679. + device_remove_file(&dev->dev, &dev_attr_wr_reg_test);
  52680. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52681. + device_remove_file(&dev->dev, &dev_attr_lpm_response);
  52682. + device_remove_file(&dev->dev, &dev_attr_sleep_status);
  52683. +#endif
  52684. +}
  52685. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_attr.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h
  52686. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_attr.h 1970-01-01 01:00:00.000000000 +0100
  52687. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_attr.h 2014-06-11 21:03:43.000000000 +0200
  52688. @@ -0,0 +1,89 @@
  52689. +/* ==========================================================================
  52690. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_attr.h $
  52691. + * $Revision: #13 $
  52692. + * $Date: 2010/06/21 $
  52693. + * $Change: 1532021 $
  52694. + *
  52695. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52696. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52697. + * otherwise expressly agreed to in writing between Synopsys and you.
  52698. + *
  52699. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52700. + * any End User Software License Agreement or Agreement for Licensed Product
  52701. + * with Synopsys or any supplement thereto. You are permitted to use and
  52702. + * redistribute this Software in source and binary forms, with or without
  52703. + * modification, provided that redistributions of source code must retain this
  52704. + * notice. You may not view, use, disclose, copy or distribute this file or
  52705. + * any information contained herein except pursuant to this license grant from
  52706. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52707. + * below, then you are not authorized to use the Software.
  52708. + *
  52709. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52710. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52711. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52712. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52713. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52714. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52715. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52716. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52717. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52718. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52719. + * DAMAGE.
  52720. + * ========================================================================== */
  52721. +
  52722. +#if !defined(__DWC_OTG_ATTR_H__)
  52723. +#define __DWC_OTG_ATTR_H__
  52724. +
  52725. +/** @file
  52726. + * This file contains the interface to the Linux device attributes.
  52727. + */
  52728. +extern struct device_attribute dev_attr_regoffset;
  52729. +extern struct device_attribute dev_attr_regvalue;
  52730. +
  52731. +extern struct device_attribute dev_attr_mode;
  52732. +extern struct device_attribute dev_attr_hnpcapable;
  52733. +extern struct device_attribute dev_attr_srpcapable;
  52734. +extern struct device_attribute dev_attr_hnp;
  52735. +extern struct device_attribute dev_attr_srp;
  52736. +extern struct device_attribute dev_attr_buspower;
  52737. +extern struct device_attribute dev_attr_bussuspend;
  52738. +extern struct device_attribute dev_attr_mode_ch_tim_en;
  52739. +extern struct device_attribute dev_attr_fr_interval;
  52740. +extern struct device_attribute dev_attr_busconnected;
  52741. +extern struct device_attribute dev_attr_gotgctl;
  52742. +extern struct device_attribute dev_attr_gusbcfg;
  52743. +extern struct device_attribute dev_attr_grxfsiz;
  52744. +extern struct device_attribute dev_attr_gnptxfsiz;
  52745. +extern struct device_attribute dev_attr_gpvndctl;
  52746. +extern struct device_attribute dev_attr_ggpio;
  52747. +extern struct device_attribute dev_attr_guid;
  52748. +extern struct device_attribute dev_attr_gsnpsid;
  52749. +extern struct device_attribute dev_attr_devspeed;
  52750. +extern struct device_attribute dev_attr_enumspeed;
  52751. +extern struct device_attribute dev_attr_hptxfsiz;
  52752. +extern struct device_attribute dev_attr_hprt0;
  52753. +#ifdef CONFIG_USB_DWC_OTG_LPM
  52754. +extern struct device_attribute dev_attr_lpm_response;
  52755. +extern struct device_attribute devi_attr_sleep_status;
  52756. +#endif
  52757. +
  52758. +void dwc_otg_attr_create(
  52759. +#ifdef LM_INTERFACE
  52760. + struct lm_device *dev
  52761. +#elif defined(PCI_INTERFACE)
  52762. + struct pci_dev *dev
  52763. +#elif defined(PLATFORM_INTERFACE)
  52764. + struct platform_device *dev
  52765. +#endif
  52766. + );
  52767. +
  52768. +void dwc_otg_attr_remove(
  52769. +#ifdef LM_INTERFACE
  52770. + struct lm_device *dev
  52771. +#elif defined(PCI_INTERFACE)
  52772. + struct pci_dev *dev
  52773. +#elif defined(PLATFORM_INTERFACE)
  52774. + struct platform_device *dev
  52775. +#endif
  52776. + );
  52777. +#endif
  52778. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cfi.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c
  52779. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 1970-01-01 01:00:00.000000000 +0100
  52780. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.c 2014-06-11 21:03:43.000000000 +0200
  52781. @@ -0,0 +1,1876 @@
  52782. +/* ==========================================================================
  52783. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  52784. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  52785. + * otherwise expressly agreed to in writing between Synopsys and you.
  52786. + *
  52787. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  52788. + * any End User Software License Agreement or Agreement for Licensed Product
  52789. + * with Synopsys or any supplement thereto. You are permitted to use and
  52790. + * redistribute this Software in source and binary forms, with or without
  52791. + * modification, provided that redistributions of source code must retain this
  52792. + * notice. You may not view, use, disclose, copy or distribute this file or
  52793. + * any information contained herein except pursuant to this license grant from
  52794. + * Synopsys. If you do not agree with this notice, including the disclaimer
  52795. + * below, then you are not authorized to use the Software.
  52796. + *
  52797. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  52798. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52799. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52800. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  52801. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  52802. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  52803. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  52804. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  52805. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  52806. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  52807. + * DAMAGE.
  52808. + * ========================================================================== */
  52809. +
  52810. +/** @file
  52811. + *
  52812. + * This file contains the most of the CFI(Core Feature Interface)
  52813. + * implementation for the OTG.
  52814. + */
  52815. +
  52816. +#ifdef DWC_UTE_CFI
  52817. +
  52818. +#include "dwc_otg_pcd.h"
  52819. +#include "dwc_otg_cfi.h"
  52820. +
  52821. +/** This definition should actually migrate to the Portability Library */
  52822. +#define DWC_CONSTANT_CPU_TO_LE16(x) (x)
  52823. +
  52824. +extern dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex);
  52825. +
  52826. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen);
  52827. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  52828. + struct dwc_otg_pcd *pcd,
  52829. + struct cfi_usb_ctrlrequest *ctrl_req);
  52830. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd);
  52831. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52832. + struct cfi_usb_ctrlrequest *req);
  52833. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52834. + struct cfi_usb_ctrlrequest *req);
  52835. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  52836. + struct cfi_usb_ctrlrequest *req);
  52837. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  52838. + struct cfi_usb_ctrlrequest *req);
  52839. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep);
  52840. +
  52841. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if);
  52842. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue);
  52843. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue);
  52844. +
  52845. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if);
  52846. +
  52847. +/** This is the header of the all features descriptor */
  52848. +static cfi_all_features_header_t all_props_desc_header = {
  52849. + .wVersion = DWC_CONSTANT_CPU_TO_LE16(0x100),
  52850. + .wCoreID = DWC_CONSTANT_CPU_TO_LE16(CFI_CORE_ID_OTG),
  52851. + .wNumFeatures = DWC_CONSTANT_CPU_TO_LE16(9),
  52852. +};
  52853. +
  52854. +/** This is an array of statically allocated feature descriptors */
  52855. +static cfi_feature_desc_header_t prop_descs[] = {
  52856. +
  52857. + /* FT_ID_DMA_MODE */
  52858. + {
  52859. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_MODE),
  52860. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52861. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(1),
  52862. + },
  52863. +
  52864. + /* FT_ID_DMA_BUFFER_SETUP */
  52865. + {
  52866. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFFER_SETUP),
  52867. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52868. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52869. + },
  52870. +
  52871. + /* FT_ID_DMA_BUFF_ALIGN */
  52872. + {
  52873. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_BUFF_ALIGN),
  52874. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52875. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52876. + },
  52877. +
  52878. + /* FT_ID_DMA_CONCAT_SETUP */
  52879. + {
  52880. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CONCAT_SETUP),
  52881. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52882. + //.wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52883. + },
  52884. +
  52885. + /* FT_ID_DMA_CIRCULAR */
  52886. + {
  52887. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DMA_CIRCULAR),
  52888. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52889. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52890. + },
  52891. +
  52892. + /* FT_ID_THRESHOLD_SETUP */
  52893. + {
  52894. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_THRESHOLD_SETUP),
  52895. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52896. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(6),
  52897. + },
  52898. +
  52899. + /* FT_ID_DFIFO_DEPTH */
  52900. + {
  52901. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_DFIFO_DEPTH),
  52902. + .bmAttributes = CFI_FEATURE_ATTR_RO,
  52903. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52904. + },
  52905. +
  52906. + /* FT_ID_TX_FIFO_DEPTH */
  52907. + {
  52908. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_TX_FIFO_DEPTH),
  52909. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52910. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52911. + },
  52912. +
  52913. + /* FT_ID_RX_FIFO_DEPTH */
  52914. + {
  52915. + .wFeatureID = DWC_CONSTANT_CPU_TO_LE16(FT_ID_RX_FIFO_DEPTH),
  52916. + .bmAttributes = CFI_FEATURE_ATTR_RW,
  52917. + .wDataLength = DWC_CONSTANT_CPU_TO_LE16(2),
  52918. + }
  52919. +};
  52920. +
  52921. +/** The table of feature names */
  52922. +cfi_string_t prop_name_table[] = {
  52923. + {FT_ID_DMA_MODE, "dma_mode"},
  52924. + {FT_ID_DMA_BUFFER_SETUP, "buffer_setup"},
  52925. + {FT_ID_DMA_BUFF_ALIGN, "buffer_align"},
  52926. + {FT_ID_DMA_CONCAT_SETUP, "concat_setup"},
  52927. + {FT_ID_DMA_CIRCULAR, "buffer_circular"},
  52928. + {FT_ID_THRESHOLD_SETUP, "threshold_setup"},
  52929. + {FT_ID_DFIFO_DEPTH, "dfifo_depth"},
  52930. + {FT_ID_TX_FIFO_DEPTH, "txfifo_depth"},
  52931. + {FT_ID_RX_FIFO_DEPTH, "rxfifo_depth"},
  52932. + {}
  52933. +};
  52934. +
  52935. +/************************************************************************/
  52936. +
  52937. +/**
  52938. + * Returns the name of the feature by its ID
  52939. + * or NULL if no featute ID matches.
  52940. + *
  52941. + */
  52942. +const uint8_t *get_prop_name(uint16_t prop_id, int *len)
  52943. +{
  52944. + cfi_string_t *pstr;
  52945. + *len = 0;
  52946. +
  52947. + for (pstr = prop_name_table; pstr && pstr->s; pstr++) {
  52948. + if (pstr->id == prop_id) {
  52949. + *len = DWC_STRLEN(pstr->s);
  52950. + return pstr->s;
  52951. + }
  52952. + }
  52953. + return NULL;
  52954. +}
  52955. +
  52956. +/**
  52957. + * This function handles all CFI specific control requests.
  52958. + *
  52959. + * Return a negative value to stall the DCE.
  52960. + */
  52961. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl)
  52962. +{
  52963. + int retval = 0;
  52964. + dwc_otg_pcd_ep_t *ep = NULL;
  52965. + cfiobject_t *cfi = pcd->cfi;
  52966. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  52967. + uint16_t wLen = DWC_LE16_TO_CPU(&ctrl->wLength);
  52968. + uint16_t wValue = DWC_LE16_TO_CPU(&ctrl->wValue);
  52969. + uint16_t wIndex = DWC_LE16_TO_CPU(&ctrl->wIndex);
  52970. + uint32_t regaddr = 0;
  52971. + uint32_t regval = 0;
  52972. +
  52973. + /* Save this Control Request in the CFI object.
  52974. + * The data field will be assigned in the data stage completion CB function.
  52975. + */
  52976. + cfi->ctrl_req = *ctrl;
  52977. + cfi->ctrl_req.data = NULL;
  52978. +
  52979. + cfi->need_gadget_att = 0;
  52980. + cfi->need_status_in_complete = 0;
  52981. +
  52982. + switch (ctrl->bRequest) {
  52983. + case VEN_CORE_GET_FEATURES:
  52984. + retval = cfi_core_features_buf(cfi->buf_in.buf, CFI_IN_BUF_LEN);
  52985. + if (retval >= 0) {
  52986. + //dump_msg(cfi->buf_in.buf, retval);
  52987. + ep = &pcd->ep0;
  52988. +
  52989. + retval = min((uint16_t) retval, wLen);
  52990. + /* Transfer this buffer to the host through the EP0-IN EP */
  52991. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  52992. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  52993. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  52994. + ep->dwc_ep.xfer_len = retval;
  52995. + ep->dwc_ep.xfer_count = 0;
  52996. + ep->dwc_ep.sent_zlp = 0;
  52997. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  52998. +
  52999. + pcd->ep0_pending = 1;
  53000. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53001. + }
  53002. + retval = 0;
  53003. + break;
  53004. +
  53005. + case VEN_CORE_GET_FEATURE:
  53006. + CFI_INFO("VEN_CORE_GET_FEATURE\n");
  53007. + retval = cfi_get_feature_value(cfi->buf_in.buf, CFI_IN_BUF_LEN,
  53008. + pcd, ctrl);
  53009. + if (retval >= 0) {
  53010. + ep = &pcd->ep0;
  53011. +
  53012. + retval = min((uint16_t) retval, wLen);
  53013. + /* Transfer this buffer to the host through the EP0-IN EP */
  53014. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53015. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53016. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53017. + ep->dwc_ep.xfer_len = retval;
  53018. + ep->dwc_ep.xfer_count = 0;
  53019. + ep->dwc_ep.sent_zlp = 0;
  53020. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53021. +
  53022. + pcd->ep0_pending = 1;
  53023. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53024. + }
  53025. + CFI_INFO("VEN_CORE_GET_FEATURE=%d\n", retval);
  53026. + dump_msg(cfi->buf_in.buf, retval);
  53027. + break;
  53028. +
  53029. + case VEN_CORE_SET_FEATURE:
  53030. + CFI_INFO("VEN_CORE_SET_FEATURE\n");
  53031. + /* Set up an XFER to get the data stage of the control request,
  53032. + * which is the new value of the feature to be modified.
  53033. + */
  53034. + ep = &pcd->ep0;
  53035. + ep->dwc_ep.is_in = 0;
  53036. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53037. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53038. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53039. + ep->dwc_ep.xfer_len = wLen;
  53040. + ep->dwc_ep.xfer_count = 0;
  53041. + ep->dwc_ep.sent_zlp = 0;
  53042. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53043. +
  53044. + pcd->ep0_pending = 1;
  53045. + /* Read the control write's data stage */
  53046. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53047. + retval = 0;
  53048. + break;
  53049. +
  53050. + case VEN_CORE_RESET_FEATURES:
  53051. + CFI_INFO("VEN_CORE_RESET_FEATURES\n");
  53052. + cfi->need_gadget_att = 1;
  53053. + cfi->need_status_in_complete = 1;
  53054. + retval = cfi_preproc_reset(pcd, ctrl);
  53055. + CFI_INFO("VEN_CORE_RESET_FEATURES = (%d)\n", retval);
  53056. + break;
  53057. +
  53058. + case VEN_CORE_ACTIVATE_FEATURES:
  53059. + CFI_INFO("VEN_CORE_ACTIVATE_FEATURES\n");
  53060. + break;
  53061. +
  53062. + case VEN_CORE_READ_REGISTER:
  53063. + CFI_INFO("VEN_CORE_READ_REGISTER\n");
  53064. + /* wValue optionally contains the HI WORD of the register offset and
  53065. + * wIndex contains the LOW WORD of the register offset
  53066. + */
  53067. + if (wValue == 0) {
  53068. + /* @TODO - MAS - fix the access to the base field */
  53069. + regaddr = 0;
  53070. + //regaddr = (uint32_t) pcd->otg_dev->os_dep.base;
  53071. + //GET_CORE_IF(pcd)->co
  53072. + regaddr |= wIndex;
  53073. + } else {
  53074. + regaddr = (wValue << 16) | wIndex;
  53075. + }
  53076. +
  53077. + /* Read a 32-bit value of the memory at the regaddr */
  53078. + regval = DWC_READ_REG32((uint32_t *) regaddr);
  53079. +
  53080. + ep = &pcd->ep0;
  53081. + dwc_memcpy(cfi->buf_in.buf, &regval, sizeof(uint32_t));
  53082. + ep->dwc_ep.is_in = 1;
  53083. + ep->dwc_ep.dma_addr = cfi->buf_in.addr;
  53084. + ep->dwc_ep.start_xfer_buff = cfi->buf_in.buf;
  53085. + ep->dwc_ep.xfer_buff = cfi->buf_in.buf;
  53086. + ep->dwc_ep.xfer_len = wLen;
  53087. + ep->dwc_ep.xfer_count = 0;
  53088. + ep->dwc_ep.sent_zlp = 0;
  53089. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53090. +
  53091. + pcd->ep0_pending = 1;
  53092. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53093. + cfi->need_gadget_att = 0;
  53094. + retval = 0;
  53095. + break;
  53096. +
  53097. + case VEN_CORE_WRITE_REGISTER:
  53098. + CFI_INFO("VEN_CORE_WRITE_REGISTER\n");
  53099. + /* Set up an XFER to get the data stage of the control request,
  53100. + * which is the new value of the register to be modified.
  53101. + */
  53102. + ep = &pcd->ep0;
  53103. + ep->dwc_ep.is_in = 0;
  53104. + ep->dwc_ep.dma_addr = cfi->buf_out.addr;
  53105. + ep->dwc_ep.start_xfer_buff = cfi->buf_out.buf;
  53106. + ep->dwc_ep.xfer_buff = cfi->buf_out.buf;
  53107. + ep->dwc_ep.xfer_len = wLen;
  53108. + ep->dwc_ep.xfer_count = 0;
  53109. + ep->dwc_ep.sent_zlp = 0;
  53110. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  53111. +
  53112. + pcd->ep0_pending = 1;
  53113. + /* Read the control write's data stage */
  53114. + dwc_otg_ep0_start_transfer(coreif, &ep->dwc_ep);
  53115. + retval = 0;
  53116. + break;
  53117. +
  53118. + default:
  53119. + retval = -DWC_E_NOT_SUPPORTED;
  53120. + break;
  53121. + }
  53122. +
  53123. + return retval;
  53124. +}
  53125. +
  53126. +/**
  53127. + * This function prepares the core features descriptors and copies its
  53128. + * raw representation into the buffer <buf>.
  53129. + *
  53130. + * The buffer structure is as follows:
  53131. + * all_features_header (8 bytes)
  53132. + * features_#1 (8 bytes + feature name string length)
  53133. + * features_#2 (8 bytes + feature name string length)
  53134. + * .....
  53135. + * features_#n - where n=the total count of feature descriptors
  53136. + */
  53137. +static int cfi_core_features_buf(uint8_t * buf, uint16_t buflen)
  53138. +{
  53139. + cfi_feature_desc_header_t *prop_hdr = prop_descs;
  53140. + cfi_feature_desc_header_t *prop;
  53141. + cfi_all_features_header_t *all_props_hdr = &all_props_desc_header;
  53142. + cfi_all_features_header_t *tmp;
  53143. + uint8_t *tmpbuf = buf;
  53144. + const uint8_t *pname = NULL;
  53145. + int i, j, namelen = 0, totlen;
  53146. +
  53147. + /* Prepare and copy the core features into the buffer */
  53148. + CFI_INFO("%s:\n", __func__);
  53149. +
  53150. + tmp = (cfi_all_features_header_t *) tmpbuf;
  53151. + *tmp = *all_props_hdr;
  53152. + tmpbuf += CFI_ALL_FEATURES_HDR_LEN;
  53153. +
  53154. + j = sizeof(prop_descs) / sizeof(cfi_all_features_header_t);
  53155. + for (i = 0; i < j; i++, prop_hdr++) {
  53156. + pname = get_prop_name(prop_hdr->wFeatureID, &namelen);
  53157. + prop = (cfi_feature_desc_header_t *) tmpbuf;
  53158. + *prop = *prop_hdr;
  53159. +
  53160. + prop->bNameLen = namelen;
  53161. + prop->wLength =
  53162. + DWC_CONSTANT_CPU_TO_LE16(CFI_FEATURE_DESC_HDR_LEN +
  53163. + namelen);
  53164. +
  53165. + tmpbuf += CFI_FEATURE_DESC_HDR_LEN;
  53166. + dwc_memcpy(tmpbuf, pname, namelen);
  53167. + tmpbuf += namelen;
  53168. + }
  53169. +
  53170. + totlen = tmpbuf - buf;
  53171. +
  53172. + if (totlen > 0) {
  53173. + tmp = (cfi_all_features_header_t *) buf;
  53174. + tmp->wTotalLen = DWC_CONSTANT_CPU_TO_LE16(totlen);
  53175. + }
  53176. +
  53177. + return totlen;
  53178. +}
  53179. +
  53180. +/**
  53181. + * This function releases all the dynamic memory in the CFI object.
  53182. + */
  53183. +static void cfi_release(cfiobject_t * cfiobj)
  53184. +{
  53185. + cfi_ep_t *cfiep;
  53186. + dwc_list_link_t *tmp;
  53187. +
  53188. + CFI_INFO("%s\n", __func__);
  53189. +
  53190. + if (cfiobj->buf_in.buf) {
  53191. + DWC_DMA_FREE(CFI_IN_BUF_LEN, cfiobj->buf_in.buf,
  53192. + cfiobj->buf_in.addr);
  53193. + cfiobj->buf_in.buf = NULL;
  53194. + }
  53195. +
  53196. + if (cfiobj->buf_out.buf) {
  53197. + DWC_DMA_FREE(CFI_OUT_BUF_LEN, cfiobj->buf_out.buf,
  53198. + cfiobj->buf_out.addr);
  53199. + cfiobj->buf_out.buf = NULL;
  53200. + }
  53201. +
  53202. + /* Free the Buffer Setup values for each EP */
  53203. + //list_for_each_entry(cfiep, &cfiobj->active_eps, lh) {
  53204. + DWC_LIST_FOREACH(tmp, &cfiobj->active_eps) {
  53205. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53206. + cfi_free_ep_bs_dyn_data(cfiep);
  53207. + }
  53208. +}
  53209. +
  53210. +/**
  53211. + * This function frees the dynamically allocated EP buffer setup data.
  53212. + */
  53213. +static void cfi_free_ep_bs_dyn_data(cfi_ep_t * cfiep)
  53214. +{
  53215. + if (cfiep->bm_sg) {
  53216. + DWC_FREE(cfiep->bm_sg);
  53217. + cfiep->bm_sg = NULL;
  53218. + }
  53219. +
  53220. + if (cfiep->bm_align) {
  53221. + DWC_FREE(cfiep->bm_align);
  53222. + cfiep->bm_align = NULL;
  53223. + }
  53224. +
  53225. + if (cfiep->bm_concat) {
  53226. + if (NULL != cfiep->bm_concat->wTxBytes) {
  53227. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53228. + cfiep->bm_concat->wTxBytes = NULL;
  53229. + }
  53230. + DWC_FREE(cfiep->bm_concat);
  53231. + cfiep->bm_concat = NULL;
  53232. + }
  53233. +}
  53234. +
  53235. +/**
  53236. + * This function initializes the default values of the features
  53237. + * for a specific endpoint and should be called only once when
  53238. + * the EP is enabled first time.
  53239. + */
  53240. +static int cfi_ep_init_defaults(struct dwc_otg_pcd *pcd, cfi_ep_t * cfiep)
  53241. +{
  53242. + int retval = 0;
  53243. +
  53244. + cfiep->bm_sg = DWC_ALLOC(sizeof(ddma_sg_buffer_setup_t));
  53245. + if (NULL == cfiep->bm_sg) {
  53246. + CFI_INFO("Failed to allocate memory for SG feature value\n");
  53247. + return -DWC_E_NO_MEMORY;
  53248. + }
  53249. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53250. +
  53251. + /* For the Concatenation feature's default value we do not allocate
  53252. + * memory for the wTxBytes field - it will be done in the set_feature_value
  53253. + * request handler.
  53254. + */
  53255. + cfiep->bm_concat = DWC_ALLOC(sizeof(ddma_concat_buffer_setup_t));
  53256. + if (NULL == cfiep->bm_concat) {
  53257. + CFI_INFO
  53258. + ("Failed to allocate memory for CONCATENATION feature value\n");
  53259. + DWC_FREE(cfiep->bm_sg);
  53260. + return -DWC_E_NO_MEMORY;
  53261. + }
  53262. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53263. +
  53264. + cfiep->bm_align = DWC_ALLOC(sizeof(ddma_align_buffer_setup_t));
  53265. + if (NULL == cfiep->bm_align) {
  53266. + CFI_INFO
  53267. + ("Failed to allocate memory for Alignment feature value\n");
  53268. + DWC_FREE(cfiep->bm_sg);
  53269. + DWC_FREE(cfiep->bm_concat);
  53270. + return -DWC_E_NO_MEMORY;
  53271. + }
  53272. + dwc_memset(cfiep->bm_align, 0, sizeof(ddma_align_buffer_setup_t));
  53273. +
  53274. + return retval;
  53275. +}
  53276. +
  53277. +/**
  53278. + * The callback function that notifies the CFI on the activation of
  53279. + * an endpoint in the PCD. The following steps are done in this function:
  53280. + *
  53281. + * Create a dynamically allocated cfi_ep_t object (a CFI wrapper to the PCD's
  53282. + * active endpoint)
  53283. + * Create MAX_DMA_DESCS_PER_EP count DMA Descriptors for the EP
  53284. + * Set the Buffer Mode to standard
  53285. + * Initialize the default values for all EP modes (SG, Circular, Concat, Align)
  53286. + * Add the cfi_ep_t object to the list of active endpoints in the CFI object
  53287. + */
  53288. +static int cfi_ep_enable(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53289. + struct dwc_otg_pcd_ep *ep)
  53290. +{
  53291. + cfi_ep_t *cfiep;
  53292. + int retval = -DWC_E_NOT_SUPPORTED;
  53293. +
  53294. + CFI_INFO("%s: epname=%s; epnum=0x%02x\n", __func__,
  53295. + "EP_" /*ep->ep.name */ , ep->desc->bEndpointAddress);
  53296. + /* MAS - Check whether this endpoint already is in the list */
  53297. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53298. +
  53299. + if (NULL == cfiep) {
  53300. + /* Allocate a cfi_ep_t object */
  53301. + cfiep = DWC_ALLOC(sizeof(cfi_ep_t));
  53302. + if (NULL == cfiep) {
  53303. + CFI_INFO
  53304. + ("Unable to allocate memory for <cfiep> in function %s\n",
  53305. + __func__);
  53306. + return -DWC_E_NO_MEMORY;
  53307. + }
  53308. + dwc_memset(cfiep, 0, sizeof(cfi_ep_t));
  53309. +
  53310. + /* Save the dwc_otg_pcd_ep pointer in the cfiep object */
  53311. + cfiep->ep = ep;
  53312. +
  53313. + /* Allocate the DMA Descriptors chain of MAX_DMA_DESCS_PER_EP count */
  53314. + ep->dwc_ep.descs =
  53315. + DWC_DMA_ALLOC(MAX_DMA_DESCS_PER_EP *
  53316. + sizeof(dwc_otg_dma_desc_t),
  53317. + &ep->dwc_ep.descs_dma_addr);
  53318. +
  53319. + if (NULL == ep->dwc_ep.descs) {
  53320. + DWC_FREE(cfiep);
  53321. + return -DWC_E_NO_MEMORY;
  53322. + }
  53323. +
  53324. + DWC_LIST_INIT(&cfiep->lh);
  53325. +
  53326. + /* Set the buffer mode to BM_STANDARD. It will be modified
  53327. + * when building descriptors for a specific buffer mode */
  53328. + ep->dwc_ep.buff_mode = BM_STANDARD;
  53329. +
  53330. + /* Create and initialize the default values for this EP's Buffer modes */
  53331. + if ((retval = cfi_ep_init_defaults(pcd, cfiep)) < 0)
  53332. + return retval;
  53333. +
  53334. + /* Add the cfi_ep_t object to the CFI object's list of active endpoints */
  53335. + DWC_LIST_INSERT_TAIL(&cfi->active_eps, &cfiep->lh);
  53336. + retval = 0;
  53337. + } else { /* The sought EP already is in the list */
  53338. + CFI_INFO("%s: The sought EP already is in the list\n",
  53339. + __func__);
  53340. + }
  53341. +
  53342. + return retval;
  53343. +}
  53344. +
  53345. +/**
  53346. + * This function is called when the data stage of a 3-stage Control Write request
  53347. + * is complete.
  53348. + *
  53349. + */
  53350. +static int cfi_ctrl_write_complete(struct cfiobject *cfi,
  53351. + struct dwc_otg_pcd *pcd)
  53352. +{
  53353. + uint32_t addr, reg_value;
  53354. + uint16_t wIndex, wValue;
  53355. + uint8_t bRequest;
  53356. + uint8_t *buf = cfi->buf_out.buf;
  53357. + //struct usb_ctrlrequest *ctrl_req = &cfi->ctrl_req_saved;
  53358. + struct cfi_usb_ctrlrequest *ctrl_req = &cfi->ctrl_req;
  53359. + int retval = -DWC_E_NOT_SUPPORTED;
  53360. +
  53361. + CFI_INFO("%s\n", __func__);
  53362. +
  53363. + bRequest = ctrl_req->bRequest;
  53364. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  53365. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  53366. +
  53367. + /*
  53368. + * Save the pointer to the data stage in the ctrl_req's <data> field.
  53369. + * The request should be already saved in the command stage by now.
  53370. + */
  53371. + ctrl_req->data = cfi->buf_out.buf;
  53372. + cfi->need_status_in_complete = 0;
  53373. + cfi->need_gadget_att = 0;
  53374. +
  53375. + switch (bRequest) {
  53376. + case VEN_CORE_WRITE_REGISTER:
  53377. + /* The buffer contains raw data of the new value for the register */
  53378. + reg_value = *((uint32_t *) buf);
  53379. + if (wValue == 0) {
  53380. + addr = 0;
  53381. + //addr = (uint32_t) pcd->otg_dev->os_dep.base;
  53382. + addr += wIndex;
  53383. + } else {
  53384. + addr = (wValue << 16) | wIndex;
  53385. + }
  53386. +
  53387. + //writel(reg_value, addr);
  53388. +
  53389. + retval = 0;
  53390. + cfi->need_status_in_complete = 1;
  53391. + break;
  53392. +
  53393. + case VEN_CORE_SET_FEATURE:
  53394. + /* The buffer contains raw data of the new value of the feature */
  53395. + retval = cfi_set_feature_value(pcd);
  53396. + if (retval < 0)
  53397. + return retval;
  53398. +
  53399. + cfi->need_status_in_complete = 1;
  53400. + break;
  53401. +
  53402. + default:
  53403. + break;
  53404. + }
  53405. +
  53406. + return retval;
  53407. +}
  53408. +
  53409. +/**
  53410. + * This function builds the DMA descriptors for the SG buffer mode.
  53411. + */
  53412. +static void cfi_build_sg_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53413. + dwc_otg_pcd_request_t * req)
  53414. +{
  53415. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53416. + ddma_sg_buffer_setup_t *sgval = cfiep->bm_sg;
  53417. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53418. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53419. + dma_addr_t buff_addr = req->dma;
  53420. + int i;
  53421. + uint32_t txsize, off;
  53422. +
  53423. + txsize = sgval->wSize;
  53424. + off = sgval->bOffset;
  53425. +
  53426. +// CFI_INFO("%s: %s TXSIZE=0x%08x; OFFSET=0x%08x\n",
  53427. +// __func__, cfiep->ep->ep.name, txsize, off);
  53428. +
  53429. + for (i = 0; i < sgval->bCount; i++) {
  53430. + desc->status.b.bs = BS_HOST_BUSY;
  53431. + desc->buf = buff_addr;
  53432. + desc->status.b.l = 0;
  53433. + desc->status.b.ioc = 0;
  53434. + desc->status.b.sp = 0;
  53435. + desc->status.b.bytes = txsize;
  53436. + desc->status.b.bs = BS_HOST_READY;
  53437. +
  53438. + /* Set the next address of the buffer */
  53439. + buff_addr += txsize + off;
  53440. + desc_last = desc;
  53441. + desc++;
  53442. + }
  53443. +
  53444. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53445. + desc_last->status.b.l = 1;
  53446. + desc_last->status.b.ioc = 1;
  53447. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53448. + /* Save the last DMA descriptor pointer */
  53449. + cfiep->dma_desc_last = desc_last;
  53450. + cfiep->desc_count = sgval->bCount;
  53451. +}
  53452. +
  53453. +/**
  53454. + * This function builds the DMA descriptors for the Concatenation buffer mode.
  53455. + */
  53456. +static void cfi_build_concat_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53457. + dwc_otg_pcd_request_t * req)
  53458. +{
  53459. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53460. + ddma_concat_buffer_setup_t *concatval = cfiep->bm_concat;
  53461. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53462. + struct dwc_otg_dma_desc *desc_last = cfiep->ep->dwc_ep.descs;
  53463. + dma_addr_t buff_addr = req->dma;
  53464. + int i;
  53465. + uint16_t *txsize;
  53466. +
  53467. + txsize = concatval->wTxBytes;
  53468. +
  53469. + for (i = 0; i < concatval->hdr.bDescCount; i++) {
  53470. + desc->buf = buff_addr;
  53471. + desc->status.b.bs = BS_HOST_BUSY;
  53472. + desc->status.b.l = 0;
  53473. + desc->status.b.ioc = 0;
  53474. + desc->status.b.sp = 0;
  53475. + desc->status.b.bytes = *txsize;
  53476. + desc->status.b.bs = BS_HOST_READY;
  53477. +
  53478. + txsize++;
  53479. + /* Set the next address of the buffer */
  53480. + buff_addr += UGETW(ep->desc->wMaxPacketSize);
  53481. + desc_last = desc;
  53482. + desc++;
  53483. + }
  53484. +
  53485. + /* Set the last, ioc and sp bits on the Last DMA Descriptor */
  53486. + desc_last->status.b.l = 1;
  53487. + desc_last->status.b.ioc = 1;
  53488. + desc_last->status.b.sp = ep->dwc_ep.sent_zlp;
  53489. + cfiep->dma_desc_last = desc_last;
  53490. + cfiep->desc_count = concatval->hdr.bDescCount;
  53491. +}
  53492. +
  53493. +/**
  53494. + * This function builds the DMA descriptors for the Circular buffer mode
  53495. + */
  53496. +static void cfi_build_circ_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53497. + dwc_otg_pcd_request_t * req)
  53498. +{
  53499. + /* @todo: MAS - add implementation when this feature needs to be tested */
  53500. +}
  53501. +
  53502. +/**
  53503. + * This function builds the DMA descriptors for the Alignment buffer mode
  53504. + */
  53505. +static void cfi_build_align_descs(struct cfiobject *cfi, cfi_ep_t * cfiep,
  53506. + dwc_otg_pcd_request_t * req)
  53507. +{
  53508. + struct dwc_otg_pcd_ep *ep = cfiep->ep;
  53509. + ddma_align_buffer_setup_t *alignval = cfiep->bm_align;
  53510. + struct dwc_otg_dma_desc *desc = cfiep->ep->dwc_ep.descs;
  53511. + dma_addr_t buff_addr = req->dma;
  53512. +
  53513. + desc->status.b.bs = BS_HOST_BUSY;
  53514. + desc->status.b.l = 1;
  53515. + desc->status.b.ioc = 1;
  53516. + desc->status.b.sp = ep->dwc_ep.sent_zlp;
  53517. + desc->status.b.bytes = req->length;
  53518. + /* Adjust the buffer alignment */
  53519. + desc->buf = (buff_addr + alignval->bAlign);
  53520. + desc->status.b.bs = BS_HOST_READY;
  53521. + cfiep->dma_desc_last = desc;
  53522. + cfiep->desc_count = 1;
  53523. +}
  53524. +
  53525. +/**
  53526. + * This function builds the DMA descriptors chain for different modes of the
  53527. + * buffer setup of an endpoint.
  53528. + */
  53529. +static void cfi_build_descriptors(struct cfiobject *cfi,
  53530. + struct dwc_otg_pcd *pcd,
  53531. + struct dwc_otg_pcd_ep *ep,
  53532. + dwc_otg_pcd_request_t * req)
  53533. +{
  53534. + cfi_ep_t *cfiep;
  53535. +
  53536. + /* Get the cfiep by the dwc_otg_pcd_ep */
  53537. + cfiep = get_cfi_ep_by_pcd_ep(cfi, ep);
  53538. + if (NULL == cfiep) {
  53539. + CFI_INFO("%s: Unable to find a matching active endpoint\n",
  53540. + __func__);
  53541. + return;
  53542. + }
  53543. +
  53544. + cfiep->xfer_len = req->length;
  53545. +
  53546. + /* Iterate through all the DMA descriptors */
  53547. + switch (cfiep->ep->dwc_ep.buff_mode) {
  53548. + case BM_SG:
  53549. + cfi_build_sg_descs(cfi, cfiep, req);
  53550. + break;
  53551. +
  53552. + case BM_CONCAT:
  53553. + cfi_build_concat_descs(cfi, cfiep, req);
  53554. + break;
  53555. +
  53556. + case BM_CIRCULAR:
  53557. + cfi_build_circ_descs(cfi, cfiep, req);
  53558. + break;
  53559. +
  53560. + case BM_ALIGN:
  53561. + cfi_build_align_descs(cfi, cfiep, req);
  53562. + break;
  53563. +
  53564. + default:
  53565. + break;
  53566. + }
  53567. +}
  53568. +
  53569. +/**
  53570. + * Allocate DMA buffer for different Buffer modes.
  53571. + */
  53572. +static void *cfi_ep_alloc_buf(struct cfiobject *cfi, struct dwc_otg_pcd *pcd,
  53573. + struct dwc_otg_pcd_ep *ep, dma_addr_t * dma,
  53574. + unsigned size, gfp_t flags)
  53575. +{
  53576. + return DWC_DMA_ALLOC(size, dma);
  53577. +}
  53578. +
  53579. +/**
  53580. + * This function initializes the CFI object.
  53581. + */
  53582. +int init_cfi(cfiobject_t * cfiobj)
  53583. +{
  53584. + CFI_INFO("%s\n", __func__);
  53585. +
  53586. + /* Allocate a buffer for IN XFERs */
  53587. + cfiobj->buf_in.buf =
  53588. + DWC_DMA_ALLOC(CFI_IN_BUF_LEN, &cfiobj->buf_in.addr);
  53589. + if (NULL == cfiobj->buf_in.buf) {
  53590. + CFI_INFO("Unable to allocate buffer for INs\n");
  53591. + return -DWC_E_NO_MEMORY;
  53592. + }
  53593. +
  53594. + /* Allocate a buffer for OUT XFERs */
  53595. + cfiobj->buf_out.buf =
  53596. + DWC_DMA_ALLOC(CFI_OUT_BUF_LEN, &cfiobj->buf_out.addr);
  53597. + if (NULL == cfiobj->buf_out.buf) {
  53598. + CFI_INFO("Unable to allocate buffer for OUT\n");
  53599. + return -DWC_E_NO_MEMORY;
  53600. + }
  53601. +
  53602. + /* Initialize the callback function pointers */
  53603. + cfiobj->ops.release = cfi_release;
  53604. + cfiobj->ops.ep_enable = cfi_ep_enable;
  53605. + cfiobj->ops.ctrl_write_complete = cfi_ctrl_write_complete;
  53606. + cfiobj->ops.build_descriptors = cfi_build_descriptors;
  53607. + cfiobj->ops.ep_alloc_buf = cfi_ep_alloc_buf;
  53608. +
  53609. + /* Initialize the list of active endpoints in the CFI object */
  53610. + DWC_LIST_INIT(&cfiobj->active_eps);
  53611. +
  53612. + return 0;
  53613. +}
  53614. +
  53615. +/**
  53616. + * This function reads the required feature's current value into the buffer
  53617. + *
  53618. + * @retval: Returns negative as error, or the data length of the feature
  53619. + */
  53620. +static int cfi_get_feature_value(uint8_t * buf, uint16_t buflen,
  53621. + struct dwc_otg_pcd *pcd,
  53622. + struct cfi_usb_ctrlrequest *ctrl_req)
  53623. +{
  53624. + int retval = -DWC_E_NOT_SUPPORTED;
  53625. + struct dwc_otg_core_if *coreif = GET_CORE_IF(pcd);
  53626. + uint16_t dfifo, rxfifo, txfifo;
  53627. +
  53628. + switch (ctrl_req->wIndex) {
  53629. + /* Whether the DDMA is enabled or not */
  53630. + case FT_ID_DMA_MODE:
  53631. + *buf = (coreif->dma_enable && coreif->dma_desc_enable) ? 1 : 0;
  53632. + retval = 1;
  53633. + break;
  53634. +
  53635. + case FT_ID_DMA_BUFFER_SETUP:
  53636. + retval = cfi_ep_get_sg_val(buf, pcd, ctrl_req);
  53637. + break;
  53638. +
  53639. + case FT_ID_DMA_BUFF_ALIGN:
  53640. + retval = cfi_ep_get_align_val(buf, pcd, ctrl_req);
  53641. + break;
  53642. +
  53643. + case FT_ID_DMA_CONCAT_SETUP:
  53644. + retval = cfi_ep_get_concat_val(buf, pcd, ctrl_req);
  53645. + break;
  53646. +
  53647. + case FT_ID_DMA_CIRCULAR:
  53648. + CFI_INFO("GetFeature value (FT_ID_DMA_CIRCULAR)\n");
  53649. + break;
  53650. +
  53651. + case FT_ID_THRESHOLD_SETUP:
  53652. + CFI_INFO("GetFeature value (FT_ID_THRESHOLD_SETUP)\n");
  53653. + break;
  53654. +
  53655. + case FT_ID_DFIFO_DEPTH:
  53656. + dfifo = get_dfifo_size(coreif);
  53657. + *((uint16_t *) buf) = dfifo;
  53658. + retval = sizeof(uint16_t);
  53659. + break;
  53660. +
  53661. + case FT_ID_TX_FIFO_DEPTH:
  53662. + retval = get_txfifo_size(pcd, ctrl_req->wValue);
  53663. + if (retval >= 0) {
  53664. + txfifo = retval;
  53665. + *((uint16_t *) buf) = txfifo;
  53666. + retval = sizeof(uint16_t);
  53667. + }
  53668. + break;
  53669. +
  53670. + case FT_ID_RX_FIFO_DEPTH:
  53671. + retval = get_rxfifo_size(coreif, ctrl_req->wValue);
  53672. + if (retval >= 0) {
  53673. + rxfifo = retval;
  53674. + *((uint16_t *) buf) = rxfifo;
  53675. + retval = sizeof(uint16_t);
  53676. + }
  53677. + break;
  53678. + }
  53679. +
  53680. + return retval;
  53681. +}
  53682. +
  53683. +/**
  53684. + * This function resets the SG for the specified EP to its default value
  53685. + */
  53686. +static int cfi_reset_sg_val(cfi_ep_t * cfiep)
  53687. +{
  53688. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53689. + return 0;
  53690. +}
  53691. +
  53692. +/**
  53693. + * This function resets the Alignment for the specified EP to its default value
  53694. + */
  53695. +static int cfi_reset_align_val(cfi_ep_t * cfiep)
  53696. +{
  53697. + dwc_memset(cfiep->bm_sg, 0, sizeof(ddma_sg_buffer_setup_t));
  53698. + return 0;
  53699. +}
  53700. +
  53701. +/**
  53702. + * This function resets the Concatenation for the specified EP to its default value
  53703. + * This function will also set the value of the wTxBytes field to NULL after
  53704. + * freeing the memory previously allocated for this field.
  53705. + */
  53706. +static int cfi_reset_concat_val(cfi_ep_t * cfiep)
  53707. +{
  53708. + /* First we need to free the wTxBytes field */
  53709. + if (cfiep->bm_concat->wTxBytes) {
  53710. + DWC_FREE(cfiep->bm_concat->wTxBytes);
  53711. + cfiep->bm_concat->wTxBytes = NULL;
  53712. + }
  53713. +
  53714. + dwc_memset(cfiep->bm_concat, 0, sizeof(ddma_concat_buffer_setup_t));
  53715. + return 0;
  53716. +}
  53717. +
  53718. +/**
  53719. + * This function resets all the buffer setups of the specified endpoint
  53720. + */
  53721. +static int cfi_ep_reset_all_setup_vals(cfi_ep_t * cfiep)
  53722. +{
  53723. + cfi_reset_sg_val(cfiep);
  53724. + cfi_reset_align_val(cfiep);
  53725. + cfi_reset_concat_val(cfiep);
  53726. + return 0;
  53727. +}
  53728. +
  53729. +static int cfi_handle_reset_fifo_val(struct dwc_otg_pcd *pcd, uint8_t ep_addr,
  53730. + uint8_t rx_rst, uint8_t tx_rst)
  53731. +{
  53732. + int retval = -DWC_E_INVALID;
  53733. + uint16_t tx_siz[15];
  53734. + uint16_t rx_siz = 0;
  53735. + dwc_otg_pcd_ep_t *ep = NULL;
  53736. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  53737. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  53738. +
  53739. + if (rx_rst) {
  53740. + rx_siz = params->dev_rx_fifo_size;
  53741. + params->dev_rx_fifo_size = GET_CORE_IF(pcd)->init_rxfsiz;
  53742. + }
  53743. +
  53744. + if (tx_rst) {
  53745. + if (ep_addr == 0) {
  53746. + int i;
  53747. +
  53748. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  53749. + tx_siz[i] =
  53750. + core_if->core_params->dev_tx_fifo_size[i];
  53751. + core_if->core_params->dev_tx_fifo_size[i] =
  53752. + core_if->init_txfsiz[i];
  53753. + }
  53754. + } else {
  53755. +
  53756. + ep = get_ep_by_addr(pcd, ep_addr);
  53757. +
  53758. + if (NULL == ep) {
  53759. + CFI_INFO
  53760. + ("%s: Unable to get the endpoint addr=0x%02x\n",
  53761. + __func__, ep_addr);
  53762. + return -DWC_E_INVALID;
  53763. + }
  53764. +
  53765. + tx_siz[0] =
  53766. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num -
  53767. + 1];
  53768. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] =
  53769. + GET_CORE_IF(pcd)->init_txfsiz[ep->
  53770. + dwc_ep.tx_fifo_num -
  53771. + 1];
  53772. + }
  53773. + }
  53774. +
  53775. + if (resize_fifos(GET_CORE_IF(pcd))) {
  53776. + retval = 0;
  53777. + } else {
  53778. + CFI_INFO
  53779. + ("%s: Error resetting the feature Reset All(FIFO size)\n",
  53780. + __func__);
  53781. + if (rx_rst) {
  53782. + params->dev_rx_fifo_size = rx_siz;
  53783. + }
  53784. +
  53785. + if (tx_rst) {
  53786. + if (ep_addr == 0) {
  53787. + int i;
  53788. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps;
  53789. + i++) {
  53790. + core_if->
  53791. + core_params->dev_tx_fifo_size[i] =
  53792. + tx_siz[i];
  53793. + }
  53794. + } else {
  53795. + params->dev_tx_fifo_size[ep->
  53796. + dwc_ep.tx_fifo_num -
  53797. + 1] = tx_siz[0];
  53798. + }
  53799. + }
  53800. + retval = -DWC_E_INVALID;
  53801. + }
  53802. + return retval;
  53803. +}
  53804. +
  53805. +static int cfi_handle_reset_all(struct dwc_otg_pcd *pcd, uint8_t addr)
  53806. +{
  53807. + int retval = 0;
  53808. + cfi_ep_t *cfiep;
  53809. + cfiobject_t *cfi = pcd->cfi;
  53810. + dwc_list_link_t *tmp;
  53811. +
  53812. + retval = cfi_handle_reset_fifo_val(pcd, addr, 1, 1);
  53813. + if (retval < 0) {
  53814. + return retval;
  53815. + }
  53816. +
  53817. + /* If the EP address is known then reset the features for only that EP */
  53818. + if (addr) {
  53819. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53820. + if (NULL == cfiep) {
  53821. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53822. + __func__, addr);
  53823. + return -DWC_E_INVALID;
  53824. + }
  53825. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53826. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53827. + }
  53828. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53829. + else {
  53830. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53831. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53832. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53833. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53834. + retval = cfi_ep_reset_all_setup_vals(cfiep);
  53835. + cfiep->ep->dwc_ep.buff_mode = BM_STANDARD;
  53836. + if (retval < 0) {
  53837. + CFI_INFO
  53838. + ("%s: Error resetting the feature Reset All\n",
  53839. + __func__);
  53840. + return retval;
  53841. + }
  53842. + }
  53843. + }
  53844. + return retval;
  53845. +}
  53846. +
  53847. +static int cfi_handle_reset_dma_buff_setup(struct dwc_otg_pcd *pcd,
  53848. + uint8_t addr)
  53849. +{
  53850. + int retval = 0;
  53851. + cfi_ep_t *cfiep;
  53852. + cfiobject_t *cfi = pcd->cfi;
  53853. + dwc_list_link_t *tmp;
  53854. +
  53855. + /* If the EP address is known then reset the features for only that EP */
  53856. + if (addr) {
  53857. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53858. + if (NULL == cfiep) {
  53859. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53860. + __func__, addr);
  53861. + return -DWC_E_INVALID;
  53862. + }
  53863. + retval = cfi_reset_sg_val(cfiep);
  53864. + }
  53865. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53866. + else {
  53867. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53868. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53869. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53870. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53871. + retval = cfi_reset_sg_val(cfiep);
  53872. + if (retval < 0) {
  53873. + CFI_INFO
  53874. + ("%s: Error resetting the feature Buffer Setup\n",
  53875. + __func__);
  53876. + return retval;
  53877. + }
  53878. + }
  53879. + }
  53880. + return retval;
  53881. +}
  53882. +
  53883. +static int cfi_handle_reset_concat_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53884. +{
  53885. + int retval = 0;
  53886. + cfi_ep_t *cfiep;
  53887. + cfiobject_t *cfi = pcd->cfi;
  53888. + dwc_list_link_t *tmp;
  53889. +
  53890. + /* If the EP address is known then reset the features for only that EP */
  53891. + if (addr) {
  53892. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53893. + if (NULL == cfiep) {
  53894. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53895. + __func__, addr);
  53896. + return -DWC_E_INVALID;
  53897. + }
  53898. + retval = cfi_reset_concat_val(cfiep);
  53899. + }
  53900. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53901. + else {
  53902. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53903. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53904. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53905. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53906. + retval = cfi_reset_concat_val(cfiep);
  53907. + if (retval < 0) {
  53908. + CFI_INFO
  53909. + ("%s: Error resetting the feature Concatenation Value\n",
  53910. + __func__);
  53911. + return retval;
  53912. + }
  53913. + }
  53914. + }
  53915. + return retval;
  53916. +}
  53917. +
  53918. +static int cfi_handle_reset_align_val(struct dwc_otg_pcd *pcd, uint8_t addr)
  53919. +{
  53920. + int retval = 0;
  53921. + cfi_ep_t *cfiep;
  53922. + cfiobject_t *cfi = pcd->cfi;
  53923. + dwc_list_link_t *tmp;
  53924. +
  53925. + /* If the EP address is known then reset the features for only that EP */
  53926. + if (addr) {
  53927. + cfiep = get_cfi_ep_by_addr(pcd->cfi, addr);
  53928. + if (NULL == cfiep) {
  53929. + CFI_INFO("%s: Error getting the EP address 0x%02x\n",
  53930. + __func__, addr);
  53931. + return -DWC_E_INVALID;
  53932. + }
  53933. + retval = cfi_reset_align_val(cfiep);
  53934. + }
  53935. + /* Otherwise (wValue == 0), reset all features of all EP's */
  53936. + else {
  53937. + /* Traverse all the active EP's and reset the feature(s) value(s) */
  53938. + //list_for_each_entry(cfiep, &cfi->active_eps, lh) {
  53939. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  53940. + cfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  53941. + retval = cfi_reset_align_val(cfiep);
  53942. + if (retval < 0) {
  53943. + CFI_INFO
  53944. + ("%s: Error resetting the feature Aliignment Value\n",
  53945. + __func__);
  53946. + return retval;
  53947. + }
  53948. + }
  53949. + }
  53950. + return retval;
  53951. +
  53952. +}
  53953. +
  53954. +static int cfi_preproc_reset(struct dwc_otg_pcd *pcd,
  53955. + struct cfi_usb_ctrlrequest *req)
  53956. +{
  53957. + int retval = 0;
  53958. +
  53959. + switch (req->wIndex) {
  53960. + case 0:
  53961. + /* Reset all features */
  53962. + retval = cfi_handle_reset_all(pcd, req->wValue & 0xff);
  53963. + break;
  53964. +
  53965. + case FT_ID_DMA_BUFFER_SETUP:
  53966. + /* Reset the SG buffer setup */
  53967. + retval =
  53968. + cfi_handle_reset_dma_buff_setup(pcd, req->wValue & 0xff);
  53969. + break;
  53970. +
  53971. + case FT_ID_DMA_CONCAT_SETUP:
  53972. + /* Reset the Concatenation buffer setup */
  53973. + retval = cfi_handle_reset_concat_val(pcd, req->wValue & 0xff);
  53974. + break;
  53975. +
  53976. + case FT_ID_DMA_BUFF_ALIGN:
  53977. + /* Reset the Alignment buffer setup */
  53978. + retval = cfi_handle_reset_align_val(pcd, req->wValue & 0xff);
  53979. + break;
  53980. +
  53981. + case FT_ID_TX_FIFO_DEPTH:
  53982. + retval =
  53983. + cfi_handle_reset_fifo_val(pcd, req->wValue & 0xff, 0, 1);
  53984. + pcd->cfi->need_gadget_att = 0;
  53985. + break;
  53986. +
  53987. + case FT_ID_RX_FIFO_DEPTH:
  53988. + retval = cfi_handle_reset_fifo_val(pcd, 0, 1, 0);
  53989. + pcd->cfi->need_gadget_att = 0;
  53990. + break;
  53991. + default:
  53992. + break;
  53993. + }
  53994. + return retval;
  53995. +}
  53996. +
  53997. +/**
  53998. + * This function sets a new value for the SG buffer setup.
  53999. + */
  54000. +static int cfi_ep_set_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54001. +{
  54002. + uint8_t inaddr, outaddr;
  54003. + cfi_ep_t *epin, *epout;
  54004. + ddma_sg_buffer_setup_t *psgval;
  54005. + uint32_t desccount, size;
  54006. +
  54007. + CFI_INFO("%s\n", __func__);
  54008. +
  54009. + psgval = (ddma_sg_buffer_setup_t *) buf;
  54010. + desccount = (uint32_t) psgval->bCount;
  54011. + size = (uint32_t) psgval->wSize;
  54012. +
  54013. + /* Check the DMA descriptor count */
  54014. + if ((desccount > MAX_DMA_DESCS_PER_EP) || (desccount == 0)) {
  54015. + CFI_INFO
  54016. + ("%s: The count of DMA Descriptors should be between 1 and %d\n",
  54017. + __func__, MAX_DMA_DESCS_PER_EP);
  54018. + return -DWC_E_INVALID;
  54019. + }
  54020. +
  54021. + /* Check the DMA descriptor count */
  54022. +
  54023. + if (size == 0) {
  54024. +
  54025. + CFI_INFO("%s: The transfer size should be at least 1 byte\n",
  54026. + __func__);
  54027. +
  54028. + return -DWC_E_INVALID;
  54029. +
  54030. + }
  54031. +
  54032. + inaddr = psgval->bInEndpointAddress;
  54033. + outaddr = psgval->bOutEndpointAddress;
  54034. +
  54035. + epin = get_cfi_ep_by_addr(pcd->cfi, inaddr);
  54036. + epout = get_cfi_ep_by_addr(pcd->cfi, outaddr);
  54037. +
  54038. + if (NULL == epin || NULL == epout) {
  54039. + CFI_INFO
  54040. + ("%s: Unable to get the endpoints inaddr=0x%02x outaddr=0x%02x\n",
  54041. + __func__, inaddr, outaddr);
  54042. + return -DWC_E_INVALID;
  54043. + }
  54044. +
  54045. + epin->ep->dwc_ep.buff_mode = BM_SG;
  54046. + dwc_memcpy(epin->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54047. +
  54048. + epout->ep->dwc_ep.buff_mode = BM_SG;
  54049. + dwc_memcpy(epout->bm_sg, psgval, sizeof(ddma_sg_buffer_setup_t));
  54050. +
  54051. + return 0;
  54052. +}
  54053. +
  54054. +/**
  54055. + * This function sets a new value for the buffer Alignment setup.
  54056. + */
  54057. +static int cfi_ep_set_alignment_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54058. +{
  54059. + cfi_ep_t *ep;
  54060. + uint8_t addr;
  54061. + ddma_align_buffer_setup_t *palignval;
  54062. +
  54063. + palignval = (ddma_align_buffer_setup_t *) buf;
  54064. + addr = palignval->bEndpointAddress;
  54065. +
  54066. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54067. +
  54068. + if (NULL == ep) {
  54069. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54070. + __func__, addr);
  54071. + return -DWC_E_INVALID;
  54072. + }
  54073. +
  54074. + ep->ep->dwc_ep.buff_mode = BM_ALIGN;
  54075. + dwc_memcpy(ep->bm_align, palignval, sizeof(ddma_align_buffer_setup_t));
  54076. +
  54077. + return 0;
  54078. +}
  54079. +
  54080. +/**
  54081. + * This function sets a new value for the Concatenation buffer setup.
  54082. + */
  54083. +static int cfi_ep_set_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd)
  54084. +{
  54085. + uint8_t addr;
  54086. + cfi_ep_t *ep;
  54087. + struct _ddma_concat_buffer_setup_hdr *pConcatValHdr;
  54088. + uint16_t *pVals;
  54089. + uint32_t desccount;
  54090. + int i;
  54091. + uint16_t mps;
  54092. +
  54093. + pConcatValHdr = (struct _ddma_concat_buffer_setup_hdr *)buf;
  54094. + desccount = (uint32_t) pConcatValHdr->bDescCount;
  54095. + pVals = (uint16_t *) (buf + BS_CONCAT_VAL_HDR_LEN);
  54096. +
  54097. + /* Check the DMA descriptor count */
  54098. + if (desccount > MAX_DMA_DESCS_PER_EP) {
  54099. + CFI_INFO("%s: Maximum DMA Descriptor count should be %d\n",
  54100. + __func__, MAX_DMA_DESCS_PER_EP);
  54101. + return -DWC_E_INVALID;
  54102. + }
  54103. +
  54104. + addr = pConcatValHdr->bEndpointAddress;
  54105. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54106. + if (NULL == ep) {
  54107. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54108. + __func__, addr);
  54109. + return -DWC_E_INVALID;
  54110. + }
  54111. +
  54112. + mps = UGETW(ep->ep->desc->wMaxPacketSize);
  54113. +
  54114. +#if 0
  54115. + for (i = 0; i < desccount; i++) {
  54116. + CFI_INFO("%s: wTxSize[%d]=0x%04x\n", __func__, i, pVals[i]);
  54117. + }
  54118. + CFI_INFO("%s: epname=%s; mps=%d\n", __func__, ep->ep->ep.name, mps);
  54119. +#endif
  54120. +
  54121. + /* Check the wTxSizes to be less than or equal to the mps */
  54122. + for (i = 0; i < desccount; i++) {
  54123. + if (pVals[i] > mps) {
  54124. + CFI_INFO
  54125. + ("%s: ERROR - the wTxSize[%d] should be <= MPS (wTxSize=%d)\n",
  54126. + __func__, i, pVals[i]);
  54127. + return -DWC_E_INVALID;
  54128. + }
  54129. + }
  54130. +
  54131. + ep->ep->dwc_ep.buff_mode = BM_CONCAT;
  54132. + dwc_memcpy(ep->bm_concat, pConcatValHdr, BS_CONCAT_VAL_HDR_LEN);
  54133. +
  54134. + /* Free the previously allocated storage for the wTxBytes */
  54135. + if (ep->bm_concat->wTxBytes) {
  54136. + DWC_FREE(ep->bm_concat->wTxBytes);
  54137. + }
  54138. +
  54139. + /* Allocate a new storage for the wTxBytes field */
  54140. + ep->bm_concat->wTxBytes =
  54141. + DWC_ALLOC(sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54142. + if (NULL == ep->bm_concat->wTxBytes) {
  54143. + CFI_INFO("%s: Unable to allocate memory\n", __func__);
  54144. + return -DWC_E_NO_MEMORY;
  54145. + }
  54146. +
  54147. + /* Copy the new values into the wTxBytes filed */
  54148. + dwc_memcpy(ep->bm_concat->wTxBytes, buf + BS_CONCAT_VAL_HDR_LEN,
  54149. + sizeof(uint16_t) * pConcatValHdr->bDescCount);
  54150. +
  54151. + return 0;
  54152. +}
  54153. +
  54154. +/**
  54155. + * This function calculates the total of all FIFO sizes
  54156. + *
  54157. + * @param core_if Programming view of DWC_otg controller
  54158. + *
  54159. + * @return The total of data FIFO sizes.
  54160. + *
  54161. + */
  54162. +static uint16_t get_dfifo_size(dwc_otg_core_if_t * core_if)
  54163. +{
  54164. + dwc_otg_core_params_t *params = core_if->core_params;
  54165. + uint16_t dfifo_total = 0;
  54166. + int i;
  54167. +
  54168. + /* The shared RxFIFO size */
  54169. + dfifo_total =
  54170. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54171. +
  54172. + /* Add up each TxFIFO size to the total */
  54173. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54174. + dfifo_total += params->dev_tx_fifo_size[i];
  54175. + }
  54176. +
  54177. + return dfifo_total;
  54178. +}
  54179. +
  54180. +/**
  54181. + * This function returns Rx FIFO size
  54182. + *
  54183. + * @param core_if Programming view of DWC_otg controller
  54184. + *
  54185. + * @return The total of data FIFO sizes.
  54186. + *
  54187. + */
  54188. +static int32_t get_rxfifo_size(dwc_otg_core_if_t * core_if, uint16_t wValue)
  54189. +{
  54190. + switch (wValue >> 8) {
  54191. + case 0:
  54192. + return (core_if->pwron_rxfsiz <
  54193. + 32768) ? core_if->pwron_rxfsiz : 32768;
  54194. + break;
  54195. + case 1:
  54196. + return core_if->core_params->dev_rx_fifo_size;
  54197. + break;
  54198. + default:
  54199. + return -DWC_E_INVALID;
  54200. + break;
  54201. + }
  54202. +}
  54203. +
  54204. +/**
  54205. + * This function returns Tx FIFO size for IN EP
  54206. + *
  54207. + * @param core_if Programming view of DWC_otg controller
  54208. + *
  54209. + * @return The total of data FIFO sizes.
  54210. + *
  54211. + */
  54212. +static int32_t get_txfifo_size(struct dwc_otg_pcd *pcd, uint16_t wValue)
  54213. +{
  54214. + dwc_otg_pcd_ep_t *ep;
  54215. +
  54216. + ep = get_ep_by_addr(pcd, wValue & 0xff);
  54217. +
  54218. + if (NULL == ep) {
  54219. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54220. + __func__, wValue & 0xff);
  54221. + return -DWC_E_INVALID;
  54222. + }
  54223. +
  54224. + if (!ep->dwc_ep.is_in) {
  54225. + CFI_INFO
  54226. + ("%s: No Tx FIFO assingned to the Out endpoint addr=0x%02x\n",
  54227. + __func__, wValue & 0xff);
  54228. + return -DWC_E_INVALID;
  54229. + }
  54230. +
  54231. + switch (wValue >> 8) {
  54232. + case 0:
  54233. + return (GET_CORE_IF(pcd)->pwron_txfsiz
  54234. + [ep->dwc_ep.tx_fifo_num - 1] <
  54235. + 768) ? GET_CORE_IF(pcd)->pwron_txfsiz[ep->
  54236. + dwc_ep.tx_fifo_num
  54237. + - 1] : 32768;
  54238. + break;
  54239. + case 1:
  54240. + return GET_CORE_IF(pcd)->core_params->
  54241. + dev_tx_fifo_size[ep->dwc_ep.num - 1];
  54242. + break;
  54243. + default:
  54244. + return -DWC_E_INVALID;
  54245. + break;
  54246. + }
  54247. +}
  54248. +
  54249. +/**
  54250. + * This function checks if the submitted combination of
  54251. + * device mode FIFO sizes is possible or not.
  54252. + *
  54253. + * @param core_if Programming view of DWC_otg controller
  54254. + *
  54255. + * @return 1 if possible, 0 otherwise.
  54256. + *
  54257. + */
  54258. +static uint8_t check_fifo_sizes(dwc_otg_core_if_t * core_if)
  54259. +{
  54260. + uint16_t dfifo_actual = 0;
  54261. + dwc_otg_core_params_t *params = core_if->core_params;
  54262. + uint16_t start_addr = 0;
  54263. + int i;
  54264. +
  54265. + dfifo_actual =
  54266. + params->dev_rx_fifo_size + params->dev_nperio_tx_fifo_size;
  54267. +
  54268. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54269. + dfifo_actual += params->dev_tx_fifo_size[i];
  54270. + }
  54271. +
  54272. + if (dfifo_actual > core_if->total_fifo_size) {
  54273. + return 0;
  54274. + }
  54275. +
  54276. + if (params->dev_rx_fifo_size > 32768 || params->dev_rx_fifo_size < 16)
  54277. + return 0;
  54278. +
  54279. + if (params->dev_nperio_tx_fifo_size > 32768
  54280. + || params->dev_nperio_tx_fifo_size < 16)
  54281. + return 0;
  54282. +
  54283. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54284. +
  54285. + if (params->dev_tx_fifo_size[i] > 768
  54286. + || params->dev_tx_fifo_size[i] < 4)
  54287. + return 0;
  54288. + }
  54289. +
  54290. + if (params->dev_rx_fifo_size > core_if->pwron_rxfsiz)
  54291. + return 0;
  54292. + start_addr = params->dev_rx_fifo_size;
  54293. +
  54294. + if (params->dev_nperio_tx_fifo_size > core_if->pwron_gnptxfsiz)
  54295. + return 0;
  54296. + start_addr += params->dev_nperio_tx_fifo_size;
  54297. +
  54298. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54299. +
  54300. + if (params->dev_tx_fifo_size[i] > core_if->pwron_txfsiz[i])
  54301. + return 0;
  54302. + start_addr += params->dev_tx_fifo_size[i];
  54303. + }
  54304. +
  54305. + return 1;
  54306. +}
  54307. +
  54308. +/**
  54309. + * This function resizes Device mode FIFOs
  54310. + *
  54311. + * @param core_if Programming view of DWC_otg controller
  54312. + *
  54313. + * @return 1 if successful, 0 otherwise
  54314. + *
  54315. + */
  54316. +static uint8_t resize_fifos(dwc_otg_core_if_t * core_if)
  54317. +{
  54318. + int i = 0;
  54319. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  54320. + dwc_otg_core_params_t *params = core_if->core_params;
  54321. + uint32_t rx_fifo_size;
  54322. + fifosize_data_t nptxfifosize;
  54323. + fifosize_data_t txfifosize[15];
  54324. +
  54325. + uint32_t rx_fsz_bak;
  54326. + uint32_t nptxfsz_bak;
  54327. + uint32_t txfsz_bak[15];
  54328. +
  54329. + uint16_t start_address;
  54330. + uint8_t retval = 1;
  54331. +
  54332. + if (!check_fifo_sizes(core_if)) {
  54333. + return 0;
  54334. + }
  54335. +
  54336. + /* Configure data FIFO sizes */
  54337. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  54338. + rx_fsz_bak = DWC_READ_REG32(&global_regs->grxfsiz);
  54339. + rx_fifo_size = params->dev_rx_fifo_size;
  54340. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  54341. +
  54342. + /*
  54343. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  54344. + * Indexes of the FIFO size module parameters in the
  54345. + * dev_tx_fifo_size array and the FIFO size registers in
  54346. + * the dtxfsiz array run from 0 to 14.
  54347. + */
  54348. +
  54349. + /* Non-periodic Tx FIFO */
  54350. + nptxfsz_bak = DWC_READ_REG32(&global_regs->gnptxfsiz);
  54351. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  54352. + start_address = params->dev_rx_fifo_size;
  54353. + nptxfifosize.b.startaddr = start_address;
  54354. +
  54355. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  54356. +
  54357. + start_address += nptxfifosize.b.depth;
  54358. +
  54359. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54360. + txfsz_bak[i] = DWC_READ_REG32(&global_regs->dtxfsiz[i]);
  54361. +
  54362. + txfifosize[i].b.depth = params->dev_tx_fifo_size[i];
  54363. + txfifosize[i].b.startaddr = start_address;
  54364. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54365. + txfifosize[i].d32);
  54366. +
  54367. + start_address += txfifosize[i].b.depth;
  54368. + }
  54369. +
  54370. + /** Check if register values are set correctly */
  54371. + if (rx_fifo_size != DWC_READ_REG32(&global_regs->grxfsiz)) {
  54372. + retval = 0;
  54373. + }
  54374. +
  54375. + if (nptxfifosize.d32 != DWC_READ_REG32(&global_regs->gnptxfsiz)) {
  54376. + retval = 0;
  54377. + }
  54378. +
  54379. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54380. + if (txfifosize[i].d32 !=
  54381. + DWC_READ_REG32(&global_regs->dtxfsiz[i])) {
  54382. + retval = 0;
  54383. + }
  54384. + }
  54385. +
  54386. + /** If register values are not set correctly, reset old values */
  54387. + if (retval == 0) {
  54388. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fsz_bak);
  54389. +
  54390. + /* Non-periodic Tx FIFO */
  54391. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfsz_bak);
  54392. +
  54393. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  54394. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  54395. + txfsz_bak[i]);
  54396. + }
  54397. + }
  54398. + } else {
  54399. + return 0;
  54400. + }
  54401. +
  54402. + /* Flush the FIFOs */
  54403. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  54404. + dwc_otg_flush_rx_fifo(core_if);
  54405. +
  54406. + return retval;
  54407. +}
  54408. +
  54409. +/**
  54410. + * This function sets a new value for the buffer Alignment setup.
  54411. + */
  54412. +static int cfi_ep_set_tx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54413. +{
  54414. + int retval;
  54415. + uint32_t fsiz;
  54416. + uint16_t size;
  54417. + uint16_t ep_addr;
  54418. + dwc_otg_pcd_ep_t *ep;
  54419. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54420. + tx_fifo_size_setup_t *ptxfifoval;
  54421. +
  54422. + ptxfifoval = (tx_fifo_size_setup_t *) buf;
  54423. + ep_addr = ptxfifoval->bEndpointAddress;
  54424. + size = ptxfifoval->wDepth;
  54425. +
  54426. + ep = get_ep_by_addr(pcd, ep_addr);
  54427. +
  54428. + CFI_INFO
  54429. + ("%s: Set Tx FIFO size: endpoint addr=0x%02x, depth=%d, FIFO Num=%d\n",
  54430. + __func__, ep_addr, size, ep->dwc_ep.tx_fifo_num);
  54431. +
  54432. + if (NULL == ep) {
  54433. + CFI_INFO("%s: Unable to get the endpoint addr=0x%02x\n",
  54434. + __func__, ep_addr);
  54435. + return -DWC_E_INVALID;
  54436. + }
  54437. +
  54438. + fsiz = params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1];
  54439. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = size;
  54440. +
  54441. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54442. + retval = 0;
  54443. + } else {
  54444. + CFI_INFO
  54445. + ("%s: Error setting the feature Tx FIFO Size for EP%d\n",
  54446. + __func__, ep_addr);
  54447. + params->dev_tx_fifo_size[ep->dwc_ep.tx_fifo_num - 1] = fsiz;
  54448. + retval = -DWC_E_INVALID;
  54449. + }
  54450. +
  54451. + return retval;
  54452. +}
  54453. +
  54454. +/**
  54455. + * This function sets a new value for the buffer Alignment setup.
  54456. + */
  54457. +static int cfi_set_rx_fifo_val(uint8_t * buf, dwc_otg_pcd_t * pcd)
  54458. +{
  54459. + int retval;
  54460. + uint32_t fsiz;
  54461. + uint16_t size;
  54462. + dwc_otg_core_params_t *params = GET_CORE_IF(pcd)->core_params;
  54463. + rx_fifo_size_setup_t *prxfifoval;
  54464. +
  54465. + prxfifoval = (rx_fifo_size_setup_t *) buf;
  54466. + size = prxfifoval->wDepth;
  54467. +
  54468. + fsiz = params->dev_rx_fifo_size;
  54469. + params->dev_rx_fifo_size = size;
  54470. +
  54471. + if (resize_fifos(GET_CORE_IF(pcd))) {
  54472. + retval = 0;
  54473. + } else {
  54474. + CFI_INFO("%s: Error setting the feature Rx FIFO Size\n",
  54475. + __func__);
  54476. + params->dev_rx_fifo_size = fsiz;
  54477. + retval = -DWC_E_INVALID;
  54478. + }
  54479. +
  54480. + return retval;
  54481. +}
  54482. +
  54483. +/**
  54484. + * This function reads the SG of an EP's buffer setup into the buffer buf
  54485. + */
  54486. +static int cfi_ep_get_sg_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54487. + struct cfi_usb_ctrlrequest *req)
  54488. +{
  54489. + int retval = -DWC_E_INVALID;
  54490. + uint8_t addr;
  54491. + cfi_ep_t *ep;
  54492. +
  54493. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54494. + addr = req->wValue & 0xFF;
  54495. + if (addr == 0) /* The address should be non-zero */
  54496. + return retval;
  54497. +
  54498. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54499. + if (NULL == ep) {
  54500. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54501. + __func__, addr);
  54502. + return retval;
  54503. + }
  54504. +
  54505. + dwc_memcpy(buf, ep->bm_sg, BS_SG_VAL_DESC_LEN);
  54506. + retval = BS_SG_VAL_DESC_LEN;
  54507. + return retval;
  54508. +}
  54509. +
  54510. +/**
  54511. + * This function reads the Concatenation value of an EP's buffer mode into
  54512. + * the buffer buf
  54513. + */
  54514. +static int cfi_ep_get_concat_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54515. + struct cfi_usb_ctrlrequest *req)
  54516. +{
  54517. + int retval = -DWC_E_INVALID;
  54518. + uint8_t addr;
  54519. + cfi_ep_t *ep;
  54520. + uint8_t desc_count;
  54521. +
  54522. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54523. + addr = req->wValue & 0xFF;
  54524. + if (addr == 0) /* The address should be non-zero */
  54525. + return retval;
  54526. +
  54527. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54528. + if (NULL == ep) {
  54529. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54530. + __func__, addr);
  54531. + return retval;
  54532. + }
  54533. +
  54534. + /* Copy the header to the buffer */
  54535. + dwc_memcpy(buf, ep->bm_concat, BS_CONCAT_VAL_HDR_LEN);
  54536. + /* Advance the buffer pointer by the header size */
  54537. + buf += BS_CONCAT_VAL_HDR_LEN;
  54538. +
  54539. + desc_count = ep->bm_concat->hdr.bDescCount;
  54540. + /* Copy alll the wTxBytes to the buffer */
  54541. + dwc_memcpy(buf, ep->bm_concat->wTxBytes, sizeof(uid16_t) * desc_count);
  54542. +
  54543. + retval = BS_CONCAT_VAL_HDR_LEN + sizeof(uid16_t) * desc_count;
  54544. + return retval;
  54545. +}
  54546. +
  54547. +/**
  54548. + * This function reads the buffer Alignment value of an EP's buffer mode into
  54549. + * the buffer buf
  54550. + *
  54551. + * @return The total number of bytes copied to the buffer or negative error code.
  54552. + */
  54553. +static int cfi_ep_get_align_val(uint8_t * buf, struct dwc_otg_pcd *pcd,
  54554. + struct cfi_usb_ctrlrequest *req)
  54555. +{
  54556. + int retval = -DWC_E_INVALID;
  54557. + uint8_t addr;
  54558. + cfi_ep_t *ep;
  54559. +
  54560. + /* The Low Byte of the wValue contains a non-zero address of the endpoint */
  54561. + addr = req->wValue & 0xFF;
  54562. + if (addr == 0) /* The address should be non-zero */
  54563. + return retval;
  54564. +
  54565. + ep = get_cfi_ep_by_addr(pcd->cfi, addr);
  54566. + if (NULL == ep) {
  54567. + CFI_INFO("%s: Unable to get the endpoint address(0x%02x)\n",
  54568. + __func__, addr);
  54569. + return retval;
  54570. + }
  54571. +
  54572. + dwc_memcpy(buf, ep->bm_align, BS_ALIGN_VAL_HDR_LEN);
  54573. + retval = BS_ALIGN_VAL_HDR_LEN;
  54574. +
  54575. + return retval;
  54576. +}
  54577. +
  54578. +/**
  54579. + * This function sets a new value for the specified feature
  54580. + *
  54581. + * @param pcd A pointer to the PCD object
  54582. + *
  54583. + * @return 0 if successful, negative error code otherwise to stall the DCE.
  54584. + */
  54585. +static int cfi_set_feature_value(struct dwc_otg_pcd *pcd)
  54586. +{
  54587. + int retval = -DWC_E_NOT_SUPPORTED;
  54588. + uint16_t wIndex, wValue;
  54589. + uint8_t bRequest;
  54590. + struct dwc_otg_core_if *coreif;
  54591. + cfiobject_t *cfi = pcd->cfi;
  54592. + struct cfi_usb_ctrlrequest *ctrl_req;
  54593. + uint8_t *buf;
  54594. + ctrl_req = &cfi->ctrl_req;
  54595. +
  54596. + buf = pcd->cfi->ctrl_req.data;
  54597. +
  54598. + coreif = GET_CORE_IF(pcd);
  54599. + bRequest = ctrl_req->bRequest;
  54600. + wIndex = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wIndex);
  54601. + wValue = DWC_CONSTANT_CPU_TO_LE16(ctrl_req->wValue);
  54602. +
  54603. + /* See which feature is to be modified */
  54604. + switch (wIndex) {
  54605. + case FT_ID_DMA_BUFFER_SETUP:
  54606. + /* Modify the feature */
  54607. + if ((retval = cfi_ep_set_sg_val(buf, pcd)) < 0)
  54608. + return retval;
  54609. +
  54610. + /* And send this request to the gadget */
  54611. + cfi->need_gadget_att = 1;
  54612. + break;
  54613. +
  54614. + case FT_ID_DMA_BUFF_ALIGN:
  54615. + if ((retval = cfi_ep_set_alignment_val(buf, pcd)) < 0)
  54616. + return retval;
  54617. + cfi->need_gadget_att = 1;
  54618. + break;
  54619. +
  54620. + case FT_ID_DMA_CONCAT_SETUP:
  54621. + /* Modify the feature */
  54622. + if ((retval = cfi_ep_set_concat_val(buf, pcd)) < 0)
  54623. + return retval;
  54624. + cfi->need_gadget_att = 1;
  54625. + break;
  54626. +
  54627. + case FT_ID_DMA_CIRCULAR:
  54628. + CFI_INFO("FT_ID_DMA_CIRCULAR\n");
  54629. + break;
  54630. +
  54631. + case FT_ID_THRESHOLD_SETUP:
  54632. + CFI_INFO("FT_ID_THRESHOLD_SETUP\n");
  54633. + break;
  54634. +
  54635. + case FT_ID_DFIFO_DEPTH:
  54636. + CFI_INFO("FT_ID_DFIFO_DEPTH\n");
  54637. + break;
  54638. +
  54639. + case FT_ID_TX_FIFO_DEPTH:
  54640. + CFI_INFO("FT_ID_TX_FIFO_DEPTH\n");
  54641. + if ((retval = cfi_ep_set_tx_fifo_val(buf, pcd)) < 0)
  54642. + return retval;
  54643. + cfi->need_gadget_att = 0;
  54644. + break;
  54645. +
  54646. + case FT_ID_RX_FIFO_DEPTH:
  54647. + CFI_INFO("FT_ID_RX_FIFO_DEPTH\n");
  54648. + if ((retval = cfi_set_rx_fifo_val(buf, pcd)) < 0)
  54649. + return retval;
  54650. + cfi->need_gadget_att = 0;
  54651. + break;
  54652. + }
  54653. +
  54654. + return retval;
  54655. +}
  54656. +
  54657. +#endif //DWC_UTE_CFI
  54658. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cfi.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h
  54659. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 1970-01-01 01:00:00.000000000 +0100
  54660. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cfi.h 2014-06-11 21:03:43.000000000 +0200
  54661. @@ -0,0 +1,320 @@
  54662. +/* ==========================================================================
  54663. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54664. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54665. + * otherwise expressly agreed to in writing between Synopsys and you.
  54666. + *
  54667. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54668. + * any End User Software License Agreement or Agreement for Licensed Product
  54669. + * with Synopsys or any supplement thereto. You are permitted to use and
  54670. + * redistribute this Software in source and binary forms, with or without
  54671. + * modification, provided that redistributions of source code must retain this
  54672. + * notice. You may not view, use, disclose, copy or distribute this file or
  54673. + * any information contained herein except pursuant to this license grant from
  54674. + * Synopsys. If you do not agree with this notice, including the disclaimer
  54675. + * below, then you are not authorized to use the Software.
  54676. + *
  54677. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  54678. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  54679. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  54680. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  54681. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  54682. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  54683. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  54684. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  54685. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  54686. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  54687. + * DAMAGE.
  54688. + * ========================================================================== */
  54689. +
  54690. +#if !defined(__DWC_OTG_CFI_H__)
  54691. +#define __DWC_OTG_CFI_H__
  54692. +
  54693. +#include "dwc_otg_pcd.h"
  54694. +#include "dwc_cfi_common.h"
  54695. +
  54696. +/**
  54697. + * @file
  54698. + * This file contains the CFI related OTG PCD specific common constants,
  54699. + * interfaces(functions and macros) and data structures.The CFI Protocol is an
  54700. + * optional interface for internal testing purposes that a DUT may implement to
  54701. + * support testing of configurable features.
  54702. + *
  54703. + */
  54704. +
  54705. +struct dwc_otg_pcd;
  54706. +struct dwc_otg_pcd_ep;
  54707. +
  54708. +/** OTG CFI Features (properties) ID constants */
  54709. +/** This is a request for all Core Features */
  54710. +#define FT_ID_DMA_MODE 0x0001
  54711. +#define FT_ID_DMA_BUFFER_SETUP 0x0002
  54712. +#define FT_ID_DMA_BUFF_ALIGN 0x0003
  54713. +#define FT_ID_DMA_CONCAT_SETUP 0x0004
  54714. +#define FT_ID_DMA_CIRCULAR 0x0005
  54715. +#define FT_ID_THRESHOLD_SETUP 0x0006
  54716. +#define FT_ID_DFIFO_DEPTH 0x0007
  54717. +#define FT_ID_TX_FIFO_DEPTH 0x0008
  54718. +#define FT_ID_RX_FIFO_DEPTH 0x0009
  54719. +
  54720. +/**********************************************************/
  54721. +#define CFI_INFO_DEF
  54722. +
  54723. +#ifdef CFI_INFO_DEF
  54724. +#define CFI_INFO(fmt...) DWC_PRINTF("CFI: " fmt);
  54725. +#else
  54726. +#define CFI_INFO(fmt...)
  54727. +#endif
  54728. +
  54729. +#define min(x,y) ({ \
  54730. + x < y ? x : y; })
  54731. +
  54732. +#define max(x,y) ({ \
  54733. + x > y ? x : y; })
  54734. +
  54735. +/**
  54736. + * Descriptor DMA SG Buffer setup structure (SG buffer). This structure is
  54737. + * also used for setting up a buffer for Circular DDMA.
  54738. + */
  54739. +struct _ddma_sg_buffer_setup {
  54740. +#define BS_SG_VAL_DESC_LEN 6
  54741. + /* The OUT EP address */
  54742. + uint8_t bOutEndpointAddress;
  54743. + /* The IN EP address */
  54744. + uint8_t bInEndpointAddress;
  54745. + /* Number of bytes to put between transfer segments (must be DWORD boundaries) */
  54746. + uint8_t bOffset;
  54747. + /* The number of transfer segments (a DMA descriptors per each segment) */
  54748. + uint8_t bCount;
  54749. + /* Size (in byte) of each transfer segment */
  54750. + uint16_t wSize;
  54751. +} __attribute__ ((packed));
  54752. +typedef struct _ddma_sg_buffer_setup ddma_sg_buffer_setup_t;
  54753. +
  54754. +/** Descriptor DMA Concatenation Buffer setup structure */
  54755. +struct _ddma_concat_buffer_setup_hdr {
  54756. +#define BS_CONCAT_VAL_HDR_LEN 4
  54757. + /* The endpoint for which the buffer is to be set up */
  54758. + uint8_t bEndpointAddress;
  54759. + /* The count of descriptors to be used */
  54760. + uint8_t bDescCount;
  54761. + /* The total size of the transfer */
  54762. + uint16_t wSize;
  54763. +} __attribute__ ((packed));
  54764. +typedef struct _ddma_concat_buffer_setup_hdr ddma_concat_buffer_setup_hdr_t;
  54765. +
  54766. +/** Descriptor DMA Concatenation Buffer setup structure */
  54767. +struct _ddma_concat_buffer_setup {
  54768. + /* The SG header */
  54769. + ddma_concat_buffer_setup_hdr_t hdr;
  54770. +
  54771. + /* The XFER sizes pointer (allocated dynamically) */
  54772. + uint16_t *wTxBytes;
  54773. +} __attribute__ ((packed));
  54774. +typedef struct _ddma_concat_buffer_setup ddma_concat_buffer_setup_t;
  54775. +
  54776. +/** Descriptor DMA Alignment Buffer setup structure */
  54777. +struct _ddma_align_buffer_setup {
  54778. +#define BS_ALIGN_VAL_HDR_LEN 2
  54779. + uint8_t bEndpointAddress;
  54780. + uint8_t bAlign;
  54781. +} __attribute__ ((packed));
  54782. +typedef struct _ddma_align_buffer_setup ddma_align_buffer_setup_t;
  54783. +
  54784. +/** Transmit FIFO Size setup structure */
  54785. +struct _tx_fifo_size_setup {
  54786. + uint8_t bEndpointAddress;
  54787. + uint16_t wDepth;
  54788. +} __attribute__ ((packed));
  54789. +typedef struct _tx_fifo_size_setup tx_fifo_size_setup_t;
  54790. +
  54791. +/** Transmit FIFO Size setup structure */
  54792. +struct _rx_fifo_size_setup {
  54793. + uint16_t wDepth;
  54794. +} __attribute__ ((packed));
  54795. +typedef struct _rx_fifo_size_setup rx_fifo_size_setup_t;
  54796. +
  54797. +/**
  54798. + * struct cfi_usb_ctrlrequest - the CFI implementation of the struct usb_ctrlrequest
  54799. + * This structure encapsulates the standard usb_ctrlrequest and adds a pointer
  54800. + * to the data returned in the data stage of a 3-stage Control Write requests.
  54801. + */
  54802. +struct cfi_usb_ctrlrequest {
  54803. + uint8_t bRequestType;
  54804. + uint8_t bRequest;
  54805. + uint16_t wValue;
  54806. + uint16_t wIndex;
  54807. + uint16_t wLength;
  54808. + uint8_t *data;
  54809. +} UPACKED;
  54810. +
  54811. +/*---------------------------------------------------------------------------*/
  54812. +
  54813. +/**
  54814. + * The CFI wrapper of the enabled and activated dwc_otg_pcd_ep structures.
  54815. + * This structure is used to store the buffer setup data for any
  54816. + * enabled endpoint in the PCD.
  54817. + */
  54818. +struct cfi_ep {
  54819. + /* Entry for the list container */
  54820. + dwc_list_link_t lh;
  54821. + /* Pointer to the active PCD endpoint structure */
  54822. + struct dwc_otg_pcd_ep *ep;
  54823. + /* The last descriptor in the chain of DMA descriptors of the endpoint */
  54824. + struct dwc_otg_dma_desc *dma_desc_last;
  54825. + /* The SG feature value */
  54826. + ddma_sg_buffer_setup_t *bm_sg;
  54827. + /* The Circular feature value */
  54828. + ddma_sg_buffer_setup_t *bm_circ;
  54829. + /* The Concatenation feature value */
  54830. + ddma_concat_buffer_setup_t *bm_concat;
  54831. + /* The Alignment feature value */
  54832. + ddma_align_buffer_setup_t *bm_align;
  54833. + /* XFER length */
  54834. + uint32_t xfer_len;
  54835. + /*
  54836. + * Count of DMA descriptors currently used.
  54837. + * The total should not exceed the MAX_DMA_DESCS_PER_EP value
  54838. + * defined in the dwc_otg_cil.h
  54839. + */
  54840. + uint32_t desc_count;
  54841. +};
  54842. +typedef struct cfi_ep cfi_ep_t;
  54843. +
  54844. +typedef struct cfi_dma_buff {
  54845. +#define CFI_IN_BUF_LEN 1024
  54846. +#define CFI_OUT_BUF_LEN 1024
  54847. + dma_addr_t addr;
  54848. + uint8_t *buf;
  54849. +} cfi_dma_buff_t;
  54850. +
  54851. +struct cfiobject;
  54852. +
  54853. +/**
  54854. + * This is the interface for the CFI operations.
  54855. + *
  54856. + * @param ep_enable Called when any endpoint is enabled and activated.
  54857. + * @param release Called when the CFI object is released and it needs to correctly
  54858. + * deallocate the dynamic memory
  54859. + * @param ctrl_write_complete Called when the data stage of the request is complete
  54860. + */
  54861. +typedef struct cfi_ops {
  54862. + int (*ep_enable) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54863. + struct dwc_otg_pcd_ep * ep);
  54864. + void *(*ep_alloc_buf) (struct cfiobject * cfi, struct dwc_otg_pcd * pcd,
  54865. + struct dwc_otg_pcd_ep * ep, dma_addr_t * dma,
  54866. + unsigned size, gfp_t flags);
  54867. + void (*release) (struct cfiobject * cfi);
  54868. + int (*ctrl_write_complete) (struct cfiobject * cfi,
  54869. + struct dwc_otg_pcd * pcd);
  54870. + void (*build_descriptors) (struct cfiobject * cfi,
  54871. + struct dwc_otg_pcd * pcd,
  54872. + struct dwc_otg_pcd_ep * ep,
  54873. + dwc_otg_pcd_request_t * req);
  54874. +} cfi_ops_t;
  54875. +
  54876. +struct cfiobject {
  54877. + cfi_ops_t ops;
  54878. + struct dwc_otg_pcd *pcd;
  54879. + struct usb_gadget *gadget;
  54880. +
  54881. + /* Buffers used to send/receive CFI-related request data */
  54882. + cfi_dma_buff_t buf_in;
  54883. + cfi_dma_buff_t buf_out;
  54884. +
  54885. + /* CFI specific Control request wrapper */
  54886. + struct cfi_usb_ctrlrequest ctrl_req;
  54887. +
  54888. + /* The list of active EP's in the PCD of type cfi_ep_t */
  54889. + dwc_list_link_t active_eps;
  54890. +
  54891. + /* This flag shall control the propagation of a specific request
  54892. + * to the gadget's processing routines.
  54893. + * 0 - no gadget handling
  54894. + * 1 - the gadget needs to know about this request (w/o completing a status
  54895. + * phase - just return a 0 to the _setup callback)
  54896. + */
  54897. + uint8_t need_gadget_att;
  54898. +
  54899. + /* Flag indicating whether the status IN phase needs to be
  54900. + * completed by the PCD
  54901. + */
  54902. + uint8_t need_status_in_complete;
  54903. +};
  54904. +typedef struct cfiobject cfiobject_t;
  54905. +
  54906. +#define DUMP_MSG
  54907. +
  54908. +#if defined(DUMP_MSG)
  54909. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54910. +{
  54911. + unsigned int start, num, i;
  54912. + char line[52], *p;
  54913. +
  54914. + if (length >= 512)
  54915. + return;
  54916. +
  54917. + start = 0;
  54918. + while (length > 0) {
  54919. + num = min(length, 16u);
  54920. + p = line;
  54921. + for (i = 0; i < num; ++i) {
  54922. + if (i == 8)
  54923. + *p++ = ' ';
  54924. + DWC_SPRINTF(p, " %02x", buf[i]);
  54925. + p += 3;
  54926. + }
  54927. + *p = 0;
  54928. + DWC_DEBUG("%6x: %s\n", start, line);
  54929. + buf += num;
  54930. + start += num;
  54931. + length -= num;
  54932. + }
  54933. +}
  54934. +#else
  54935. +static inline void dump_msg(const u8 * buf, unsigned int length)
  54936. +{
  54937. +}
  54938. +#endif
  54939. +
  54940. +/**
  54941. + * This function returns a pointer to cfi_ep_t object with the addr address.
  54942. + */
  54943. +static inline struct cfi_ep *get_cfi_ep_by_addr(struct cfiobject *cfi,
  54944. + uint8_t addr)
  54945. +{
  54946. + struct cfi_ep *pcfiep;
  54947. + dwc_list_link_t *tmp;
  54948. +
  54949. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54950. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54951. +
  54952. + if (pcfiep->ep->desc->bEndpointAddress == addr) {
  54953. + return pcfiep;
  54954. + }
  54955. + }
  54956. +
  54957. + return NULL;
  54958. +}
  54959. +
  54960. +/**
  54961. + * This function returns a pointer to cfi_ep_t object that matches
  54962. + * the dwc_otg_pcd_ep object.
  54963. + */
  54964. +static inline struct cfi_ep *get_cfi_ep_by_pcd_ep(struct cfiobject *cfi,
  54965. + struct dwc_otg_pcd_ep *ep)
  54966. +{
  54967. + struct cfi_ep *pcfiep = NULL;
  54968. + dwc_list_link_t *tmp;
  54969. +
  54970. + DWC_LIST_FOREACH(tmp, &cfi->active_eps) {
  54971. + pcfiep = DWC_LIST_ENTRY(tmp, struct cfi_ep, lh);
  54972. + if (pcfiep->ep == ep) {
  54973. + return pcfiep;
  54974. + }
  54975. + }
  54976. + return NULL;
  54977. +}
  54978. +
  54979. +int cfi_setup(struct dwc_otg_pcd *pcd, struct cfi_usb_ctrlrequest *ctrl);
  54980. +
  54981. +#endif /* (__DWC_OTG_CFI_H__) */
  54982. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c
  54983. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil.c 1970-01-01 01:00:00.000000000 +0100
  54984. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.c 2014-06-11 21:03:43.000000000 +0200
  54985. @@ -0,0 +1,7151 @@
  54986. +/* ==========================================================================
  54987. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.c $
  54988. + * $Revision: #191 $
  54989. + * $Date: 2012/08/10 $
  54990. + * $Change: 2047372 $
  54991. + *
  54992. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  54993. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  54994. + * otherwise expressly agreed to in writing between Synopsys and you.
  54995. + *
  54996. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  54997. + * any End User Software License Agreement or Agreement for Licensed Product
  54998. + * with Synopsys or any supplement thereto. You are permitted to use and
  54999. + * redistribute this Software in source and binary forms, with or without
  55000. + * modification, provided that redistributions of source code must retain this
  55001. + * notice. You may not view, use, disclose, copy or distribute this file or
  55002. + * any information contained herein except pursuant to this license grant from
  55003. + * Synopsys. If you do not agree with this notice, including the disclaimer
  55004. + * below, then you are not authorized to use the Software.
  55005. + *
  55006. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  55007. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  55008. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  55009. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  55010. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  55011. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  55012. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  55013. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  55014. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  55015. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  55016. + * DAMAGE.
  55017. + * ========================================================================== */
  55018. +
  55019. +/** @file
  55020. + *
  55021. + * The Core Interface Layer provides basic services for accessing and
  55022. + * managing the DWC_otg hardware. These services are used by both the
  55023. + * Host Controller Driver and the Peripheral Controller Driver.
  55024. + *
  55025. + * The CIL manages the memory map for the core so that the HCD and PCD
  55026. + * don't have to do this separately. It also handles basic tasks like
  55027. + * reading/writing the registers and data FIFOs in the controller.
  55028. + * Some of the data access functions provide encapsulation of several
  55029. + * operations required to perform a task, such as writing multiple
  55030. + * registers to start a transfer. Finally, the CIL performs basic
  55031. + * services that are not specific to either the host or device modes
  55032. + * of operation. These services include management of the OTG Host
  55033. + * Negotiation Protocol (HNP) and Session Request Protocol (SRP). A
  55034. + * Diagnostic API is also provided to allow testing of the controller
  55035. + * hardware.
  55036. + *
  55037. + * The Core Interface Layer has the following requirements:
  55038. + * - Provides basic controller operations.
  55039. + * - Minimal use of OS services.
  55040. + * - The OS services used will be abstracted by using inline functions
  55041. + * or macros.
  55042. + *
  55043. + */
  55044. +
  55045. +#include "dwc_os.h"
  55046. +#include "dwc_otg_regs.h"
  55047. +#include "dwc_otg_cil.h"
  55048. +
  55049. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if);
  55050. +
  55051. +/**
  55052. + * This function is called to initialize the DWC_otg CSR data
  55053. + * structures. The register addresses in the device and host
  55054. + * structures are initialized from the base address supplied by the
  55055. + * caller. The calling function must make the OS calls to get the
  55056. + * base address of the DWC_otg controller registers. The core_params
  55057. + * argument holds the parameters that specify how the core should be
  55058. + * configured.
  55059. + *
  55060. + * @param reg_base_addr Base address of DWC_otg core registers
  55061. + *
  55062. + */
  55063. +dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * reg_base_addr)
  55064. +{
  55065. + dwc_otg_core_if_t *core_if = 0;
  55066. + dwc_otg_dev_if_t *dev_if = 0;
  55067. + dwc_otg_host_if_t *host_if = 0;
  55068. + uint8_t *reg_base = (uint8_t *) reg_base_addr;
  55069. + int i = 0;
  55070. +
  55071. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, reg_base_addr);
  55072. +
  55073. + core_if = DWC_ALLOC(sizeof(dwc_otg_core_if_t));
  55074. +
  55075. + if (core_if == NULL) {
  55076. + DWC_DEBUGPL(DBG_CIL,
  55077. + "Allocation of dwc_otg_core_if_t failed\n");
  55078. + return 0;
  55079. + }
  55080. + core_if->core_global_regs = (dwc_otg_core_global_regs_t *) reg_base;
  55081. +
  55082. + /*
  55083. + * Allocate the Device Mode structures.
  55084. + */
  55085. + dev_if = DWC_ALLOC(sizeof(dwc_otg_dev_if_t));
  55086. +
  55087. + if (dev_if == NULL) {
  55088. + DWC_DEBUGPL(DBG_CIL, "Allocation of dwc_otg_dev_if_t failed\n");
  55089. + DWC_FREE(core_if);
  55090. + return 0;
  55091. + }
  55092. +
  55093. + dev_if->dev_global_regs =
  55094. + (dwc_otg_device_global_regs_t *) (reg_base +
  55095. + DWC_DEV_GLOBAL_REG_OFFSET);
  55096. +
  55097. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55098. + dev_if->in_ep_regs[i] = (dwc_otg_dev_in_ep_regs_t *)
  55099. + (reg_base + DWC_DEV_IN_EP_REG_OFFSET +
  55100. + (i * DWC_EP_REG_OFFSET));
  55101. +
  55102. + dev_if->out_ep_regs[i] = (dwc_otg_dev_out_ep_regs_t *)
  55103. + (reg_base + DWC_DEV_OUT_EP_REG_OFFSET +
  55104. + (i * DWC_EP_REG_OFFSET));
  55105. + DWC_DEBUGPL(DBG_CILV, "in_ep_regs[%d]->diepctl=%p\n",
  55106. + i, &dev_if->in_ep_regs[i]->diepctl);
  55107. + DWC_DEBUGPL(DBG_CILV, "out_ep_regs[%d]->doepctl=%p\n",
  55108. + i, &dev_if->out_ep_regs[i]->doepctl);
  55109. + }
  55110. +
  55111. + dev_if->speed = 0; // unknown
  55112. +
  55113. + core_if->dev_if = dev_if;
  55114. +
  55115. + /*
  55116. + * Allocate the Host Mode structures.
  55117. + */
  55118. + host_if = DWC_ALLOC(sizeof(dwc_otg_host_if_t));
  55119. +
  55120. + if (host_if == NULL) {
  55121. + DWC_DEBUGPL(DBG_CIL,
  55122. + "Allocation of dwc_otg_host_if_t failed\n");
  55123. + DWC_FREE(dev_if);
  55124. + DWC_FREE(core_if);
  55125. + return 0;
  55126. + }
  55127. +
  55128. + host_if->host_global_regs = (dwc_otg_host_global_regs_t *)
  55129. + (reg_base + DWC_OTG_HOST_GLOBAL_REG_OFFSET);
  55130. +
  55131. + host_if->hprt0 =
  55132. + (uint32_t *) (reg_base + DWC_OTG_HOST_PORT_REGS_OFFSET);
  55133. +
  55134. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55135. + host_if->hc_regs[i] = (dwc_otg_hc_regs_t *)
  55136. + (reg_base + DWC_OTG_HOST_CHAN_REGS_OFFSET +
  55137. + (i * DWC_OTG_CHAN_REGS_OFFSET));
  55138. + DWC_DEBUGPL(DBG_CILV, "hc_reg[%d]->hcchar=%p\n",
  55139. + i, &host_if->hc_regs[i]->hcchar);
  55140. + }
  55141. +
  55142. + host_if->num_host_channels = MAX_EPS_CHANNELS;
  55143. + core_if->host_if = host_if;
  55144. +
  55145. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55146. + core_if->data_fifo[i] =
  55147. + (uint32_t *) (reg_base + DWC_OTG_DATA_FIFO_OFFSET +
  55148. + (i * DWC_OTG_DATA_FIFO_SIZE));
  55149. + DWC_DEBUGPL(DBG_CILV, "data_fifo[%d]=0x%08lx\n",
  55150. + i, (unsigned long)core_if->data_fifo[i]);
  55151. + }
  55152. +
  55153. + core_if->pcgcctl = (uint32_t *) (reg_base + DWC_OTG_PCGCCTL_OFFSET);
  55154. +
  55155. + /* Initiate lx_state to L3 disconnected state */
  55156. + core_if->lx_state = DWC_OTG_L3;
  55157. + /*
  55158. + * Store the contents of the hardware configuration registers here for
  55159. + * easy access later.
  55160. + */
  55161. + core_if->hwcfg1.d32 =
  55162. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg1);
  55163. + core_if->hwcfg2.d32 =
  55164. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  55165. + core_if->hwcfg3.d32 =
  55166. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg3);
  55167. + core_if->hwcfg4.d32 =
  55168. + DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  55169. +
  55170. + /* Force host mode to get HPTXFSIZ exact power on value */
  55171. + {
  55172. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  55173. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55174. + gusbcfg.b.force_host_mode = 1;
  55175. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55176. + dwc_mdelay(100);
  55177. + core_if->hptxfsiz.d32 =
  55178. + DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55179. + gusbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55180. + gusbcfg.b.force_host_mode = 0;
  55181. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  55182. + dwc_mdelay(100);
  55183. + }
  55184. +
  55185. + DWC_DEBUGPL(DBG_CILV, "hwcfg1=%08x\n", core_if->hwcfg1.d32);
  55186. + DWC_DEBUGPL(DBG_CILV, "hwcfg2=%08x\n", core_if->hwcfg2.d32);
  55187. + DWC_DEBUGPL(DBG_CILV, "hwcfg3=%08x\n", core_if->hwcfg3.d32);
  55188. + DWC_DEBUGPL(DBG_CILV, "hwcfg4=%08x\n", core_if->hwcfg4.d32);
  55189. +
  55190. + core_if->hcfg.d32 =
  55191. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55192. + core_if->dcfg.d32 =
  55193. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55194. +
  55195. + DWC_DEBUGPL(DBG_CILV, "hcfg=%08x\n", core_if->hcfg.d32);
  55196. + DWC_DEBUGPL(DBG_CILV, "dcfg=%08x\n", core_if->dcfg.d32);
  55197. +
  55198. + DWC_DEBUGPL(DBG_CILV, "op_mode=%0x\n", core_if->hwcfg2.b.op_mode);
  55199. + DWC_DEBUGPL(DBG_CILV, "arch=%0x\n", core_if->hwcfg2.b.architecture);
  55200. + DWC_DEBUGPL(DBG_CILV, "num_dev_ep=%d\n", core_if->hwcfg2.b.num_dev_ep);
  55201. + DWC_DEBUGPL(DBG_CILV, "num_host_chan=%d\n",
  55202. + core_if->hwcfg2.b.num_host_chan);
  55203. + DWC_DEBUGPL(DBG_CILV, "nonperio_tx_q_depth=0x%0x\n",
  55204. + core_if->hwcfg2.b.nonperio_tx_q_depth);
  55205. + DWC_DEBUGPL(DBG_CILV, "host_perio_tx_q_depth=0x%0x\n",
  55206. + core_if->hwcfg2.b.host_perio_tx_q_depth);
  55207. + DWC_DEBUGPL(DBG_CILV, "dev_token_q_depth=0x%0x\n",
  55208. + core_if->hwcfg2.b.dev_token_q_depth);
  55209. +
  55210. + DWC_DEBUGPL(DBG_CILV, "Total FIFO SZ=%d\n",
  55211. + core_if->hwcfg3.b.dfifo_depth);
  55212. + DWC_DEBUGPL(DBG_CILV, "xfer_size_cntr_width=%0x\n",
  55213. + core_if->hwcfg3.b.xfer_size_cntr_width);
  55214. +
  55215. + /*
  55216. + * Set the SRP sucess bit for FS-I2c
  55217. + */
  55218. + core_if->srp_success = 0;
  55219. + core_if->srp_timer_started = 0;
  55220. +
  55221. + /*
  55222. + * Create new workqueue and init works
  55223. + */
  55224. + core_if->wq_otg = DWC_WORKQ_ALLOC("dwc_otg");
  55225. + if (core_if->wq_otg == 0) {
  55226. + DWC_WARN("DWC_WORKQ_ALLOC failed\n");
  55227. + DWC_FREE(host_if);
  55228. + DWC_FREE(dev_if);
  55229. + DWC_FREE(core_if);
  55230. + return 0;
  55231. + }
  55232. +
  55233. + core_if->snpsid = DWC_READ_REG32(&core_if->core_global_regs->gsnpsid);
  55234. +
  55235. + DWC_PRINTF("Core Release: %x.%x%x%x\n",
  55236. + (core_if->snpsid >> 12 & 0xF),
  55237. + (core_if->snpsid >> 8 & 0xF),
  55238. + (core_if->snpsid >> 4 & 0xF), (core_if->snpsid & 0xF));
  55239. +
  55240. + core_if->wkp_timer = DWC_TIMER_ALLOC("Wake Up Timer",
  55241. + w_wakeup_detected, core_if);
  55242. + if (core_if->wkp_timer == 0) {
  55243. + DWC_WARN("DWC_TIMER_ALLOC failed\n");
  55244. + DWC_FREE(host_if);
  55245. + DWC_FREE(dev_if);
  55246. + DWC_WORKQ_FREE(core_if->wq_otg);
  55247. + DWC_FREE(core_if);
  55248. + return 0;
  55249. + }
  55250. +
  55251. + if (dwc_otg_setup_params(core_if)) {
  55252. + DWC_WARN("Error while setting core params\n");
  55253. + }
  55254. +
  55255. + core_if->hibernation_suspend = 0;
  55256. +
  55257. + /** ADP initialization */
  55258. + dwc_otg_adp_init(core_if);
  55259. +
  55260. + return core_if;
  55261. +}
  55262. +
  55263. +/**
  55264. + * This function frees the structures allocated by dwc_otg_cil_init().
  55265. + *
  55266. + * @param core_if The core interface pointer returned from
  55267. + * dwc_otg_cil_init().
  55268. + *
  55269. + */
  55270. +void dwc_otg_cil_remove(dwc_otg_core_if_t * core_if)
  55271. +{
  55272. + dctl_data_t dctl = {.d32 = 0 };
  55273. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  55274. +
  55275. + /* Disable all interrupts */
  55276. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 1, 0);
  55277. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0);
  55278. +
  55279. + dctl.b.sftdiscon = 1;
  55280. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  55281. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0,
  55282. + dctl.d32);
  55283. + }
  55284. +
  55285. + if (core_if->wq_otg) {
  55286. + DWC_WORKQ_WAIT_WORK_DONE(core_if->wq_otg, 500);
  55287. + DWC_WORKQ_FREE(core_if->wq_otg);
  55288. + }
  55289. + if (core_if->dev_if) {
  55290. + DWC_FREE(core_if->dev_if);
  55291. + }
  55292. + if (core_if->host_if) {
  55293. + DWC_FREE(core_if->host_if);
  55294. + }
  55295. +
  55296. + /** Remove ADP Stuff */
  55297. + dwc_otg_adp_remove(core_if);
  55298. + if (core_if->core_params) {
  55299. + DWC_FREE(core_if->core_params);
  55300. + }
  55301. + if (core_if->wkp_timer) {
  55302. + DWC_TIMER_FREE(core_if->wkp_timer);
  55303. + }
  55304. + if (core_if->srp_timer) {
  55305. + DWC_TIMER_FREE(core_if->srp_timer);
  55306. + }
  55307. + DWC_FREE(core_if);
  55308. +}
  55309. +
  55310. +/**
  55311. + * This function enables the controller's Global Interrupt in the AHB Config
  55312. + * register.
  55313. + *
  55314. + * @param core_if Programming view of DWC_otg controller.
  55315. + */
  55316. +void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * core_if)
  55317. +{
  55318. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55319. + ahbcfg.b.glblintrmsk = 1; /* Enable interrupts */
  55320. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, 0, ahbcfg.d32);
  55321. +}
  55322. +
  55323. +/**
  55324. + * This function disables the controller's Global Interrupt in the AHB Config
  55325. + * register.
  55326. + *
  55327. + * @param core_if Programming view of DWC_otg controller.
  55328. + */
  55329. +void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * core_if)
  55330. +{
  55331. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  55332. + ahbcfg.b.glblintrmsk = 1; /* Disable interrupts */
  55333. + DWC_MODIFY_REG32(&core_if->core_global_regs->gahbcfg, ahbcfg.d32, 0);
  55334. +}
  55335. +
  55336. +/**
  55337. + * This function initializes the commmon interrupts, used in both
  55338. + * device and host modes.
  55339. + *
  55340. + * @param core_if Programming view of the DWC_otg controller
  55341. + *
  55342. + */
  55343. +static void dwc_otg_enable_common_interrupts(dwc_otg_core_if_t * core_if)
  55344. +{
  55345. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  55346. + gintmsk_data_t intr_mask = {.d32 = 0 };
  55347. +
  55348. + /* Clear any pending OTG Interrupts */
  55349. + DWC_WRITE_REG32(&global_regs->gotgint, 0xFFFFFFFF);
  55350. +
  55351. + /* Clear any pending interrupts */
  55352. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  55353. +
  55354. + /*
  55355. + * Enable the interrupts in the GINTMSK.
  55356. + */
  55357. + intr_mask.b.modemismatch = 1;
  55358. + intr_mask.b.otgintr = 1;
  55359. +
  55360. + if (!core_if->dma_enable) {
  55361. + intr_mask.b.rxstsqlvl = 1;
  55362. + }
  55363. +
  55364. + intr_mask.b.conidstschng = 1;
  55365. + intr_mask.b.wkupintr = 1;
  55366. + intr_mask.b.disconnect = 0;
  55367. + intr_mask.b.usbsuspend = 1;
  55368. + intr_mask.b.sessreqintr = 1;
  55369. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55370. + if (core_if->core_params->lpm_enable) {
  55371. + intr_mask.b.lpmtranrcvd = 1;
  55372. + }
  55373. +#endif
  55374. + DWC_WRITE_REG32(&global_regs->gintmsk, intr_mask.d32);
  55375. +}
  55376. +
  55377. +/*
  55378. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55379. + * Hibernation. This function is for exiting from Device mode hibernation by
  55380. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55381. + * @param core_if Programming view of DWC_otg controller.
  55382. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55383. + * @param reset - indicates whether resume is initiated by Reset.
  55384. + */
  55385. +int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  55386. + int rem_wakeup, int reset)
  55387. +{
  55388. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55389. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  55390. + dctl_data_t dctl = {.d32 = 0 };
  55391. +
  55392. + int timeout = 2000;
  55393. +
  55394. + if (!core_if->hibernation_suspend) {
  55395. + DWC_PRINTF("Already exited from Hibernation\n");
  55396. + return 1;
  55397. + }
  55398. +
  55399. + DWC_DEBUGPL(DBG_PCD, "%s called\n", __FUNCTION__);
  55400. + /* Switch-on voltage to the core */
  55401. + gpwrdn.b.pwrdnswtch = 1;
  55402. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55403. + dwc_udelay(10);
  55404. +
  55405. + /* Reset core */
  55406. + gpwrdn.d32 = 0;
  55407. + gpwrdn.b.pwrdnrstn = 1;
  55408. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55409. + dwc_udelay(10);
  55410. +
  55411. + /* Assert Restore signal */
  55412. + gpwrdn.d32 = 0;
  55413. + gpwrdn.b.restore = 1;
  55414. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55415. + dwc_udelay(10);
  55416. +
  55417. + /* Disable power clamps */
  55418. + gpwrdn.d32 = 0;
  55419. + gpwrdn.b.pwrdnclmp = 1;
  55420. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55421. +
  55422. + if (rem_wakeup) {
  55423. + dwc_udelay(70);
  55424. + }
  55425. +
  55426. + /* Deassert Reset core */
  55427. + gpwrdn.d32 = 0;
  55428. + gpwrdn.b.pwrdnrstn = 1;
  55429. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55430. + dwc_udelay(10);
  55431. +
  55432. + /* Disable PMU interrupt */
  55433. + gpwrdn.d32 = 0;
  55434. + gpwrdn.b.pmuintsel = 1;
  55435. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55436. +
  55437. + /* Mask interrupts from gpwrdn */
  55438. + gpwrdn.d32 = 0;
  55439. + gpwrdn.b.connect_det_msk = 1;
  55440. + gpwrdn.b.srp_det_msk = 1;
  55441. + gpwrdn.b.disconn_det_msk = 1;
  55442. + gpwrdn.b.rst_det_msk = 1;
  55443. + gpwrdn.b.lnstchng_msk = 1;
  55444. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55445. +
  55446. + /* Indicates that we are going out from hibernation */
  55447. + core_if->hibernation_suspend = 0;
  55448. +
  55449. + /*
  55450. + * Set Restore Essential Regs bit in PCGCCTL register, restore_mode = 1
  55451. + * indicates restore from remote_wakeup
  55452. + */
  55453. + restore_essential_regs(core_if, rem_wakeup, 0);
  55454. +
  55455. + /*
  55456. + * Wait a little for seeing new value of variable hibernation_suspend if
  55457. + * Restore done interrupt received before polling
  55458. + */
  55459. + dwc_udelay(10);
  55460. +
  55461. + if (core_if->hibernation_suspend == 0) {
  55462. + /*
  55463. + * Wait For Restore_done Interrupt. This mechanism of polling the
  55464. + * interrupt is introduced to avoid any possible race conditions
  55465. + */
  55466. + do {
  55467. + gintsts_data_t gintsts;
  55468. + gintsts.d32 =
  55469. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55470. + if (gintsts.b.restoredone) {
  55471. + gintsts.d32 = 0;
  55472. + gintsts.b.restoredone = 1;
  55473. + DWC_WRITE_REG32(&core_if->core_global_regs->
  55474. + gintsts, gintsts.d32);
  55475. + DWC_PRINTF("Restore Done Interrupt seen\n");
  55476. + break;
  55477. + }
  55478. + dwc_udelay(10);
  55479. + } while (--timeout);
  55480. + if (!timeout) {
  55481. + DWC_PRINTF("Restore Done interrupt wasn't generated here\n");
  55482. + }
  55483. + }
  55484. + /* Clear all pending interupts */
  55485. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55486. +
  55487. + /* De-assert Restore */
  55488. + gpwrdn.d32 = 0;
  55489. + gpwrdn.b.restore = 1;
  55490. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55491. + dwc_udelay(10);
  55492. +
  55493. + if (!rem_wakeup) {
  55494. + pcgcctl.d32 = 0;
  55495. + pcgcctl.b.rstpdwnmodule = 1;
  55496. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  55497. + }
  55498. +
  55499. + /* Restore GUSBCFG and DCFG */
  55500. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55501. + core_if->gr_backup->gusbcfg_local);
  55502. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  55503. + core_if->dr_backup->dcfg);
  55504. +
  55505. + /* De-assert Wakeup Logic */
  55506. + gpwrdn.d32 = 0;
  55507. + gpwrdn.b.pmuactv = 1;
  55508. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55509. + dwc_udelay(10);
  55510. +
  55511. + if (!rem_wakeup) {
  55512. + /* Set Device programming done bit */
  55513. + dctl.b.pwronprgdone = 1;
  55514. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  55515. + } else {
  55516. + /* Start Remote Wakeup Signaling */
  55517. + dctl.d32 = core_if->dr_backup->dctl;
  55518. + dctl.b.rmtwkupsig = 1;
  55519. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  55520. + }
  55521. +
  55522. + dwc_mdelay(2);
  55523. + /* Clear all pending interupts */
  55524. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55525. +
  55526. + /* Restore global registers */
  55527. + dwc_otg_restore_global_regs(core_if);
  55528. + /* Restore device global registers */
  55529. + dwc_otg_restore_dev_regs(core_if, rem_wakeup);
  55530. +
  55531. + if (rem_wakeup) {
  55532. + dwc_mdelay(7);
  55533. + dctl.d32 = 0;
  55534. + dctl.b.rmtwkupsig = 1;
  55535. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  55536. + }
  55537. +
  55538. + core_if->hibernation_suspend = 0;
  55539. + /* The core will be in ON STATE */
  55540. + core_if->lx_state = DWC_OTG_L0;
  55541. + DWC_PRINTF("Hibernation recovery completes here\n");
  55542. +
  55543. + return 1;
  55544. +}
  55545. +
  55546. +/*
  55547. + * The restore operation is modified to support Synopsys Emulated Powerdown and
  55548. + * Hibernation. This function is for exiting from Host mode hibernation by
  55549. + * Host Initiated Resume/Reset and Device Initiated Remote-Wakeup.
  55550. + * @param core_if Programming view of DWC_otg controller.
  55551. + * @param rem_wakeup - indicates whether resume is initiated by Device or Host.
  55552. + * @param reset - indicates whether resume is initiated by Reset.
  55553. + */
  55554. +int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  55555. + int rem_wakeup, int reset)
  55556. +{
  55557. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  55558. + hprt0_data_t hprt0 = {.d32 = 0 };
  55559. +
  55560. + int timeout = 2000;
  55561. +
  55562. + DWC_DEBUGPL(DBG_HCD, "%s called\n", __FUNCTION__);
  55563. + /* Switch-on voltage to the core */
  55564. + gpwrdn.b.pwrdnswtch = 1;
  55565. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55566. + dwc_udelay(10);
  55567. +
  55568. + /* Reset core */
  55569. + gpwrdn.d32 = 0;
  55570. + gpwrdn.b.pwrdnrstn = 1;
  55571. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55572. + dwc_udelay(10);
  55573. +
  55574. + /* Assert Restore signal */
  55575. + gpwrdn.d32 = 0;
  55576. + gpwrdn.b.restore = 1;
  55577. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55578. + dwc_udelay(10);
  55579. +
  55580. + /* Disable power clamps */
  55581. + gpwrdn.d32 = 0;
  55582. + gpwrdn.b.pwrdnclmp = 1;
  55583. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55584. +
  55585. + if (!rem_wakeup) {
  55586. + dwc_udelay(50);
  55587. + }
  55588. +
  55589. + /* Deassert Reset core */
  55590. + gpwrdn.d32 = 0;
  55591. + gpwrdn.b.pwrdnrstn = 1;
  55592. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  55593. + dwc_udelay(10);
  55594. +
  55595. + /* Disable PMU interrupt */
  55596. + gpwrdn.d32 = 0;
  55597. + gpwrdn.b.pmuintsel = 1;
  55598. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55599. +
  55600. + gpwrdn.d32 = 0;
  55601. + gpwrdn.b.connect_det_msk = 1;
  55602. + gpwrdn.b.srp_det_msk = 1;
  55603. + gpwrdn.b.disconn_det_msk = 1;
  55604. + gpwrdn.b.rst_det_msk = 1;
  55605. + gpwrdn.b.lnstchng_msk = 1;
  55606. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55607. +
  55608. + /* Indicates that we are going out from hibernation */
  55609. + core_if->hibernation_suspend = 0;
  55610. +
  55611. + /* Set Restore Essential Regs bit in PCGCCTL register */
  55612. + restore_essential_regs(core_if, rem_wakeup, 1);
  55613. +
  55614. + /* Wait a little for seeing new value of variable hibernation_suspend if
  55615. + * Restore done interrupt received before polling */
  55616. + dwc_udelay(10);
  55617. +
  55618. + if (core_if->hibernation_suspend == 0) {
  55619. + /* Wait For Restore_done Interrupt. This mechanism of polling the
  55620. + * interrupt is introduced to avoid any possible race conditions
  55621. + */
  55622. + do {
  55623. + gintsts_data_t gintsts;
  55624. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  55625. + if (gintsts.b.restoredone) {
  55626. + gintsts.d32 = 0;
  55627. + gintsts.b.restoredone = 1;
  55628. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  55629. + DWC_DEBUGPL(DBG_HCD,"Restore Done Interrupt seen\n");
  55630. + break;
  55631. + }
  55632. + dwc_udelay(10);
  55633. + } while (--timeout);
  55634. + if (!timeout) {
  55635. + DWC_WARN("Restore Done interrupt wasn't generated\n");
  55636. + }
  55637. + }
  55638. +
  55639. + /* Set the flag's value to 0 again after receiving restore done interrupt */
  55640. + core_if->hibernation_suspend = 0;
  55641. +
  55642. + /* This step is not described in functional spec but if not wait for this
  55643. + * delay, mismatch interrupts occurred because just after restore core is
  55644. + * in Device mode(gintsts.curmode == 0) */
  55645. + dwc_mdelay(100);
  55646. +
  55647. + /* Clear all pending interrupts */
  55648. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55649. +
  55650. + /* De-assert Restore */
  55651. + gpwrdn.d32 = 0;
  55652. + gpwrdn.b.restore = 1;
  55653. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55654. + dwc_udelay(10);
  55655. +
  55656. + /* Restore GUSBCFG and HCFG */
  55657. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  55658. + core_if->gr_backup->gusbcfg_local);
  55659. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  55660. + core_if->hr_backup->hcfg_local);
  55661. +
  55662. + /* De-assert Wakeup Logic */
  55663. + gpwrdn.d32 = 0;
  55664. + gpwrdn.b.pmuactv = 1;
  55665. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  55666. + dwc_udelay(10);
  55667. +
  55668. + /* Start the Resume operation by programming HPRT0 */
  55669. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55670. + hprt0.b.prtpwr = 1;
  55671. + hprt0.b.prtena = 0;
  55672. + hprt0.b.prtsusp = 0;
  55673. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55674. +
  55675. + DWC_PRINTF("Resume Starts Now\n");
  55676. + if (!reset) { // Indicates it is Resume Operation
  55677. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55678. + hprt0.b.prtres = 1;
  55679. + hprt0.b.prtpwr = 1;
  55680. + hprt0.b.prtena = 0;
  55681. + hprt0.b.prtsusp = 0;
  55682. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55683. +
  55684. + if (!rem_wakeup)
  55685. + hprt0.b.prtres = 0;
  55686. + /* Wait for Resume time and then program HPRT again */
  55687. + dwc_mdelay(100);
  55688. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55689. +
  55690. + } else { // Indicates it is Reset Operation
  55691. + hprt0.d32 = core_if->hr_backup->hprt0_local;
  55692. + hprt0.b.prtrst = 1;
  55693. + hprt0.b.prtpwr = 1;
  55694. + hprt0.b.prtena = 0;
  55695. + hprt0.b.prtsusp = 0;
  55696. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55697. + /* Wait for Reset time and then program HPRT again */
  55698. + dwc_mdelay(60);
  55699. + hprt0.b.prtrst = 0;
  55700. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55701. + }
  55702. + /* Clear all interrupt status */
  55703. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  55704. + hprt0.b.prtconndet = 1;
  55705. + hprt0.b.prtenchng = 1;
  55706. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  55707. +
  55708. + /* Clear all pending interupts */
  55709. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55710. +
  55711. + /* Restore global registers */
  55712. + dwc_otg_restore_global_regs(core_if);
  55713. + /* Restore host global registers */
  55714. + dwc_otg_restore_host_regs(core_if, reset);
  55715. +
  55716. + /* The core will be in ON STATE */
  55717. + core_if->lx_state = DWC_OTG_L0;
  55718. + DWC_PRINTF("Hibernation recovery is complete here\n");
  55719. + return 0;
  55720. +}
  55721. +
  55722. +/** Saves some register values into system memory. */
  55723. +int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if)
  55724. +{
  55725. + struct dwc_otg_global_regs_backup *gr;
  55726. + int i;
  55727. +
  55728. + gr = core_if->gr_backup;
  55729. + if (!gr) {
  55730. + gr = DWC_ALLOC(sizeof(*gr));
  55731. + if (!gr) {
  55732. + return -DWC_E_NO_MEMORY;
  55733. + }
  55734. + core_if->gr_backup = gr;
  55735. + }
  55736. +
  55737. + gr->gotgctl_local = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  55738. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55739. + gr->gahbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  55740. + gr->gusbcfg_local = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  55741. + gr->grxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  55742. + gr->gnptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  55743. + gr->hptxfsiz_local = DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  55744. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55745. + gr->glpmcfg_local = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  55746. +#endif
  55747. + gr->gi2cctl_local = DWC_READ_REG32(&core_if->core_global_regs->gi2cctl);
  55748. + gr->pcgcctl_local = DWC_READ_REG32(core_if->pcgcctl);
  55749. + gr->gdfifocfg_local =
  55750. + DWC_READ_REG32(&core_if->core_global_regs->gdfifocfg);
  55751. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55752. + gr->dtxfsiz_local[i] =
  55753. + DWC_READ_REG32(&(core_if->core_global_regs->dtxfsiz[i]));
  55754. + }
  55755. +
  55756. + DWC_DEBUGPL(DBG_ANY, "===========Backing Global registers==========\n");
  55757. + DWC_DEBUGPL(DBG_ANY, "Backed up gotgctl = %08x\n", gr->gotgctl_local);
  55758. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55759. + DWC_DEBUGPL(DBG_ANY, "Backed up gahbcfg = %08x\n", gr->gahbcfg_local);
  55760. + DWC_DEBUGPL(DBG_ANY, "Backed up gusbcfg = %08x\n", gr->gusbcfg_local);
  55761. + DWC_DEBUGPL(DBG_ANY, "Backed up grxfsiz = %08x\n", gr->grxfsiz_local);
  55762. + DWC_DEBUGPL(DBG_ANY, "Backed up gnptxfsiz = %08x\n",
  55763. + gr->gnptxfsiz_local);
  55764. + DWC_DEBUGPL(DBG_ANY, "Backed up hptxfsiz = %08x\n",
  55765. + gr->hptxfsiz_local);
  55766. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55767. + DWC_DEBUGPL(DBG_ANY, "Backed up glpmcfg = %08x\n", gr->glpmcfg_local);
  55768. +#endif
  55769. + DWC_DEBUGPL(DBG_ANY, "Backed up gi2cctl = %08x\n", gr->gi2cctl_local);
  55770. + DWC_DEBUGPL(DBG_ANY, "Backed up pcgcctl = %08x\n", gr->pcgcctl_local);
  55771. + DWC_DEBUGPL(DBG_ANY,"Backed up gdfifocfg = %08x\n",gr->gdfifocfg_local);
  55772. +
  55773. + return 0;
  55774. +}
  55775. +
  55776. +/** Saves GINTMSK register before setting the msk bits. */
  55777. +int dwc_otg_save_gintmsk_reg(dwc_otg_core_if_t * core_if)
  55778. +{
  55779. + struct dwc_otg_global_regs_backup *gr;
  55780. +
  55781. + gr = core_if->gr_backup;
  55782. + if (!gr) {
  55783. + gr = DWC_ALLOC(sizeof(*gr));
  55784. + if (!gr) {
  55785. + return -DWC_E_NO_MEMORY;
  55786. + }
  55787. + core_if->gr_backup = gr;
  55788. + }
  55789. +
  55790. + gr->gintmsk_local = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  55791. +
  55792. + DWC_DEBUGPL(DBG_ANY,"=============Backing GINTMSK registers============\n");
  55793. + DWC_DEBUGPL(DBG_ANY, "Backed up gintmsk = %08x\n", gr->gintmsk_local);
  55794. +
  55795. + return 0;
  55796. +}
  55797. +
  55798. +int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if)
  55799. +{
  55800. + struct dwc_otg_dev_regs_backup *dr;
  55801. + int i;
  55802. +
  55803. + dr = core_if->dr_backup;
  55804. + if (!dr) {
  55805. + dr = DWC_ALLOC(sizeof(*dr));
  55806. + if (!dr) {
  55807. + return -DWC_E_NO_MEMORY;
  55808. + }
  55809. + core_if->dr_backup = dr;
  55810. + }
  55811. +
  55812. + dr->dcfg = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  55813. + dr->dctl = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  55814. + dr->daintmsk =
  55815. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  55816. + dr->diepmsk =
  55817. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->diepmsk);
  55818. + dr->doepmsk =
  55819. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->doepmsk);
  55820. +
  55821. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55822. + dr->diepctl[i] =
  55823. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  55824. + dr->dieptsiz[i] =
  55825. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz);
  55826. + dr->diepdma[i] =
  55827. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma);
  55828. + }
  55829. +
  55830. + DWC_DEBUGPL(DBG_ANY,
  55831. + "=============Backing Host registers==============\n");
  55832. + DWC_DEBUGPL(DBG_ANY, "Backed up dcfg = %08x\n", dr->dcfg);
  55833. + DWC_DEBUGPL(DBG_ANY, "Backed up dctl = %08x\n", dr->dctl);
  55834. + DWC_DEBUGPL(DBG_ANY, "Backed up daintmsk = %08x\n",
  55835. + dr->daintmsk);
  55836. + DWC_DEBUGPL(DBG_ANY, "Backed up diepmsk = %08x\n", dr->diepmsk);
  55837. + DWC_DEBUGPL(DBG_ANY, "Backed up doepmsk = %08x\n", dr->doepmsk);
  55838. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55839. + DWC_DEBUGPL(DBG_ANY, "Backed up diepctl[%d] = %08x\n", i,
  55840. + dr->diepctl[i]);
  55841. + DWC_DEBUGPL(DBG_ANY, "Backed up dieptsiz[%d] = %08x\n",
  55842. + i, dr->dieptsiz[i]);
  55843. + DWC_DEBUGPL(DBG_ANY, "Backed up diepdma[%d] = %08x\n", i,
  55844. + dr->diepdma[i]);
  55845. + }
  55846. +
  55847. + return 0;
  55848. +}
  55849. +
  55850. +int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if)
  55851. +{
  55852. + struct dwc_otg_host_regs_backup *hr;
  55853. + int i;
  55854. +
  55855. + hr = core_if->hr_backup;
  55856. + if (!hr) {
  55857. + hr = DWC_ALLOC(sizeof(*hr));
  55858. + if (!hr) {
  55859. + return -DWC_E_NO_MEMORY;
  55860. + }
  55861. + core_if->hr_backup = hr;
  55862. + }
  55863. +
  55864. + hr->hcfg_local =
  55865. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  55866. + hr->haintmsk_local =
  55867. + DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  55868. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55869. + hr->hcintmsk_local[i] =
  55870. + DWC_READ_REG32(&core_if->host_if->hc_regs[i]->hcintmsk);
  55871. + }
  55872. + hr->hprt0_local = DWC_READ_REG32(core_if->host_if->hprt0);
  55873. + hr->hfir_local =
  55874. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  55875. +
  55876. + DWC_DEBUGPL(DBG_ANY,
  55877. + "=============Backing Host registers===============\n");
  55878. + DWC_DEBUGPL(DBG_ANY, "Backed up hcfg = %08x\n",
  55879. + hr->hcfg_local);
  55880. + DWC_DEBUGPL(DBG_ANY, "Backed up haintmsk = %08x\n", hr->haintmsk_local);
  55881. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55882. + DWC_DEBUGPL(DBG_ANY, "Backed up hcintmsk[%02d]=%08x\n", i,
  55883. + hr->hcintmsk_local[i]);
  55884. + }
  55885. + DWC_DEBUGPL(DBG_ANY, "Backed up hprt0 = %08x\n",
  55886. + hr->hprt0_local);
  55887. + DWC_DEBUGPL(DBG_ANY, "Backed up hfir = %08x\n",
  55888. + hr->hfir_local);
  55889. +
  55890. + return 0;
  55891. +}
  55892. +
  55893. +int dwc_otg_restore_global_regs(dwc_otg_core_if_t *core_if)
  55894. +{
  55895. + struct dwc_otg_global_regs_backup *gr;
  55896. + int i;
  55897. +
  55898. + gr = core_if->gr_backup;
  55899. + if (!gr) {
  55900. + return -DWC_E_INVALID;
  55901. + }
  55902. +
  55903. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, gr->gotgctl_local);
  55904. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gr->gintmsk_local);
  55905. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gr->gusbcfg_local);
  55906. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gr->gahbcfg_local);
  55907. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, gr->grxfsiz_local);
  55908. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz,
  55909. + gr->gnptxfsiz_local);
  55910. + DWC_WRITE_REG32(&core_if->core_global_regs->hptxfsiz,
  55911. + gr->hptxfsiz_local);
  55912. + DWC_WRITE_REG32(&core_if->core_global_regs->gdfifocfg,
  55913. + gr->gdfifocfg_local);
  55914. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  55915. + DWC_WRITE_REG32(&core_if->core_global_regs->dtxfsiz[i],
  55916. + gr->dtxfsiz_local[i]);
  55917. + }
  55918. +
  55919. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  55920. + DWC_WRITE_REG32(core_if->host_if->hprt0, 0x0000100A);
  55921. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg,
  55922. + (gr->gahbcfg_local));
  55923. + return 0;
  55924. +}
  55925. +
  55926. +int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if, int rem_wakeup)
  55927. +{
  55928. + struct dwc_otg_dev_regs_backup *dr;
  55929. + int i;
  55930. +
  55931. + dr = core_if->dr_backup;
  55932. +
  55933. + if (!dr) {
  55934. + return -DWC_E_INVALID;
  55935. + }
  55936. +
  55937. + if (!rem_wakeup) {
  55938. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  55939. + dr->dctl);
  55940. + }
  55941. +
  55942. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->daintmsk, dr->daintmsk);
  55943. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->diepmsk, dr->diepmsk);
  55944. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->doepmsk, dr->doepmsk);
  55945. +
  55946. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  55947. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->dieptsiz, dr->dieptsiz[i]);
  55948. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepdma, dr->diepdma[i]);
  55949. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl, dr->diepctl[i]);
  55950. + }
  55951. +
  55952. + return 0;
  55953. +}
  55954. +
  55955. +int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset)
  55956. +{
  55957. + struct dwc_otg_host_regs_backup *hr;
  55958. + int i;
  55959. + hr = core_if->hr_backup;
  55960. +
  55961. + if (!hr) {
  55962. + return -DWC_E_INVALID;
  55963. + }
  55964. +
  55965. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hr->hcfg_local);
  55966. + //if (!reset)
  55967. + //{
  55968. + // DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hr->hfir_local);
  55969. + //}
  55970. +
  55971. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->haintmsk,
  55972. + hr->haintmsk_local);
  55973. + for (i = 0; i < dwc_otg_get_param_host_channels(core_if); ++i) {
  55974. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[i]->hcintmsk,
  55975. + hr->hcintmsk_local[i]);
  55976. + }
  55977. +
  55978. + return 0;
  55979. +}
  55980. +
  55981. +int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if)
  55982. +{
  55983. + struct dwc_otg_global_regs_backup *gr;
  55984. +
  55985. + gr = core_if->gr_backup;
  55986. +
  55987. + /* Restore values for LPM and I2C */
  55988. +#ifdef CONFIG_USB_DWC_OTG_LPM
  55989. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, gr->glpmcfg_local);
  55990. +#endif
  55991. + DWC_WRITE_REG32(&core_if->core_global_regs->gi2cctl, gr->gi2cctl_local);
  55992. +
  55993. + return 0;
  55994. +}
  55995. +
  55996. +int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode, int is_host)
  55997. +{
  55998. + struct dwc_otg_global_regs_backup *gr;
  55999. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  56000. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  56001. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56002. + gintmsk_data_t gintmsk = {.d32 = 0 };
  56003. +
  56004. + /* Restore LPM and I2C registers */
  56005. + restore_lpm_i2c_regs(core_if);
  56006. +
  56007. + /* Set PCGCCTL to 0 */
  56008. + DWC_WRITE_REG32(core_if->pcgcctl, 0x00000000);
  56009. +
  56010. + gr = core_if->gr_backup;
  56011. + /* Load restore values for [31:14] bits */
  56012. + DWC_WRITE_REG32(core_if->pcgcctl,
  56013. + ((gr->pcgcctl_local & 0xffffc000) | 0x00020000));
  56014. +
  56015. + /* Umnask global Interrupt in GAHBCFG and restore it */
  56016. + gahbcfg.d32 = gr->gahbcfg_local;
  56017. + gahbcfg.b.glblintrmsk = 1;
  56018. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  56019. +
  56020. + /* Clear all pending interupts */
  56021. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  56022. +
  56023. + /* Unmask restore done interrupt */
  56024. + gintmsk.b.restoredone = 1;
  56025. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32);
  56026. +
  56027. + /* Restore GUSBCFG and HCFG/DCFG */
  56028. + gusbcfg.d32 = core_if->gr_backup->gusbcfg_local;
  56029. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, gusbcfg.d32);
  56030. +
  56031. + if (is_host) {
  56032. + hcfg_data_t hcfg = {.d32 = 0 };
  56033. + hcfg.d32 = core_if->hr_backup->hcfg_local;
  56034. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg,
  56035. + hcfg.d32);
  56036. +
  56037. + /* Load restore values for [31:14] bits */
  56038. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56039. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56040. +
  56041. + if (rmode)
  56042. + pcgcctl.b.restoremode = 1;
  56043. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56044. + dwc_udelay(10);
  56045. +
  56046. + /* Load restore values for [31:14] bits and set EssRegRestored bit */
  56047. + pcgcctl.d32 = gr->pcgcctl_local | 0xffffc000;
  56048. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56049. + pcgcctl.b.ess_reg_restored = 1;
  56050. + if (rmode)
  56051. + pcgcctl.b.restoremode = 1;
  56052. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56053. + } else {
  56054. + dcfg_data_t dcfg = {.d32 = 0 };
  56055. + dcfg.d32 = core_if->dr_backup->dcfg;
  56056. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56057. +
  56058. + /* Load restore values for [31:14] bits */
  56059. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56060. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56061. + if (!rmode) {
  56062. + pcgcctl.d32 |= 0x208;
  56063. + }
  56064. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56065. + dwc_udelay(10);
  56066. +
  56067. + /* Load restore values for [31:14] bits */
  56068. + pcgcctl.d32 = gr->pcgcctl_local & 0xffffc000;
  56069. + pcgcctl.d32 = gr->pcgcctl_local | 0x00020000;
  56070. + pcgcctl.b.ess_reg_restored = 1;
  56071. + if (!rmode)
  56072. + pcgcctl.d32 |= 0x208;
  56073. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  56074. + }
  56075. +
  56076. + return 0;
  56077. +}
  56078. +
  56079. +/**
  56080. + * Initializes the FSLSPClkSel field of the HCFG register depending on the PHY
  56081. + * type.
  56082. + */
  56083. +static void init_fslspclksel(dwc_otg_core_if_t * core_if)
  56084. +{
  56085. + uint32_t val;
  56086. + hcfg_data_t hcfg;
  56087. +
  56088. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56089. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56090. + (core_if->core_params->ulpi_fs_ls)) ||
  56091. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56092. + /* Full speed PHY */
  56093. + val = DWC_HCFG_48_MHZ;
  56094. + } else {
  56095. + /* High speed PHY running at full speed or high speed */
  56096. + val = DWC_HCFG_30_60_MHZ;
  56097. + }
  56098. +
  56099. + DWC_DEBUGPL(DBG_CIL, "Initializing HCFG.FSLSPClkSel to 0x%1x\n", val);
  56100. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  56101. + hcfg.b.fslspclksel = val;
  56102. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  56103. +}
  56104. +
  56105. +/**
  56106. + * Initializes the DevSpd field of the DCFG register depending on the PHY type
  56107. + * and the enumeration speed of the device.
  56108. + */
  56109. +static void init_devspd(dwc_otg_core_if_t * core_if)
  56110. +{
  56111. + uint32_t val;
  56112. + dcfg_data_t dcfg;
  56113. +
  56114. + if (((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56115. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56116. + (core_if->core_params->ulpi_fs_ls)) ||
  56117. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56118. + /* Full speed PHY */
  56119. + val = 0x3;
  56120. + } else if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  56121. + /* High speed PHY running at full speed */
  56122. + val = 0x1;
  56123. + } else {
  56124. + /* High speed PHY running at high speed */
  56125. + val = 0x0;
  56126. + }
  56127. +
  56128. + DWC_DEBUGPL(DBG_CIL, "Initializing DCFG.DevSpd to 0x%1x\n", val);
  56129. +
  56130. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  56131. + dcfg.b.devspd = val;
  56132. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  56133. +}
  56134. +
  56135. +/**
  56136. + * This function calculates the number of IN EPS
  56137. + * using GHWCFG1 and GHWCFG2 registers values
  56138. + *
  56139. + * @param core_if Programming view of the DWC_otg controller
  56140. + */
  56141. +static uint32_t calc_num_in_eps(dwc_otg_core_if_t * core_if)
  56142. +{
  56143. + uint32_t num_in_eps = 0;
  56144. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56145. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 3;
  56146. + uint32_t num_tx_fifos = core_if->hwcfg4.b.num_in_eps;
  56147. + int i;
  56148. +
  56149. + for (i = 0; i < num_eps; ++i) {
  56150. + if (!(hwcfg1 & 0x1))
  56151. + num_in_eps++;
  56152. +
  56153. + hwcfg1 >>= 2;
  56154. + }
  56155. +
  56156. + if (core_if->hwcfg4.b.ded_fifo_en) {
  56157. + num_in_eps =
  56158. + (num_in_eps > num_tx_fifos) ? num_tx_fifos : num_in_eps;
  56159. + }
  56160. +
  56161. + return num_in_eps;
  56162. +}
  56163. +
  56164. +/**
  56165. + * This function calculates the number of OUT EPS
  56166. + * using GHWCFG1 and GHWCFG2 registers values
  56167. + *
  56168. + * @param core_if Programming view of the DWC_otg controller
  56169. + */
  56170. +static uint32_t calc_num_out_eps(dwc_otg_core_if_t * core_if)
  56171. +{
  56172. + uint32_t num_out_eps = 0;
  56173. + uint32_t num_eps = core_if->hwcfg2.b.num_dev_ep;
  56174. + uint32_t hwcfg1 = core_if->hwcfg1.d32 >> 2;
  56175. + int i;
  56176. +
  56177. + for (i = 0; i < num_eps; ++i) {
  56178. + if (!(hwcfg1 & 0x1))
  56179. + num_out_eps++;
  56180. +
  56181. + hwcfg1 >>= 2;
  56182. + }
  56183. + return num_out_eps;
  56184. +}
  56185. +
  56186. +/**
  56187. + * This function initializes the DWC_otg controller registers and
  56188. + * prepares the core for device mode or host mode operation.
  56189. + *
  56190. + * @param core_if Programming view of the DWC_otg controller
  56191. + *
  56192. + */
  56193. +void dwc_otg_core_init(dwc_otg_core_if_t * core_if)
  56194. +{
  56195. + int i = 0;
  56196. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56197. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56198. + gahbcfg_data_t ahbcfg = {.d32 = 0 };
  56199. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  56200. + gi2cctl_data_t i2cctl = {.d32 = 0 };
  56201. +
  56202. + DWC_DEBUGPL(DBG_CILV, "dwc_otg_core_init(%p) regs at %p\n",
  56203. + core_if, global_regs);
  56204. +
  56205. + /* Common Initialization */
  56206. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56207. +
  56208. + /* Program the ULPI External VBUS bit if needed */
  56209. + usbcfg.b.ulpi_ext_vbus_drv =
  56210. + (core_if->core_params->phy_ulpi_ext_vbus ==
  56211. + DWC_PHY_ULPI_EXTERNAL_VBUS) ? 1 : 0;
  56212. +
  56213. + /* Set external TS Dline pulsing */
  56214. + usbcfg.b.term_sel_dl_pulse =
  56215. + (core_if->core_params->ts_dline == 1) ? 1 : 0;
  56216. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56217. +
  56218. + /* Reset the Controller */
  56219. + dwc_otg_core_reset(core_if);
  56220. +
  56221. + core_if->adp_enable = core_if->core_params->adp_supp_enable;
  56222. + core_if->power_down = core_if->core_params->power_down;
  56223. + core_if->otg_sts = 0;
  56224. +
  56225. + /* Initialize parameters from Hardware configuration registers. */
  56226. + dev_if->num_in_eps = calc_num_in_eps(core_if);
  56227. + dev_if->num_out_eps = calc_num_out_eps(core_if);
  56228. +
  56229. + DWC_DEBUGPL(DBG_CIL, "num_dev_perio_in_ep=%d\n",
  56230. + core_if->hwcfg4.b.num_dev_perio_in_ep);
  56231. +
  56232. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56233. + dev_if->perio_tx_fifo_size[i] =
  56234. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56235. + DWC_DEBUGPL(DBG_CIL, "Periodic Tx FIFO SZ #%d=0x%0x\n",
  56236. + i, dev_if->perio_tx_fifo_size[i]);
  56237. + }
  56238. +
  56239. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56240. + dev_if->tx_fifo_size[i] =
  56241. + DWC_READ_REG32(&global_regs->dtxfsiz[i]) >> 16;
  56242. + DWC_DEBUGPL(DBG_CIL, "Tx FIFO SZ #%d=0x%0x\n",
  56243. + i, dev_if->tx_fifo_size[i]);
  56244. + }
  56245. +
  56246. + core_if->total_fifo_size = core_if->hwcfg3.b.dfifo_depth;
  56247. + core_if->rx_fifo_size = DWC_READ_REG32(&global_regs->grxfsiz);
  56248. + core_if->nperio_tx_fifo_size =
  56249. + DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16;
  56250. +
  56251. + DWC_DEBUGPL(DBG_CIL, "Total FIFO SZ=%d\n", core_if->total_fifo_size);
  56252. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO SZ=%d\n", core_if->rx_fifo_size);
  56253. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO SZ=%d\n",
  56254. + core_if->nperio_tx_fifo_size);
  56255. +
  56256. + /* This programming sequence needs to happen in FS mode before any other
  56257. + * programming occurs */
  56258. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) &&
  56259. + (core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS)) {
  56260. + /* If FS mode with FS PHY */
  56261. +
  56262. + /* core_init() is now called on every switch so only call the
  56263. + * following for the first time through. */
  56264. + if (!core_if->phy_init_done) {
  56265. + core_if->phy_init_done = 1;
  56266. + DWC_DEBUGPL(DBG_CIL, "FS_PHY detected\n");
  56267. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56268. + usbcfg.b.physel = 1;
  56269. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56270. +
  56271. + /* Reset after a PHY select */
  56272. + dwc_otg_core_reset(core_if);
  56273. + }
  56274. +
  56275. + /* Program DCFG.DevSpd or HCFG.FSLSPclkSel to 48Mhz in FS. Also
  56276. + * do this on HNP Dev/Host mode switches (done in dev_init and
  56277. + * host_init). */
  56278. + if (dwc_otg_is_host_mode(core_if)) {
  56279. + init_fslspclksel(core_if);
  56280. + } else {
  56281. + init_devspd(core_if);
  56282. + }
  56283. +
  56284. + if (core_if->core_params->i2c_enable) {
  56285. + DWC_DEBUGPL(DBG_CIL, "FS_PHY Enabling I2c\n");
  56286. + /* Program GUSBCFG.OtgUtmifsSel to I2C */
  56287. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56288. + usbcfg.b.otgutmifssel = 1;
  56289. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56290. +
  56291. + /* Program GI2CCTL.I2CEn */
  56292. + i2cctl.d32 = DWC_READ_REG32(&global_regs->gi2cctl);
  56293. + i2cctl.b.i2cdevaddr = 1;
  56294. + i2cctl.b.i2cen = 0;
  56295. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56296. + i2cctl.b.i2cen = 1;
  56297. + DWC_WRITE_REG32(&global_regs->gi2cctl, i2cctl.d32);
  56298. + }
  56299. +
  56300. + } /* endif speed == DWC_SPEED_PARAM_FULL */
  56301. + else {
  56302. + /* High speed PHY. */
  56303. + if (!core_if->phy_init_done) {
  56304. + core_if->phy_init_done = 1;
  56305. + /* HS PHY parameters. These parameters are preserved
  56306. + * during soft reset so only program the first time. Do
  56307. + * a soft reset immediately after setting phyif. */
  56308. +
  56309. + if (core_if->core_params->phy_type == 2) {
  56310. + /* ULPI interface */
  56311. + usbcfg.b.ulpi_utmi_sel = 1;
  56312. + usbcfg.b.phyif = 0;
  56313. + usbcfg.b.ddrsel =
  56314. + core_if->core_params->phy_ulpi_ddr;
  56315. + } else if (core_if->core_params->phy_type == 1) {
  56316. + /* UTMI+ interface */
  56317. + usbcfg.b.ulpi_utmi_sel = 0;
  56318. + if (core_if->core_params->phy_utmi_width == 16) {
  56319. + usbcfg.b.phyif = 1;
  56320. +
  56321. + } else {
  56322. + usbcfg.b.phyif = 0;
  56323. + }
  56324. + } else {
  56325. + DWC_ERROR("FS PHY TYPE\n");
  56326. + }
  56327. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56328. + /* Reset after setting the PHY parameters */
  56329. + dwc_otg_core_reset(core_if);
  56330. + }
  56331. + }
  56332. +
  56333. + if ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  56334. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  56335. + (core_if->core_params->ulpi_fs_ls)) {
  56336. + DWC_DEBUGPL(DBG_CIL, "Setting ULPI FSLS\n");
  56337. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56338. + usbcfg.b.ulpi_fsls = 1;
  56339. + usbcfg.b.ulpi_clk_sus_m = 1;
  56340. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56341. + } else {
  56342. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56343. + usbcfg.b.ulpi_fsls = 0;
  56344. + usbcfg.b.ulpi_clk_sus_m = 0;
  56345. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56346. + }
  56347. +
  56348. + /* Program the GAHBCFG Register. */
  56349. + switch (core_if->hwcfg2.b.architecture) {
  56350. +
  56351. + case DWC_SLAVE_ONLY_ARCH:
  56352. + DWC_DEBUGPL(DBG_CIL, "Slave Only Mode\n");
  56353. + ahbcfg.b.nptxfemplvl_txfemplvl =
  56354. + DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56355. + ahbcfg.b.ptxfemplvl = DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY;
  56356. + core_if->dma_enable = 0;
  56357. + core_if->dma_desc_enable = 0;
  56358. + break;
  56359. +
  56360. + case DWC_EXT_DMA_ARCH:
  56361. + DWC_DEBUGPL(DBG_CIL, "External DMA Mode\n");
  56362. + {
  56363. + uint8_t brst_sz = core_if->core_params->dma_burst_size;
  56364. + ahbcfg.b.hburstlen = 0;
  56365. + while (brst_sz > 1) {
  56366. + ahbcfg.b.hburstlen++;
  56367. + brst_sz >>= 1;
  56368. + }
  56369. + }
  56370. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56371. + core_if->dma_desc_enable =
  56372. + (core_if->core_params->dma_desc_enable != 0);
  56373. + break;
  56374. +
  56375. + case DWC_INT_DMA_ARCH:
  56376. + DWC_DEBUGPL(DBG_CIL, "Internal DMA Mode\n");
  56377. + /* Old value was DWC_GAHBCFG_INT_DMA_BURST_INCR - done for
  56378. + Host mode ISOC in issue fix - vahrama */
  56379. + /* Broadcom had altered to (1<<3)|(0<<0) - WRESP=1, max 4 beats */
  56380. + ahbcfg.b.hburstlen = (1<<3)|(0<<0);//DWC_GAHBCFG_INT_DMA_BURST_INCR4;
  56381. + core_if->dma_enable = (core_if->core_params->dma_enable != 0);
  56382. + core_if->dma_desc_enable =
  56383. + (core_if->core_params->dma_desc_enable != 0);
  56384. + break;
  56385. +
  56386. + }
  56387. + if (core_if->dma_enable) {
  56388. + if (core_if->dma_desc_enable) {
  56389. + DWC_PRINTF("Using Descriptor DMA mode\n");
  56390. + } else {
  56391. + DWC_PRINTF("Using Buffer DMA mode\n");
  56392. +
  56393. + }
  56394. + } else {
  56395. + DWC_PRINTF("Using Slave mode\n");
  56396. + core_if->dma_desc_enable = 0;
  56397. + }
  56398. +
  56399. + if (core_if->core_params->ahb_single) {
  56400. + ahbcfg.b.ahbsingle = 1;
  56401. + }
  56402. +
  56403. + ahbcfg.b.dmaenable = core_if->dma_enable;
  56404. + DWC_WRITE_REG32(&global_regs->gahbcfg, ahbcfg.d32);
  56405. +
  56406. + core_if->en_multiple_tx_fifo = core_if->hwcfg4.b.ded_fifo_en;
  56407. +
  56408. + core_if->pti_enh_enable = core_if->core_params->pti_enable != 0;
  56409. + core_if->multiproc_int_enable = core_if->core_params->mpi_enable;
  56410. + DWC_PRINTF("Periodic Transfer Interrupt Enhancement - %s\n",
  56411. + ((core_if->pti_enh_enable) ? "enabled" : "disabled"));
  56412. + DWC_PRINTF("Multiprocessor Interrupt Enhancement - %s\n",
  56413. + ((core_if->multiproc_int_enable) ? "enabled" : "disabled"));
  56414. +
  56415. + /*
  56416. + * Program the GUSBCFG register.
  56417. + */
  56418. + usbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  56419. +
  56420. + switch (core_if->hwcfg2.b.op_mode) {
  56421. + case DWC_MODE_HNP_SRP_CAPABLE:
  56422. + usbcfg.b.hnpcap = (core_if->core_params->otg_cap ==
  56423. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  56424. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56425. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56426. + break;
  56427. +
  56428. + case DWC_MODE_SRP_ONLY_CAPABLE:
  56429. + usbcfg.b.hnpcap = 0;
  56430. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56431. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56432. + break;
  56433. +
  56434. + case DWC_MODE_NO_HNP_SRP_CAPABLE:
  56435. + usbcfg.b.hnpcap = 0;
  56436. + usbcfg.b.srpcap = 0;
  56437. + break;
  56438. +
  56439. + case DWC_MODE_SRP_CAPABLE_DEVICE:
  56440. + usbcfg.b.hnpcap = 0;
  56441. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56442. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56443. + break;
  56444. +
  56445. + case DWC_MODE_NO_SRP_CAPABLE_DEVICE:
  56446. + usbcfg.b.hnpcap = 0;
  56447. + usbcfg.b.srpcap = 0;
  56448. + break;
  56449. +
  56450. + case DWC_MODE_SRP_CAPABLE_HOST:
  56451. + usbcfg.b.hnpcap = 0;
  56452. + usbcfg.b.srpcap = (core_if->core_params->otg_cap !=
  56453. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  56454. + break;
  56455. +
  56456. + case DWC_MODE_NO_SRP_CAPABLE_HOST:
  56457. + usbcfg.b.hnpcap = 0;
  56458. + usbcfg.b.srpcap = 0;
  56459. + break;
  56460. + }
  56461. +
  56462. + DWC_WRITE_REG32(&global_regs->gusbcfg, usbcfg.d32);
  56463. +
  56464. +#ifdef CONFIG_USB_DWC_OTG_LPM
  56465. + if (core_if->core_params->lpm_enable) {
  56466. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  56467. +
  56468. + /* To enable LPM support set lpm_cap_en bit */
  56469. + lpmcfg.b.lpm_cap_en = 1;
  56470. +
  56471. + /* Make AppL1Res ACK */
  56472. + lpmcfg.b.appl_resp = 1;
  56473. +
  56474. + /* Retry 3 times */
  56475. + lpmcfg.b.retry_count = 3;
  56476. +
  56477. + DWC_MODIFY_REG32(&core_if->core_global_regs->glpmcfg,
  56478. + 0, lpmcfg.d32);
  56479. +
  56480. + }
  56481. +#endif
  56482. + if (core_if->core_params->ic_usb_cap) {
  56483. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  56484. + gusbcfg.b.ic_usb_cap = 1;
  56485. + DWC_MODIFY_REG32(&core_if->core_global_regs->gusbcfg,
  56486. + 0, gusbcfg.d32);
  56487. + }
  56488. + {
  56489. + gotgctl_data_t gotgctl = {.d32 = 0 };
  56490. + gotgctl.b.otgver = core_if->core_params->otg_ver;
  56491. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl, 0,
  56492. + gotgctl.d32);
  56493. + /* Set OTG version supported */
  56494. + core_if->otg_ver = core_if->core_params->otg_ver;
  56495. + DWC_PRINTF("OTG VER PARAM: %d, OTG VER FLAG: %d\n",
  56496. + core_if->core_params->otg_ver, core_if->otg_ver);
  56497. + }
  56498. +
  56499. +
  56500. + /* Enable common interrupts */
  56501. + dwc_otg_enable_common_interrupts(core_if);
  56502. +
  56503. + /* Do device or host intialization based on mode during PCD
  56504. + * and HCD initialization */
  56505. + if (dwc_otg_is_host_mode(core_if)) {
  56506. + DWC_DEBUGPL(DBG_ANY, "Host Mode\n");
  56507. + core_if->op_state = A_HOST;
  56508. + } else {
  56509. + DWC_DEBUGPL(DBG_ANY, "Device Mode\n");
  56510. + core_if->op_state = B_PERIPHERAL;
  56511. +#ifdef DWC_DEVICE_ONLY
  56512. + dwc_otg_core_dev_init(core_if);
  56513. +#endif
  56514. + }
  56515. +}
  56516. +
  56517. +/**
  56518. + * This function enables the Device mode interrupts.
  56519. + *
  56520. + * @param core_if Programming view of DWC_otg controller
  56521. + */
  56522. +void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * core_if)
  56523. +{
  56524. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56525. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56526. +
  56527. + DWC_DEBUGPL(DBG_CIL, "%s()\n", __func__);
  56528. +
  56529. + /* Disable all interrupts. */
  56530. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56531. +
  56532. + /* Clear any pending interrupts */
  56533. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56534. +
  56535. + /* Enable the common interrupts */
  56536. + dwc_otg_enable_common_interrupts(core_if);
  56537. +
  56538. + /* Enable interrupts */
  56539. + intr_mask.b.usbreset = 1;
  56540. + intr_mask.b.enumdone = 1;
  56541. + /* Disable Disconnect interrupt in Device mode */
  56542. + intr_mask.b.disconnect = 0;
  56543. +
  56544. + if (!core_if->multiproc_int_enable) {
  56545. + intr_mask.b.inepintr = 1;
  56546. + intr_mask.b.outepintr = 1;
  56547. + }
  56548. +
  56549. + intr_mask.b.erlysuspend = 1;
  56550. +
  56551. + if (core_if->en_multiple_tx_fifo == 0) {
  56552. + intr_mask.b.epmismatch = 1;
  56553. + }
  56554. +
  56555. + //intr_mask.b.incomplisoout = 1;
  56556. + intr_mask.b.incomplisoin = 1;
  56557. +
  56558. +/* Enable the ignore frame number for ISOC xfers - MAS */
  56559. +/* Disable to support high bandwith ISOC transfers - manukz */
  56560. +#if 0
  56561. +#ifdef DWC_UTE_PER_IO
  56562. + if (core_if->dma_enable) {
  56563. + if (core_if->dma_desc_enable) {
  56564. + dctl_data_t dctl1 = {.d32 = 0 };
  56565. + dctl1.b.ifrmnum = 1;
  56566. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  56567. + dctl, 0, dctl1.d32);
  56568. + DWC_DEBUG("----Enabled Ignore frame number (0x%08x)",
  56569. + DWC_READ_REG32(&core_if->dev_if->
  56570. + dev_global_regs->dctl));
  56571. + }
  56572. + }
  56573. +#endif
  56574. +#endif
  56575. +#ifdef DWC_EN_ISOC
  56576. + if (core_if->dma_enable) {
  56577. + if (core_if->dma_desc_enable == 0) {
  56578. + if (core_if->pti_enh_enable) {
  56579. + dctl_data_t dctl = {.d32 = 0 };
  56580. + dctl.b.ifrmnum = 1;
  56581. + DWC_MODIFY_REG32(&core_if->
  56582. + dev_if->dev_global_regs->dctl,
  56583. + 0, dctl.d32);
  56584. + } else {
  56585. + intr_mask.b.incomplisoin = 1;
  56586. + intr_mask.b.incomplisoout = 1;
  56587. + }
  56588. + }
  56589. + } else {
  56590. + intr_mask.b.incomplisoin = 1;
  56591. + intr_mask.b.incomplisoout = 1;
  56592. + }
  56593. +#endif /* DWC_EN_ISOC */
  56594. +
  56595. + /** @todo NGS: Should this be a module parameter? */
  56596. +#ifdef USE_PERIODIC_EP
  56597. + intr_mask.b.isooutdrop = 1;
  56598. + intr_mask.b.eopframe = 1;
  56599. + intr_mask.b.incomplisoin = 1;
  56600. + intr_mask.b.incomplisoout = 1;
  56601. +#endif
  56602. +
  56603. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  56604. +
  56605. + DWC_DEBUGPL(DBG_CIL, "%s() gintmsk=%0x\n", __func__,
  56606. + DWC_READ_REG32(&global_regs->gintmsk));
  56607. +}
  56608. +
  56609. +/**
  56610. + * This function initializes the DWC_otg controller registers for
  56611. + * device mode.
  56612. + *
  56613. + * @param core_if Programming view of DWC_otg controller
  56614. + *
  56615. + */
  56616. +void dwc_otg_core_dev_init(dwc_otg_core_if_t * core_if)
  56617. +{
  56618. + int i;
  56619. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56620. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  56621. + dwc_otg_core_params_t *params = core_if->core_params;
  56622. + dcfg_data_t dcfg = {.d32 = 0 };
  56623. + depctl_data_t diepctl = {.d32 = 0 };
  56624. + grstctl_t resetctl = {.d32 = 0 };
  56625. + uint32_t rx_fifo_size;
  56626. + fifosize_data_t nptxfifosize;
  56627. + fifosize_data_t txfifosize;
  56628. + dthrctl_data_t dthrctl;
  56629. + fifosize_data_t ptxfifosize;
  56630. + uint16_t rxfsiz, nptxfsiz;
  56631. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  56632. + hwcfg3_data_t hwcfg3 = {.d32 = 0 };
  56633. +
  56634. + /* Restart the Phy Clock */
  56635. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  56636. +
  56637. + /* Device configuration register */
  56638. + init_devspd(core_if);
  56639. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56640. + dcfg.b.descdma = (core_if->dma_desc_enable) ? 1 : 0;
  56641. + dcfg.b.perfrint = DWC_DCFG_FRAME_INTERVAL_80;
  56642. + /* Enable Device OUT NAK in case of DDMA mode*/
  56643. + if (core_if->core_params->dev_out_nak) {
  56644. + dcfg.b.endevoutnak = 1;
  56645. + }
  56646. +
  56647. + if (core_if->core_params->cont_on_bna) {
  56648. + dctl_data_t dctl = {.d32 = 0 };
  56649. + dctl.b.encontonbna = 1;
  56650. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56651. + }
  56652. +
  56653. +
  56654. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56655. +
  56656. + /* Configure data FIFO sizes */
  56657. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  56658. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  56659. + core_if->total_fifo_size);
  56660. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  56661. + params->dev_rx_fifo_size);
  56662. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  56663. + params->dev_nperio_tx_fifo_size);
  56664. +
  56665. + /* Rx FIFO */
  56666. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  56667. + DWC_READ_REG32(&global_regs->grxfsiz));
  56668. +
  56669. +#ifdef DWC_UTE_CFI
  56670. + core_if->pwron_rxfsiz = DWC_READ_REG32(&global_regs->grxfsiz);
  56671. + core_if->init_rxfsiz = params->dev_rx_fifo_size;
  56672. +#endif
  56673. + rx_fifo_size = params->dev_rx_fifo_size;
  56674. + DWC_WRITE_REG32(&global_regs->grxfsiz, rx_fifo_size);
  56675. +
  56676. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  56677. + DWC_READ_REG32(&global_regs->grxfsiz));
  56678. +
  56679. + /** Set Periodic Tx FIFO Mask all bits 0 */
  56680. + core_if->p_tx_msk = 0;
  56681. +
  56682. + /** Set Tx FIFO Mask all bits 0 */
  56683. + core_if->tx_msk = 0;
  56684. +
  56685. + if (core_if->en_multiple_tx_fifo == 0) {
  56686. + /* Non-periodic Tx FIFO */
  56687. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56688. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56689. +
  56690. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56691. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56692. +
  56693. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56694. + nptxfifosize.d32);
  56695. +
  56696. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56697. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56698. +
  56699. + /**@todo NGS: Fix Periodic FIFO Sizing! */
  56700. + /*
  56701. + * Periodic Tx FIFOs These FIFOs are numbered from 1 to 15.
  56702. + * Indexes of the FIFO size module parameters in the
  56703. + * dev_perio_tx_fifo_size array and the FIFO size registers in
  56704. + * the dptxfsiz array run from 0 to 14.
  56705. + */
  56706. + /** @todo Finish debug of this */
  56707. + ptxfifosize.b.startaddr =
  56708. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56709. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; i++) {
  56710. + ptxfifosize.b.depth =
  56711. + params->dev_perio_tx_fifo_size[i];
  56712. + DWC_DEBUGPL(DBG_CIL,
  56713. + "initial dtxfsiz[%d]=%08x\n", i,
  56714. + DWC_READ_REG32(&global_regs->dtxfsiz
  56715. + [i]));
  56716. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56717. + ptxfifosize.d32);
  56718. + DWC_DEBUGPL(DBG_CIL, "new dtxfsiz[%d]=%08x\n",
  56719. + i,
  56720. + DWC_READ_REG32(&global_regs->dtxfsiz
  56721. + [i]));
  56722. + ptxfifosize.b.startaddr += ptxfifosize.b.depth;
  56723. + }
  56724. + } else {
  56725. + /*
  56726. + * Tx FIFOs These FIFOs are numbered from 1 to 15.
  56727. + * Indexes of the FIFO size module parameters in the
  56728. + * dev_tx_fifo_size array and the FIFO size registers in
  56729. + * the dtxfsiz array run from 0 to 14.
  56730. + */
  56731. +
  56732. + /* Non-periodic Tx FIFO */
  56733. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  56734. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56735. +
  56736. +#ifdef DWC_UTE_CFI
  56737. + core_if->pwron_gnptxfsiz =
  56738. + (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56739. + core_if->init_gnptxfsiz =
  56740. + params->dev_nperio_tx_fifo_size;
  56741. +#endif
  56742. + nptxfifosize.b.depth = params->dev_nperio_tx_fifo_size;
  56743. + nptxfifosize.b.startaddr = params->dev_rx_fifo_size;
  56744. +
  56745. + DWC_WRITE_REG32(&global_regs->gnptxfsiz,
  56746. + nptxfifosize.d32);
  56747. +
  56748. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  56749. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  56750. +
  56751. + txfifosize.b.startaddr =
  56752. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  56753. +
  56754. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; i++) {
  56755. +
  56756. + txfifosize.b.depth =
  56757. + params->dev_tx_fifo_size[i];
  56758. +
  56759. + DWC_DEBUGPL(DBG_CIL,
  56760. + "initial dtxfsiz[%d]=%08x\n",
  56761. + i,
  56762. + DWC_READ_REG32(&global_regs->dtxfsiz
  56763. + [i]));
  56764. +
  56765. +#ifdef DWC_UTE_CFI
  56766. + core_if->pwron_txfsiz[i] =
  56767. + (DWC_READ_REG32
  56768. + (&global_regs->dtxfsiz[i]) >> 16);
  56769. + core_if->init_txfsiz[i] =
  56770. + params->dev_tx_fifo_size[i];
  56771. +#endif
  56772. + DWC_WRITE_REG32(&global_regs->dtxfsiz[i],
  56773. + txfifosize.d32);
  56774. +
  56775. + DWC_DEBUGPL(DBG_CIL,
  56776. + "new dtxfsiz[%d]=%08x\n",
  56777. + i,
  56778. + DWC_READ_REG32(&global_regs->dtxfsiz
  56779. + [i]));
  56780. +
  56781. + txfifosize.b.startaddr += txfifosize.b.depth;
  56782. + }
  56783. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  56784. + /* Calculating DFIFOCFG for Device mode to include RxFIFO and NPTXFIFO */
  56785. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  56786. + hwcfg3.d32 = DWC_READ_REG32(&global_regs->ghwcfg3);
  56787. + gdfifocfg.b.gdfifocfg = (DWC_READ_REG32(&global_regs->ghwcfg3) >> 16);
  56788. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56789. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  56790. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  56791. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz;
  56792. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  56793. + }
  56794. + }
  56795. +
  56796. + /* Flush the FIFOs */
  56797. + dwc_otg_flush_tx_fifo(core_if, 0x10); /* all Tx FIFOs */
  56798. + dwc_otg_flush_rx_fifo(core_if);
  56799. +
  56800. + /* Flush the Learning Queue. */
  56801. + resetctl.b.intknqflsh = 1;
  56802. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  56803. +
  56804. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  56805. + core_if->start_predict = 0;
  56806. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  56807. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  56808. + }
  56809. + core_if->nextep_seq[0] = 0;
  56810. + core_if->first_in_nextep_seq = 0;
  56811. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  56812. + diepctl.b.nextep = 0;
  56813. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  56814. +
  56815. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  56816. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  56817. + dcfg.b.epmscnt = 2;
  56818. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  56819. +
  56820. + DWC_DEBUGPL(DBG_CILV,"%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  56821. + __func__, core_if->first_in_nextep_seq);
  56822. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  56823. + DWC_DEBUGPL(DBG_CILV, "%2d ", core_if->nextep_seq[i]);
  56824. + }
  56825. + DWC_DEBUGPL(DBG_CILV,"\n");
  56826. + }
  56827. +
  56828. + /* Clear all pending Device Interrupts */
  56829. + /** @todo - if the condition needed to be checked
  56830. + * or in any case all pending interrutps should be cleared?
  56831. + */
  56832. + if (core_if->multiproc_int_enable) {
  56833. + for (i = 0; i < core_if->dev_if->num_in_eps; ++i) {
  56834. + DWC_WRITE_REG32(&dev_if->
  56835. + dev_global_regs->diepeachintmsk[i], 0);
  56836. + }
  56837. + }
  56838. +
  56839. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  56840. + DWC_WRITE_REG32(&dev_if->
  56841. + dev_global_regs->doepeachintmsk[i], 0);
  56842. + }
  56843. +
  56844. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachint, 0xFFFFFFFF);
  56845. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk, 0);
  56846. + } else {
  56847. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, 0);
  56848. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, 0);
  56849. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daint, 0xFFFFFFFF);
  56850. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk, 0);
  56851. + }
  56852. +
  56853. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  56854. + depctl_data_t depctl;
  56855. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  56856. + if (depctl.b.epena) {
  56857. + depctl.d32 = 0;
  56858. + depctl.b.epdis = 1;
  56859. + depctl.b.snak = 1;
  56860. + } else {
  56861. + depctl.d32 = 0;
  56862. + }
  56863. +
  56864. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  56865. +
  56866. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, 0);
  56867. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, 0);
  56868. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepint, 0xFF);
  56869. + }
  56870. +
  56871. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  56872. + depctl_data_t depctl;
  56873. + depctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  56874. + if (depctl.b.epena) {
  56875. + dctl_data_t dctl = {.d32 = 0 };
  56876. + gintmsk_data_t gintsts = {.d32 = 0 };
  56877. + doepint_data_t doepint = {.d32 = 0 };
  56878. + dctl.b.sgoutnak = 1;
  56879. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56880. + do {
  56881. + dwc_udelay(10);
  56882. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  56883. + } while (!gintsts.b.goutnakeff);
  56884. + gintsts.d32 = 0;
  56885. + gintsts.b.goutnakeff = 1;
  56886. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  56887. +
  56888. + depctl.d32 = 0;
  56889. + depctl.b.epdis = 1;
  56890. + depctl.b.snak = 1;
  56891. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56892. + do {
  56893. + dwc_udelay(10);
  56894. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  56895. + out_ep_regs[i]->doepint);
  56896. + } while (!doepint.b.epdisabled);
  56897. +
  56898. + doepint.b.epdisabled = 1;
  56899. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[i]->doepint, doepint.d32);
  56900. +
  56901. + dctl.d32 = 0;
  56902. + dctl.b.cgoutnak = 1;
  56903. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56904. + } else {
  56905. + depctl.d32 = 0;
  56906. + }
  56907. +
  56908. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, depctl.d32);
  56909. +
  56910. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doeptsiz, 0);
  56911. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepdma, 0);
  56912. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepint, 0xFF);
  56913. + }
  56914. +
  56915. + if (core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  56916. + dev_if->non_iso_tx_thr_en = params->thr_ctl & 0x1;
  56917. + dev_if->iso_tx_thr_en = (params->thr_ctl >> 1) & 0x1;
  56918. + dev_if->rx_thr_en = (params->thr_ctl >> 2) & 0x1;
  56919. +
  56920. + dev_if->rx_thr_length = params->rx_thr_length;
  56921. + dev_if->tx_thr_length = params->tx_thr_length;
  56922. +
  56923. + dev_if->setup_desc_index = 0;
  56924. +
  56925. + dthrctl.d32 = 0;
  56926. + dthrctl.b.non_iso_thr_en = dev_if->non_iso_tx_thr_en;
  56927. + dthrctl.b.iso_thr_en = dev_if->iso_tx_thr_en;
  56928. + dthrctl.b.tx_thr_len = dev_if->tx_thr_length;
  56929. + dthrctl.b.rx_thr_en = dev_if->rx_thr_en;
  56930. + dthrctl.b.rx_thr_len = dev_if->rx_thr_length;
  56931. + dthrctl.b.ahb_thr_ratio = params->ahb_thr_ratio;
  56932. +
  56933. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dtknqr3_dthrctl,
  56934. + dthrctl.d32);
  56935. +
  56936. + DWC_DEBUGPL(DBG_CIL,
  56937. + "Non ISO Tx Thr - %d\nISO Tx Thr - %d\nRx Thr - %d\nTx Thr Len - %d\nRx Thr Len - %d\n",
  56938. + dthrctl.b.non_iso_thr_en, dthrctl.b.iso_thr_en,
  56939. + dthrctl.b.rx_thr_en, dthrctl.b.tx_thr_len,
  56940. + dthrctl.b.rx_thr_len);
  56941. +
  56942. + }
  56943. +
  56944. + dwc_otg_enable_device_interrupts(core_if);
  56945. +
  56946. + {
  56947. + diepmsk_data_t msk = {.d32 = 0 };
  56948. + msk.b.txfifoundrn = 1;
  56949. + if (core_if->multiproc_int_enable) {
  56950. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->
  56951. + diepeachintmsk[0], msk.d32, msk.d32);
  56952. + } else {
  56953. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk,
  56954. + msk.d32, msk.d32);
  56955. + }
  56956. + }
  56957. +
  56958. + if (core_if->multiproc_int_enable) {
  56959. + /* Set NAK on Babble */
  56960. + dctl_data_t dctl = {.d32 = 0 };
  56961. + dctl.b.nakonbble = 1;
  56962. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, 0, dctl.d32);
  56963. + }
  56964. +
  56965. + if (core_if->snpsid >= OTG_CORE_REV_2_94a) {
  56966. + dctl_data_t dctl = {.d32 = 0 };
  56967. + dctl.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  56968. + dctl.b.sftdiscon = 0;
  56969. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl, dctl.d32);
  56970. + }
  56971. +}
  56972. +
  56973. +/**
  56974. + * This function enables the Host mode interrupts.
  56975. + *
  56976. + * @param core_if Programming view of DWC_otg controller
  56977. + */
  56978. +void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * core_if)
  56979. +{
  56980. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  56981. + gintmsk_data_t intr_mask = {.d32 = 0 };
  56982. +
  56983. + DWC_DEBUGPL(DBG_CIL, "%s(%p)\n", __func__, core_if);
  56984. +
  56985. + /* Disable all interrupts. */
  56986. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  56987. +
  56988. + /* Clear any pending interrupts. */
  56989. + DWC_WRITE_REG32(&global_regs->gintsts, 0xFFFFFFFF);
  56990. +
  56991. + /* Enable the common interrupts */
  56992. + dwc_otg_enable_common_interrupts(core_if);
  56993. +
  56994. + /*
  56995. + * Enable host mode interrupts without disturbing common
  56996. + * interrupts.
  56997. + */
  56998. +
  56999. + intr_mask.b.disconnect = 1;
  57000. + intr_mask.b.portintr = 1;
  57001. + intr_mask.b.hcintr = 1;
  57002. +
  57003. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, intr_mask.d32);
  57004. +}
  57005. +
  57006. +/**
  57007. + * This function disables the Host Mode interrupts.
  57008. + *
  57009. + * @param core_if Programming view of DWC_otg controller
  57010. + */
  57011. +void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * core_if)
  57012. +{
  57013. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57014. + gintmsk_data_t intr_mask = {.d32 = 0 };
  57015. +
  57016. + DWC_DEBUGPL(DBG_CILV, "%s()\n", __func__);
  57017. +
  57018. + /*
  57019. + * Disable host mode interrupts without disturbing common
  57020. + * interrupts.
  57021. + */
  57022. + intr_mask.b.sofintr = 1;
  57023. + intr_mask.b.portintr = 1;
  57024. + intr_mask.b.hcintr = 1;
  57025. + intr_mask.b.ptxfempty = 1;
  57026. + intr_mask.b.nptxfempty = 1;
  57027. +
  57028. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32, 0);
  57029. +}
  57030. +
  57031. +/**
  57032. + * This function initializes the DWC_otg controller registers for
  57033. + * host mode.
  57034. + *
  57035. + * This function flushes the Tx and Rx FIFOs and it flushes any entries in the
  57036. + * request queues. Host channels are reset to ensure that they are ready for
  57037. + * performing transfers.
  57038. + *
  57039. + * @param core_if Programming view of DWC_otg controller
  57040. + *
  57041. + */
  57042. +void dwc_otg_core_host_init(dwc_otg_core_if_t * core_if)
  57043. +{
  57044. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  57045. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57046. + dwc_otg_core_params_t *params = core_if->core_params;
  57047. + hprt0_data_t hprt0 = {.d32 = 0 };
  57048. + fifosize_data_t nptxfifosize;
  57049. + fifosize_data_t ptxfifosize;
  57050. + uint16_t rxfsiz, nptxfsiz, hptxfsiz;
  57051. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  57052. + int i;
  57053. + hcchar_data_t hcchar;
  57054. + hcfg_data_t hcfg;
  57055. + hfir_data_t hfir;
  57056. + dwc_otg_hc_regs_t *hc_regs;
  57057. + int num_channels;
  57058. + gotgctl_data_t gotgctl = {.d32 = 0 };
  57059. +
  57060. + DWC_DEBUGPL(DBG_CILV, "%s(%p)\n", __func__, core_if);
  57061. +
  57062. + /* Restart the Phy Clock */
  57063. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  57064. +
  57065. + /* Initialize Host Configuration Register */
  57066. + init_fslspclksel(core_if);
  57067. + if (core_if->core_params->speed == DWC_SPEED_PARAM_FULL) {
  57068. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57069. + hcfg.b.fslssupp = 1;
  57070. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57071. +
  57072. + }
  57073. +
  57074. + /* This bit allows dynamic reloading of the HFIR register
  57075. + * during runtime. This bit needs to be programmed during
  57076. + * initial configuration and its value must not be changed
  57077. + * during runtime.*/
  57078. + if (core_if->core_params->reload_ctl == 1) {
  57079. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  57080. + hfir.b.hfirrldctrl = 1;
  57081. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  57082. + }
  57083. +
  57084. + if (core_if->core_params->dma_desc_enable) {
  57085. + uint8_t op_mode = core_if->hwcfg2.b.op_mode;
  57086. + if (!
  57087. + (core_if->hwcfg4.b.desc_dma
  57088. + && (core_if->snpsid >= OTG_CORE_REV_2_90a)
  57089. + && ((op_mode == DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  57090. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  57091. + || (op_mode ==
  57092. + DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG)
  57093. + || (op_mode == DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)
  57094. + || (op_mode ==
  57095. + DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST)))) {
  57096. +
  57097. + DWC_ERROR("Host can't operate in Descriptor DMA mode.\n"
  57098. + "Either core version is below 2.90a or "
  57099. + "GHWCFG2, GHWCFG4 registers' values do not allow Descriptor DMA in host mode.\n"
  57100. + "To run the driver in Buffer DMA host mode set dma_desc_enable "
  57101. + "module parameter to 0.\n");
  57102. + return;
  57103. + }
  57104. + hcfg.d32 = DWC_READ_REG32(&host_if->host_global_regs->hcfg);
  57105. + hcfg.b.descdma = 1;
  57106. + DWC_WRITE_REG32(&host_if->host_global_regs->hcfg, hcfg.d32);
  57107. + }
  57108. +
  57109. + /* Configure data FIFO sizes */
  57110. + if (core_if->hwcfg2.b.dynamic_fifo && params->enable_dynamic_fifo) {
  57111. + DWC_DEBUGPL(DBG_CIL, "Total FIFO Size=%d\n",
  57112. + core_if->total_fifo_size);
  57113. + DWC_DEBUGPL(DBG_CIL, "Rx FIFO Size=%d\n",
  57114. + params->host_rx_fifo_size);
  57115. + DWC_DEBUGPL(DBG_CIL, "NP Tx FIFO Size=%d\n",
  57116. + params->host_nperio_tx_fifo_size);
  57117. + DWC_DEBUGPL(DBG_CIL, "P Tx FIFO Size=%d\n",
  57118. + params->host_perio_tx_fifo_size);
  57119. +
  57120. + /* Rx FIFO */
  57121. + DWC_DEBUGPL(DBG_CIL, "initial grxfsiz=%08x\n",
  57122. + DWC_READ_REG32(&global_regs->grxfsiz));
  57123. + DWC_WRITE_REG32(&global_regs->grxfsiz,
  57124. + params->host_rx_fifo_size);
  57125. + DWC_DEBUGPL(DBG_CIL, "new grxfsiz=%08x\n",
  57126. + DWC_READ_REG32(&global_regs->grxfsiz));
  57127. +
  57128. + /* Non-periodic Tx FIFO */
  57129. + DWC_DEBUGPL(DBG_CIL, "initial gnptxfsiz=%08x\n",
  57130. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57131. + nptxfifosize.b.depth = params->host_nperio_tx_fifo_size;
  57132. + nptxfifosize.b.startaddr = params->host_rx_fifo_size;
  57133. + DWC_WRITE_REG32(&global_regs->gnptxfsiz, nptxfifosize.d32);
  57134. + DWC_DEBUGPL(DBG_CIL, "new gnptxfsiz=%08x\n",
  57135. + DWC_READ_REG32(&global_regs->gnptxfsiz));
  57136. +
  57137. + /* Periodic Tx FIFO */
  57138. + DWC_DEBUGPL(DBG_CIL, "initial hptxfsiz=%08x\n",
  57139. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57140. + ptxfifosize.b.depth = params->host_perio_tx_fifo_size;
  57141. + ptxfifosize.b.startaddr =
  57142. + nptxfifosize.b.startaddr + nptxfifosize.b.depth;
  57143. + DWC_WRITE_REG32(&global_regs->hptxfsiz, ptxfifosize.d32);
  57144. + DWC_DEBUGPL(DBG_CIL, "new hptxfsiz=%08x\n",
  57145. + DWC_READ_REG32(&global_regs->hptxfsiz));
  57146. +
  57147. + if (core_if->en_multiple_tx_fifo
  57148. + && core_if->snpsid <= OTG_CORE_REV_2_94a) {
  57149. + /* Global DFIFOCFG calculation for Host mode - include RxFIFO, NPTXFIFO and HPTXFIFO */
  57150. + gdfifocfg.d32 = DWC_READ_REG32(&global_regs->gdfifocfg);
  57151. + rxfsiz = (DWC_READ_REG32(&global_regs->grxfsiz) & 0x0000ffff);
  57152. + nptxfsiz = (DWC_READ_REG32(&global_regs->gnptxfsiz) >> 16);
  57153. + hptxfsiz = (DWC_READ_REG32(&global_regs->hptxfsiz) >> 16);
  57154. + gdfifocfg.b.epinfobase = rxfsiz + nptxfsiz + hptxfsiz;
  57155. + DWC_WRITE_REG32(&global_regs->gdfifocfg, gdfifocfg.d32);
  57156. + }
  57157. + }
  57158. +
  57159. + /* TODO - check this */
  57160. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57161. + gotgctl.b.hstsethnpen = 1;
  57162. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57163. + /* Make sure the FIFOs are flushed. */
  57164. + dwc_otg_flush_tx_fifo(core_if, 0x10 /* all TX FIFOs */ );
  57165. + dwc_otg_flush_rx_fifo(core_if);
  57166. +
  57167. + /* Clear Host Set HNP Enable in the OTG Control Register */
  57168. + gotgctl.b.hstsethnpen = 1;
  57169. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  57170. +
  57171. + if (!core_if->core_params->dma_desc_enable) {
  57172. + /* Flush out any leftover queued requests. */
  57173. + num_channels = core_if->core_params->host_channels;
  57174. +
  57175. + for (i = 0; i < num_channels; i++) {
  57176. + hc_regs = core_if->host_if->hc_regs[i];
  57177. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57178. + hcchar.b.chen = 0;
  57179. + hcchar.b.chdis = 1;
  57180. + hcchar.b.epdir = 0;
  57181. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57182. + }
  57183. +
  57184. + /* Halt all channels to put them into a known state. */
  57185. + for (i = 0; i < num_channels; i++) {
  57186. + int count = 0;
  57187. + hc_regs = core_if->host_if->hc_regs[i];
  57188. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57189. + hcchar.b.chen = 1;
  57190. + hcchar.b.chdis = 1;
  57191. + hcchar.b.epdir = 0;
  57192. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57193. + DWC_DEBUGPL(DBG_HCDV, "%s: Halt channel %d regs %p\n", __func__, i, hc_regs);
  57194. + do {
  57195. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57196. + if (++count > 1000) {
  57197. + DWC_ERROR
  57198. + ("%s: Unable to clear halt on channel %d (timeout HCCHAR 0x%X @%p)\n",
  57199. + __func__, i, hcchar.d32, &hc_regs->hcchar);
  57200. + break;
  57201. + }
  57202. + dwc_udelay(1);
  57203. + } while (hcchar.b.chen);
  57204. + }
  57205. + }
  57206. +
  57207. + /* Turn on the vbus power. */
  57208. + DWC_PRINTF("Init: Port Power? op_state=%d\n", core_if->op_state);
  57209. + if (core_if->op_state == A_HOST) {
  57210. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  57211. + DWC_PRINTF("Init: Power Port (%d)\n", hprt0.b.prtpwr);
  57212. + if (hprt0.b.prtpwr == 0) {
  57213. + hprt0.b.prtpwr = 1;
  57214. + DWC_WRITE_REG32(host_if->hprt0, hprt0.d32);
  57215. + }
  57216. + }
  57217. +
  57218. + dwc_otg_enable_host_interrupts(core_if);
  57219. +}
  57220. +
  57221. +/**
  57222. + * Prepares a host channel for transferring packets to/from a specific
  57223. + * endpoint. The HCCHARn register is set up with the characteristics specified
  57224. + * in _hc. Host channel interrupts that may need to be serviced while this
  57225. + * transfer is in progress are enabled.
  57226. + *
  57227. + * @param core_if Programming view of DWC_otg controller
  57228. + * @param hc Information needed to initialize the host channel
  57229. + */
  57230. +void dwc_otg_hc_init(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57231. +{
  57232. + uint32_t intr_enable;
  57233. + hcintmsk_data_t hc_intr_mask;
  57234. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57235. + hcchar_data_t hcchar;
  57236. + hcsplt_data_t hcsplt;
  57237. +
  57238. + uint8_t hc_num = hc->hc_num;
  57239. + dwc_otg_host_if_t *host_if = core_if->host_if;
  57240. + dwc_otg_hc_regs_t *hc_regs = host_if->hc_regs[hc_num];
  57241. +
  57242. + /* Clear old interrupt conditions for this host channel. */
  57243. + hc_intr_mask.d32 = 0xFFFFFFFF;
  57244. + hc_intr_mask.b.reserved14_31 = 0;
  57245. + DWC_WRITE_REG32(&hc_regs->hcint, hc_intr_mask.d32);
  57246. +
  57247. + /* Enable channel interrupts required for this transfer. */
  57248. + hc_intr_mask.d32 = 0;
  57249. + hc_intr_mask.b.chhltd = 1;
  57250. + if (core_if->dma_enable) {
  57251. + /* For Descriptor DMA mode core halts the channel on AHB error. Interrupt is not required */
  57252. + if (!core_if->dma_desc_enable)
  57253. + hc_intr_mask.b.ahberr = 1;
  57254. + else {
  57255. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57256. + hc_intr_mask.b.xfercompl = 1;
  57257. + }
  57258. +
  57259. + if (hc->error_state && !hc->do_split &&
  57260. + hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  57261. + hc_intr_mask.b.ack = 1;
  57262. + if (hc->ep_is_in) {
  57263. + hc_intr_mask.b.datatglerr = 1;
  57264. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57265. + hc_intr_mask.b.nak = 1;
  57266. + }
  57267. + }
  57268. + }
  57269. + } else {
  57270. + switch (hc->ep_type) {
  57271. + case DWC_OTG_EP_TYPE_CONTROL:
  57272. + case DWC_OTG_EP_TYPE_BULK:
  57273. + hc_intr_mask.b.xfercompl = 1;
  57274. + hc_intr_mask.b.stall = 1;
  57275. + hc_intr_mask.b.xacterr = 1;
  57276. + hc_intr_mask.b.datatglerr = 1;
  57277. + if (hc->ep_is_in) {
  57278. + hc_intr_mask.b.bblerr = 1;
  57279. + } else {
  57280. + hc_intr_mask.b.nak = 1;
  57281. + hc_intr_mask.b.nyet = 1;
  57282. + if (hc->do_ping) {
  57283. + hc_intr_mask.b.ack = 1;
  57284. + }
  57285. + }
  57286. +
  57287. + if (hc->do_split) {
  57288. + hc_intr_mask.b.nak = 1;
  57289. + if (hc->complete_split) {
  57290. + hc_intr_mask.b.nyet = 1;
  57291. + } else {
  57292. + hc_intr_mask.b.ack = 1;
  57293. + }
  57294. + }
  57295. +
  57296. + if (hc->error_state) {
  57297. + hc_intr_mask.b.ack = 1;
  57298. + }
  57299. + break;
  57300. + case DWC_OTG_EP_TYPE_INTR:
  57301. + hc_intr_mask.b.xfercompl = 1;
  57302. + hc_intr_mask.b.nak = 1;
  57303. + hc_intr_mask.b.stall = 1;
  57304. + hc_intr_mask.b.xacterr = 1;
  57305. + hc_intr_mask.b.datatglerr = 1;
  57306. + hc_intr_mask.b.frmovrun = 1;
  57307. +
  57308. + if (hc->ep_is_in) {
  57309. + hc_intr_mask.b.bblerr = 1;
  57310. + }
  57311. + if (hc->error_state) {
  57312. + hc_intr_mask.b.ack = 1;
  57313. + }
  57314. + if (hc->do_split) {
  57315. + if (hc->complete_split) {
  57316. + hc_intr_mask.b.nyet = 1;
  57317. + } else {
  57318. + hc_intr_mask.b.ack = 1;
  57319. + }
  57320. + }
  57321. + break;
  57322. + case DWC_OTG_EP_TYPE_ISOC:
  57323. + hc_intr_mask.b.xfercompl = 1;
  57324. + hc_intr_mask.b.frmovrun = 1;
  57325. + hc_intr_mask.b.ack = 1;
  57326. +
  57327. + if (hc->ep_is_in) {
  57328. + hc_intr_mask.b.xacterr = 1;
  57329. + hc_intr_mask.b.bblerr = 1;
  57330. + }
  57331. + break;
  57332. + }
  57333. + }
  57334. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hc_intr_mask.d32);
  57335. +
  57336. + /* Enable the top level host channel interrupt. */
  57337. + intr_enable = (1 << hc_num);
  57338. + DWC_MODIFY_REG32(&host_if->host_global_regs->haintmsk, 0, intr_enable);
  57339. +
  57340. + /* Make sure host channel interrupts are enabled. */
  57341. + gintmsk.b.hcintr = 1;
  57342. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  57343. +
  57344. + /*
  57345. + * Program the HCCHARn register with the endpoint characteristics for
  57346. + * the current transfer.
  57347. + */
  57348. + hcchar.d32 = 0;
  57349. + hcchar.b.devaddr = hc->dev_addr;
  57350. + hcchar.b.epnum = hc->ep_num;
  57351. + hcchar.b.epdir = hc->ep_is_in;
  57352. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  57353. + hcchar.b.eptype = hc->ep_type;
  57354. + hcchar.b.mps = hc->max_packet;
  57355. +
  57356. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcchar, hcchar.d32);
  57357. +
  57358. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d, Dev Addr %d, EP #%d\n",
  57359. + __func__, hc->hc_num, hcchar.b.devaddr, hcchar.b.epnum);
  57360. + DWC_DEBUGPL(DBG_HCDV, " Is In %d, Is Low Speed %d, EP Type %d, "
  57361. + "Max Pkt %d, Multi Cnt %d\n",
  57362. + hcchar.b.epdir, hcchar.b.lspddev, hcchar.b.eptype,
  57363. + hcchar.b.mps, hcchar.b.multicnt);
  57364. +
  57365. + /*
  57366. + * Program the HCSPLIT register for SPLITs
  57367. + */
  57368. + hcsplt.d32 = 0;
  57369. + if (hc->do_split) {
  57370. + DWC_DEBUGPL(DBG_HCDV, "Programming HC %d with split --> %s\n",
  57371. + hc->hc_num,
  57372. + hc->complete_split ? "CSPLIT" : "SSPLIT");
  57373. + hcsplt.b.compsplt = hc->complete_split;
  57374. + hcsplt.b.xactpos = hc->xact_pos;
  57375. + hcsplt.b.hubaddr = hc->hub_addr;
  57376. + hcsplt.b.prtaddr = hc->port_addr;
  57377. + DWC_DEBUGPL(DBG_HCDV, "\t comp split %d\n", hc->complete_split);
  57378. + DWC_DEBUGPL(DBG_HCDV, "\t xact pos %d\n", hc->xact_pos);
  57379. + DWC_DEBUGPL(DBG_HCDV, "\t hub addr %d\n", hc->hub_addr);
  57380. + DWC_DEBUGPL(DBG_HCDV, "\t port addr %d\n", hc->port_addr);
  57381. + DWC_DEBUGPL(DBG_HCDV, "\t is_in %d\n", hc->ep_is_in);
  57382. + DWC_DEBUGPL(DBG_HCDV, "\t Max Pkt: %d\n", hcchar.b.mps);
  57383. + DWC_DEBUGPL(DBG_HCDV, "\t xferlen: %d\n", hc->xfer_len);
  57384. + }
  57385. + DWC_WRITE_REG32(&host_if->hc_regs[hc_num]->hcsplt, hcsplt.d32);
  57386. +
  57387. +}
  57388. +
  57389. +/**
  57390. + * Attempts to halt a host channel. This function should only be called in
  57391. + * Slave mode or to abort a transfer in either Slave mode or DMA mode. Under
  57392. + * normal circumstances in DMA mode, the controller halts the channel when the
  57393. + * transfer is complete or a condition occurs that requires application
  57394. + * intervention.
  57395. + *
  57396. + * In slave mode, checks for a free request queue entry, then sets the Channel
  57397. + * Enable and Channel Disable bits of the Host Channel Characteristics
  57398. + * register of the specified channel to intiate the halt. If there is no free
  57399. + * request queue entry, sets only the Channel Disable bit of the HCCHARn
  57400. + * register to flush requests for this channel. In the latter case, sets a
  57401. + * flag to indicate that the host channel needs to be halted when a request
  57402. + * queue slot is open.
  57403. + *
  57404. + * In DMA mode, always sets the Channel Enable and Channel Disable bits of the
  57405. + * HCCHARn register. The controller ensures there is space in the request
  57406. + * queue before submitting the halt request.
  57407. + *
  57408. + * Some time may elapse before the core flushes any posted requests for this
  57409. + * host channel and halts. The Channel Halted interrupt handler completes the
  57410. + * deactivation of the host channel.
  57411. + *
  57412. + * @param core_if Controller register interface.
  57413. + * @param hc Host channel to halt.
  57414. + * @param halt_status Reason for halting the channel.
  57415. + */
  57416. +void dwc_otg_hc_halt(dwc_otg_core_if_t * core_if,
  57417. + dwc_hc_t * hc, dwc_otg_halt_status_e halt_status)
  57418. +{
  57419. + gnptxsts_data_t nptxsts;
  57420. + hptxsts_data_t hptxsts;
  57421. + hcchar_data_t hcchar;
  57422. + dwc_otg_hc_regs_t *hc_regs;
  57423. + dwc_otg_core_global_regs_t *global_regs;
  57424. + dwc_otg_host_global_regs_t *host_global_regs;
  57425. +
  57426. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57427. + global_regs = core_if->core_global_regs;
  57428. + host_global_regs = core_if->host_if->host_global_regs;
  57429. +
  57430. + DWC_ASSERT(!(halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS),
  57431. + "halt_status = %d\n", halt_status);
  57432. +
  57433. + if (halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  57434. + halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  57435. + /*
  57436. + * Disable all channel interrupts except Ch Halted. The QTD
  57437. + * and QH state associated with this transfer has been cleared
  57438. + * (in the case of URB_DEQUEUE), so the channel needs to be
  57439. + * shut down carefully to prevent crashes.
  57440. + */
  57441. + hcintmsk_data_t hcintmsk;
  57442. + hcintmsk.d32 = 0;
  57443. + hcintmsk.b.chhltd = 1;
  57444. + DWC_WRITE_REG32(&hc_regs->hcintmsk, hcintmsk.d32);
  57445. +
  57446. + /*
  57447. + * Make sure no other interrupts besides halt are currently
  57448. + * pending. Handling another interrupt could cause a crash due
  57449. + * to the QTD and QH state.
  57450. + */
  57451. + DWC_WRITE_REG32(&hc_regs->hcint, ~hcintmsk.d32);
  57452. +
  57453. + /*
  57454. + * Make sure the halt status is set to URB_DEQUEUE or AHB_ERR
  57455. + * even if the channel was already halted for some other
  57456. + * reason.
  57457. + */
  57458. + hc->halt_status = halt_status;
  57459. +
  57460. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57461. + if (hcchar.b.chen == 0) {
  57462. + /*
  57463. + * The channel is either already halted or it hasn't
  57464. + * started yet. In DMA mode, the transfer may halt if
  57465. + * it finishes normally or a condition occurs that
  57466. + * requires driver intervention. Don't want to halt
  57467. + * the channel again. In either Slave or DMA mode,
  57468. + * it's possible that the transfer has been assigned
  57469. + * to a channel, but not started yet when an URB is
  57470. + * dequeued. Don't want to halt a channel that hasn't
  57471. + * started yet.
  57472. + */
  57473. + return;
  57474. + }
  57475. + }
  57476. + if (hc->halt_pending) {
  57477. + /*
  57478. + * A halt has already been issued for this channel. This might
  57479. + * happen when a transfer is aborted by a higher level in
  57480. + * the stack.
  57481. + */
  57482. +#ifdef DEBUG
  57483. + DWC_PRINTF
  57484. + ("*** %s: Channel %d, _hc->halt_pending already set ***\n",
  57485. + __func__, hc->hc_num);
  57486. +
  57487. +#endif
  57488. + return;
  57489. + }
  57490. +
  57491. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57492. +
  57493. + /* No need to set the bit in DDMA for disabling the channel */
  57494. + //TODO check it everywhere channel is disabled
  57495. + if (!core_if->core_params->dma_desc_enable)
  57496. + hcchar.b.chen = 1;
  57497. + hcchar.b.chdis = 1;
  57498. +
  57499. + if (!core_if->dma_enable) {
  57500. + /* Check for space in the request queue to issue the halt. */
  57501. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  57502. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  57503. + nptxsts.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  57504. + if (nptxsts.b.nptxqspcavail == 0) {
  57505. + hcchar.b.chen = 0;
  57506. + }
  57507. + } else {
  57508. + hptxsts.d32 =
  57509. + DWC_READ_REG32(&host_global_regs->hptxsts);
  57510. + if ((hptxsts.b.ptxqspcavail == 0)
  57511. + || (core_if->queuing_high_bandwidth)) {
  57512. + hcchar.b.chen = 0;
  57513. + }
  57514. + }
  57515. + }
  57516. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57517. +
  57518. + hc->halt_status = halt_status;
  57519. +
  57520. + if (hcchar.b.chen) {
  57521. + hc->halt_pending = 1;
  57522. + hc->halt_on_queue = 0;
  57523. + } else {
  57524. + hc->halt_on_queue = 1;
  57525. + }
  57526. +
  57527. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57528. + DWC_DEBUGPL(DBG_HCDV, " hcchar: 0x%08x\n", hcchar.d32);
  57529. + DWC_DEBUGPL(DBG_HCDV, " halt_pending: %d\n", hc->halt_pending);
  57530. + DWC_DEBUGPL(DBG_HCDV, " halt_on_queue: %d\n", hc->halt_on_queue);
  57531. + DWC_DEBUGPL(DBG_HCDV, " halt_status: %d\n", hc->halt_status);
  57532. +
  57533. + return;
  57534. +}
  57535. +
  57536. +/**
  57537. + * Clears the transfer state for a host channel. This function is normally
  57538. + * called after a transfer is done and the host channel is being released.
  57539. + *
  57540. + * @param core_if Programming view of DWC_otg controller.
  57541. + * @param hc Identifies the host channel to clean up.
  57542. + */
  57543. +void dwc_otg_hc_cleanup(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57544. +{
  57545. + dwc_otg_hc_regs_t *hc_regs;
  57546. +
  57547. + hc->xfer_started = 0;
  57548. +
  57549. + /*
  57550. + * Clear channel interrupt enables and any unhandled channel interrupt
  57551. + * conditions.
  57552. + */
  57553. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57554. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0);
  57555. + DWC_WRITE_REG32(&hc_regs->hcint, 0xFFFFFFFF);
  57556. +#ifdef DEBUG
  57557. + DWC_TIMER_CANCEL(core_if->hc_xfer_timer[hc->hc_num]);
  57558. +#endif
  57559. +}
  57560. +
  57561. +/**
  57562. + * Sets the channel property that indicates in which frame a periodic transfer
  57563. + * should occur. This is always set to the _next_ frame. This function has no
  57564. + * effect on non-periodic transfers.
  57565. + *
  57566. + * @param core_if Programming view of DWC_otg controller.
  57567. + * @param hc Identifies the host channel to set up and its properties.
  57568. + * @param hcchar Current value of the HCCHAR register for the specified host
  57569. + * channel.
  57570. + */
  57571. +static inline void hc_set_even_odd_frame(dwc_otg_core_if_t * core_if,
  57572. + dwc_hc_t * hc, hcchar_data_t * hcchar)
  57573. +{
  57574. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57575. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57576. + hfnum_data_t hfnum;
  57577. + hfnum.d32 =
  57578. + DWC_READ_REG32(&core_if->host_if->host_global_regs->hfnum);
  57579. +
  57580. + /* 1 if _next_ frame is odd, 0 if it's even */
  57581. + hcchar->b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  57582. +#ifdef DEBUG
  57583. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR && hc->do_split
  57584. + && !hc->complete_split) {
  57585. + switch (hfnum.b.frnum & 0x7) {
  57586. + case 7:
  57587. + core_if->hfnum_7_samples++;
  57588. + core_if->hfnum_7_frrem_accum += hfnum.b.frrem;
  57589. + break;
  57590. + case 0:
  57591. + core_if->hfnum_0_samples++;
  57592. + core_if->hfnum_0_frrem_accum += hfnum.b.frrem;
  57593. + break;
  57594. + default:
  57595. + core_if->hfnum_other_samples++;
  57596. + core_if->hfnum_other_frrem_accum +=
  57597. + hfnum.b.frrem;
  57598. + break;
  57599. + }
  57600. + }
  57601. +#endif
  57602. + }
  57603. +}
  57604. +
  57605. +#ifdef DEBUG
  57606. +void hc_xfer_timeout(void *ptr)
  57607. +{
  57608. + hc_xfer_info_t *xfer_info = NULL;
  57609. + int hc_num = 0;
  57610. +
  57611. + if (ptr)
  57612. + xfer_info = (hc_xfer_info_t *) ptr;
  57613. +
  57614. + if (!xfer_info->hc) {
  57615. + DWC_ERROR("xfer_info->hc = %p\n", xfer_info->hc);
  57616. + return;
  57617. + }
  57618. +
  57619. + hc_num = xfer_info->hc->hc_num;
  57620. + DWC_WARN("%s: timeout on channel %d\n", __func__, hc_num);
  57621. + DWC_WARN(" start_hcchar_val 0x%08x\n",
  57622. + xfer_info->core_if->start_hcchar_val[hc_num]);
  57623. +}
  57624. +#endif
  57625. +
  57626. +void ep_xfer_timeout(void *ptr)
  57627. +{
  57628. + ep_xfer_info_t *xfer_info = NULL;
  57629. + int ep_num = 0;
  57630. + dctl_data_t dctl = {.d32 = 0 };
  57631. + gintsts_data_t gintsts = {.d32 = 0 };
  57632. + gintmsk_data_t gintmsk = {.d32 = 0 };
  57633. +
  57634. + if (ptr)
  57635. + xfer_info = (ep_xfer_info_t *) ptr;
  57636. +
  57637. + if (!xfer_info->ep) {
  57638. + DWC_ERROR("xfer_info->ep = %p\n", xfer_info->ep);
  57639. + return;
  57640. + }
  57641. +
  57642. + ep_num = xfer_info->ep->num;
  57643. + DWC_WARN("%s: timeout on endpoit %d\n", __func__, ep_num);
  57644. + /* Put the sate to 2 as it was time outed */
  57645. + xfer_info->state = 2;
  57646. +
  57647. + dctl.d32 =
  57648. + DWC_READ_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl);
  57649. + gintsts.d32 =
  57650. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintsts);
  57651. + gintmsk.d32 =
  57652. + DWC_READ_REG32(&xfer_info->core_if->core_global_regs->gintmsk);
  57653. +
  57654. + if (!gintmsk.b.goutnakeff) {
  57655. + /* Unmask it */
  57656. + gintmsk.b.goutnakeff = 1;
  57657. + DWC_WRITE_REG32(&xfer_info->core_if->core_global_regs->gintmsk,
  57658. + gintmsk.d32);
  57659. +
  57660. + }
  57661. +
  57662. + if (!gintsts.b.goutnakeff) {
  57663. + dctl.b.sgoutnak = 1;
  57664. + }
  57665. + DWC_WRITE_REG32(&xfer_info->core_if->dev_if->dev_global_regs->dctl,
  57666. + dctl.d32);
  57667. +
  57668. +}
  57669. +
  57670. +void set_pid_isoc(dwc_hc_t * hc)
  57671. +{
  57672. + /* Set up the initial PID for the transfer. */
  57673. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  57674. + if (hc->ep_is_in) {
  57675. + if (hc->multi_count == 1) {
  57676. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57677. + } else if (hc->multi_count == 2) {
  57678. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  57679. + } else {
  57680. + hc->data_pid_start = DWC_OTG_HC_PID_DATA2;
  57681. + }
  57682. + } else {
  57683. + if (hc->multi_count == 1) {
  57684. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57685. + } else {
  57686. + hc->data_pid_start = DWC_OTG_HC_PID_MDATA;
  57687. + }
  57688. + }
  57689. + } else {
  57690. + hc->data_pid_start = DWC_OTG_HC_PID_DATA0;
  57691. + }
  57692. +}
  57693. +
  57694. +/**
  57695. + * This function does the setup for a data transfer for a host channel and
  57696. + * starts the transfer. May be called in either Slave mode or DMA mode. In
  57697. + * Slave mode, the caller must ensure that there is sufficient space in the
  57698. + * request queue and Tx Data FIFO.
  57699. + *
  57700. + * For an OUT transfer in Slave mode, it loads a data packet into the
  57701. + * appropriate FIFO. If necessary, additional data packets will be loaded in
  57702. + * the Host ISR.
  57703. + *
  57704. + * For an IN transfer in Slave mode, a data packet is requested. The data
  57705. + * packets are unloaded from the Rx FIFO in the Host ISR. If necessary,
  57706. + * additional data packets are requested in the Host ISR.
  57707. + *
  57708. + * For a PING transfer in Slave mode, the Do Ping bit is set in the HCTSIZ
  57709. + * register along with a packet count of 1 and the channel is enabled. This
  57710. + * causes a single PING transaction to occur. Other fields in HCTSIZ are
  57711. + * simply set to 0 since no data transfer occurs in this case.
  57712. + *
  57713. + * For a PING transfer in DMA mode, the HCTSIZ register is initialized with
  57714. + * all the information required to perform the subsequent data transfer. In
  57715. + * addition, the Do Ping bit is set in the HCTSIZ register. In this case, the
  57716. + * controller performs the entire PING protocol, then starts the data
  57717. + * transfer.
  57718. + *
  57719. + * @param core_if Programming view of DWC_otg controller.
  57720. + * @param hc Information needed to initialize the host channel. The xfer_len
  57721. + * value may be reduced to accommodate the max widths of the XferSize and
  57722. + * PktCnt fields in the HCTSIZn register. The multi_count value may be changed
  57723. + * to reflect the final xfer_len value.
  57724. + */
  57725. +void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57726. +{
  57727. + hcchar_data_t hcchar;
  57728. + hctsiz_data_t hctsiz;
  57729. + uint16_t num_packets;
  57730. + uint32_t max_hc_xfer_size = core_if->core_params->max_transfer_size;
  57731. + uint16_t max_hc_pkt_count = core_if->core_params->max_packet_count;
  57732. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57733. +
  57734. + hctsiz.d32 = 0;
  57735. +
  57736. + if (hc->do_ping) {
  57737. + if (!core_if->dma_enable) {
  57738. + dwc_otg_hc_do_ping(core_if, hc);
  57739. + hc->xfer_started = 1;
  57740. + return;
  57741. + } else {
  57742. + hctsiz.b.dopng = 1;
  57743. + }
  57744. + }
  57745. +
  57746. + if (hc->do_split) {
  57747. + num_packets = 1;
  57748. +
  57749. + if (hc->complete_split && !hc->ep_is_in) {
  57750. + /* For CSPLIT OUT Transfer, set the size to 0 so the
  57751. + * core doesn't expect any data written to the FIFO */
  57752. + hc->xfer_len = 0;
  57753. + } else if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  57754. + hc->xfer_len = hc->max_packet;
  57755. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  57756. + hc->xfer_len = 188;
  57757. + }
  57758. +
  57759. + hctsiz.b.xfersize = hc->xfer_len;
  57760. + } else {
  57761. + /*
  57762. + * Ensure that the transfer length and packet count will fit
  57763. + * in the widths allocated for them in the HCTSIZn register.
  57764. + */
  57765. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57766. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57767. + /*
  57768. + * Make sure the transfer size is no larger than one
  57769. + * (micro)frame's worth of data. (A check was done
  57770. + * when the periodic transfer was accepted to ensure
  57771. + * that a (micro)frame's worth of data can be
  57772. + * programmed into a channel.)
  57773. + */
  57774. + uint32_t max_periodic_len =
  57775. + hc->multi_count * hc->max_packet;
  57776. + if (hc->xfer_len > max_periodic_len) {
  57777. + hc->xfer_len = max_periodic_len;
  57778. + } else {
  57779. + }
  57780. + } else if (hc->xfer_len > max_hc_xfer_size) {
  57781. + /* Make sure that xfer_len is a multiple of max packet size. */
  57782. + hc->xfer_len = max_hc_xfer_size - hc->max_packet + 1;
  57783. + }
  57784. +
  57785. + if (hc->xfer_len > 0) {
  57786. + num_packets =
  57787. + (hc->xfer_len + hc->max_packet -
  57788. + 1) / hc->max_packet;
  57789. + if (num_packets > max_hc_pkt_count) {
  57790. + num_packets = max_hc_pkt_count;
  57791. + hc->xfer_len = num_packets * hc->max_packet;
  57792. + }
  57793. + } else {
  57794. + /* Need 1 packet for transfer length of 0. */
  57795. + num_packets = 1;
  57796. + }
  57797. +
  57798. + if (hc->ep_is_in) {
  57799. + /* Always program an integral # of max packets for IN transfers. */
  57800. + hc->xfer_len = num_packets * hc->max_packet;
  57801. + }
  57802. +
  57803. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  57804. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  57805. + /*
  57806. + * Make sure that the multi_count field matches the
  57807. + * actual transfer length.
  57808. + */
  57809. + hc->multi_count = num_packets;
  57810. + }
  57811. +
  57812. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57813. + set_pid_isoc(hc);
  57814. +
  57815. + hctsiz.b.xfersize = hc->xfer_len;
  57816. + }
  57817. +
  57818. + hc->start_pkt_count = num_packets;
  57819. + hctsiz.b.pktcnt = num_packets;
  57820. + hctsiz.b.pid = hc->data_pid_start;
  57821. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57822. +
  57823. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57824. + DWC_DEBUGPL(DBG_HCDV, " Xfer Size: %d\n", hctsiz.b.xfersize);
  57825. + DWC_DEBUGPL(DBG_HCDV, " Num Pkts: %d\n", hctsiz.b.pktcnt);
  57826. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57827. +
  57828. + if (core_if->dma_enable) {
  57829. + dwc_dma_t dma_addr;
  57830. + if (hc->align_buff) {
  57831. + dma_addr = hc->align_buff;
  57832. + } else {
  57833. + dma_addr = ((unsigned long)hc->xfer_buff & 0xffffffff);
  57834. + }
  57835. + DWC_WRITE_REG32(&hc_regs->hcdma, dma_addr);
  57836. + }
  57837. +
  57838. + /* Start the split */
  57839. + if (hc->do_split) {
  57840. + hcsplt_data_t hcsplt;
  57841. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  57842. + hcsplt.b.spltena = 1;
  57843. + DWC_WRITE_REG32(&hc_regs->hcsplt, hcsplt.d32);
  57844. + }
  57845. +
  57846. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57847. + hcchar.b.multicnt = hc->multi_count;
  57848. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  57849. +#ifdef DEBUG
  57850. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57851. + if (hcchar.b.chdis) {
  57852. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57853. + __func__, hc->hc_num, hcchar.d32);
  57854. + }
  57855. +#endif
  57856. +
  57857. + /* Set host channel enable after all other setup is complete. */
  57858. + hcchar.b.chen = 1;
  57859. + hcchar.b.chdis = 0;
  57860. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57861. +
  57862. + hc->xfer_started = 1;
  57863. + hc->requests++;
  57864. +
  57865. + if (!core_if->dma_enable && !hc->ep_is_in && hc->xfer_len > 0) {
  57866. + /* Load OUT packet into the appropriate Tx FIFO. */
  57867. + dwc_otg_hc_write_packet(core_if, hc);
  57868. + }
  57869. +#ifdef DEBUG
  57870. + if (hc->ep_type != DWC_OTG_EP_TYPE_INTR) {
  57871. + DWC_DEBUGPL(DBG_HCDV, "transfer %d from core_if %p\n",
  57872. + hc->hc_num, core_if);//GRAYG
  57873. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57874. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57875. +
  57876. + /* Start a timer for this transfer. */
  57877. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57878. + }
  57879. +#endif
  57880. +}
  57881. +
  57882. +/**
  57883. + * This function does the setup for a data transfer for a host channel
  57884. + * and starts the transfer in Descriptor DMA mode.
  57885. + *
  57886. + * Initializes HCTSIZ register. For a PING transfer the Do Ping bit is set.
  57887. + * Sets PID and NTD values. For periodic transfers
  57888. + * initializes SCHED_INFO field with micro-frame bitmap.
  57889. + *
  57890. + * Initializes HCDMA register with descriptor list address and CTD value
  57891. + * then starts the transfer via enabling the channel.
  57892. + *
  57893. + * @param core_if Programming view of DWC_otg controller.
  57894. + * @param hc Information needed to initialize the host channel.
  57895. + */
  57896. +void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57897. +{
  57898. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  57899. + hcchar_data_t hcchar;
  57900. + hctsiz_data_t hctsiz;
  57901. + hcdma_data_t hcdma;
  57902. +
  57903. + hctsiz.d32 = 0;
  57904. +
  57905. + if (hc->do_ping)
  57906. + hctsiz.b_ddma.dopng = 1;
  57907. +
  57908. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  57909. + set_pid_isoc(hc);
  57910. +
  57911. + /* Packet Count and Xfer Size are not used in Descriptor DMA mode */
  57912. + hctsiz.b_ddma.pid = hc->data_pid_start;
  57913. + hctsiz.b_ddma.ntd = hc->ntd - 1; /* 0 - 1 descriptor, 1 - 2 descriptors, etc. */
  57914. + hctsiz.b_ddma.schinfo = hc->schinfo; /* Non-zero only for high-speed interrupt endpoints */
  57915. +
  57916. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57917. + DWC_DEBUGPL(DBG_HCDV, " Start PID: %d\n", hctsiz.b.pid);
  57918. + DWC_DEBUGPL(DBG_HCDV, " NTD: %d\n", hctsiz.b_ddma.ntd);
  57919. +
  57920. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  57921. +
  57922. + hcdma.d32 = 0;
  57923. + hcdma.b.dma_addr = ((uint32_t) hc->desc_list_addr) >> 11;
  57924. +
  57925. + /* Always start from first descriptor. */
  57926. + hcdma.b.ctd = 0;
  57927. + DWC_WRITE_REG32(&hc_regs->hcdma, hcdma.d32);
  57928. +
  57929. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  57930. + hcchar.b.multicnt = hc->multi_count;
  57931. +
  57932. +#ifdef DEBUG
  57933. + core_if->start_hcchar_val[hc->hc_num] = hcchar.d32;
  57934. + if (hcchar.b.chdis) {
  57935. + DWC_WARN("%s: chdis set, channel %d, hcchar 0x%08x\n",
  57936. + __func__, hc->hc_num, hcchar.d32);
  57937. + }
  57938. +#endif
  57939. +
  57940. + /* Set host channel enable after all other setup is complete. */
  57941. + hcchar.b.chen = 1;
  57942. + hcchar.b.chdis = 0;
  57943. +
  57944. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  57945. +
  57946. + hc->xfer_started = 1;
  57947. + hc->requests++;
  57948. +
  57949. +#ifdef DEBUG
  57950. + if ((hc->ep_type != DWC_OTG_EP_TYPE_INTR)
  57951. + && (hc->ep_type != DWC_OTG_EP_TYPE_ISOC)) {
  57952. + DWC_DEBUGPL(DBG_HCDV, "DMA transfer %d from core_if %p\n",
  57953. + hc->hc_num, core_if);//GRAYG
  57954. + core_if->hc_xfer_info[hc->hc_num].core_if = core_if;
  57955. + core_if->hc_xfer_info[hc->hc_num].hc = hc;
  57956. + /* Start a timer for this transfer. */
  57957. + DWC_TIMER_SCHEDULE(core_if->hc_xfer_timer[hc->hc_num], 10000);
  57958. + }
  57959. +#endif
  57960. +
  57961. +}
  57962. +
  57963. +/**
  57964. + * This function continues a data transfer that was started by previous call
  57965. + * to <code>dwc_otg_hc_start_transfer</code>. The caller must ensure there is
  57966. + * sufficient space in the request queue and Tx Data FIFO. This function
  57967. + * should only be called in Slave mode. In DMA mode, the controller acts
  57968. + * autonomously to complete transfers programmed to a host channel.
  57969. + *
  57970. + * For an OUT transfer, a new data packet is loaded into the appropriate FIFO
  57971. + * if there is any data remaining to be queued. For an IN transfer, another
  57972. + * data packet is always requested. For the SETUP phase of a control transfer,
  57973. + * this function does nothing.
  57974. + *
  57975. + * @return 1 if a new request is queued, 0 if no more requests are required
  57976. + * for this transfer.
  57977. + */
  57978. +int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  57979. +{
  57980. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  57981. +
  57982. + if (hc->do_split) {
  57983. + /* SPLITs always queue just once per channel */
  57984. + return 0;
  57985. + } else if (hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  57986. + /* SETUPs are queued only once since they can't be NAKed. */
  57987. + return 0;
  57988. + } else if (hc->ep_is_in) {
  57989. + /*
  57990. + * Always queue another request for other IN transfers. If
  57991. + * back-to-back INs are issued and NAKs are received for both,
  57992. + * the driver may still be processing the first NAK when the
  57993. + * second NAK is received. When the interrupt handler clears
  57994. + * the NAK interrupt for the first NAK, the second NAK will
  57995. + * not be seen. So we can't depend on the NAK interrupt
  57996. + * handler to requeue a NAKed request. Instead, IN requests
  57997. + * are issued each time this function is called. When the
  57998. + * transfer completes, the extra requests for the channel will
  57999. + * be flushed.
  58000. + */
  58001. + hcchar_data_t hcchar;
  58002. + dwc_otg_hc_regs_t *hc_regs =
  58003. + core_if->host_if->hc_regs[hc->hc_num];
  58004. +
  58005. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58006. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58007. + hcchar.b.chen = 1;
  58008. + hcchar.b.chdis = 0;
  58009. + DWC_DEBUGPL(DBG_HCDV, " IN xfer: hcchar = 0x%08x\n",
  58010. + hcchar.d32);
  58011. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58012. + hc->requests++;
  58013. + return 1;
  58014. + } else {
  58015. + /* OUT transfers. */
  58016. + if (hc->xfer_count < hc->xfer_len) {
  58017. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  58018. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  58019. + hcchar_data_t hcchar;
  58020. + dwc_otg_hc_regs_t *hc_regs;
  58021. + hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58022. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58023. + hc_set_even_odd_frame(core_if, hc, &hcchar);
  58024. + }
  58025. +
  58026. + /* Load OUT packet into the appropriate Tx FIFO. */
  58027. + dwc_otg_hc_write_packet(core_if, hc);
  58028. + hc->requests++;
  58029. + return 1;
  58030. + } else {
  58031. + return 0;
  58032. + }
  58033. + }
  58034. +}
  58035. +
  58036. +/**
  58037. + * Starts a PING transfer. This function should only be called in Slave mode.
  58038. + * The Do Ping bit is set in the HCTSIZ register, then the channel is enabled.
  58039. + */
  58040. +void dwc_otg_hc_do_ping(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58041. +{
  58042. + hcchar_data_t hcchar;
  58043. + hctsiz_data_t hctsiz;
  58044. + dwc_otg_hc_regs_t *hc_regs = core_if->host_if->hc_regs[hc->hc_num];
  58045. +
  58046. + DWC_DEBUGPL(DBG_HCDV, "%s: Channel %d\n", __func__, hc->hc_num);
  58047. +
  58048. + hctsiz.d32 = 0;
  58049. + hctsiz.b.dopng = 1;
  58050. + hctsiz.b.pktcnt = 1;
  58051. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  58052. +
  58053. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  58054. + hcchar.b.chen = 1;
  58055. + hcchar.b.chdis = 0;
  58056. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  58057. +}
  58058. +
  58059. +/*
  58060. + * This function writes a packet into the Tx FIFO associated with the Host
  58061. + * Channel. For a channel associated with a non-periodic EP, the non-periodic
  58062. + * Tx FIFO is written. For a channel associated with a periodic EP, the
  58063. + * periodic Tx FIFO is written. This function should only be called in Slave
  58064. + * mode.
  58065. + *
  58066. + * Upon return the xfer_buff and xfer_count fields in _hc are incremented by
  58067. + * then number of bytes written to the Tx FIFO.
  58068. + */
  58069. +void dwc_otg_hc_write_packet(dwc_otg_core_if_t * core_if, dwc_hc_t * hc)
  58070. +{
  58071. + uint32_t i;
  58072. + uint32_t remaining_count;
  58073. + uint32_t byte_count;
  58074. + uint32_t dword_count;
  58075. +
  58076. + uint32_t *data_buff = (uint32_t *) (hc->xfer_buff);
  58077. + uint32_t *data_fifo = core_if->data_fifo[hc->hc_num];
  58078. +
  58079. + remaining_count = hc->xfer_len - hc->xfer_count;
  58080. + if (remaining_count > hc->max_packet) {
  58081. + byte_count = hc->max_packet;
  58082. + } else {
  58083. + byte_count = remaining_count;
  58084. + }
  58085. +
  58086. + dword_count = (byte_count + 3) / 4;
  58087. +
  58088. + if ((((unsigned long)data_buff) & 0x3) == 0) {
  58089. + /* xfer_buff is DWORD aligned. */
  58090. + for (i = 0; i < dword_count; i++, data_buff++) {
  58091. + DWC_WRITE_REG32(data_fifo, *data_buff);
  58092. + }
  58093. + } else {
  58094. + /* xfer_buff is not DWORD aligned. */
  58095. + for (i = 0; i < dword_count; i++, data_buff++) {
  58096. + uint32_t data;
  58097. + data =
  58098. + (data_buff[0] | data_buff[1] << 8 | data_buff[2] <<
  58099. + 16 | data_buff[3] << 24);
  58100. + DWC_WRITE_REG32(data_fifo, data);
  58101. + }
  58102. + }
  58103. +
  58104. + hc->xfer_count += byte_count;
  58105. + hc->xfer_buff += byte_count;
  58106. +}
  58107. +
  58108. +/**
  58109. + * Gets the current USB frame number. This is the frame number from the last
  58110. + * SOF packet.
  58111. + */
  58112. +uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * core_if)
  58113. +{
  58114. + dsts_data_t dsts;
  58115. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  58116. +
  58117. + /* read current frame/microframe number from DSTS register */
  58118. + return dsts.b.soffn;
  58119. +}
  58120. +
  58121. +/**
  58122. + * Calculates and gets the frame Interval value of HFIR register according PHY
  58123. + * type and speed.The application can modify a value of HFIR register only after
  58124. + * the Port Enable bit of the Host Port Control and Status register
  58125. + * (HPRT.PrtEnaPort) has been set.
  58126. +*/
  58127. +
  58128. +uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if)
  58129. +{
  58130. + gusbcfg_data_t usbcfg;
  58131. + hwcfg2_data_t hwcfg2;
  58132. + hprt0_data_t hprt0;
  58133. + int clock = 60; // default value
  58134. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  58135. + hwcfg2.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg2);
  58136. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  58137. + if (!usbcfg.b.physel && usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58138. + clock = 60;
  58139. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 3)
  58140. + clock = 48;
  58141. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58142. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58143. + clock = 30;
  58144. + if (!usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58145. + !usbcfg.b.ulpi_utmi_sel && !usbcfg.b.phyif)
  58146. + clock = 60;
  58147. + if (usbcfg.b.phylpwrclksel && !usbcfg.b.physel &&
  58148. + !usbcfg.b.ulpi_utmi_sel && usbcfg.b.phyif)
  58149. + clock = 48;
  58150. + if (usbcfg.b.physel && !usbcfg.b.phyif && hwcfg2.b.fs_phy_type == 2)
  58151. + clock = 48;
  58152. + if (usbcfg.b.physel && hwcfg2.b.fs_phy_type == 1)
  58153. + clock = 48;
  58154. + if (hprt0.b.prtspd == 0)
  58155. + /* High speed case */
  58156. + return 125 * clock;
  58157. + else
  58158. + /* FS/LS case */
  58159. + return 1000 * clock;
  58160. +}
  58161. +
  58162. +/**
  58163. + * This function reads a setup packet from the Rx FIFO into the destination
  58164. + * buffer. This function is called from the Rx Status Queue Level (RxStsQLvl)
  58165. + * Interrupt routine when a SETUP packet has been received in Slave mode.
  58166. + *
  58167. + * @param core_if Programming view of DWC_otg controller.
  58168. + * @param dest Destination buffer for packet data.
  58169. + */
  58170. +void dwc_otg_read_setup_packet(dwc_otg_core_if_t * core_if, uint32_t * dest)
  58171. +{
  58172. + device_grxsts_data_t status;
  58173. + /* Get the 8 bytes of a setup transaction data */
  58174. +
  58175. + /* Pop 2 DWORDS off the receive data FIFO into memory */
  58176. + dest[0] = DWC_READ_REG32(core_if->data_fifo[0]);
  58177. + dest[1] = DWC_READ_REG32(core_if->data_fifo[0]);
  58178. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  58179. + status.d32 =
  58180. + DWC_READ_REG32(&core_if->core_global_regs->grxstsp);
  58181. + DWC_DEBUGPL(DBG_ANY,
  58182. + "EP:%d BCnt:%d " "pktsts:%x Frame:%d(0x%0x)\n",
  58183. + status.b.epnum, status.b.bcnt, status.b.pktsts,
  58184. + status.b.fn, status.b.fn);
  58185. + }
  58186. +}
  58187. +
  58188. +/**
  58189. + * This function enables EP0 OUT to receive SETUP packets and configures EP0
  58190. + * IN for transmitting packets. It is normally called when the
  58191. + * "Enumeration Done" interrupt occurs.
  58192. + *
  58193. + * @param core_if Programming view of DWC_otg controller.
  58194. + * @param ep The EP0 data.
  58195. + */
  58196. +void dwc_otg_ep0_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58197. +{
  58198. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58199. + dsts_data_t dsts;
  58200. + depctl_data_t diepctl;
  58201. + depctl_data_t doepctl;
  58202. + dctl_data_t dctl = {.d32 = 0 };
  58203. +
  58204. + ep->stp_rollover = 0;
  58205. + /* Read the Device Status and Endpoint 0 Control registers */
  58206. + dsts.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dsts);
  58207. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  58208. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  58209. +
  58210. + /* Set the MPS of the IN EP based on the enumeration speed */
  58211. + switch (dsts.b.enumspd) {
  58212. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  58213. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  58214. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  58215. + diepctl.b.mps = DWC_DEP0CTL_MPS_64;
  58216. + break;
  58217. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  58218. + diepctl.b.mps = DWC_DEP0CTL_MPS_8;
  58219. + break;
  58220. + }
  58221. +
  58222. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  58223. +
  58224. + /* Enable OUT EP for receive */
  58225. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  58226. + doepctl.b.epena = 1;
  58227. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  58228. + }
  58229. +#ifdef VERBOSE
  58230. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  58231. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  58232. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  58233. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  58234. +#endif
  58235. + dctl.b.cgnpinnak = 1;
  58236. +
  58237. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  58238. + DWC_DEBUGPL(DBG_PCDV, "dctl=%0x\n",
  58239. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl));
  58240. +
  58241. +}
  58242. +
  58243. +/**
  58244. + * This function activates an EP. The Device EP control register for
  58245. + * the EP is configured as defined in the ep structure. Note: This
  58246. + * function is not used for EP0.
  58247. + *
  58248. + * @param core_if Programming view of DWC_otg controller.
  58249. + * @param ep The EP to activate.
  58250. + */
  58251. +void dwc_otg_ep_activate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58252. +{
  58253. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58254. + depctl_data_t depctl;
  58255. + volatile uint32_t *addr;
  58256. + daint_data_t daintmsk = {.d32 = 0 };
  58257. + dcfg_data_t dcfg;
  58258. + uint8_t i;
  58259. +
  58260. + DWC_DEBUGPL(DBG_PCDV, "%s() EP%d-%s\n", __func__, ep->num,
  58261. + (ep->is_in ? "IN" : "OUT"));
  58262. +
  58263. +#ifdef DWC_UTE_PER_IO
  58264. + ep->xiso_frame_num = 0xFFFFFFFF;
  58265. + ep->xiso_active_xfers = 0;
  58266. + ep->xiso_queued_xfers = 0;
  58267. +#endif
  58268. + /* Read DEPCTLn register */
  58269. + if (ep->is_in == 1) {
  58270. + addr = &dev_if->in_ep_regs[ep->num]->diepctl;
  58271. + daintmsk.ep.in = 1 << ep->num;
  58272. + } else {
  58273. + addr = &dev_if->out_ep_regs[ep->num]->doepctl;
  58274. + daintmsk.ep.out = 1 << ep->num;
  58275. + }
  58276. +
  58277. + /* If the EP is already active don't change the EP Control
  58278. + * register. */
  58279. + depctl.d32 = DWC_READ_REG32(addr);
  58280. + if (!depctl.b.usbactep) {
  58281. + depctl.b.mps = ep->maxpacket;
  58282. + depctl.b.eptype = ep->type;
  58283. + depctl.b.txfnum = ep->tx_fifo_num;
  58284. +
  58285. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58286. + depctl.b.setd0pid = 1; // ???
  58287. + } else {
  58288. + depctl.b.setd0pid = 1;
  58289. + }
  58290. + depctl.b.usbactep = 1;
  58291. +
  58292. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58293. + if (!(depctl.b.eptype & 1) && (ep->is_in == 1)) { // NP IN EP
  58294. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58295. + if (core_if->nextep_seq[i] == core_if->first_in_nextep_seq)
  58296. + break;
  58297. + }
  58298. + core_if->nextep_seq[i] = ep->num;
  58299. + core_if->nextep_seq[ep->num] = core_if->first_in_nextep_seq;
  58300. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58301. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  58302. + dcfg.b.epmscnt++;
  58303. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  58304. +
  58305. + DWC_DEBUGPL(DBG_PCDV,
  58306. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58307. + __func__, core_if->first_in_nextep_seq);
  58308. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58309. + DWC_DEBUGPL(DBG_PCDV, "%2d\n",
  58310. + core_if->nextep_seq[i]);
  58311. + }
  58312. +
  58313. + }
  58314. +
  58315. +
  58316. + DWC_WRITE_REG32(addr, depctl.d32);
  58317. + DWC_DEBUGPL(DBG_PCDV, "DEPCTL=%08x\n", DWC_READ_REG32(addr));
  58318. + }
  58319. +
  58320. + /* Enable the Interrupt for this EP */
  58321. + if (core_if->multiproc_int_enable) {
  58322. + if (ep->is_in == 1) {
  58323. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58324. + diepmsk.b.xfercompl = 1;
  58325. + diepmsk.b.timeout = 1;
  58326. + diepmsk.b.epdisabled = 1;
  58327. + diepmsk.b.ahberr = 1;
  58328. + diepmsk.b.intknepmis = 1;
  58329. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  58330. + diepmsk.b.intknepmis = 0;
  58331. + diepmsk.b.txfifoundrn = 1; //?????
  58332. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58333. + diepmsk.b.nak = 1;
  58334. + }
  58335. +
  58336. +
  58337. +
  58338. +/*
  58339. + if (core_if->dma_desc_enable) {
  58340. + diepmsk.b.bna = 1;
  58341. + }
  58342. +*/
  58343. +/*
  58344. + if (core_if->dma_enable) {
  58345. + doepmsk.b.nak = 1;
  58346. + }
  58347. +*/
  58348. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58349. + diepeachintmsk[ep->num], diepmsk.d32);
  58350. +
  58351. + } else {
  58352. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58353. + doepmsk.b.xfercompl = 1;
  58354. + doepmsk.b.ahberr = 1;
  58355. + doepmsk.b.epdisabled = 1;
  58356. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58357. + doepmsk.b.outtknepdis = 1;
  58358. +
  58359. +/*
  58360. +
  58361. + if (core_if->dma_desc_enable) {
  58362. + doepmsk.b.bna = 1;
  58363. + }
  58364. +*/
  58365. +/*
  58366. + doepmsk.b.babble = 1;
  58367. + doepmsk.b.nyet = 1;
  58368. + doepmsk.b.nak = 1;
  58369. +*/
  58370. + DWC_WRITE_REG32(&dev_if->dev_global_regs->
  58371. + doepeachintmsk[ep->num], doepmsk.d32);
  58372. + }
  58373. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->deachintmsk,
  58374. + 0, daintmsk.d32);
  58375. + } else {
  58376. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58377. + if (ep->is_in) {
  58378. + diepmsk_data_t diepmsk = {.d32 = 0 };
  58379. + diepmsk.b.nak = 1;
  58380. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->diepmsk, 0, diepmsk.d32);
  58381. + } else {
  58382. + doepmsk_data_t doepmsk = {.d32 = 0 };
  58383. + doepmsk.b.outtknepdis = 1;
  58384. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->doepmsk, 0, doepmsk.d32);
  58385. + }
  58386. + }
  58387. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->daintmsk,
  58388. + 0, daintmsk.d32);
  58389. + }
  58390. +
  58391. + DWC_DEBUGPL(DBG_PCDV, "DAINTMSK=%0x\n",
  58392. + DWC_READ_REG32(&dev_if->dev_global_regs->daintmsk));
  58393. +
  58394. + ep->stall_clear_flag = 0;
  58395. +
  58396. + return;
  58397. +}
  58398. +
  58399. +/**
  58400. + * This function deactivates an EP. This is done by clearing the USB Active
  58401. + * EP bit in the Device EP control register. Note: This function is not used
  58402. + * for EP0. EP0 cannot be deactivated.
  58403. + *
  58404. + * @param core_if Programming view of DWC_otg controller.
  58405. + * @param ep The EP to deactivate.
  58406. + */
  58407. +void dwc_otg_ep_deactivate(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58408. +{
  58409. + depctl_data_t depctl = {.d32 = 0 };
  58410. + volatile uint32_t *addr;
  58411. + daint_data_t daintmsk = {.d32 = 0 };
  58412. + dcfg_data_t dcfg;
  58413. + uint8_t i = 0;
  58414. +
  58415. +#ifdef DWC_UTE_PER_IO
  58416. + ep->xiso_frame_num = 0xFFFFFFFF;
  58417. + ep->xiso_active_xfers = 0;
  58418. + ep->xiso_queued_xfers = 0;
  58419. +#endif
  58420. +
  58421. + /* Read DEPCTLn register */
  58422. + if (ep->is_in == 1) {
  58423. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  58424. + daintmsk.ep.in = 1 << ep->num;
  58425. + } else {
  58426. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  58427. + daintmsk.ep.out = 1 << ep->num;
  58428. + }
  58429. +
  58430. + depctl.d32 = DWC_READ_REG32(addr);
  58431. +
  58432. + depctl.b.usbactep = 0;
  58433. +
  58434. + /* Update nextep_seq array and EPMSCNT in DCFG*/
  58435. + if (!(depctl.b.eptype & 1) && ep->is_in == 1) { // NP EP IN
  58436. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  58437. + if (core_if->nextep_seq[i] == ep->num)
  58438. + break;
  58439. + }
  58440. + core_if->nextep_seq[i] = core_if->nextep_seq[ep->num];
  58441. + if (core_if->first_in_nextep_seq == ep->num)
  58442. + core_if->first_in_nextep_seq = i;
  58443. + core_if->nextep_seq[ep->num] = 0xff;
  58444. + depctl.b.nextep = 0;
  58445. + dcfg.d32 =
  58446. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  58447. + dcfg.b.epmscnt--;
  58448. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  58449. + dcfg.d32);
  58450. +
  58451. + DWC_DEBUGPL(DBG_PCDV,
  58452. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  58453. + __func__, core_if->first_in_nextep_seq);
  58454. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  58455. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  58456. + }
  58457. + }
  58458. +
  58459. + if (ep->is_in == 1)
  58460. + depctl.b.txfnum = 0;
  58461. +
  58462. + if (core_if->dma_desc_enable)
  58463. + depctl.b.epdis = 1;
  58464. +
  58465. + DWC_WRITE_REG32(addr, depctl.d32);
  58466. + depctl.d32 = DWC_READ_REG32(addr);
  58467. + if (core_if->dma_enable && ep->type == DWC_OTG_EP_TYPE_ISOC
  58468. + && depctl.b.epena) {
  58469. + depctl_data_t depctl = {.d32 = 0};
  58470. + if (ep->is_in) {
  58471. + diepint_data_t diepint = {.d32 = 0};
  58472. +
  58473. + depctl.b.snak = 1;
  58474. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58475. + diepctl, depctl.d32);
  58476. + do {
  58477. + dwc_udelay(10);
  58478. + diepint.d32 =
  58479. + DWC_READ_REG32(&core_if->
  58480. + dev_if->in_ep_regs[ep->num]->
  58481. + diepint);
  58482. + } while (!diepint.b.inepnakeff);
  58483. + diepint.b.inepnakeff = 1;
  58484. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58485. + diepint, diepint.d32);
  58486. + depctl.d32 = 0;
  58487. + depctl.b.epdis = 1;
  58488. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58489. + diepctl, depctl.d32);
  58490. + do {
  58491. + dwc_udelay(10);
  58492. + diepint.d32 =
  58493. + DWC_READ_REG32(&core_if->
  58494. + dev_if->in_ep_regs[ep->num]->
  58495. + diepint);
  58496. + } while (!diepint.b.epdisabled);
  58497. + diepint.b.epdisabled = 1;
  58498. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  58499. + diepint, diepint.d32);
  58500. + } else {
  58501. + dctl_data_t dctl = {.d32 = 0};
  58502. + gintmsk_data_t gintsts = {.d32 = 0};
  58503. + doepint_data_t doepint = {.d32 = 0};
  58504. + dctl.b.sgoutnak = 1;
  58505. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  58506. + dctl, 0, dctl.d32);
  58507. + do {
  58508. + dwc_udelay(10);
  58509. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  58510. + } while (!gintsts.b.goutnakeff);
  58511. + gintsts.d32 = 0;
  58512. + gintsts.b.goutnakeff = 1;
  58513. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  58514. +
  58515. + depctl.d32 = 0;
  58516. + depctl.b.epdis = 1;
  58517. + depctl.b.snak = 1;
  58518. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepctl, depctl.d32);
  58519. + do
  58520. + {
  58521. + dwc_udelay(10);
  58522. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  58523. + out_ep_regs[ep->num]->doepint);
  58524. + } while (!doepint.b.epdisabled);
  58525. +
  58526. + doepint.b.epdisabled = 1;
  58527. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->doepint, doepint.d32);
  58528. +
  58529. + dctl.d32 = 0;
  58530. + dctl.b.cgoutnak = 1;
  58531. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  58532. + }
  58533. + }
  58534. +
  58535. + /* Disable the Interrupt for this EP */
  58536. + if (core_if->multiproc_int_enable) {
  58537. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->deachintmsk,
  58538. + daintmsk.d32, 0);
  58539. +
  58540. + if (ep->is_in == 1) {
  58541. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58542. + diepeachintmsk[ep->num], 0);
  58543. + } else {
  58544. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->
  58545. + doepeachintmsk[ep->num], 0);
  58546. + }
  58547. + } else {
  58548. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->daintmsk,
  58549. + daintmsk.d32, 0);
  58550. + }
  58551. +
  58552. +}
  58553. +
  58554. +/**
  58555. + * This function initializes dma descriptor chain.
  58556. + *
  58557. + * @param core_if Programming view of DWC_otg controller.
  58558. + * @param ep The EP to start the transfer on.
  58559. + */
  58560. +static void init_dma_desc_chain(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58561. +{
  58562. + dwc_otg_dev_dma_desc_t *dma_desc;
  58563. + uint32_t offset;
  58564. + uint32_t xfer_est;
  58565. + int i;
  58566. + unsigned maxxfer_local, total_len;
  58567. +
  58568. + if (!ep->is_in && ep->type == DWC_OTG_EP_TYPE_INTR &&
  58569. + (ep->maxpacket%4)) {
  58570. + maxxfer_local = ep->maxpacket;
  58571. + total_len = ep->xfer_len;
  58572. + } else {
  58573. + maxxfer_local = ep->maxxfer;
  58574. + total_len = ep->total_len;
  58575. + }
  58576. +
  58577. + ep->desc_cnt = (total_len / maxxfer_local) +
  58578. + ((total_len % maxxfer_local) ? 1 : 0);
  58579. +
  58580. + if (!ep->desc_cnt)
  58581. + ep->desc_cnt = 1;
  58582. +
  58583. + if (ep->desc_cnt > MAX_DMA_DESC_CNT)
  58584. + ep->desc_cnt = MAX_DMA_DESC_CNT;
  58585. +
  58586. + dma_desc = ep->desc_addr;
  58587. + if (maxxfer_local == ep->maxpacket) {
  58588. + if ((total_len % maxxfer_local) &&
  58589. + (total_len/maxxfer_local < MAX_DMA_DESC_CNT)) {
  58590. + xfer_est = (ep->desc_cnt - 1) * maxxfer_local +
  58591. + (total_len % maxxfer_local);
  58592. + } else
  58593. + xfer_est = ep->desc_cnt * maxxfer_local;
  58594. + } else
  58595. + xfer_est = total_len;
  58596. + offset = 0;
  58597. + for (i = 0; i < ep->desc_cnt; ++i) {
  58598. + /** DMA Descriptor Setup */
  58599. + if (xfer_est > maxxfer_local) {
  58600. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58601. + dma_desc->status.b.l = 0;
  58602. + dma_desc->status.b.ioc = 0;
  58603. + dma_desc->status.b.sp = 0;
  58604. + dma_desc->status.b.bytes = maxxfer_local;
  58605. + dma_desc->buf = ep->dma_addr + offset;
  58606. + dma_desc->status.b.sts = 0;
  58607. + dma_desc->status.b.bs = BS_HOST_READY;
  58608. +
  58609. + xfer_est -= maxxfer_local;
  58610. + offset += maxxfer_local;
  58611. + } else {
  58612. + dma_desc->status.b.bs = BS_HOST_BUSY;
  58613. + dma_desc->status.b.l = 1;
  58614. + dma_desc->status.b.ioc = 1;
  58615. + if (ep->is_in) {
  58616. + dma_desc->status.b.sp =
  58617. + (xfer_est %
  58618. + ep->maxpacket) ? 1 : ((ep->
  58619. + sent_zlp) ? 1 : 0);
  58620. + dma_desc->status.b.bytes = xfer_est;
  58621. + } else {
  58622. + if (maxxfer_local == ep->maxpacket)
  58623. + dma_desc->status.b.bytes = xfer_est;
  58624. + else
  58625. + dma_desc->status.b.bytes =
  58626. + xfer_est + ((4 - (xfer_est & 0x3)) & 0x3);
  58627. + }
  58628. +
  58629. + dma_desc->buf = ep->dma_addr + offset;
  58630. + dma_desc->status.b.sts = 0;
  58631. + dma_desc->status.b.bs = BS_HOST_READY;
  58632. + }
  58633. + dma_desc++;
  58634. + }
  58635. +}
  58636. +/**
  58637. + * This function is called when to write ISOC data into appropriate dedicated
  58638. + * periodic FIFO.
  58639. + */
  58640. +static int32_t write_isoc_tx_fifo(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  58641. +{
  58642. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  58643. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  58644. + dtxfsts_data_t txstatus = {.d32 = 0 };
  58645. + uint32_t len = 0;
  58646. + int epnum = dwc_ep->num;
  58647. + int dwords;
  58648. +
  58649. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  58650. +
  58651. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  58652. +
  58653. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58654. +
  58655. + if (len > dwc_ep->maxpacket) {
  58656. + len = dwc_ep->maxpacket;
  58657. + }
  58658. +
  58659. + dwords = (len + 3) / 4;
  58660. +
  58661. + /* While there is space in the queue and space in the FIFO and
  58662. + * More data to tranfer, Write packets to the Tx FIFO */
  58663. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58664. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  58665. +
  58666. + while (txstatus.b.txfspcavail > dwords &&
  58667. + dwc_ep->xfer_count < dwc_ep->xfer_len && dwc_ep->xfer_len != 0) {
  58668. + /* Write the FIFO */
  58669. + dwc_otg_ep_write_packet(core_if, dwc_ep, 0);
  58670. +
  58671. + len = dwc_ep->xfer_len - dwc_ep->xfer_count;
  58672. + if (len > dwc_ep->maxpacket) {
  58673. + len = dwc_ep->maxpacket;
  58674. + }
  58675. +
  58676. + dwords = (len + 3) / 4;
  58677. + txstatus.d32 =
  58678. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  58679. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  58680. + txstatus.d32);
  58681. + }
  58682. +
  58683. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  58684. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  58685. +
  58686. + return 1;
  58687. +}
  58688. +/**
  58689. + * This function does the setup for a data transfer for an EP and
  58690. + * starts the transfer. For an IN transfer, the packets will be
  58691. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  58692. + * the packets are unloaded from the Rx FIFO in the ISR. the ISR.
  58693. + *
  58694. + * @param core_if Programming view of DWC_otg controller.
  58695. + * @param ep The EP to start the transfer on.
  58696. + */
  58697. +
  58698. +void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58699. +{
  58700. + depctl_data_t depctl;
  58701. + deptsiz_data_t deptsiz;
  58702. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58703. +
  58704. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58705. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  58706. + "xfer_buff=%p start_xfer_buff=%p, total_len = %d\n",
  58707. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  58708. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff,
  58709. + ep->total_len);
  58710. + /* IN endpoint */
  58711. + if (ep->is_in == 1) {
  58712. + dwc_otg_dev_in_ep_regs_t *in_regs =
  58713. + core_if->dev_if->in_ep_regs[ep->num];
  58714. +
  58715. + gnptxsts_data_t gtxstatus;
  58716. +
  58717. + gtxstatus.d32 =
  58718. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  58719. +
  58720. + if (core_if->en_multiple_tx_fifo == 0
  58721. + && gtxstatus.b.nptxqspcavail == 0 && !core_if->dma_enable) {
  58722. +#ifdef DEBUG
  58723. + DWC_PRINTF("TX Queue Full (0x%0x)\n", gtxstatus.d32);
  58724. +#endif
  58725. + return;
  58726. + }
  58727. +
  58728. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  58729. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  58730. +
  58731. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58732. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58733. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58734. + else
  58735. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len - ep->xfer_len)) ?
  58736. + MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58737. +
  58738. +
  58739. + /* Zero Length Packet? */
  58740. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58741. + deptsiz.b.xfersize = 0;
  58742. + deptsiz.b.pktcnt = 1;
  58743. + } else {
  58744. + /* Program the transfer size and packet count
  58745. + * as follows: xfersize = N * maxpacket +
  58746. + * short_packet pktcnt = N + (short_packet
  58747. + * exist ? 1 : 0)
  58748. + */
  58749. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58750. + deptsiz.b.pktcnt =
  58751. + (ep->xfer_len - ep->xfer_count - 1 +
  58752. + ep->maxpacket) / ep->maxpacket;
  58753. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58754. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58755. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  58756. + }
  58757. + if (ep->type == DWC_OTG_EP_TYPE_ISOC)
  58758. + deptsiz.b.mc = deptsiz.b.pktcnt;
  58759. + }
  58760. +
  58761. + /* Write the DMA register */
  58762. + if (core_if->dma_enable) {
  58763. + if (core_if->dma_desc_enable == 0) {
  58764. + if (ep->type != DWC_OTG_EP_TYPE_ISOC)
  58765. + deptsiz.b.mc = 1;
  58766. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  58767. + deptsiz.d32);
  58768. + DWC_WRITE_REG32(&(in_regs->diepdma),
  58769. + (uint32_t) ep->dma_addr);
  58770. + } else {
  58771. +#ifdef DWC_UTE_CFI
  58772. + /* The descriptor chain should be already initialized by now */
  58773. + if (ep->buff_mode != BM_STANDARD) {
  58774. + DWC_WRITE_REG32(&in_regs->diepdma,
  58775. + ep->descs_dma_addr);
  58776. + } else {
  58777. +#endif
  58778. + init_dma_desc_chain(core_if, ep);
  58779. + /** DIEPDMAn Register write */
  58780. + DWC_WRITE_REG32(&in_regs->diepdma,
  58781. + ep->dma_desc_addr);
  58782. +#ifdef DWC_UTE_CFI
  58783. + }
  58784. +#endif
  58785. + }
  58786. + } else {
  58787. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  58788. + if (ep->type != DWC_OTG_EP_TYPE_ISOC) {
  58789. + /**
  58790. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  58791. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  58792. + * the data will be written into the fifo by the ISR.
  58793. + */
  58794. + if (core_if->en_multiple_tx_fifo == 0) {
  58795. + intr_mask.b.nptxfempty = 1;
  58796. + DWC_MODIFY_REG32
  58797. + (&core_if->core_global_regs->gintmsk,
  58798. + intr_mask.d32, intr_mask.d32);
  58799. + } else {
  58800. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  58801. + if (ep->xfer_len > 0) {
  58802. + uint32_t fifoemptymsk = 0;
  58803. + fifoemptymsk = 1 << ep->num;
  58804. + DWC_MODIFY_REG32
  58805. + (&core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  58806. + 0, fifoemptymsk);
  58807. +
  58808. + }
  58809. + }
  58810. + } else {
  58811. + write_isoc_tx_fifo(core_if, ep);
  58812. + }
  58813. + }
  58814. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  58815. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  58816. +
  58817. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58818. + dsts_data_t dsts = {.d32 = 0};
  58819. + if (ep->bInterval == 1) {
  58820. + dsts.d32 =
  58821. + DWC_READ_REG32(&core_if->dev_if->
  58822. + dev_global_regs->dsts);
  58823. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58824. + if (ep->frame_num > 0x3FFF) {
  58825. + ep->frm_overrun = 1;
  58826. + ep->frame_num &= 0x3FFF;
  58827. + } else
  58828. + ep->frm_overrun = 0;
  58829. + if (ep->frame_num & 0x1) {
  58830. + depctl.b.setd1pid = 1;
  58831. + } else {
  58832. + depctl.b.setd0pid = 1;
  58833. + }
  58834. + }
  58835. + }
  58836. + /* EP enable, IN data in FIFO */
  58837. + depctl.b.cnak = 1;
  58838. + depctl.b.epena = 1;
  58839. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  58840. +
  58841. + } else {
  58842. + /* OUT endpoint */
  58843. + dwc_otg_dev_out_ep_regs_t *out_regs =
  58844. + core_if->dev_if->out_ep_regs[ep->num];
  58845. +
  58846. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  58847. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  58848. +
  58849. + if (!core_if->dma_desc_enable) {
  58850. + if (ep->maxpacket > ep->maxxfer / MAX_PKT_CNT)
  58851. + ep->xfer_len += (ep->maxxfer < (ep->total_len - ep->xfer_len)) ?
  58852. + ep->maxxfer : (ep->total_len - ep->xfer_len);
  58853. + else
  58854. + ep->xfer_len += (MAX_PKT_CNT * ep->maxpacket < (ep->total_len
  58855. + - ep->xfer_len)) ? MAX_PKT_CNT * ep->maxpacket : (ep->total_len - ep->xfer_len);
  58856. + }
  58857. +
  58858. + /* Program the transfer size and packet count as follows:
  58859. + *
  58860. + * pktcnt = N
  58861. + * xfersize = N * maxpacket
  58862. + */
  58863. + if ((ep->xfer_len - ep->xfer_count) == 0) {
  58864. + /* Zero Length Packet */
  58865. + deptsiz.b.xfersize = ep->maxpacket;
  58866. + deptsiz.b.pktcnt = 1;
  58867. + } else {
  58868. + deptsiz.b.pktcnt =
  58869. + (ep->xfer_len - ep->xfer_count +
  58870. + (ep->maxpacket - 1)) / ep->maxpacket;
  58871. + if (deptsiz.b.pktcnt > MAX_PKT_CNT) {
  58872. + deptsiz.b.pktcnt = MAX_PKT_CNT;
  58873. + }
  58874. + if (!core_if->dma_desc_enable) {
  58875. + ep->xfer_len =
  58876. + deptsiz.b.pktcnt * ep->maxpacket + ep->xfer_count;
  58877. + }
  58878. + deptsiz.b.xfersize = ep->xfer_len - ep->xfer_count;
  58879. + }
  58880. +
  58881. + DWC_DEBUGPL(DBG_PCDV, "ep%d xfersize=%d pktcnt=%d\n",
  58882. + ep->num, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  58883. +
  58884. + if (core_if->dma_enable) {
  58885. + if (!core_if->dma_desc_enable) {
  58886. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58887. + deptsiz.d32);
  58888. +
  58889. + DWC_WRITE_REG32(&(out_regs->doepdma),
  58890. + (uint32_t) ep->dma_addr);
  58891. + } else {
  58892. +#ifdef DWC_UTE_CFI
  58893. + /* The descriptor chain should be already initialized by now */
  58894. + if (ep->buff_mode != BM_STANDARD) {
  58895. + DWC_WRITE_REG32(&out_regs->doepdma,
  58896. + ep->descs_dma_addr);
  58897. + } else {
  58898. +#endif
  58899. + /** This is used for interrupt out transfers*/
  58900. + if (!ep->xfer_len)
  58901. + ep->xfer_len = ep->total_len;
  58902. + init_dma_desc_chain(core_if, ep);
  58903. +
  58904. + if (core_if->core_params->dev_out_nak) {
  58905. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58906. + deptsiz.b.pktcnt = (ep->total_len +
  58907. + (ep->maxpacket - 1)) / ep->maxpacket;
  58908. + deptsiz.b.xfersize = ep->total_len;
  58909. + /* Remember initial value of doeptsiz */
  58910. + core_if->start_doeptsiz_val[ep->num] = deptsiz.d32;
  58911. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  58912. + deptsiz.d32);
  58913. + }
  58914. + }
  58915. + /** DOEPDMAn Register write */
  58916. + DWC_WRITE_REG32(&out_regs->doepdma,
  58917. + ep->dma_desc_addr);
  58918. +#ifdef DWC_UTE_CFI
  58919. + }
  58920. +#endif
  58921. + }
  58922. + } else {
  58923. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  58924. + }
  58925. +
  58926. + if (ep->type == DWC_OTG_EP_TYPE_ISOC) {
  58927. + dsts_data_t dsts = {.d32 = 0};
  58928. + if (ep->bInterval == 1) {
  58929. + dsts.d32 =
  58930. + DWC_READ_REG32(&core_if->dev_if->
  58931. + dev_global_regs->dsts);
  58932. + ep->frame_num = dsts.b.soffn + ep->bInterval;
  58933. + if (ep->frame_num > 0x3FFF) {
  58934. + ep->frm_overrun = 1;
  58935. + ep->frame_num &= 0x3FFF;
  58936. + } else
  58937. + ep->frm_overrun = 0;
  58938. +
  58939. + if (ep->frame_num & 0x1) {
  58940. + depctl.b.setd1pid = 1;
  58941. + } else {
  58942. + depctl.b.setd0pid = 1;
  58943. + }
  58944. + }
  58945. + }
  58946. +
  58947. + /* EP enable */
  58948. + depctl.b.cnak = 1;
  58949. + depctl.b.epena = 1;
  58950. +
  58951. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  58952. +
  58953. + DWC_DEBUGPL(DBG_PCD, "DOEPCTL=%08x DOEPTSIZ=%08x\n",
  58954. + DWC_READ_REG32(&out_regs->doepctl),
  58955. + DWC_READ_REG32(&out_regs->doeptsiz));
  58956. + DWC_DEBUGPL(DBG_PCD, "DAINTMSK=%08x GINTMSK=%08x\n",
  58957. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  58958. + daintmsk),
  58959. + DWC_READ_REG32(&core_if->core_global_regs->
  58960. + gintmsk));
  58961. +
  58962. + /* Timer is scheduling only for out bulk transfers for
  58963. + * "Device DDMA OUT NAK Enhancement" feature to inform user
  58964. + * about received data payload in case of timeout
  58965. + */
  58966. + if (core_if->core_params->dev_out_nak) {
  58967. + if (ep->type == DWC_OTG_EP_TYPE_BULK) {
  58968. + core_if->ep_xfer_info[ep->num].core_if = core_if;
  58969. + core_if->ep_xfer_info[ep->num].ep = ep;
  58970. + core_if->ep_xfer_info[ep->num].state = 1;
  58971. +
  58972. + /* Start a timer for this transfer. */
  58973. + DWC_TIMER_SCHEDULE(core_if->ep_xfer_timer[ep->num], 10000);
  58974. + }
  58975. + }
  58976. + }
  58977. +}
  58978. +
  58979. +/**
  58980. + * This function setup a zero length transfer in Buffer DMA and
  58981. + * Slave modes for usb requests with zero field set
  58982. + *
  58983. + * @param core_if Programming view of DWC_otg controller.
  58984. + * @param ep The EP to start the transfer on.
  58985. + *
  58986. + */
  58987. +void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  58988. +{
  58989. +
  58990. + depctl_data_t depctl;
  58991. + deptsiz_data_t deptsiz;
  58992. + gintmsk_data_t intr_mask = {.d32 = 0 };
  58993. +
  58994. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s()\n", __func__);
  58995. + DWC_PRINTF("zero length transfer is called\n");
  58996. +
  58997. + /* IN endpoint */
  58998. + if (ep->is_in == 1) {
  58999. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59000. + core_if->dev_if->in_ep_regs[ep->num];
  59001. +
  59002. + depctl.d32 = DWC_READ_REG32(&(in_regs->diepctl));
  59003. + deptsiz.d32 = DWC_READ_REG32(&(in_regs->dieptsiz));
  59004. +
  59005. + deptsiz.b.xfersize = 0;
  59006. + deptsiz.b.pktcnt = 1;
  59007. +
  59008. + /* Write the DMA register */
  59009. + if (core_if->dma_enable) {
  59010. + if (core_if->dma_desc_enable == 0) {
  59011. + deptsiz.b.mc = 1;
  59012. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59013. + deptsiz.d32);
  59014. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59015. + (uint32_t) ep->dma_addr);
  59016. + }
  59017. + } else {
  59018. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59019. + /**
  59020. + * Enable the Non-Periodic Tx FIFO empty interrupt,
  59021. + * or the Tx FIFO epmty interrupt in dedicated Tx FIFO mode,
  59022. + * the data will be written into the fifo by the ISR.
  59023. + */
  59024. + if (core_if->en_multiple_tx_fifo == 0) {
  59025. + intr_mask.b.nptxfempty = 1;
  59026. + DWC_MODIFY_REG32(&core_if->
  59027. + core_global_regs->gintmsk,
  59028. + intr_mask.d32, intr_mask.d32);
  59029. + } else {
  59030. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59031. + if (ep->xfer_len > 0) {
  59032. + uint32_t fifoemptymsk = 0;
  59033. + fifoemptymsk = 1 << ep->num;
  59034. + DWC_MODIFY_REG32(&core_if->
  59035. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59036. + 0, fifoemptymsk);
  59037. + }
  59038. + }
  59039. + }
  59040. +
  59041. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59042. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59043. + /* EP enable, IN data in FIFO */
  59044. + depctl.b.cnak = 1;
  59045. + depctl.b.epena = 1;
  59046. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59047. +
  59048. + } else {
  59049. + /* OUT endpoint */
  59050. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59051. + core_if->dev_if->out_ep_regs[ep->num];
  59052. +
  59053. + depctl.d32 = DWC_READ_REG32(&(out_regs->doepctl));
  59054. + deptsiz.d32 = DWC_READ_REG32(&(out_regs->doeptsiz));
  59055. +
  59056. + /* Zero Length Packet */
  59057. + deptsiz.b.xfersize = ep->maxpacket;
  59058. + deptsiz.b.pktcnt = 1;
  59059. +
  59060. + if (core_if->dma_enable) {
  59061. + if (!core_if->dma_desc_enable) {
  59062. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59063. + deptsiz.d32);
  59064. +
  59065. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59066. + (uint32_t) ep->dma_addr);
  59067. + }
  59068. + } else {
  59069. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59070. + }
  59071. +
  59072. + /* EP enable */
  59073. + depctl.b.cnak = 1;
  59074. + depctl.b.epena = 1;
  59075. +
  59076. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59077. +
  59078. + }
  59079. +}
  59080. +
  59081. +/**
  59082. + * This function does the setup for a data transfer for EP0 and starts
  59083. + * the transfer. For an IN transfer, the packets will be loaded into
  59084. + * the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are
  59085. + * unloaded from the Rx FIFO in the ISR.
  59086. + *
  59087. + * @param core_if Programming view of DWC_otg controller.
  59088. + * @param ep The EP0 data.
  59089. + */
  59090. +void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59091. +{
  59092. + depctl_data_t depctl;
  59093. + deptsiz0_data_t deptsiz;
  59094. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59095. + dwc_otg_dev_dma_desc_t *dma_desc;
  59096. +
  59097. + DWC_DEBUGPL(DBG_PCD, "ep%d-%s xfer_len=%d xfer_cnt=%d "
  59098. + "xfer_buff=%p start_xfer_buff=%p \n",
  59099. + ep->num, (ep->is_in ? "IN" : "OUT"), ep->xfer_len,
  59100. + ep->xfer_count, ep->xfer_buff, ep->start_xfer_buff);
  59101. +
  59102. + ep->total_len = ep->xfer_len;
  59103. +
  59104. + /* IN endpoint */
  59105. + if (ep->is_in == 1) {
  59106. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59107. + core_if->dev_if->in_ep_regs[0];
  59108. +
  59109. + gnptxsts_data_t gtxstatus;
  59110. +
  59111. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59112. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59113. + if (depctl.b.epena)
  59114. + return;
  59115. + }
  59116. +
  59117. + gtxstatus.d32 =
  59118. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59119. +
  59120. + /* If dedicated FIFO every time flush fifo before enable ep*/
  59121. + if (core_if->en_multiple_tx_fifo && core_if->snpsid >= OTG_CORE_REV_3_00a)
  59122. + dwc_otg_flush_tx_fifo(core_if, ep->tx_fifo_num);
  59123. +
  59124. + if (core_if->en_multiple_tx_fifo == 0
  59125. + && gtxstatus.b.nptxqspcavail == 0
  59126. + && !core_if->dma_enable) {
  59127. +#ifdef DEBUG
  59128. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59129. + DWC_DEBUGPL(DBG_PCD, "DIEPCTL0=%0x\n",
  59130. + DWC_READ_REG32(&in_regs->diepctl));
  59131. + DWC_DEBUGPL(DBG_PCD, "DIEPTSIZ0=%0x (sz=%d, pcnt=%d)\n",
  59132. + deptsiz.d32,
  59133. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59134. + DWC_PRINTF("TX Queue or FIFO Full (0x%0x)\n",
  59135. + gtxstatus.d32);
  59136. +#endif
  59137. + return;
  59138. + }
  59139. +
  59140. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59141. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59142. +
  59143. + /* Zero Length Packet? */
  59144. + if (ep->xfer_len == 0) {
  59145. + deptsiz.b.xfersize = 0;
  59146. + deptsiz.b.pktcnt = 1;
  59147. + } else {
  59148. + /* Program the transfer size and packet count
  59149. + * as follows: xfersize = N * maxpacket +
  59150. + * short_packet pktcnt = N + (short_packet
  59151. + * exist ? 1 : 0)
  59152. + */
  59153. + if (ep->xfer_len > ep->maxpacket) {
  59154. + ep->xfer_len = ep->maxpacket;
  59155. + deptsiz.b.xfersize = ep->maxpacket;
  59156. + } else {
  59157. + deptsiz.b.xfersize = ep->xfer_len;
  59158. + }
  59159. + deptsiz.b.pktcnt = 1;
  59160. +
  59161. + }
  59162. + DWC_DEBUGPL(DBG_PCDV,
  59163. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59164. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59165. + deptsiz.d32);
  59166. +
  59167. + /* Write the DMA register */
  59168. + if (core_if->dma_enable) {
  59169. + if (core_if->dma_desc_enable == 0) {
  59170. + DWC_WRITE_REG32(&in_regs->dieptsiz,
  59171. + deptsiz.d32);
  59172. +
  59173. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59174. + (uint32_t) ep->dma_addr);
  59175. + } else {
  59176. + dma_desc = core_if->dev_if->in_desc_addr;
  59177. +
  59178. + /** DMA Descriptor Setup */
  59179. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59180. + dma_desc->status.b.l = 1;
  59181. + dma_desc->status.b.ioc = 1;
  59182. + dma_desc->status.b.sp =
  59183. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59184. + dma_desc->status.b.bytes = ep->xfer_len;
  59185. + dma_desc->buf = ep->dma_addr;
  59186. + dma_desc->status.b.sts = 0;
  59187. + dma_desc->status.b.bs = BS_HOST_READY;
  59188. +
  59189. + /** DIEPDMA0 Register write */
  59190. + DWC_WRITE_REG32(&in_regs->diepdma,
  59191. + core_if->
  59192. + dev_if->dma_in_desc_addr);
  59193. + }
  59194. + } else {
  59195. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59196. + }
  59197. +
  59198. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59199. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59200. + /* EP enable, IN data in FIFO */
  59201. + depctl.b.cnak = 1;
  59202. + depctl.b.epena = 1;
  59203. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59204. +
  59205. + /**
  59206. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59207. + * data will be written into the fifo by the ISR.
  59208. + */
  59209. + if (!core_if->dma_enable) {
  59210. + if (core_if->en_multiple_tx_fifo == 0) {
  59211. + intr_mask.b.nptxfempty = 1;
  59212. + DWC_MODIFY_REG32(&core_if->
  59213. + core_global_regs->gintmsk,
  59214. + intr_mask.d32, intr_mask.d32);
  59215. + } else {
  59216. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59217. + if (ep->xfer_len > 0) {
  59218. + uint32_t fifoemptymsk = 0;
  59219. + fifoemptymsk |= 1 << ep->num;
  59220. + DWC_MODIFY_REG32(&core_if->
  59221. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59222. + 0, fifoemptymsk);
  59223. + }
  59224. + }
  59225. + }
  59226. + } else {
  59227. + /* OUT endpoint */
  59228. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59229. + core_if->dev_if->out_ep_regs[0];
  59230. +
  59231. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59232. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59233. +
  59234. + /* Program the transfer size and packet count as follows:
  59235. + * xfersize = N * (maxpacket + 4 - (maxpacket % 4))
  59236. + * pktcnt = N */
  59237. + /* Zero Length Packet */
  59238. + deptsiz.b.xfersize = ep->maxpacket;
  59239. + deptsiz.b.pktcnt = 1;
  59240. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  59241. + deptsiz.b.supcnt = 3;
  59242. +
  59243. + DWC_DEBUGPL(DBG_PCDV, "len=%d xfersize=%d pktcnt=%d\n",
  59244. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt);
  59245. +
  59246. + if (core_if->dma_enable) {
  59247. + if (!core_if->dma_desc_enable) {
  59248. + DWC_WRITE_REG32(&out_regs->doeptsiz,
  59249. + deptsiz.d32);
  59250. +
  59251. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59252. + (uint32_t) ep->dma_addr);
  59253. + } else {
  59254. + dma_desc = core_if->dev_if->out_desc_addr;
  59255. +
  59256. + /** DMA Descriptor Setup */
  59257. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59258. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  59259. + dma_desc->status.b.mtrf = 0;
  59260. + dma_desc->status.b.sr = 0;
  59261. + }
  59262. + dma_desc->status.b.l = 1;
  59263. + dma_desc->status.b.ioc = 1;
  59264. + dma_desc->status.b.bytes = ep->maxpacket;
  59265. + dma_desc->buf = ep->dma_addr;
  59266. + dma_desc->status.b.sts = 0;
  59267. + dma_desc->status.b.bs = BS_HOST_READY;
  59268. +
  59269. + /** DOEPDMA0 Register write */
  59270. + DWC_WRITE_REG32(&out_regs->doepdma,
  59271. + core_if->dev_if->
  59272. + dma_out_desc_addr);
  59273. + }
  59274. + } else {
  59275. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59276. + }
  59277. +
  59278. + /* EP enable */
  59279. + depctl.b.cnak = 1;
  59280. + depctl.b.epena = 1;
  59281. + DWC_WRITE_REG32(&(out_regs->doepctl), depctl.d32);
  59282. + }
  59283. +}
  59284. +
  59285. +/**
  59286. + * This function continues control IN transfers started by
  59287. + * dwc_otg_ep0_start_transfer, when the transfer does not fit in a
  59288. + * single packet. NOTE: The DIEPCTL0/DOEPCTL0 registers only have one
  59289. + * bit for the packet count.
  59290. + *
  59291. + * @param core_if Programming view of DWC_otg controller.
  59292. + * @param ep The EP0 data.
  59293. + */
  59294. +void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59295. +{
  59296. + depctl_data_t depctl;
  59297. + deptsiz0_data_t deptsiz;
  59298. + gintmsk_data_t intr_mask = {.d32 = 0 };
  59299. + dwc_otg_dev_dma_desc_t *dma_desc;
  59300. +
  59301. + if (ep->is_in == 1) {
  59302. + dwc_otg_dev_in_ep_regs_t *in_regs =
  59303. + core_if->dev_if->in_ep_regs[0];
  59304. + gnptxsts_data_t tx_status = {.d32 = 0 };
  59305. +
  59306. + tx_status.d32 =
  59307. + DWC_READ_REG32(&core_if->core_global_regs->gnptxsts);
  59308. + /** @todo Should there be check for room in the Tx
  59309. + * Status Queue. If not remove the code above this comment. */
  59310. +
  59311. + depctl.d32 = DWC_READ_REG32(&in_regs->diepctl);
  59312. + deptsiz.d32 = DWC_READ_REG32(&in_regs->dieptsiz);
  59313. +
  59314. + /* Program the transfer size and packet count
  59315. + * as follows: xfersize = N * maxpacket +
  59316. + * short_packet pktcnt = N + (short_packet
  59317. + * exist ? 1 : 0)
  59318. + */
  59319. +
  59320. + if (core_if->dma_desc_enable == 0) {
  59321. + deptsiz.b.xfersize =
  59322. + (ep->total_len - ep->xfer_count) >
  59323. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59324. + ep->xfer_count);
  59325. + deptsiz.b.pktcnt = 1;
  59326. + if (core_if->dma_enable == 0) {
  59327. + ep->xfer_len += deptsiz.b.xfersize;
  59328. + } else {
  59329. + ep->xfer_len = deptsiz.b.xfersize;
  59330. + }
  59331. + DWC_WRITE_REG32(&in_regs->dieptsiz, deptsiz.d32);
  59332. + } else {
  59333. + ep->xfer_len =
  59334. + (ep->total_len - ep->xfer_count) >
  59335. + ep->maxpacket ? ep->maxpacket : (ep->total_len -
  59336. + ep->xfer_count);
  59337. +
  59338. + dma_desc = core_if->dev_if->in_desc_addr;
  59339. +
  59340. + /** DMA Descriptor Setup */
  59341. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59342. + dma_desc->status.b.l = 1;
  59343. + dma_desc->status.b.ioc = 1;
  59344. + dma_desc->status.b.sp =
  59345. + (ep->xfer_len == ep->maxpacket) ? 0 : 1;
  59346. + dma_desc->status.b.bytes = ep->xfer_len;
  59347. + dma_desc->buf = ep->dma_addr;
  59348. + dma_desc->status.b.sts = 0;
  59349. + dma_desc->status.b.bs = BS_HOST_READY;
  59350. +
  59351. + /** DIEPDMA0 Register write */
  59352. + DWC_WRITE_REG32(&in_regs->diepdma,
  59353. + core_if->dev_if->dma_in_desc_addr);
  59354. + }
  59355. +
  59356. + DWC_DEBUGPL(DBG_PCDV,
  59357. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59358. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59359. + deptsiz.d32);
  59360. +
  59361. + /* Write the DMA register */
  59362. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59363. + if (core_if->dma_desc_enable == 0)
  59364. + DWC_WRITE_REG32(&(in_regs->diepdma),
  59365. + (uint32_t) ep->dma_addr);
  59366. + }
  59367. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable)
  59368. + depctl.b.nextep = core_if->nextep_seq[ep->num];
  59369. + /* EP enable, IN data in FIFO */
  59370. + depctl.b.cnak = 1;
  59371. + depctl.b.epena = 1;
  59372. + DWC_WRITE_REG32(&in_regs->diepctl, depctl.d32);
  59373. +
  59374. + /**
  59375. + * Enable the Non-Periodic Tx FIFO empty interrupt, the
  59376. + * data will be written into the fifo by the ISR.
  59377. + */
  59378. + if (!core_if->dma_enable) {
  59379. + if (core_if->en_multiple_tx_fifo == 0) {
  59380. + /* First clear it from GINTSTS */
  59381. + intr_mask.b.nptxfempty = 1;
  59382. + DWC_MODIFY_REG32(&core_if->
  59383. + core_global_regs->gintmsk,
  59384. + intr_mask.d32, intr_mask.d32);
  59385. +
  59386. + } else {
  59387. + /* Enable the Tx FIFO Empty Interrupt for this EP */
  59388. + if (ep->xfer_len > 0) {
  59389. + uint32_t fifoemptymsk = 0;
  59390. + fifoemptymsk |= 1 << ep->num;
  59391. + DWC_MODIFY_REG32(&core_if->
  59392. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  59393. + 0, fifoemptymsk);
  59394. + }
  59395. + }
  59396. + }
  59397. + } else {
  59398. + dwc_otg_dev_out_ep_regs_t *out_regs =
  59399. + core_if->dev_if->out_ep_regs[0];
  59400. +
  59401. + depctl.d32 = DWC_READ_REG32(&out_regs->doepctl);
  59402. + deptsiz.d32 = DWC_READ_REG32(&out_regs->doeptsiz);
  59403. +
  59404. + /* Program the transfer size and packet count
  59405. + * as follows: xfersize = N * maxpacket +
  59406. + * short_packet pktcnt = N + (short_packet
  59407. + * exist ? 1 : 0)
  59408. + */
  59409. + deptsiz.b.xfersize = ep->maxpacket;
  59410. + deptsiz.b.pktcnt = 1;
  59411. +
  59412. + if (core_if->dma_desc_enable == 0) {
  59413. + DWC_WRITE_REG32(&out_regs->doeptsiz, deptsiz.d32);
  59414. + } else {
  59415. + dma_desc = core_if->dev_if->out_desc_addr;
  59416. +
  59417. + /** DMA Descriptor Setup */
  59418. + dma_desc->status.b.bs = BS_HOST_BUSY;
  59419. + dma_desc->status.b.l = 1;
  59420. + dma_desc->status.b.ioc = 1;
  59421. + dma_desc->status.b.bytes = ep->maxpacket;
  59422. + dma_desc->buf = ep->dma_addr;
  59423. + dma_desc->status.b.sts = 0;
  59424. + dma_desc->status.b.bs = BS_HOST_READY;
  59425. +
  59426. + /** DOEPDMA0 Register write */
  59427. + DWC_WRITE_REG32(&out_regs->doepdma,
  59428. + core_if->dev_if->dma_out_desc_addr);
  59429. + }
  59430. +
  59431. + DWC_DEBUGPL(DBG_PCDV,
  59432. + "IN len=%d xfersize=%d pktcnt=%d [%08x]\n",
  59433. + ep->xfer_len, deptsiz.b.xfersize, deptsiz.b.pktcnt,
  59434. + deptsiz.d32);
  59435. +
  59436. + /* Write the DMA register */
  59437. + if (core_if->hwcfg2.b.architecture == DWC_INT_DMA_ARCH) {
  59438. + if (core_if->dma_desc_enable == 0)
  59439. + DWC_WRITE_REG32(&(out_regs->doepdma),
  59440. + (uint32_t) ep->dma_addr);
  59441. +
  59442. + }
  59443. +
  59444. + /* EP enable, IN data in FIFO */
  59445. + depctl.b.cnak = 1;
  59446. + depctl.b.epena = 1;
  59447. + DWC_WRITE_REG32(&out_regs->doepctl, depctl.d32);
  59448. +
  59449. + }
  59450. +}
  59451. +
  59452. +#ifdef DEBUG
  59453. +void dump_msg(const u8 * buf, unsigned int length)
  59454. +{
  59455. + unsigned int start, num, i;
  59456. + char line[52], *p;
  59457. +
  59458. + if (length >= 512)
  59459. + return;
  59460. + start = 0;
  59461. + while (length > 0) {
  59462. + num = length < 16u ? length : 16u;
  59463. + p = line;
  59464. + for (i = 0; i < num; ++i) {
  59465. + if (i == 8)
  59466. + *p++ = ' ';
  59467. + DWC_SPRINTF(p, " %02x", buf[i]);
  59468. + p += 3;
  59469. + }
  59470. + *p = 0;
  59471. + DWC_PRINTF("%6x: %s\n", start, line);
  59472. + buf += num;
  59473. + start += num;
  59474. + length -= num;
  59475. + }
  59476. +}
  59477. +#else
  59478. +static inline void dump_msg(const u8 * buf, unsigned int length)
  59479. +{
  59480. +}
  59481. +#endif
  59482. +
  59483. +/**
  59484. + * This function writes a packet into the Tx FIFO associated with the
  59485. + * EP. For non-periodic EPs the non-periodic Tx FIFO is written. For
  59486. + * periodic EPs the periodic Tx FIFO associated with the EP is written
  59487. + * with all packets for the next micro-frame.
  59488. + *
  59489. + * @param core_if Programming view of DWC_otg controller.
  59490. + * @param ep The EP to write packet for.
  59491. + * @param dma Indicates if DMA is being used.
  59492. + */
  59493. +void dwc_otg_ep_write_packet(dwc_otg_core_if_t * core_if, dwc_ep_t * ep,
  59494. + int dma)
  59495. +{
  59496. + /**
  59497. + * The buffer is padded to DWORD on a per packet basis in
  59498. + * slave/dma mode if the MPS is not DWORD aligned. The last
  59499. + * packet, if short, is also padded to a multiple of DWORD.
  59500. + *
  59501. + * ep->xfer_buff always starts DWORD aligned in memory and is a
  59502. + * multiple of DWORD in length
  59503. + *
  59504. + * ep->xfer_len can be any number of bytes
  59505. + *
  59506. + * ep->xfer_count is a multiple of ep->maxpacket until the last
  59507. + * packet
  59508. + *
  59509. + * FIFO access is DWORD */
  59510. +
  59511. + uint32_t i;
  59512. + uint32_t byte_count;
  59513. + uint32_t dword_count;
  59514. + uint32_t *fifo;
  59515. + uint32_t *data_buff = (uint32_t *) ep->xfer_buff;
  59516. +
  59517. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p)\n", __func__, core_if,
  59518. + ep);
  59519. + if (ep->xfer_count >= ep->xfer_len) {
  59520. + DWC_WARN("%s() No data for EP%d!!!\n", __func__, ep->num);
  59521. + return;
  59522. + }
  59523. +
  59524. + /* Find the byte length of the packet either short packet or MPS */
  59525. + if ((ep->xfer_len - ep->xfer_count) < ep->maxpacket) {
  59526. + byte_count = ep->xfer_len - ep->xfer_count;
  59527. + } else {
  59528. + byte_count = ep->maxpacket;
  59529. + }
  59530. +
  59531. + /* Find the DWORD length, padded by extra bytes as neccessary if MPS
  59532. + * is not a multiple of DWORD */
  59533. + dword_count = (byte_count + 3) / 4;
  59534. +
  59535. +#ifdef VERBOSE
  59536. + dump_msg(ep->xfer_buff, byte_count);
  59537. +#endif
  59538. +
  59539. + /**@todo NGS Where are the Periodic Tx FIFO addresses
  59540. + * intialized? What should this be? */
  59541. +
  59542. + fifo = core_if->data_fifo[ep->num];
  59543. +
  59544. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "fifo=%p buff=%p *p=%08x bc=%d\n",
  59545. + fifo, data_buff, *data_buff, byte_count);
  59546. +
  59547. + if (!dma) {
  59548. + for (i = 0; i < dword_count; i++, data_buff++) {
  59549. + DWC_WRITE_REG32(fifo, *data_buff);
  59550. + }
  59551. + }
  59552. +
  59553. + ep->xfer_count += byte_count;
  59554. + ep->xfer_buff += byte_count;
  59555. + ep->dma_addr += byte_count;
  59556. +}
  59557. +
  59558. +/**
  59559. + * Set the EP STALL.
  59560. + *
  59561. + * @param core_if Programming view of DWC_otg controller.
  59562. + * @param ep The EP to set the stall on.
  59563. + */
  59564. +void dwc_otg_ep_set_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59565. +{
  59566. + depctl_data_t depctl;
  59567. + volatile uint32_t *depctl_addr;
  59568. +
  59569. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59570. + (ep->is_in ? "IN" : "OUT"));
  59571. +
  59572. + if (ep->is_in == 1) {
  59573. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59574. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59575. +
  59576. + /* set the disable and stall bits */
  59577. + if (depctl.b.epena) {
  59578. + depctl.b.epdis = 1;
  59579. + }
  59580. + depctl.b.stall = 1;
  59581. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59582. + } else {
  59583. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59584. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59585. +
  59586. + /* set the stall bit */
  59587. + depctl.b.stall = 1;
  59588. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59589. + }
  59590. +
  59591. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59592. +
  59593. + return;
  59594. +}
  59595. +
  59596. +/**
  59597. + * Clear the EP STALL.
  59598. + *
  59599. + * @param core_if Programming view of DWC_otg controller.
  59600. + * @param ep The EP to clear stall from.
  59601. + */
  59602. +void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  59603. +{
  59604. + depctl_data_t depctl;
  59605. + volatile uint32_t *depctl_addr;
  59606. +
  59607. + DWC_DEBUGPL(DBG_PCD, "%s ep%d-%s\n", __func__, ep->num,
  59608. + (ep->is_in ? "IN" : "OUT"));
  59609. +
  59610. + if (ep->is_in == 1) {
  59611. + depctl_addr = &(core_if->dev_if->in_ep_regs[ep->num]->diepctl);
  59612. + } else {
  59613. + depctl_addr = &(core_if->dev_if->out_ep_regs[ep->num]->doepctl);
  59614. + }
  59615. +
  59616. + depctl.d32 = DWC_READ_REG32(depctl_addr);
  59617. +
  59618. + /* clear the stall bits */
  59619. + depctl.b.stall = 0;
  59620. +
  59621. + /*
  59622. + * USB Spec 9.4.5: For endpoints using data toggle, regardless
  59623. + * of whether an endpoint has the Halt feature set, a
  59624. + * ClearFeature(ENDPOINT_HALT) request always results in the
  59625. + * data toggle being reinitialized to DATA0.
  59626. + */
  59627. + if (ep->type == DWC_OTG_EP_TYPE_INTR ||
  59628. + ep->type == DWC_OTG_EP_TYPE_BULK) {
  59629. + depctl.b.setd0pid = 1; /* DATA0 */
  59630. + }
  59631. +
  59632. + DWC_WRITE_REG32(depctl_addr, depctl.d32);
  59633. + DWC_DEBUGPL(DBG_PCD, "DEPCTL=%0x\n", DWC_READ_REG32(depctl_addr));
  59634. + return;
  59635. +}
  59636. +
  59637. +/**
  59638. + * This function reads a packet from the Rx FIFO into the destination
  59639. + * buffer. To read SETUP data use dwc_otg_read_setup_packet.
  59640. + *
  59641. + * @param core_if Programming view of DWC_otg controller.
  59642. + * @param dest Destination buffer for the packet.
  59643. + * @param bytes Number of bytes to copy to the destination.
  59644. + */
  59645. +void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  59646. + uint8_t * dest, uint16_t bytes)
  59647. +{
  59648. + int i;
  59649. + int word_count = (bytes + 3) / 4;
  59650. +
  59651. + volatile uint32_t *fifo = core_if->data_fifo[0];
  59652. + uint32_t *data_buff = (uint32_t *) dest;
  59653. +
  59654. + /**
  59655. + * @todo Account for the case where _dest is not dword aligned. This
  59656. + * requires reading data from the FIFO into a uint32_t temp buffer,
  59657. + * then moving it into the data buffer.
  59658. + */
  59659. +
  59660. + DWC_DEBUGPL((DBG_PCDV | DBG_CILV), "%s(%p,%p,%d)\n", __func__,
  59661. + core_if, dest, bytes);
  59662. +
  59663. + for (i = 0; i < word_count; i++, data_buff++) {
  59664. + *data_buff = DWC_READ_REG32(fifo);
  59665. + }
  59666. +
  59667. + return;
  59668. +}
  59669. +
  59670. +/**
  59671. + * This functions reads the device registers and prints them
  59672. + *
  59673. + * @param core_if Programming view of DWC_otg controller.
  59674. + */
  59675. +void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * core_if)
  59676. +{
  59677. + int i;
  59678. + volatile uint32_t *addr;
  59679. +
  59680. + DWC_PRINTF("Device Global Registers\n");
  59681. + addr = &core_if->dev_if->dev_global_regs->dcfg;
  59682. + DWC_PRINTF("DCFG @0x%08lX : 0x%08X\n",
  59683. + (unsigned long)addr, DWC_READ_REG32(addr));
  59684. + addr = &core_if->dev_if->dev_global_regs->dctl;
  59685. + DWC_PRINTF("DCTL @0x%08lX : 0x%08X\n",
  59686. + (unsigned long)addr, DWC_READ_REG32(addr));
  59687. + addr = &core_if->dev_if->dev_global_regs->dsts;
  59688. + DWC_PRINTF("DSTS @0x%08lX : 0x%08X\n",
  59689. + (unsigned long)addr, DWC_READ_REG32(addr));
  59690. + addr = &core_if->dev_if->dev_global_regs->diepmsk;
  59691. + DWC_PRINTF("DIEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59692. + DWC_READ_REG32(addr));
  59693. + addr = &core_if->dev_if->dev_global_regs->doepmsk;
  59694. + DWC_PRINTF("DOEPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59695. + DWC_READ_REG32(addr));
  59696. + addr = &core_if->dev_if->dev_global_regs->daint;
  59697. + DWC_PRINTF("DAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59698. + DWC_READ_REG32(addr));
  59699. + addr = &core_if->dev_if->dev_global_regs->daintmsk;
  59700. + DWC_PRINTF("DAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59701. + DWC_READ_REG32(addr));
  59702. + addr = &core_if->dev_if->dev_global_regs->dtknqr1;
  59703. + DWC_PRINTF("DTKNQR1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59704. + DWC_READ_REG32(addr));
  59705. + if (core_if->hwcfg2.b.dev_token_q_depth > 6) {
  59706. + addr = &core_if->dev_if->dev_global_regs->dtknqr2;
  59707. + DWC_PRINTF("DTKNQR2 @0x%08lX : 0x%08X\n",
  59708. + (unsigned long)addr, DWC_READ_REG32(addr));
  59709. + }
  59710. +
  59711. + addr = &core_if->dev_if->dev_global_regs->dvbusdis;
  59712. + DWC_PRINTF("DVBUSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59713. + DWC_READ_REG32(addr));
  59714. +
  59715. + addr = &core_if->dev_if->dev_global_regs->dvbuspulse;
  59716. + DWC_PRINTF("DVBUSPULSE @0x%08lX : 0x%08X\n",
  59717. + (unsigned long)addr, DWC_READ_REG32(addr));
  59718. +
  59719. + addr = &core_if->dev_if->dev_global_regs->dtknqr3_dthrctl;
  59720. + DWC_PRINTF("DTKNQR3_DTHRCTL @0x%08lX : 0x%08X\n",
  59721. + (unsigned long)addr, DWC_READ_REG32(addr));
  59722. +
  59723. + if (core_if->hwcfg2.b.dev_token_q_depth > 22) {
  59724. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59725. + DWC_PRINTF("DTKNQR4 @0x%08lX : 0x%08X\n",
  59726. + (unsigned long)addr, DWC_READ_REG32(addr));
  59727. + }
  59728. +
  59729. + addr = &core_if->dev_if->dev_global_regs->dtknqr4_fifoemptymsk;
  59730. + DWC_PRINTF("FIFOEMPMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59731. + DWC_READ_REG32(addr));
  59732. +
  59733. + if (core_if->hwcfg2.b.multi_proc_int) {
  59734. +
  59735. + addr = &core_if->dev_if->dev_global_regs->deachint;
  59736. + DWC_PRINTF("DEACHINT @0x%08lX : 0x%08X\n",
  59737. + (unsigned long)addr, DWC_READ_REG32(addr));
  59738. + addr = &core_if->dev_if->dev_global_regs->deachintmsk;
  59739. + DWC_PRINTF("DEACHINTMSK @0x%08lX : 0x%08X\n",
  59740. + (unsigned long)addr, DWC_READ_REG32(addr));
  59741. +
  59742. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59743. + addr =
  59744. + &core_if->dev_if->
  59745. + dev_global_regs->diepeachintmsk[i];
  59746. + DWC_PRINTF("DIEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59747. + i, (unsigned long)addr,
  59748. + DWC_READ_REG32(addr));
  59749. + }
  59750. +
  59751. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59752. + addr =
  59753. + &core_if->dev_if->
  59754. + dev_global_regs->doepeachintmsk[i];
  59755. + DWC_PRINTF("DOEPEACHINTMSK[%d] @0x%08lX : 0x%08X\n",
  59756. + i, (unsigned long)addr,
  59757. + DWC_READ_REG32(addr));
  59758. + }
  59759. + }
  59760. +
  59761. + for (i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  59762. + DWC_PRINTF("Device IN EP %d Registers\n", i);
  59763. + addr = &core_if->dev_if->in_ep_regs[i]->diepctl;
  59764. + DWC_PRINTF("DIEPCTL @0x%08lX : 0x%08X\n",
  59765. + (unsigned long)addr, DWC_READ_REG32(addr));
  59766. + addr = &core_if->dev_if->in_ep_regs[i]->diepint;
  59767. + DWC_PRINTF("DIEPINT @0x%08lX : 0x%08X\n",
  59768. + (unsigned long)addr, DWC_READ_REG32(addr));
  59769. + addr = &core_if->dev_if->in_ep_regs[i]->dieptsiz;
  59770. + DWC_PRINTF("DIETSIZ @0x%08lX : 0x%08X\n",
  59771. + (unsigned long)addr, DWC_READ_REG32(addr));
  59772. + addr = &core_if->dev_if->in_ep_regs[i]->diepdma;
  59773. + DWC_PRINTF("DIEPDMA @0x%08lX : 0x%08X\n",
  59774. + (unsigned long)addr, DWC_READ_REG32(addr));
  59775. + addr = &core_if->dev_if->in_ep_regs[i]->dtxfsts;
  59776. + DWC_PRINTF("DTXFSTS @0x%08lX : 0x%08X\n",
  59777. + (unsigned long)addr, DWC_READ_REG32(addr));
  59778. + addr = &core_if->dev_if->in_ep_regs[i]->diepdmab;
  59779. + DWC_PRINTF("DIEPDMAB @0x%08lX : 0x%08X\n",
  59780. + (unsigned long)addr, 0 /*DWC_READ_REG32(addr) */ );
  59781. + }
  59782. +
  59783. + for (i = 0; i <= core_if->dev_if->num_out_eps; i++) {
  59784. + DWC_PRINTF("Device OUT EP %d Registers\n", i);
  59785. + addr = &core_if->dev_if->out_ep_regs[i]->doepctl;
  59786. + DWC_PRINTF("DOEPCTL @0x%08lX : 0x%08X\n",
  59787. + (unsigned long)addr, DWC_READ_REG32(addr));
  59788. + addr = &core_if->dev_if->out_ep_regs[i]->doepint;
  59789. + DWC_PRINTF("DOEPINT @0x%08lX : 0x%08X\n",
  59790. + (unsigned long)addr, DWC_READ_REG32(addr));
  59791. + addr = &core_if->dev_if->out_ep_regs[i]->doeptsiz;
  59792. + DWC_PRINTF("DOETSIZ @0x%08lX : 0x%08X\n",
  59793. + (unsigned long)addr, DWC_READ_REG32(addr));
  59794. + addr = &core_if->dev_if->out_ep_regs[i]->doepdma;
  59795. + DWC_PRINTF("DOEPDMA @0x%08lX : 0x%08X\n",
  59796. + (unsigned long)addr, DWC_READ_REG32(addr));
  59797. + if (core_if->dma_enable) { /* Don't access this register in SLAVE mode */
  59798. + addr = &core_if->dev_if->out_ep_regs[i]->doepdmab;
  59799. + DWC_PRINTF("DOEPDMAB @0x%08lX : 0x%08X\n",
  59800. + (unsigned long)addr, DWC_READ_REG32(addr));
  59801. + }
  59802. +
  59803. + }
  59804. +}
  59805. +
  59806. +/**
  59807. + * This functions reads the SPRAM and prints its content
  59808. + *
  59809. + * @param core_if Programming view of DWC_otg controller.
  59810. + */
  59811. +void dwc_otg_dump_spram(dwc_otg_core_if_t * core_if)
  59812. +{
  59813. + volatile uint8_t *addr, *start_addr, *end_addr;
  59814. +
  59815. + DWC_PRINTF("SPRAM Data:\n");
  59816. + start_addr = (void *)core_if->core_global_regs;
  59817. + DWC_PRINTF("Base Address: 0x%8lX\n", (unsigned long)start_addr);
  59818. + start_addr += 0x00028000;
  59819. + end_addr = (void *)core_if->core_global_regs;
  59820. + end_addr += 0x000280e0;
  59821. +
  59822. + for (addr = start_addr; addr < end_addr; addr += 16) {
  59823. + DWC_PRINTF
  59824. + ("0x%8lX:\t%2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X %2X\n",
  59825. + (unsigned long)addr, addr[0], addr[1], addr[2], addr[3],
  59826. + addr[4], addr[5], addr[6], addr[7], addr[8], addr[9],
  59827. + addr[10], addr[11], addr[12], addr[13], addr[14], addr[15]
  59828. + );
  59829. + }
  59830. +
  59831. + return;
  59832. +}
  59833. +
  59834. +/**
  59835. + * This function reads the host registers and prints them
  59836. + *
  59837. + * @param core_if Programming view of DWC_otg controller.
  59838. + */
  59839. +void dwc_otg_dump_host_registers(dwc_otg_core_if_t * core_if)
  59840. +{
  59841. + int i;
  59842. + volatile uint32_t *addr;
  59843. +
  59844. + DWC_PRINTF("Host Global Registers\n");
  59845. + addr = &core_if->host_if->host_global_regs->hcfg;
  59846. + DWC_PRINTF("HCFG @0x%08lX : 0x%08X\n",
  59847. + (unsigned long)addr, DWC_READ_REG32(addr));
  59848. + addr = &core_if->host_if->host_global_regs->hfir;
  59849. + DWC_PRINTF("HFIR @0x%08lX : 0x%08X\n",
  59850. + (unsigned long)addr, DWC_READ_REG32(addr));
  59851. + addr = &core_if->host_if->host_global_regs->hfnum;
  59852. + DWC_PRINTF("HFNUM @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59853. + DWC_READ_REG32(addr));
  59854. + addr = &core_if->host_if->host_global_regs->hptxsts;
  59855. + DWC_PRINTF("HPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59856. + DWC_READ_REG32(addr));
  59857. + addr = &core_if->host_if->host_global_regs->haint;
  59858. + DWC_PRINTF("HAINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59859. + DWC_READ_REG32(addr));
  59860. + addr = &core_if->host_if->host_global_regs->haintmsk;
  59861. + DWC_PRINTF("HAINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59862. + DWC_READ_REG32(addr));
  59863. + if (core_if->dma_desc_enable) {
  59864. + addr = &core_if->host_if->host_global_regs->hflbaddr;
  59865. + DWC_PRINTF("HFLBADDR @0x%08lX : 0x%08X\n",
  59866. + (unsigned long)addr, DWC_READ_REG32(addr));
  59867. + }
  59868. +
  59869. + addr = core_if->host_if->hprt0;
  59870. + DWC_PRINTF("HPRT0 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59871. + DWC_READ_REG32(addr));
  59872. +
  59873. + for (i = 0; i < core_if->core_params->host_channels; i++) {
  59874. + DWC_PRINTF("Host Channel %d Specific Registers\n", i);
  59875. + addr = &core_if->host_if->hc_regs[i]->hcchar;
  59876. + DWC_PRINTF("HCCHAR @0x%08lX : 0x%08X\n",
  59877. + (unsigned long)addr, DWC_READ_REG32(addr));
  59878. + addr = &core_if->host_if->hc_regs[i]->hcsplt;
  59879. + DWC_PRINTF("HCSPLT @0x%08lX : 0x%08X\n",
  59880. + (unsigned long)addr, DWC_READ_REG32(addr));
  59881. + addr = &core_if->host_if->hc_regs[i]->hcint;
  59882. + DWC_PRINTF("HCINT @0x%08lX : 0x%08X\n",
  59883. + (unsigned long)addr, DWC_READ_REG32(addr));
  59884. + addr = &core_if->host_if->hc_regs[i]->hcintmsk;
  59885. + DWC_PRINTF("HCINTMSK @0x%08lX : 0x%08X\n",
  59886. + (unsigned long)addr, DWC_READ_REG32(addr));
  59887. + addr = &core_if->host_if->hc_regs[i]->hctsiz;
  59888. + DWC_PRINTF("HCTSIZ @0x%08lX : 0x%08X\n",
  59889. + (unsigned long)addr, DWC_READ_REG32(addr));
  59890. + addr = &core_if->host_if->hc_regs[i]->hcdma;
  59891. + DWC_PRINTF("HCDMA @0x%08lX : 0x%08X\n",
  59892. + (unsigned long)addr, DWC_READ_REG32(addr));
  59893. + if (core_if->dma_desc_enable) {
  59894. + addr = &core_if->host_if->hc_regs[i]->hcdmab;
  59895. + DWC_PRINTF("HCDMAB @0x%08lX : 0x%08X\n",
  59896. + (unsigned long)addr, DWC_READ_REG32(addr));
  59897. + }
  59898. +
  59899. + }
  59900. + return;
  59901. +}
  59902. +
  59903. +/**
  59904. + * This function reads the core global registers and prints them
  59905. + *
  59906. + * @param core_if Programming view of DWC_otg controller.
  59907. + */
  59908. +void dwc_otg_dump_global_registers(dwc_otg_core_if_t * core_if)
  59909. +{
  59910. + int i, ep_num;
  59911. + volatile uint32_t *addr;
  59912. + char *txfsiz;
  59913. +
  59914. + DWC_PRINTF("Core Global Registers\n");
  59915. + addr = &core_if->core_global_regs->gotgctl;
  59916. + DWC_PRINTF("GOTGCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59917. + DWC_READ_REG32(addr));
  59918. + addr = &core_if->core_global_regs->gotgint;
  59919. + DWC_PRINTF("GOTGINT @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59920. + DWC_READ_REG32(addr));
  59921. + addr = &core_if->core_global_regs->gahbcfg;
  59922. + DWC_PRINTF("GAHBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59923. + DWC_READ_REG32(addr));
  59924. + addr = &core_if->core_global_regs->gusbcfg;
  59925. + DWC_PRINTF("GUSBCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59926. + DWC_READ_REG32(addr));
  59927. + addr = &core_if->core_global_regs->grstctl;
  59928. + DWC_PRINTF("GRSTCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59929. + DWC_READ_REG32(addr));
  59930. + addr = &core_if->core_global_regs->gintsts;
  59931. + DWC_PRINTF("GINTSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59932. + DWC_READ_REG32(addr));
  59933. + addr = &core_if->core_global_regs->gintmsk;
  59934. + DWC_PRINTF("GINTMSK @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59935. + DWC_READ_REG32(addr));
  59936. + addr = &core_if->core_global_regs->grxstsr;
  59937. + DWC_PRINTF("GRXSTSR @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59938. + DWC_READ_REG32(addr));
  59939. + addr = &core_if->core_global_regs->grxfsiz;
  59940. + DWC_PRINTF("GRXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59941. + DWC_READ_REG32(addr));
  59942. + addr = &core_if->core_global_regs->gnptxfsiz;
  59943. + DWC_PRINTF("GNPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59944. + DWC_READ_REG32(addr));
  59945. + addr = &core_if->core_global_regs->gnptxsts;
  59946. + DWC_PRINTF("GNPTXSTS @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59947. + DWC_READ_REG32(addr));
  59948. + addr = &core_if->core_global_regs->gi2cctl;
  59949. + DWC_PRINTF("GI2CCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59950. + DWC_READ_REG32(addr));
  59951. + addr = &core_if->core_global_regs->gpvndctl;
  59952. + DWC_PRINTF("GPVNDCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59953. + DWC_READ_REG32(addr));
  59954. + addr = &core_if->core_global_regs->ggpio;
  59955. + DWC_PRINTF("GGPIO @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59956. + DWC_READ_REG32(addr));
  59957. + addr = &core_if->core_global_regs->guid;
  59958. + DWC_PRINTF("GUID @0x%08lX : 0x%08X\n",
  59959. + (unsigned long)addr, DWC_READ_REG32(addr));
  59960. + addr = &core_if->core_global_regs->gsnpsid;
  59961. + DWC_PRINTF("GSNPSID @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59962. + DWC_READ_REG32(addr));
  59963. + addr = &core_if->core_global_regs->ghwcfg1;
  59964. + DWC_PRINTF("GHWCFG1 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59965. + DWC_READ_REG32(addr));
  59966. + addr = &core_if->core_global_regs->ghwcfg2;
  59967. + DWC_PRINTF("GHWCFG2 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59968. + DWC_READ_REG32(addr));
  59969. + addr = &core_if->core_global_regs->ghwcfg3;
  59970. + DWC_PRINTF("GHWCFG3 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59971. + DWC_READ_REG32(addr));
  59972. + addr = &core_if->core_global_regs->ghwcfg4;
  59973. + DWC_PRINTF("GHWCFG4 @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59974. + DWC_READ_REG32(addr));
  59975. + addr = &core_if->core_global_regs->glpmcfg;
  59976. + DWC_PRINTF("GLPMCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59977. + DWC_READ_REG32(addr));
  59978. + addr = &core_if->core_global_regs->gpwrdn;
  59979. + DWC_PRINTF("GPWRDN @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59980. + DWC_READ_REG32(addr));
  59981. + addr = &core_if->core_global_regs->gdfifocfg;
  59982. + DWC_PRINTF("GDFIFOCFG @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59983. + DWC_READ_REG32(addr));
  59984. + addr = &core_if->core_global_regs->adpctl;
  59985. + DWC_PRINTF("ADPCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59986. + dwc_otg_adp_read_reg(core_if));
  59987. + addr = &core_if->core_global_regs->hptxfsiz;
  59988. + DWC_PRINTF("HPTXFSIZ @0x%08lX : 0x%08X\n", (unsigned long)addr,
  59989. + DWC_READ_REG32(addr));
  59990. +
  59991. + if (core_if->en_multiple_tx_fifo == 0) {
  59992. + ep_num = core_if->hwcfg4.b.num_dev_perio_in_ep;
  59993. + txfsiz = "DPTXFSIZ";
  59994. + } else {
  59995. + ep_num = core_if->hwcfg4.b.num_in_eps;
  59996. + txfsiz = "DIENPTXF";
  59997. + }
  59998. + for (i = 0; i < ep_num; i++) {
  59999. + addr = &core_if->core_global_regs->dtxfsiz[i];
  60000. + DWC_PRINTF("%s[%d] @0x%08lX : 0x%08X\n", txfsiz, i + 1,
  60001. + (unsigned long)addr, DWC_READ_REG32(addr));
  60002. + }
  60003. + addr = core_if->pcgcctl;
  60004. + DWC_PRINTF("PCGCCTL @0x%08lX : 0x%08X\n", (unsigned long)addr,
  60005. + DWC_READ_REG32(addr));
  60006. +}
  60007. +
  60008. +/**
  60009. + * Flush a Tx FIFO.
  60010. + *
  60011. + * @param core_if Programming view of DWC_otg controller.
  60012. + * @param num Tx FIFO to flush.
  60013. + */
  60014. +void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * core_if, const int num)
  60015. +{
  60016. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60017. + volatile grstctl_t greset = {.d32 = 0 };
  60018. + int count = 0;
  60019. +
  60020. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "Flush Tx FIFO %d\n", num);
  60021. +
  60022. + greset.b.txfflsh = 1;
  60023. + greset.b.txfnum = num;
  60024. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60025. +
  60026. + do {
  60027. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60028. + if (++count > 10000) {
  60029. + DWC_WARN("%s() HANG! GRSTCTL=%0x GNPTXSTS=0x%08x\n",
  60030. + __func__, greset.d32,
  60031. + DWC_READ_REG32(&global_regs->gnptxsts));
  60032. + break;
  60033. + }
  60034. + dwc_udelay(1);
  60035. + } while (greset.b.txfflsh == 1);
  60036. +
  60037. + /* Wait for 3 PHY Clocks */
  60038. + dwc_udelay(1);
  60039. +}
  60040. +
  60041. +/**
  60042. + * Flush Rx FIFO.
  60043. + *
  60044. + * @param core_if Programming view of DWC_otg controller.
  60045. + */
  60046. +void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * core_if)
  60047. +{
  60048. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60049. + volatile grstctl_t greset = {.d32 = 0 };
  60050. + int count = 0;
  60051. +
  60052. + DWC_DEBUGPL((DBG_CIL | DBG_PCDV), "%s\n", __func__);
  60053. + /*
  60054. + *
  60055. + */
  60056. + greset.b.rxfflsh = 1;
  60057. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60058. +
  60059. + do {
  60060. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60061. + if (++count > 10000) {
  60062. + DWC_WARN("%s() HANG! GRSTCTL=%0x\n", __func__,
  60063. + greset.d32);
  60064. + break;
  60065. + }
  60066. + dwc_udelay(1);
  60067. + } while (greset.b.rxfflsh == 1);
  60068. +
  60069. + /* Wait for 3 PHY Clocks */
  60070. + dwc_udelay(1);
  60071. +}
  60072. +
  60073. +/**
  60074. + * Do core a soft reset of the core. Be careful with this because it
  60075. + * resets all the internal state machines of the core.
  60076. + */
  60077. +void dwc_otg_core_reset(dwc_otg_core_if_t * core_if)
  60078. +{
  60079. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  60080. + volatile grstctl_t greset = {.d32 = 0 };
  60081. + int count = 0;
  60082. +
  60083. + DWC_DEBUGPL(DBG_CILV, "%s\n", __func__);
  60084. + /* Wait for AHB master IDLE state. */
  60085. + do {
  60086. + dwc_udelay(10);
  60087. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60088. + if (++count > 100000) {
  60089. + DWC_WARN("%s() HANG! AHB Idle GRSTCTL=%0x\n", __func__,
  60090. + greset.d32);
  60091. + return;
  60092. + }
  60093. + }
  60094. + while (greset.b.ahbidle == 0);
  60095. +
  60096. + /* Core Soft Reset */
  60097. + count = 0;
  60098. + greset.b.csftrst = 1;
  60099. + DWC_WRITE_REG32(&global_regs->grstctl, greset.d32);
  60100. + do {
  60101. + greset.d32 = DWC_READ_REG32(&global_regs->grstctl);
  60102. + if (++count > 10000) {
  60103. + DWC_WARN("%s() HANG! Soft Reset GRSTCTL=%0x\n",
  60104. + __func__, greset.d32);
  60105. + break;
  60106. + }
  60107. + dwc_udelay(1);
  60108. + }
  60109. + while (greset.b.csftrst == 1);
  60110. +
  60111. + /* Wait for 3 PHY Clocks */
  60112. + dwc_mdelay(100);
  60113. +}
  60114. +
  60115. +uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if)
  60116. +{
  60117. + return (dwc_otg_mode(_core_if) != DWC_HOST_MODE);
  60118. +}
  60119. +
  60120. +uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if)
  60121. +{
  60122. + return (dwc_otg_mode(_core_if) == DWC_HOST_MODE);
  60123. +}
  60124. +
  60125. +/**
  60126. + * Register HCD callbacks. The callbacks are used to start and stop
  60127. + * the HCD for interrupt processing.
  60128. + *
  60129. + * @param core_if Programming view of DWC_otg controller.
  60130. + * @param cb the HCD callback structure.
  60131. + * @param p pointer to be passed to callback function (usb_hcd*).
  60132. + */
  60133. +void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * core_if,
  60134. + dwc_otg_cil_callbacks_t * cb, void *p)
  60135. +{
  60136. + core_if->hcd_cb = cb;
  60137. + cb->p = p;
  60138. +}
  60139. +
  60140. +/**
  60141. + * Register PCD callbacks. The callbacks are used to start and stop
  60142. + * the PCD for interrupt processing.
  60143. + *
  60144. + * @param core_if Programming view of DWC_otg controller.
  60145. + * @param cb the PCD callback structure.
  60146. + * @param p pointer to be passed to callback function (pcd*).
  60147. + */
  60148. +void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * core_if,
  60149. + dwc_otg_cil_callbacks_t * cb, void *p)
  60150. +{
  60151. + core_if->pcd_cb = cb;
  60152. + cb->p = p;
  60153. +}
  60154. +
  60155. +#ifdef DWC_EN_ISOC
  60156. +
  60157. +/**
  60158. + * This function writes isoc data per 1 (micro)frame into tx fifo
  60159. + *
  60160. + * @param core_if Programming view of DWC_otg controller.
  60161. + * @param ep The EP to start the transfer on.
  60162. + *
  60163. + */
  60164. +void write_isoc_frame_data(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  60165. +{
  60166. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  60167. + dtxfsts_data_t txstatus = {.d32 = 0 };
  60168. + uint32_t len = 0;
  60169. + uint32_t dwords;
  60170. +
  60171. + ep->xfer_len = ep->data_per_frame;
  60172. + ep->xfer_count = 0;
  60173. +
  60174. + ep_regs = core_if->dev_if->in_ep_regs[ep->num];
  60175. +
  60176. + len = ep->xfer_len - ep->xfer_count;
  60177. +
  60178. + if (len > ep->maxpacket) {
  60179. + len = ep->maxpacket;
  60180. + }
  60181. +
  60182. + dwords = (len + 3) / 4;
  60183. +
  60184. + /* While there is space in the queue and space in the FIFO and
  60185. + * More data to tranfer, Write packets to the Tx FIFO */
  60186. + txstatus.d32 =
  60187. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dtxfsts);
  60188. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", ep->num, txstatus.d32);
  60189. +
  60190. + while (txstatus.b.txfspcavail > dwords &&
  60191. + ep->xfer_count < ep->xfer_len && ep->xfer_len != 0) {
  60192. + /* Write the FIFO */
  60193. + dwc_otg_ep_write_packet(core_if, ep, 0);
  60194. +
  60195. + len = ep->xfer_len - ep->xfer_count;
  60196. + if (len > ep->maxpacket) {
  60197. + len = ep->maxpacket;
  60198. + }
  60199. +
  60200. + dwords = (len + 3) / 4;
  60201. + txstatus.d32 =
  60202. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  60203. + dtxfsts);
  60204. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", ep->num,
  60205. + txstatus.d32);
  60206. + }
  60207. +}
  60208. +
  60209. +/**
  60210. + * This function initializes a descriptor chain for Isochronous transfer
  60211. + *
  60212. + * @param core_if Programming view of DWC_otg controller.
  60213. + * @param ep The EP to start the transfer on.
  60214. + *
  60215. + */
  60216. +void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  60217. + dwc_ep_t * ep)
  60218. +{
  60219. + deptsiz_data_t deptsiz = {.d32 = 0 };
  60220. + depctl_data_t depctl = {.d32 = 0 };
  60221. + dsts_data_t dsts = {.d32 = 0 };
  60222. + volatile uint32_t *addr;
  60223. +
  60224. + if (ep->is_in) {
  60225. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  60226. + } else {
  60227. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  60228. + }
  60229. +
  60230. + ep->xfer_len = ep->data_per_frame;
  60231. + ep->xfer_count = 0;
  60232. + ep->xfer_buff = ep->cur_pkt_addr;
  60233. + ep->dma_addr = ep->cur_pkt_dma_addr;
  60234. +
  60235. + if (ep->is_in) {
  60236. + /* Program the transfer size and packet count
  60237. + * as follows: xfersize = N * maxpacket +
  60238. + * short_packet pktcnt = N + (short_packet
  60239. + * exist ? 1 : 0)
  60240. + */
  60241. + deptsiz.b.xfersize = ep->xfer_len;
  60242. + deptsiz.b.pktcnt =
  60243. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  60244. + deptsiz.b.mc = deptsiz.b.pktcnt;
  60245. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->dieptsiz,
  60246. + deptsiz.d32);
  60247. +
  60248. + /* Write the DMA register */
  60249. + if (core_if->dma_enable) {
  60250. + DWC_WRITE_REG32(&
  60251. + (core_if->dev_if->in_ep_regs[ep->num]->
  60252. + diepdma), (uint32_t) ep->dma_addr);
  60253. + }
  60254. + } else {
  60255. + deptsiz.b.pktcnt =
  60256. + (ep->xfer_len + (ep->maxpacket - 1)) / ep->maxpacket;
  60257. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  60258. +
  60259. + DWC_WRITE_REG32(&core_if->dev_if->
  60260. + out_ep_regs[ep->num]->doeptsiz, deptsiz.d32);
  60261. +
  60262. + if (core_if->dma_enable) {
  60263. + DWC_WRITE_REG32(&
  60264. + (core_if->dev_if->
  60265. + out_ep_regs[ep->num]->doepdma),
  60266. + (uint32_t) ep->dma_addr);
  60267. + }
  60268. + }
  60269. +
  60270. + /** Enable endpoint, clear nak */
  60271. +
  60272. + depctl.d32 = 0;
  60273. + if (ep->bInterval == 1) {
  60274. + dsts.d32 =
  60275. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  60276. + ep->next_frame = dsts.b.soffn + ep->bInterval;
  60277. +
  60278. + if (ep->next_frame & 0x1) {
  60279. + depctl.b.setd1pid = 1;
  60280. + } else {
  60281. + depctl.b.setd0pid = 1;
  60282. + }
  60283. + } else {
  60284. + ep->next_frame += ep->bInterval;
  60285. +
  60286. + if (ep->next_frame & 0x1) {
  60287. + depctl.b.setd1pid = 1;
  60288. + } else {
  60289. + depctl.b.setd0pid = 1;
  60290. + }
  60291. + }
  60292. + depctl.b.epena = 1;
  60293. + depctl.b.cnak = 1;
  60294. +
  60295. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  60296. + depctl.d32 = DWC_READ_REG32(addr);
  60297. +
  60298. + if (ep->is_in && core_if->dma_enable == 0) {
  60299. + write_isoc_frame_data(core_if, ep);
  60300. + }
  60301. +
  60302. +}
  60303. +#endif /* DWC_EN_ISOC */
  60304. +
  60305. +static void dwc_otg_set_uninitialized(int32_t * p, int size)
  60306. +{
  60307. + int i;
  60308. + for (i = 0; i < size; i++) {
  60309. + p[i] = -1;
  60310. + }
  60311. +}
  60312. +
  60313. +static int dwc_otg_param_initialized(int32_t val)
  60314. +{
  60315. + return val != -1;
  60316. +}
  60317. +
  60318. +static int dwc_otg_setup_params(dwc_otg_core_if_t * core_if)
  60319. +{
  60320. + int i;
  60321. + core_if->core_params = DWC_ALLOC(sizeof(*core_if->core_params));
  60322. + if (!core_if->core_params) {
  60323. + return -DWC_E_NO_MEMORY;
  60324. + }
  60325. + dwc_otg_set_uninitialized((int32_t *) core_if->core_params,
  60326. + sizeof(*core_if->core_params) /
  60327. + sizeof(int32_t));
  60328. + DWC_PRINTF("Setting default values for core params\n");
  60329. + dwc_otg_set_param_otg_cap(core_if, dwc_param_otg_cap_default);
  60330. + dwc_otg_set_param_dma_enable(core_if, dwc_param_dma_enable_default);
  60331. + dwc_otg_set_param_dma_desc_enable(core_if,
  60332. + dwc_param_dma_desc_enable_default);
  60333. + dwc_otg_set_param_opt(core_if, dwc_param_opt_default);
  60334. + dwc_otg_set_param_dma_burst_size(core_if,
  60335. + dwc_param_dma_burst_size_default);
  60336. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  60337. + dwc_param_host_support_fs_ls_low_power_default);
  60338. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  60339. + dwc_param_enable_dynamic_fifo_default);
  60340. + dwc_otg_set_param_data_fifo_size(core_if,
  60341. + dwc_param_data_fifo_size_default);
  60342. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  60343. + dwc_param_dev_rx_fifo_size_default);
  60344. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  60345. + dwc_param_dev_nperio_tx_fifo_size_default);
  60346. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  60347. + dwc_param_host_rx_fifo_size_default);
  60348. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  60349. + dwc_param_host_nperio_tx_fifo_size_default);
  60350. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  60351. + dwc_param_host_perio_tx_fifo_size_default);
  60352. + dwc_otg_set_param_max_transfer_size(core_if,
  60353. + dwc_param_max_transfer_size_default);
  60354. + dwc_otg_set_param_max_packet_count(core_if,
  60355. + dwc_param_max_packet_count_default);
  60356. + dwc_otg_set_param_host_channels(core_if,
  60357. + dwc_param_host_channels_default);
  60358. + dwc_otg_set_param_dev_endpoints(core_if,
  60359. + dwc_param_dev_endpoints_default);
  60360. + dwc_otg_set_param_phy_type(core_if, dwc_param_phy_type_default);
  60361. + dwc_otg_set_param_speed(core_if, dwc_param_speed_default);
  60362. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  60363. + dwc_param_host_ls_low_power_phy_clk_default);
  60364. + dwc_otg_set_param_phy_ulpi_ddr(core_if, dwc_param_phy_ulpi_ddr_default);
  60365. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  60366. + dwc_param_phy_ulpi_ext_vbus_default);
  60367. + dwc_otg_set_param_phy_utmi_width(core_if,
  60368. + dwc_param_phy_utmi_width_default);
  60369. + dwc_otg_set_param_ts_dline(core_if, dwc_param_ts_dline_default);
  60370. + dwc_otg_set_param_i2c_enable(core_if, dwc_param_i2c_enable_default);
  60371. + dwc_otg_set_param_ulpi_fs_ls(core_if, dwc_param_ulpi_fs_ls_default);
  60372. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  60373. + dwc_param_en_multiple_tx_fifo_default);
  60374. + for (i = 0; i < 15; i++) {
  60375. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  60376. + dwc_param_dev_perio_tx_fifo_size_default,
  60377. + i);
  60378. + }
  60379. +
  60380. + for (i = 0; i < 15; i++) {
  60381. + dwc_otg_set_param_dev_tx_fifo_size(core_if,
  60382. + dwc_param_dev_tx_fifo_size_default,
  60383. + i);
  60384. + }
  60385. + dwc_otg_set_param_thr_ctl(core_if, dwc_param_thr_ctl_default);
  60386. + dwc_otg_set_param_mpi_enable(core_if, dwc_param_mpi_enable_default);
  60387. + dwc_otg_set_param_pti_enable(core_if, dwc_param_pti_enable_default);
  60388. + dwc_otg_set_param_lpm_enable(core_if, dwc_param_lpm_enable_default);
  60389. + dwc_otg_set_param_ic_usb_cap(core_if, dwc_param_ic_usb_cap_default);
  60390. + dwc_otg_set_param_tx_thr_length(core_if,
  60391. + dwc_param_tx_thr_length_default);
  60392. + dwc_otg_set_param_rx_thr_length(core_if,
  60393. + dwc_param_rx_thr_length_default);
  60394. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  60395. + dwc_param_ahb_thr_ratio_default);
  60396. + dwc_otg_set_param_power_down(core_if, dwc_param_power_down_default);
  60397. + dwc_otg_set_param_reload_ctl(core_if, dwc_param_reload_ctl_default);
  60398. + dwc_otg_set_param_dev_out_nak(core_if, dwc_param_dev_out_nak_default);
  60399. + dwc_otg_set_param_cont_on_bna(core_if, dwc_param_cont_on_bna_default);
  60400. + dwc_otg_set_param_ahb_single(core_if, dwc_param_ahb_single_default);
  60401. + dwc_otg_set_param_otg_ver(core_if, dwc_param_otg_ver_default);
  60402. + dwc_otg_set_param_adp_enable(core_if, dwc_param_adp_enable_default);
  60403. + DWC_PRINTF("Finished setting default values for core params\n");
  60404. +
  60405. + return 0;
  60406. +}
  60407. +
  60408. +uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if)
  60409. +{
  60410. + return core_if->dma_enable;
  60411. +}
  60412. +
  60413. +/* Checks if the parameter is outside of its valid range of values */
  60414. +#define DWC_OTG_PARAM_TEST(_param_, _low_, _high_) \
  60415. + (((_param_) < (_low_)) || \
  60416. + ((_param_) > (_high_)))
  60417. +
  60418. +/* Parameter access functions */
  60419. +int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val)
  60420. +{
  60421. + int valid;
  60422. + int retval = 0;
  60423. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60424. + DWC_WARN("Wrong value for otg_cap parameter\n");
  60425. + DWC_WARN("otg_cap parameter must be 0,1 or 2\n");
  60426. + retval = -DWC_E_INVALID;
  60427. + goto out;
  60428. + }
  60429. +
  60430. + valid = 1;
  60431. + switch (val) {
  60432. + case DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE:
  60433. + if (core_if->hwcfg2.b.op_mode !=
  60434. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60435. + valid = 0;
  60436. + break;
  60437. + case DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE:
  60438. + if ((core_if->hwcfg2.b.op_mode !=
  60439. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60440. + && (core_if->hwcfg2.b.op_mode !=
  60441. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60442. + && (core_if->hwcfg2.b.op_mode !=
  60443. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60444. + && (core_if->hwcfg2.b.op_mode !=
  60445. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) {
  60446. + valid = 0;
  60447. + }
  60448. + break;
  60449. + case DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE:
  60450. + /* always valid */
  60451. + break;
  60452. + }
  60453. + if (!valid) {
  60454. + if (dwc_otg_param_initialized(core_if->core_params->otg_cap)) {
  60455. + DWC_ERROR
  60456. + ("%d invalid for otg_cap paremter. Check HW configuration.\n",
  60457. + val);
  60458. + }
  60459. + val =
  60460. + (((core_if->hwcfg2.b.op_mode ==
  60461. + DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG)
  60462. + || (core_if->hwcfg2.b.op_mode ==
  60463. + DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG)
  60464. + || (core_if->hwcfg2.b.op_mode ==
  60465. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE)
  60466. + || (core_if->hwcfg2.b.op_mode ==
  60467. + DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST)) ?
  60468. + DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE :
  60469. + DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE);
  60470. + retval = -DWC_E_INVALID;
  60471. + }
  60472. +
  60473. + core_if->core_params->otg_cap = val;
  60474. +out:
  60475. + return retval;
  60476. +}
  60477. +
  60478. +int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if)
  60479. +{
  60480. + return core_if->core_params->otg_cap;
  60481. +}
  60482. +
  60483. +int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val)
  60484. +{
  60485. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60486. + DWC_WARN("Wrong value for opt parameter\n");
  60487. + return -DWC_E_INVALID;
  60488. + }
  60489. + core_if->core_params->opt = val;
  60490. + return 0;
  60491. +}
  60492. +
  60493. +int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if)
  60494. +{
  60495. + return core_if->core_params->opt;
  60496. +}
  60497. +
  60498. +int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60499. +{
  60500. + int retval = 0;
  60501. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60502. + DWC_WARN("Wrong value for dma enable\n");
  60503. + return -DWC_E_INVALID;
  60504. + }
  60505. +
  60506. + if ((val == 1) && (core_if->hwcfg2.b.architecture == 0)) {
  60507. + if (dwc_otg_param_initialized(core_if->core_params->dma_enable)) {
  60508. + DWC_ERROR
  60509. + ("%d invalid for dma_enable paremter. Check HW configuration.\n",
  60510. + val);
  60511. + }
  60512. + val = 0;
  60513. + retval = -DWC_E_INVALID;
  60514. + }
  60515. +
  60516. + core_if->core_params->dma_enable = val;
  60517. + if (val == 0) {
  60518. + dwc_otg_set_param_dma_desc_enable(core_if, 0);
  60519. + }
  60520. + return retval;
  60521. +}
  60522. +
  60523. +int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if)
  60524. +{
  60525. + return core_if->core_params->dma_enable;
  60526. +}
  60527. +
  60528. +int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if, int32_t val)
  60529. +{
  60530. + int retval = 0;
  60531. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60532. + DWC_WARN("Wrong value for dma_enable\n");
  60533. + DWC_WARN("dma_desc_enable must be 0 or 1\n");
  60534. + return -DWC_E_INVALID;
  60535. + }
  60536. +
  60537. + if ((val == 1)
  60538. + && ((dwc_otg_get_param_dma_enable(core_if) == 0)
  60539. + || (core_if->hwcfg4.b.desc_dma == 0))) {
  60540. + if (dwc_otg_param_initialized
  60541. + (core_if->core_params->dma_desc_enable)) {
  60542. + DWC_ERROR
  60543. + ("%d invalid for dma_desc_enable paremter. Check HW configuration.\n",
  60544. + val);
  60545. + }
  60546. + val = 0;
  60547. + retval = -DWC_E_INVALID;
  60548. + }
  60549. + core_if->core_params->dma_desc_enable = val;
  60550. + return retval;
  60551. +}
  60552. +
  60553. +int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if)
  60554. +{
  60555. + return core_if->core_params->dma_desc_enable;
  60556. +}
  60557. +
  60558. +int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t * core_if,
  60559. + int32_t val)
  60560. +{
  60561. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60562. + DWC_WARN("Wrong value for host_support_fs_low_power\n");
  60563. + DWC_WARN("host_support_fs_low_power must be 0 or 1\n");
  60564. + return -DWC_E_INVALID;
  60565. + }
  60566. + core_if->core_params->host_support_fs_ls_low_power = val;
  60567. + return 0;
  60568. +}
  60569. +
  60570. +int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  60571. + core_if)
  60572. +{
  60573. + return core_if->core_params->host_support_fs_ls_low_power;
  60574. +}
  60575. +
  60576. +int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  60577. + int32_t val)
  60578. +{
  60579. + int retval = 0;
  60580. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60581. + DWC_WARN("Wrong value for enable_dynamic_fifo\n");
  60582. + DWC_WARN("enable_dynamic_fifo must be 0 or 1\n");
  60583. + return -DWC_E_INVALID;
  60584. + }
  60585. +
  60586. + if ((val == 1) && (core_if->hwcfg2.b.dynamic_fifo == 0)) {
  60587. + if (dwc_otg_param_initialized
  60588. + (core_if->core_params->enable_dynamic_fifo)) {
  60589. + DWC_ERROR
  60590. + ("%d invalid for enable_dynamic_fifo paremter. Check HW configuration.\n",
  60591. + val);
  60592. + }
  60593. + val = 0;
  60594. + retval = -DWC_E_INVALID;
  60595. + }
  60596. + core_if->core_params->enable_dynamic_fifo = val;
  60597. + return retval;
  60598. +}
  60599. +
  60600. +int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if)
  60601. +{
  60602. + return core_if->core_params->enable_dynamic_fifo;
  60603. +}
  60604. +
  60605. +int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60606. +{
  60607. + int retval = 0;
  60608. + if (DWC_OTG_PARAM_TEST(val, 32, 32768)) {
  60609. + DWC_WARN("Wrong value for data_fifo_size\n");
  60610. + DWC_WARN("data_fifo_size must be 32-32768\n");
  60611. + return -DWC_E_INVALID;
  60612. + }
  60613. +
  60614. + if (val > core_if->hwcfg3.b.dfifo_depth) {
  60615. + if (dwc_otg_param_initialized
  60616. + (core_if->core_params->data_fifo_size)) {
  60617. + DWC_ERROR
  60618. + ("%d invalid for data_fifo_size parameter. Check HW configuration.\n",
  60619. + val);
  60620. + }
  60621. + val = core_if->hwcfg3.b.dfifo_depth;
  60622. + retval = -DWC_E_INVALID;
  60623. + }
  60624. +
  60625. + core_if->core_params->data_fifo_size = val;
  60626. + return retval;
  60627. +}
  60628. +
  60629. +int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if)
  60630. +{
  60631. + return core_if->core_params->data_fifo_size;
  60632. +}
  60633. +
  60634. +int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val)
  60635. +{
  60636. + int retval = 0;
  60637. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60638. + DWC_WARN("Wrong value for dev_rx_fifo_size\n");
  60639. + DWC_WARN("dev_rx_fifo_size must be 16-32768\n");
  60640. + return -DWC_E_INVALID;
  60641. + }
  60642. +
  60643. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60644. + if (dwc_otg_param_initialized(core_if->core_params->dev_rx_fifo_size)) {
  60645. + DWC_WARN("%d invalid for dev_rx_fifo_size parameter\n", val);
  60646. + }
  60647. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60648. + retval = -DWC_E_INVALID;
  60649. + }
  60650. +
  60651. + core_if->core_params->dev_rx_fifo_size = val;
  60652. + return retval;
  60653. +}
  60654. +
  60655. +int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60656. +{
  60657. + return core_if->core_params->dev_rx_fifo_size;
  60658. +}
  60659. +
  60660. +int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60661. + int32_t val)
  60662. +{
  60663. + int retval = 0;
  60664. +
  60665. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60666. + DWC_WARN("Wrong value for dev_nperio_tx_fifo\n");
  60667. + DWC_WARN("dev_nperio_tx_fifo must be 16-32768\n");
  60668. + return -DWC_E_INVALID;
  60669. + }
  60670. +
  60671. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60672. + if (dwc_otg_param_initialized
  60673. + (core_if->core_params->dev_nperio_tx_fifo_size)) {
  60674. + DWC_ERROR
  60675. + ("%d invalid for dev_nperio_tx_fifo_size. Check HW configuration.\n",
  60676. + val);
  60677. + }
  60678. + val =
  60679. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60680. + 16);
  60681. + retval = -DWC_E_INVALID;
  60682. + }
  60683. +
  60684. + core_if->core_params->dev_nperio_tx_fifo_size = val;
  60685. + return retval;
  60686. +}
  60687. +
  60688. +int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60689. +{
  60690. + return core_if->core_params->dev_nperio_tx_fifo_size;
  60691. +}
  60692. +
  60693. +int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  60694. + int32_t val)
  60695. +{
  60696. + int retval = 0;
  60697. +
  60698. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60699. + DWC_WARN("Wrong value for host_rx_fifo_size\n");
  60700. + DWC_WARN("host_rx_fifo_size must be 16-32768\n");
  60701. + return -DWC_E_INVALID;
  60702. + }
  60703. +
  60704. + if (val > DWC_READ_REG32(&core_if->core_global_regs->grxfsiz)) {
  60705. + if (dwc_otg_param_initialized
  60706. + (core_if->core_params->host_rx_fifo_size)) {
  60707. + DWC_ERROR
  60708. + ("%d invalid for host_rx_fifo_size. Check HW configuration.\n",
  60709. + val);
  60710. + }
  60711. + val = DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  60712. + retval = -DWC_E_INVALID;
  60713. + }
  60714. +
  60715. + core_if->core_params->host_rx_fifo_size = val;
  60716. + return retval;
  60717. +
  60718. +}
  60719. +
  60720. +int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if)
  60721. +{
  60722. + return core_if->core_params->host_rx_fifo_size;
  60723. +}
  60724. +
  60725. +int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60726. + int32_t val)
  60727. +{
  60728. + int retval = 0;
  60729. +
  60730. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60731. + DWC_WARN("Wrong value for host_nperio_tx_fifo_size\n");
  60732. + DWC_WARN("host_nperio_tx_fifo_size must be 16-32768\n");
  60733. + return -DWC_E_INVALID;
  60734. + }
  60735. +
  60736. + if (val > (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >> 16)) {
  60737. + if (dwc_otg_param_initialized
  60738. + (core_if->core_params->host_nperio_tx_fifo_size)) {
  60739. + DWC_ERROR
  60740. + ("%d invalid for host_nperio_tx_fifo_size. Check HW configuration.\n",
  60741. + val);
  60742. + }
  60743. + val =
  60744. + (DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz) >>
  60745. + 16);
  60746. + retval = -DWC_E_INVALID;
  60747. + }
  60748. +
  60749. + core_if->core_params->host_nperio_tx_fifo_size = val;
  60750. + return retval;
  60751. +}
  60752. +
  60753. +int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60754. +{
  60755. + return core_if->core_params->host_nperio_tx_fifo_size;
  60756. +}
  60757. +
  60758. +int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  60759. + int32_t val)
  60760. +{
  60761. + int retval = 0;
  60762. + if (DWC_OTG_PARAM_TEST(val, 16, 32768)) {
  60763. + DWC_WARN("Wrong value for host_perio_tx_fifo_size\n");
  60764. + DWC_WARN("host_perio_tx_fifo_size must be 16-32768\n");
  60765. + return -DWC_E_INVALID;
  60766. + }
  60767. +
  60768. + if (val > ((core_if->hptxfsiz.d32) >> 16)) {
  60769. + if (dwc_otg_param_initialized
  60770. + (core_if->core_params->host_perio_tx_fifo_size)) {
  60771. + DWC_ERROR
  60772. + ("%d invalid for host_perio_tx_fifo_size. Check HW configuration.\n",
  60773. + val);
  60774. + }
  60775. + val = (core_if->hptxfsiz.d32) >> 16;
  60776. + retval = -DWC_E_INVALID;
  60777. + }
  60778. +
  60779. + core_if->core_params->host_perio_tx_fifo_size = val;
  60780. + return retval;
  60781. +}
  60782. +
  60783. +int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t * core_if)
  60784. +{
  60785. + return core_if->core_params->host_perio_tx_fifo_size;
  60786. +}
  60787. +
  60788. +int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  60789. + int32_t val)
  60790. +{
  60791. + int retval = 0;
  60792. +
  60793. + if (DWC_OTG_PARAM_TEST(val, 2047, 524288)) {
  60794. + DWC_WARN("Wrong value for max_transfer_size\n");
  60795. + DWC_WARN("max_transfer_size must be 2047-524288\n");
  60796. + return -DWC_E_INVALID;
  60797. + }
  60798. +
  60799. + if (val >= (1 << (core_if->hwcfg3.b.xfer_size_cntr_width + 11))) {
  60800. + if (dwc_otg_param_initialized
  60801. + (core_if->core_params->max_transfer_size)) {
  60802. + DWC_ERROR
  60803. + ("%d invalid for max_transfer_size. Check HW configuration.\n",
  60804. + val);
  60805. + }
  60806. + val =
  60807. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 11)) -
  60808. + 1);
  60809. + retval = -DWC_E_INVALID;
  60810. + }
  60811. +
  60812. + core_if->core_params->max_transfer_size = val;
  60813. + return retval;
  60814. +}
  60815. +
  60816. +int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if)
  60817. +{
  60818. + return core_if->core_params->max_transfer_size;
  60819. +}
  60820. +
  60821. +int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if, int32_t val)
  60822. +{
  60823. + int retval = 0;
  60824. +
  60825. + if (DWC_OTG_PARAM_TEST(val, 15, 511)) {
  60826. + DWC_WARN("Wrong value for max_packet_count\n");
  60827. + DWC_WARN("max_packet_count must be 15-511\n");
  60828. + return -DWC_E_INVALID;
  60829. + }
  60830. +
  60831. + if (val > (1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4))) {
  60832. + if (dwc_otg_param_initialized
  60833. + (core_if->core_params->max_packet_count)) {
  60834. + DWC_ERROR
  60835. + ("%d invalid for max_packet_count. Check HW configuration.\n",
  60836. + val);
  60837. + }
  60838. + val =
  60839. + ((1 << (core_if->hwcfg3.b.packet_size_cntr_width + 4)) - 1);
  60840. + retval = -DWC_E_INVALID;
  60841. + }
  60842. +
  60843. + core_if->core_params->max_packet_count = val;
  60844. + return retval;
  60845. +}
  60846. +
  60847. +int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if)
  60848. +{
  60849. + return core_if->core_params->max_packet_count;
  60850. +}
  60851. +
  60852. +int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if, int32_t val)
  60853. +{
  60854. + int retval = 0;
  60855. +
  60856. + if (DWC_OTG_PARAM_TEST(val, 1, 16)) {
  60857. + DWC_WARN("Wrong value for host_channels\n");
  60858. + DWC_WARN("host_channels must be 1-16\n");
  60859. + return -DWC_E_INVALID;
  60860. + }
  60861. +
  60862. + if (val > (core_if->hwcfg2.b.num_host_chan + 1)) {
  60863. + if (dwc_otg_param_initialized
  60864. + (core_if->core_params->host_channels)) {
  60865. + DWC_ERROR
  60866. + ("%d invalid for host_channels. Check HW configurations.\n",
  60867. + val);
  60868. + }
  60869. + val = (core_if->hwcfg2.b.num_host_chan + 1);
  60870. + retval = -DWC_E_INVALID;
  60871. + }
  60872. +
  60873. + core_if->core_params->host_channels = val;
  60874. + return retval;
  60875. +}
  60876. +
  60877. +int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if)
  60878. +{
  60879. + return core_if->core_params->host_channels;
  60880. +}
  60881. +
  60882. +int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if, int32_t val)
  60883. +{
  60884. + int retval = 0;
  60885. +
  60886. + if (DWC_OTG_PARAM_TEST(val, 1, 15)) {
  60887. + DWC_WARN("Wrong value for dev_endpoints\n");
  60888. + DWC_WARN("dev_endpoints must be 1-15\n");
  60889. + return -DWC_E_INVALID;
  60890. + }
  60891. +
  60892. + if (val > (core_if->hwcfg2.b.num_dev_ep)) {
  60893. + if (dwc_otg_param_initialized
  60894. + (core_if->core_params->dev_endpoints)) {
  60895. + DWC_ERROR
  60896. + ("%d invalid for dev_endpoints. Check HW configurations.\n",
  60897. + val);
  60898. + }
  60899. + val = core_if->hwcfg2.b.num_dev_ep;
  60900. + retval = -DWC_E_INVALID;
  60901. + }
  60902. +
  60903. + core_if->core_params->dev_endpoints = val;
  60904. + return retval;
  60905. +}
  60906. +
  60907. +int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if)
  60908. +{
  60909. + return core_if->core_params->dev_endpoints;
  60910. +}
  60911. +
  60912. +int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val)
  60913. +{
  60914. + int retval = 0;
  60915. + int valid = 0;
  60916. +
  60917. + if (DWC_OTG_PARAM_TEST(val, 0, 2)) {
  60918. + DWC_WARN("Wrong value for phy_type\n");
  60919. + DWC_WARN("phy_type must be 0,1 or 2\n");
  60920. + return -DWC_E_INVALID;
  60921. + }
  60922. +#ifndef NO_FS_PHY_HW_CHECKS
  60923. + if ((val == DWC_PHY_TYPE_PARAM_UTMI) &&
  60924. + ((core_if->hwcfg2.b.hs_phy_type == 1) ||
  60925. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60926. + valid = 1;
  60927. + } else if ((val == DWC_PHY_TYPE_PARAM_ULPI) &&
  60928. + ((core_if->hwcfg2.b.hs_phy_type == 2) ||
  60929. + (core_if->hwcfg2.b.hs_phy_type == 3))) {
  60930. + valid = 1;
  60931. + } else if ((val == DWC_PHY_TYPE_PARAM_FS) &&
  60932. + (core_if->hwcfg2.b.fs_phy_type == 1)) {
  60933. + valid = 1;
  60934. + }
  60935. + if (!valid) {
  60936. + if (dwc_otg_param_initialized(core_if->core_params->phy_type)) {
  60937. + DWC_ERROR
  60938. + ("%d invalid for phy_type. Check HW configurations.\n",
  60939. + val);
  60940. + }
  60941. + if (core_if->hwcfg2.b.hs_phy_type) {
  60942. + if ((core_if->hwcfg2.b.hs_phy_type == 3) ||
  60943. + (core_if->hwcfg2.b.hs_phy_type == 1)) {
  60944. + val = DWC_PHY_TYPE_PARAM_UTMI;
  60945. + } else {
  60946. + val = DWC_PHY_TYPE_PARAM_ULPI;
  60947. + }
  60948. + }
  60949. + retval = -DWC_E_INVALID;
  60950. + }
  60951. +#endif
  60952. + core_if->core_params->phy_type = val;
  60953. + return retval;
  60954. +}
  60955. +
  60956. +int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if)
  60957. +{
  60958. + return core_if->core_params->phy_type;
  60959. +}
  60960. +
  60961. +int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val)
  60962. +{
  60963. + int retval = 0;
  60964. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60965. + DWC_WARN("Wrong value for speed parameter\n");
  60966. + DWC_WARN("max_speed parameter must be 0 or 1\n");
  60967. + return -DWC_E_INVALID;
  60968. + }
  60969. + if ((val == 0)
  60970. + && dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS) {
  60971. + if (dwc_otg_param_initialized(core_if->core_params->speed)) {
  60972. + DWC_ERROR
  60973. + ("%d invalid for speed paremter. Check HW configuration.\n",
  60974. + val);
  60975. + }
  60976. + val =
  60977. + (dwc_otg_get_param_phy_type(core_if) ==
  60978. + DWC_PHY_TYPE_PARAM_FS ? 1 : 0);
  60979. + retval = -DWC_E_INVALID;
  60980. + }
  60981. + core_if->core_params->speed = val;
  60982. + return retval;
  60983. +}
  60984. +
  60985. +int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if)
  60986. +{
  60987. + return core_if->core_params->speed;
  60988. +}
  60989. +
  60990. +int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if,
  60991. + int32_t val)
  60992. +{
  60993. + int retval = 0;
  60994. +
  60995. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  60996. + DWC_WARN
  60997. + ("Wrong value for host_ls_low_power_phy_clk parameter\n");
  60998. + DWC_WARN("host_ls_low_power_phy_clk must be 0 or 1\n");
  60999. + return -DWC_E_INVALID;
  61000. + }
  61001. +
  61002. + if ((val == DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ)
  61003. + && (dwc_otg_get_param_phy_type(core_if) == DWC_PHY_TYPE_PARAM_FS)) {
  61004. + if (dwc_otg_param_initialized
  61005. + (core_if->core_params->host_ls_low_power_phy_clk)) {
  61006. + DWC_ERROR
  61007. + ("%d invalid for host_ls_low_power_phy_clk. Check HW configuration.\n",
  61008. + val);
  61009. + }
  61010. + val =
  61011. + (dwc_otg_get_param_phy_type(core_if) ==
  61012. + DWC_PHY_TYPE_PARAM_FS) ?
  61013. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ :
  61014. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ;
  61015. + retval = -DWC_E_INVALID;
  61016. + }
  61017. +
  61018. + core_if->core_params->host_ls_low_power_phy_clk = val;
  61019. + return retval;
  61020. +}
  61021. +
  61022. +int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t * core_if)
  61023. +{
  61024. + return core_if->core_params->host_ls_low_power_phy_clk;
  61025. +}
  61026. +
  61027. +int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if, int32_t val)
  61028. +{
  61029. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61030. + DWC_WARN("Wrong value for phy_ulpi_ddr\n");
  61031. + DWC_WARN("phy_upli_ddr must be 0 or 1\n");
  61032. + return -DWC_E_INVALID;
  61033. + }
  61034. +
  61035. + core_if->core_params->phy_ulpi_ddr = val;
  61036. + return 0;
  61037. +}
  61038. +
  61039. +int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if)
  61040. +{
  61041. + return core_if->core_params->phy_ulpi_ddr;
  61042. +}
  61043. +
  61044. +int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  61045. + int32_t val)
  61046. +{
  61047. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61048. + DWC_WARN("Wrong valaue for phy_ulpi_ext_vbus\n");
  61049. + DWC_WARN("phy_ulpi_ext_vbus must be 0 or 1\n");
  61050. + return -DWC_E_INVALID;
  61051. + }
  61052. +
  61053. + core_if->core_params->phy_ulpi_ext_vbus = val;
  61054. + return 0;
  61055. +}
  61056. +
  61057. +int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if)
  61058. +{
  61059. + return core_if->core_params->phy_ulpi_ext_vbus;
  61060. +}
  61061. +
  61062. +int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if, int32_t val)
  61063. +{
  61064. + if (DWC_OTG_PARAM_TEST(val, 8, 8) && DWC_OTG_PARAM_TEST(val, 16, 16)) {
  61065. + DWC_WARN("Wrong valaue for phy_utmi_width\n");
  61066. + DWC_WARN("phy_utmi_width must be 8 or 16\n");
  61067. + return -DWC_E_INVALID;
  61068. + }
  61069. +
  61070. + core_if->core_params->phy_utmi_width = val;
  61071. + return 0;
  61072. +}
  61073. +
  61074. +int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if)
  61075. +{
  61076. + return core_if->core_params->phy_utmi_width;
  61077. +}
  61078. +
  61079. +int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if, int32_t val)
  61080. +{
  61081. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61082. + DWC_WARN("Wrong valaue for ulpi_fs_ls\n");
  61083. + DWC_WARN("ulpi_fs_ls must be 0 or 1\n");
  61084. + return -DWC_E_INVALID;
  61085. + }
  61086. +
  61087. + core_if->core_params->ulpi_fs_ls = val;
  61088. + return 0;
  61089. +}
  61090. +
  61091. +int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if)
  61092. +{
  61093. + return core_if->core_params->ulpi_fs_ls;
  61094. +}
  61095. +
  61096. +int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val)
  61097. +{
  61098. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61099. + DWC_WARN("Wrong valaue for ts_dline\n");
  61100. + DWC_WARN("ts_dline must be 0 or 1\n");
  61101. + return -DWC_E_INVALID;
  61102. + }
  61103. +
  61104. + core_if->core_params->ts_dline = val;
  61105. + return 0;
  61106. +}
  61107. +
  61108. +int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if)
  61109. +{
  61110. + return core_if->core_params->ts_dline;
  61111. +}
  61112. +
  61113. +int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61114. +{
  61115. + int retval = 0;
  61116. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61117. + DWC_WARN("Wrong valaue for i2c_enable\n");
  61118. + DWC_WARN("i2c_enable must be 0 or 1\n");
  61119. + return -DWC_E_INVALID;
  61120. + }
  61121. +#ifndef NO_FS_PHY_HW_CHECK
  61122. + if (val == 1 && core_if->hwcfg3.b.i2c == 0) {
  61123. + if (dwc_otg_param_initialized(core_if->core_params->i2c_enable)) {
  61124. + DWC_ERROR
  61125. + ("%d invalid for i2c_enable. Check HW configuration.\n",
  61126. + val);
  61127. + }
  61128. + val = 0;
  61129. + retval = -DWC_E_INVALID;
  61130. + }
  61131. +#endif
  61132. +
  61133. + core_if->core_params->i2c_enable = val;
  61134. + return retval;
  61135. +}
  61136. +
  61137. +int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if)
  61138. +{
  61139. + return core_if->core_params->i2c_enable;
  61140. +}
  61141. +
  61142. +int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61143. + int32_t val, int fifo_num)
  61144. +{
  61145. + int retval = 0;
  61146. +
  61147. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61148. + DWC_WARN("Wrong value for dev_perio_tx_fifo_size\n");
  61149. + DWC_WARN("dev_perio_tx_fifo_size must be 4-768\n");
  61150. + return -DWC_E_INVALID;
  61151. + }
  61152. +
  61153. + if (val >
  61154. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61155. + if (dwc_otg_param_initialized
  61156. + (core_if->core_params->dev_perio_tx_fifo_size[fifo_num])) {
  61157. + DWC_ERROR
  61158. + ("`%d' invalid for parameter `dev_perio_fifo_size_%d'. Check HW configuration.\n",
  61159. + val, fifo_num);
  61160. + }
  61161. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61162. + retval = -DWC_E_INVALID;
  61163. + }
  61164. +
  61165. + core_if->core_params->dev_perio_tx_fifo_size[fifo_num] = val;
  61166. + return retval;
  61167. +}
  61168. +
  61169. +int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61170. + int fifo_num)
  61171. +{
  61172. + return core_if->core_params->dev_perio_tx_fifo_size[fifo_num];
  61173. +}
  61174. +
  61175. +int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  61176. + int32_t val)
  61177. +{
  61178. + int retval = 0;
  61179. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61180. + DWC_WARN("Wrong valaue for en_multiple_tx_fifo,\n");
  61181. + DWC_WARN("en_multiple_tx_fifo must be 0 or 1\n");
  61182. + return -DWC_E_INVALID;
  61183. + }
  61184. +
  61185. + if (val == 1 && core_if->hwcfg4.b.ded_fifo_en == 0) {
  61186. + if (dwc_otg_param_initialized
  61187. + (core_if->core_params->en_multiple_tx_fifo)) {
  61188. + DWC_ERROR
  61189. + ("%d invalid for parameter en_multiple_tx_fifo. Check HW configuration.\n",
  61190. + val);
  61191. + }
  61192. + val = 0;
  61193. + retval = -DWC_E_INVALID;
  61194. + }
  61195. +
  61196. + core_if->core_params->en_multiple_tx_fifo = val;
  61197. + return retval;
  61198. +}
  61199. +
  61200. +int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if)
  61201. +{
  61202. + return core_if->core_params->en_multiple_tx_fifo;
  61203. +}
  61204. +
  61205. +int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if, int32_t val,
  61206. + int fifo_num)
  61207. +{
  61208. + int retval = 0;
  61209. +
  61210. + if (DWC_OTG_PARAM_TEST(val, 4, 768)) {
  61211. + DWC_WARN("Wrong value for dev_tx_fifo_size\n");
  61212. + DWC_WARN("dev_tx_fifo_size must be 4-768\n");
  61213. + return -DWC_E_INVALID;
  61214. + }
  61215. +
  61216. + if (val >
  61217. + (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]))) {
  61218. + if (dwc_otg_param_initialized
  61219. + (core_if->core_params->dev_tx_fifo_size[fifo_num])) {
  61220. + DWC_ERROR
  61221. + ("`%d' invalid for parameter `dev_tx_fifo_size_%d'. Check HW configuration.\n",
  61222. + val, fifo_num);
  61223. + }
  61224. + val = (DWC_READ_REG32(&core_if->core_global_regs->dtxfsiz[fifo_num]));
  61225. + retval = -DWC_E_INVALID;
  61226. + }
  61227. +
  61228. + core_if->core_params->dev_tx_fifo_size[fifo_num] = val;
  61229. + return retval;
  61230. +}
  61231. +
  61232. +int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  61233. + int fifo_num)
  61234. +{
  61235. + return core_if->core_params->dev_tx_fifo_size[fifo_num];
  61236. +}
  61237. +
  61238. +int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61239. +{
  61240. + int retval = 0;
  61241. +
  61242. + if (DWC_OTG_PARAM_TEST(val, 0, 7)) {
  61243. + DWC_WARN("Wrong value for thr_ctl\n");
  61244. + DWC_WARN("thr_ctl must be 0-7\n");
  61245. + return -DWC_E_INVALID;
  61246. + }
  61247. +
  61248. + if ((val != 0) &&
  61249. + (!dwc_otg_get_param_dma_enable(core_if) ||
  61250. + !core_if->hwcfg4.b.ded_fifo_en)) {
  61251. + if (dwc_otg_param_initialized(core_if->core_params->thr_ctl)) {
  61252. + DWC_ERROR
  61253. + ("%d invalid for parameter thr_ctl. Check HW configuration.\n",
  61254. + val);
  61255. + }
  61256. + val = 0;
  61257. + retval = -DWC_E_INVALID;
  61258. + }
  61259. +
  61260. + core_if->core_params->thr_ctl = val;
  61261. + return retval;
  61262. +}
  61263. +
  61264. +int32_t dwc_otg_get_param_thr_ctl(dwc_otg_core_if_t * core_if)
  61265. +{
  61266. + return core_if->core_params->thr_ctl;
  61267. +}
  61268. +
  61269. +int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61270. +{
  61271. + int retval = 0;
  61272. +
  61273. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61274. + DWC_WARN("Wrong value for lpm_enable\n");
  61275. + DWC_WARN("lpm_enable must be 0 or 1\n");
  61276. + return -DWC_E_INVALID;
  61277. + }
  61278. +
  61279. + if (val && !core_if->hwcfg3.b.otg_lpm_en) {
  61280. + if (dwc_otg_param_initialized(core_if->core_params->lpm_enable)) {
  61281. + DWC_ERROR
  61282. + ("%d invalid for parameter lpm_enable. Check HW configuration.\n",
  61283. + val);
  61284. + }
  61285. + val = 0;
  61286. + retval = -DWC_E_INVALID;
  61287. + }
  61288. +
  61289. + core_if->core_params->lpm_enable = val;
  61290. + return retval;
  61291. +}
  61292. +
  61293. +int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if)
  61294. +{
  61295. + return core_if->core_params->lpm_enable;
  61296. +}
  61297. +
  61298. +int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61299. +{
  61300. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61301. + DWC_WARN("Wrong valaue for tx_thr_length\n");
  61302. + DWC_WARN("tx_thr_length must be 8 - 128\n");
  61303. + return -DWC_E_INVALID;
  61304. + }
  61305. +
  61306. + core_if->core_params->tx_thr_length = val;
  61307. + return 0;
  61308. +}
  61309. +
  61310. +int32_t dwc_otg_get_param_tx_thr_length(dwc_otg_core_if_t * core_if)
  61311. +{
  61312. + return core_if->core_params->tx_thr_length;
  61313. +}
  61314. +
  61315. +int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if, int32_t val)
  61316. +{
  61317. + if (DWC_OTG_PARAM_TEST(val, 8, 128)) {
  61318. + DWC_WARN("Wrong valaue for rx_thr_length\n");
  61319. + DWC_WARN("rx_thr_length must be 8 - 128\n");
  61320. + return -DWC_E_INVALID;
  61321. + }
  61322. +
  61323. + core_if->core_params->rx_thr_length = val;
  61324. + return 0;
  61325. +}
  61326. +
  61327. +int32_t dwc_otg_get_param_rx_thr_length(dwc_otg_core_if_t * core_if)
  61328. +{
  61329. + return core_if->core_params->rx_thr_length;
  61330. +}
  61331. +
  61332. +int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if, int32_t val)
  61333. +{
  61334. + if (DWC_OTG_PARAM_TEST(val, 1, 1) &&
  61335. + DWC_OTG_PARAM_TEST(val, 4, 4) &&
  61336. + DWC_OTG_PARAM_TEST(val, 8, 8) &&
  61337. + DWC_OTG_PARAM_TEST(val, 16, 16) &&
  61338. + DWC_OTG_PARAM_TEST(val, 32, 32) &&
  61339. + DWC_OTG_PARAM_TEST(val, 64, 64) &&
  61340. + DWC_OTG_PARAM_TEST(val, 128, 128) &&
  61341. + DWC_OTG_PARAM_TEST(val, 256, 256)) {
  61342. + DWC_WARN("`%d' invalid for parameter `dma_burst_size'\n", val);
  61343. + return -DWC_E_INVALID;
  61344. + }
  61345. + core_if->core_params->dma_burst_size = val;
  61346. + return 0;
  61347. +}
  61348. +
  61349. +int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if)
  61350. +{
  61351. + return core_if->core_params->dma_burst_size;
  61352. +}
  61353. +
  61354. +int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61355. +{
  61356. + int retval = 0;
  61357. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61358. + DWC_WARN("`%d' invalid for parameter `pti_enable'\n", val);
  61359. + return -DWC_E_INVALID;
  61360. + }
  61361. + if (val && (core_if->snpsid < OTG_CORE_REV_2_72a)) {
  61362. + if (dwc_otg_param_initialized(core_if->core_params->pti_enable)) {
  61363. + DWC_ERROR
  61364. + ("%d invalid for parameter pti_enable. Check HW configuration.\n",
  61365. + val);
  61366. + }
  61367. + retval = -DWC_E_INVALID;
  61368. + val = 0;
  61369. + }
  61370. + core_if->core_params->pti_enable = val;
  61371. + return retval;
  61372. +}
  61373. +
  61374. +int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if)
  61375. +{
  61376. + return core_if->core_params->pti_enable;
  61377. +}
  61378. +
  61379. +int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61380. +{
  61381. + int retval = 0;
  61382. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61383. + DWC_WARN("`%d' invalid for parameter `mpi_enable'\n", val);
  61384. + return -DWC_E_INVALID;
  61385. + }
  61386. + if (val && (core_if->hwcfg2.b.multi_proc_int == 0)) {
  61387. + if (dwc_otg_param_initialized(core_if->core_params->mpi_enable)) {
  61388. + DWC_ERROR
  61389. + ("%d invalid for parameter mpi_enable. Check HW configuration.\n",
  61390. + val);
  61391. + }
  61392. + retval = -DWC_E_INVALID;
  61393. + val = 0;
  61394. + }
  61395. + core_if->core_params->mpi_enable = val;
  61396. + return retval;
  61397. +}
  61398. +
  61399. +int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if)
  61400. +{
  61401. + return core_if->core_params->mpi_enable;
  61402. +}
  61403. +
  61404. +int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if, int32_t val)
  61405. +{
  61406. + int retval = 0;
  61407. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61408. + DWC_WARN("`%d' invalid for parameter `adp_enable'\n", val);
  61409. + return -DWC_E_INVALID;
  61410. + }
  61411. + if (val && (core_if->hwcfg3.b.adp_supp == 0)) {
  61412. + if (dwc_otg_param_initialized
  61413. + (core_if->core_params->adp_supp_enable)) {
  61414. + DWC_ERROR
  61415. + ("%d invalid for parameter adp_enable. Check HW configuration.\n",
  61416. + val);
  61417. + }
  61418. + retval = -DWC_E_INVALID;
  61419. + val = 0;
  61420. + }
  61421. + core_if->core_params->adp_supp_enable = val;
  61422. + /*Set OTG version 2.0 in case of enabling ADP*/
  61423. + if (val)
  61424. + dwc_otg_set_param_otg_ver(core_if, 1);
  61425. +
  61426. + return retval;
  61427. +}
  61428. +
  61429. +int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if)
  61430. +{
  61431. + return core_if->core_params->adp_supp_enable;
  61432. +}
  61433. +
  61434. +int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if, int32_t val)
  61435. +{
  61436. + int retval = 0;
  61437. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61438. + DWC_WARN("`%d' invalid for parameter `ic_usb_cap'\n", val);
  61439. + DWC_WARN("ic_usb_cap must be 0 or 1\n");
  61440. + return -DWC_E_INVALID;
  61441. + }
  61442. +
  61443. + if (val && (core_if->hwcfg2.b.otg_enable_ic_usb == 0)) {
  61444. + if (dwc_otg_param_initialized(core_if->core_params->ic_usb_cap)) {
  61445. + DWC_ERROR
  61446. + ("%d invalid for parameter ic_usb_cap. Check HW configuration.\n",
  61447. + val);
  61448. + }
  61449. + retval = -DWC_E_INVALID;
  61450. + val = 0;
  61451. + }
  61452. + core_if->core_params->ic_usb_cap = val;
  61453. + return retval;
  61454. +}
  61455. +
  61456. +int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if)
  61457. +{
  61458. + return core_if->core_params->ic_usb_cap;
  61459. +}
  61460. +
  61461. +int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if, int32_t val)
  61462. +{
  61463. + int retval = 0;
  61464. + int valid = 1;
  61465. +
  61466. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61467. + DWC_WARN("`%d' invalid for parameter `ahb_thr_ratio'\n", val);
  61468. + DWC_WARN("ahb_thr_ratio must be 0 - 3\n");
  61469. + return -DWC_E_INVALID;
  61470. + }
  61471. +
  61472. + if (val
  61473. + && (core_if->snpsid < OTG_CORE_REV_2_81a
  61474. + || !dwc_otg_get_param_thr_ctl(core_if))) {
  61475. + valid = 0;
  61476. + } else if (val
  61477. + && ((dwc_otg_get_param_tx_thr_length(core_if) / (1 << val)) <
  61478. + 4)) {
  61479. + valid = 0;
  61480. + }
  61481. + if (valid == 0) {
  61482. + if (dwc_otg_param_initialized
  61483. + (core_if->core_params->ahb_thr_ratio)) {
  61484. + DWC_ERROR
  61485. + ("%d invalid for parameter ahb_thr_ratio. Check HW configuration.\n",
  61486. + val);
  61487. + }
  61488. + retval = -DWC_E_INVALID;
  61489. + val = 0;
  61490. + }
  61491. +
  61492. + core_if->core_params->ahb_thr_ratio = val;
  61493. + return retval;
  61494. +}
  61495. +
  61496. +int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if)
  61497. +{
  61498. + return core_if->core_params->ahb_thr_ratio;
  61499. +}
  61500. +
  61501. +int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if, int32_t val)
  61502. +{
  61503. + int retval = 0;
  61504. + int valid = 1;
  61505. + hwcfg4_data_t hwcfg4 = {.d32 = 0 };
  61506. + hwcfg4.d32 = DWC_READ_REG32(&core_if->core_global_regs->ghwcfg4);
  61507. +
  61508. + if (DWC_OTG_PARAM_TEST(val, 0, 3)) {
  61509. + DWC_WARN("`%d' invalid for parameter `power_down'\n", val);
  61510. + DWC_WARN("power_down must be 0 - 2\n");
  61511. + return -DWC_E_INVALID;
  61512. + }
  61513. +
  61514. + if ((val == 2) && (core_if->snpsid < OTG_CORE_REV_2_91a)) {
  61515. + valid = 0;
  61516. + }
  61517. + if ((val == 3)
  61518. + && ((core_if->snpsid < OTG_CORE_REV_3_00a)
  61519. + || (hwcfg4.b.xhiber == 0))) {
  61520. + valid = 0;
  61521. + }
  61522. + if (valid == 0) {
  61523. + if (dwc_otg_param_initialized(core_if->core_params->power_down)) {
  61524. + DWC_ERROR
  61525. + ("%d invalid for parameter power_down. Check HW configuration.\n",
  61526. + val);
  61527. + }
  61528. + retval = -DWC_E_INVALID;
  61529. + val = 0;
  61530. + }
  61531. + core_if->core_params->power_down = val;
  61532. + return retval;
  61533. +}
  61534. +
  61535. +int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if)
  61536. +{
  61537. + return core_if->core_params->power_down;
  61538. +}
  61539. +
  61540. +int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if, int32_t val)
  61541. +{
  61542. + int retval = 0;
  61543. + int valid = 1;
  61544. +
  61545. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61546. + DWC_WARN("`%d' invalid for parameter `reload_ctl'\n", val);
  61547. + DWC_WARN("reload_ctl must be 0 or 1\n");
  61548. + return -DWC_E_INVALID;
  61549. + }
  61550. +
  61551. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_92a)) {
  61552. + valid = 0;
  61553. + }
  61554. + if (valid == 0) {
  61555. + if (dwc_otg_param_initialized(core_if->core_params->reload_ctl)) {
  61556. + DWC_ERROR("%d invalid for parameter reload_ctl."
  61557. + "Check HW configuration.\n", val);
  61558. + }
  61559. + retval = -DWC_E_INVALID;
  61560. + val = 0;
  61561. + }
  61562. + core_if->core_params->reload_ctl = val;
  61563. + return retval;
  61564. +}
  61565. +
  61566. +int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if)
  61567. +{
  61568. + return core_if->core_params->reload_ctl;
  61569. +}
  61570. +
  61571. +int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if, int32_t val)
  61572. +{
  61573. + int retval = 0;
  61574. + int valid = 1;
  61575. +
  61576. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61577. + DWC_WARN("`%d' invalid for parameter `dev_out_nak'\n", val);
  61578. + DWC_WARN("dev_out_nak must be 0 or 1\n");
  61579. + return -DWC_E_INVALID;
  61580. + }
  61581. +
  61582. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_93a) ||
  61583. + !(core_if->core_params->dma_desc_enable))) {
  61584. + valid = 0;
  61585. + }
  61586. + if (valid == 0) {
  61587. + if (dwc_otg_param_initialized(core_if->core_params->dev_out_nak)) {
  61588. + DWC_ERROR("%d invalid for parameter dev_out_nak."
  61589. + "Check HW configuration.\n", val);
  61590. + }
  61591. + retval = -DWC_E_INVALID;
  61592. + val = 0;
  61593. + }
  61594. + core_if->core_params->dev_out_nak = val;
  61595. + return retval;
  61596. +}
  61597. +
  61598. +int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if)
  61599. +{
  61600. + return core_if->core_params->dev_out_nak;
  61601. +}
  61602. +
  61603. +int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if, int32_t val)
  61604. +{
  61605. + int retval = 0;
  61606. + int valid = 1;
  61607. +
  61608. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61609. + DWC_WARN("`%d' invalid for parameter `cont_on_bna'\n", val);
  61610. + DWC_WARN("cont_on_bna must be 0 or 1\n");
  61611. + return -DWC_E_INVALID;
  61612. + }
  61613. +
  61614. + if ((val == 1) && ((core_if->snpsid < OTG_CORE_REV_2_94a) ||
  61615. + !(core_if->core_params->dma_desc_enable))) {
  61616. + valid = 0;
  61617. + }
  61618. + if (valid == 0) {
  61619. + if (dwc_otg_param_initialized(core_if->core_params->cont_on_bna)) {
  61620. + DWC_ERROR("%d invalid for parameter cont_on_bna."
  61621. + "Check HW configuration.\n", val);
  61622. + }
  61623. + retval = -DWC_E_INVALID;
  61624. + val = 0;
  61625. + }
  61626. + core_if->core_params->cont_on_bna = val;
  61627. + return retval;
  61628. +}
  61629. +
  61630. +int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if)
  61631. +{
  61632. + return core_if->core_params->cont_on_bna;
  61633. +}
  61634. +
  61635. +int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if, int32_t val)
  61636. +{
  61637. + int retval = 0;
  61638. + int valid = 1;
  61639. +
  61640. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61641. + DWC_WARN("`%d' invalid for parameter `ahb_single'\n", val);
  61642. + DWC_WARN("ahb_single must be 0 or 1\n");
  61643. + return -DWC_E_INVALID;
  61644. + }
  61645. +
  61646. + if ((val == 1) && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  61647. + valid = 0;
  61648. + }
  61649. + if (valid == 0) {
  61650. + if (dwc_otg_param_initialized(core_if->core_params->ahb_single)) {
  61651. + DWC_ERROR("%d invalid for parameter ahb_single."
  61652. + "Check HW configuration.\n", val);
  61653. + }
  61654. + retval = -DWC_E_INVALID;
  61655. + val = 0;
  61656. + }
  61657. + core_if->core_params->ahb_single = val;
  61658. + return retval;
  61659. +}
  61660. +
  61661. +int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if)
  61662. +{
  61663. + return core_if->core_params->ahb_single;
  61664. +}
  61665. +
  61666. +int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val)
  61667. +{
  61668. + int retval = 0;
  61669. +
  61670. + if (DWC_OTG_PARAM_TEST(val, 0, 1)) {
  61671. + DWC_WARN("`%d' invalid for parameter `otg_ver'\n", val);
  61672. + DWC_WARN
  61673. + ("otg_ver must be 0(for OTG 1.3 support) or 1(for OTG 2.0 support)\n");
  61674. + return -DWC_E_INVALID;
  61675. + }
  61676. +
  61677. + core_if->core_params->otg_ver = val;
  61678. + return retval;
  61679. +}
  61680. +
  61681. +int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if)
  61682. +{
  61683. + return core_if->core_params->otg_ver;
  61684. +}
  61685. +
  61686. +uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if)
  61687. +{
  61688. + gotgctl_data_t otgctl;
  61689. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61690. + return otgctl.b.hstnegscs;
  61691. +}
  61692. +
  61693. +uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if)
  61694. +{
  61695. + gotgctl_data_t otgctl;
  61696. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61697. + return otgctl.b.sesreqscs;
  61698. +}
  61699. +
  61700. +void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val)
  61701. +{
  61702. + if(core_if->otg_ver == 0) {
  61703. + gotgctl_data_t otgctl;
  61704. + otgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  61705. + otgctl.b.hnpreq = val;
  61706. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, otgctl.d32);
  61707. + } else {
  61708. + core_if->otg_sts = val;
  61709. + }
  61710. +}
  61711. +
  61712. +uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if)
  61713. +{
  61714. + return core_if->snpsid;
  61715. +}
  61716. +
  61717. +uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if)
  61718. +{
  61719. + gintsts_data_t gintsts;
  61720. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  61721. + return gintsts.b.curmode;
  61722. +}
  61723. +
  61724. +uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if)
  61725. +{
  61726. + gusbcfg_data_t usbcfg;
  61727. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61728. + return usbcfg.b.hnpcap;
  61729. +}
  61730. +
  61731. +void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61732. +{
  61733. + gusbcfg_data_t usbcfg;
  61734. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61735. + usbcfg.b.hnpcap = val;
  61736. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61737. +}
  61738. +
  61739. +uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if)
  61740. +{
  61741. + gusbcfg_data_t usbcfg;
  61742. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61743. + return usbcfg.b.srpcap;
  61744. +}
  61745. +
  61746. +void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val)
  61747. +{
  61748. + gusbcfg_data_t usbcfg;
  61749. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  61750. + usbcfg.b.srpcap = val;
  61751. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, usbcfg.d32);
  61752. +}
  61753. +
  61754. +uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if)
  61755. +{
  61756. + dcfg_data_t dcfg;
  61757. + /* originally: dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg); */
  61758. +
  61759. + dcfg.d32 = -1; //GRAYG
  61760. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)\n", __func__, core_if);
  61761. + if (NULL == core_if)
  61762. + DWC_ERROR("reg request with NULL core_if\n");
  61763. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)\n", __func__,
  61764. + core_if, core_if->dev_if);
  61765. + if (NULL == core_if->dev_if)
  61766. + DWC_ERROR("reg request with NULL dev_if\n");
  61767. + DWC_DEBUGPL(DBG_CILV, "%s - core_if(%p)->dev_if(%p)->"
  61768. + "dev_global_regs(%p)\n", __func__,
  61769. + core_if, core_if->dev_if,
  61770. + core_if->dev_if->dev_global_regs);
  61771. + if (NULL == core_if->dev_if->dev_global_regs)
  61772. + DWC_ERROR("reg request with NULL dev_global_regs\n");
  61773. + else {
  61774. + DWC_DEBUGPL(DBG_CILV, "%s - &core_if(%p)->dev_if(%p)->"
  61775. + "dev_global_regs(%p)->dcfg = %p\n", __func__,
  61776. + core_if, core_if->dev_if,
  61777. + core_if->dev_if->dev_global_regs,
  61778. + &core_if->dev_if->dev_global_regs->dcfg);
  61779. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61780. + }
  61781. + return dcfg.b.devspd;
  61782. +}
  61783. +
  61784. +void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val)
  61785. +{
  61786. + dcfg_data_t dcfg;
  61787. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  61788. + dcfg.b.devspd = val;
  61789. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, dcfg.d32);
  61790. +}
  61791. +
  61792. +uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if)
  61793. +{
  61794. + hprt0_data_t hprt0;
  61795. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61796. + return hprt0.b.prtconnsts;
  61797. +}
  61798. +
  61799. +uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if)
  61800. +{
  61801. + dsts_data_t dsts;
  61802. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  61803. + return dsts.b.enumspd;
  61804. +}
  61805. +
  61806. +uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if)
  61807. +{
  61808. + hprt0_data_t hprt0;
  61809. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61810. + return hprt0.b.prtpwr;
  61811. +
  61812. +}
  61813. +
  61814. +uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if)
  61815. +{
  61816. + return core_if->hibernation_suspend;
  61817. +}
  61818. +
  61819. +void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val)
  61820. +{
  61821. + hprt0_data_t hprt0;
  61822. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61823. + hprt0.b.prtpwr = val;
  61824. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61825. +}
  61826. +
  61827. +uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if)
  61828. +{
  61829. + hprt0_data_t hprt0;
  61830. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  61831. + return hprt0.b.prtsusp;
  61832. +
  61833. +}
  61834. +
  61835. +void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val)
  61836. +{
  61837. + hprt0_data_t hprt0;
  61838. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61839. + hprt0.b.prtsusp = val;
  61840. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61841. +}
  61842. +
  61843. +uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if)
  61844. +{
  61845. + hfir_data_t hfir;
  61846. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61847. + return hfir.b.frint;
  61848. +
  61849. +}
  61850. +
  61851. +void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val)
  61852. +{
  61853. + hfir_data_t hfir;
  61854. + uint32_t fram_int;
  61855. + fram_int = calc_frame_interval(core_if);
  61856. + hfir.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hfir);
  61857. + if (!core_if->core_params->reload_ctl) {
  61858. + DWC_WARN("\nCannot reload HFIR register.HFIR.HFIRRldCtrl bit is"
  61859. + "not set to 1.\nShould load driver with reload_ctl=1"
  61860. + " module parameter\n");
  61861. + return;
  61862. + }
  61863. + switch (fram_int) {
  61864. + case 3750:
  61865. + if ((val < 3350) || (val > 4150)) {
  61866. + DWC_WARN("HFIR interval for HS core and 30 MHz"
  61867. + "clock freq should be from 3350 to 4150\n");
  61868. + return;
  61869. + }
  61870. + break;
  61871. + case 30000:
  61872. + if ((val < 26820) || (val > 33180)) {
  61873. + DWC_WARN("HFIR interval for FS/LS core and 30 MHz"
  61874. + "clock freq should be from 26820 to 33180\n");
  61875. + return;
  61876. + }
  61877. + break;
  61878. + case 6000:
  61879. + if ((val < 5360) || (val > 6640)) {
  61880. + DWC_WARN("HFIR interval for HS core and 48 MHz"
  61881. + "clock freq should be from 5360 to 6640\n");
  61882. + return;
  61883. + }
  61884. + break;
  61885. + case 48000:
  61886. + if ((val < 42912) || (val > 53088)) {
  61887. + DWC_WARN("HFIR interval for FS/LS core and 48 MHz"
  61888. + "clock freq should be from 42912 to 53088\n");
  61889. + return;
  61890. + }
  61891. + break;
  61892. + case 7500:
  61893. + if ((val < 6700) || (val > 8300)) {
  61894. + DWC_WARN("HFIR interval for HS core and 60 MHz"
  61895. + "clock freq should be from 6700 to 8300\n");
  61896. + return;
  61897. + }
  61898. + break;
  61899. + case 60000:
  61900. + if ((val < 53640) || (val > 65536)) {
  61901. + DWC_WARN("HFIR interval for FS/LS core and 60 MHz"
  61902. + "clock freq should be from 53640 to 65536\n");
  61903. + return;
  61904. + }
  61905. + break;
  61906. + default:
  61907. + DWC_WARN("Unknown frame interval\n");
  61908. + return;
  61909. + break;
  61910. +
  61911. + }
  61912. + hfir.b.frint = val;
  61913. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hfir, hfir.d32);
  61914. +}
  61915. +
  61916. +uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if)
  61917. +{
  61918. + hcfg_data_t hcfg;
  61919. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61920. + return hcfg.b.modechtimen;
  61921. +
  61922. +}
  61923. +
  61924. +void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val)
  61925. +{
  61926. + hcfg_data_t hcfg;
  61927. + hcfg.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->hcfg);
  61928. + hcfg.b.modechtimen = val;
  61929. + DWC_WRITE_REG32(&core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  61930. +}
  61931. +
  61932. +void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val)
  61933. +{
  61934. + hprt0_data_t hprt0;
  61935. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  61936. + hprt0.b.prtres = val;
  61937. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  61938. +}
  61939. +
  61940. +uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if)
  61941. +{
  61942. + dctl_data_t dctl;
  61943. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  61944. + return dctl.b.rmtwkupsig;
  61945. +}
  61946. +
  61947. +uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if)
  61948. +{
  61949. + glpmcfg_data_t lpmcfg;
  61950. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61951. +
  61952. + DWC_ASSERT(!
  61953. + ((core_if->lx_state == DWC_OTG_L1) ^ lpmcfg.b.prt_sleep_sts),
  61954. + "lx_state = %d, lmpcfg.prt_sleep_sts = %d\n",
  61955. + core_if->lx_state, lpmcfg.b.prt_sleep_sts);
  61956. +
  61957. + return lpmcfg.b.prt_sleep_sts;
  61958. +}
  61959. +
  61960. +uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if)
  61961. +{
  61962. + glpmcfg_data_t lpmcfg;
  61963. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61964. + return lpmcfg.b.rem_wkup_en;
  61965. +}
  61966. +
  61967. +uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if)
  61968. +{
  61969. + glpmcfg_data_t lpmcfg;
  61970. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61971. + return lpmcfg.b.appl_resp;
  61972. +}
  61973. +
  61974. +void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val)
  61975. +{
  61976. + glpmcfg_data_t lpmcfg;
  61977. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61978. + lpmcfg.b.appl_resp = val;
  61979. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61980. +}
  61981. +
  61982. +uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if)
  61983. +{
  61984. + glpmcfg_data_t lpmcfg;
  61985. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61986. + return lpmcfg.b.hsic_connect;
  61987. +}
  61988. +
  61989. +void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val)
  61990. +{
  61991. + glpmcfg_data_t lpmcfg;
  61992. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  61993. + lpmcfg.b.hsic_connect = val;
  61994. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  61995. +}
  61996. +
  61997. +uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if)
  61998. +{
  61999. + glpmcfg_data_t lpmcfg;
  62000. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62001. + return lpmcfg.b.inv_sel_hsic;
  62002. +
  62003. +}
  62004. +
  62005. +void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val)
  62006. +{
  62007. + glpmcfg_data_t lpmcfg;
  62008. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  62009. + lpmcfg.b.inv_sel_hsic = val;
  62010. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  62011. +}
  62012. +
  62013. +uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if)
  62014. +{
  62015. + return DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  62016. +}
  62017. +
  62018. +void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62019. +{
  62020. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgctl, val);
  62021. +}
  62022. +
  62023. +uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if)
  62024. +{
  62025. + return DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  62026. +}
  62027. +
  62028. +void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val)
  62029. +{
  62030. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, val);
  62031. +}
  62032. +
  62033. +uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if)
  62034. +{
  62035. + return DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  62036. +}
  62037. +
  62038. +void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62039. +{
  62040. + DWC_WRITE_REG32(&core_if->core_global_regs->grxfsiz, val);
  62041. +}
  62042. +
  62043. +uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if)
  62044. +{
  62045. + return DWC_READ_REG32(&core_if->core_global_regs->gnptxfsiz);
  62046. +}
  62047. +
  62048. +void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val)
  62049. +{
  62050. + DWC_WRITE_REG32(&core_if->core_global_regs->gnptxfsiz, val);
  62051. +}
  62052. +
  62053. +uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if)
  62054. +{
  62055. + return DWC_READ_REG32(&core_if->core_global_regs->gpvndctl);
  62056. +}
  62057. +
  62058. +void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val)
  62059. +{
  62060. + DWC_WRITE_REG32(&core_if->core_global_regs->gpvndctl, val);
  62061. +}
  62062. +
  62063. +uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if)
  62064. +{
  62065. + return DWC_READ_REG32(&core_if->core_global_regs->ggpio);
  62066. +}
  62067. +
  62068. +void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val)
  62069. +{
  62070. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, val);
  62071. +}
  62072. +
  62073. +uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if)
  62074. +{
  62075. + return DWC_READ_REG32(core_if->host_if->hprt0);
  62076. +
  62077. +}
  62078. +
  62079. +void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val)
  62080. +{
  62081. + DWC_WRITE_REG32(core_if->host_if->hprt0, val);
  62082. +}
  62083. +
  62084. +uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if)
  62085. +{
  62086. + return DWC_READ_REG32(&core_if->core_global_regs->guid);
  62087. +}
  62088. +
  62089. +void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val)
  62090. +{
  62091. + DWC_WRITE_REG32(&core_if->core_global_regs->guid, val);
  62092. +}
  62093. +
  62094. +uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if)
  62095. +{
  62096. + return DWC_READ_REG32(&core_if->core_global_regs->hptxfsiz);
  62097. +}
  62098. +
  62099. +uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if)
  62100. +{
  62101. + return ((core_if->otg_ver == 1) ? (uint16_t)0x0200 : (uint16_t)0x0103);
  62102. +}
  62103. +
  62104. +/**
  62105. + * Start the SRP timer to detect when the SRP does not complete within
  62106. + * 6 seconds.
  62107. + *
  62108. + * @param core_if the pointer to core_if strucure.
  62109. + */
  62110. +void dwc_otg_pcd_start_srp_timer(dwc_otg_core_if_t * core_if)
  62111. +{
  62112. + core_if->srp_timer_started = 1;
  62113. + DWC_TIMER_SCHEDULE(core_if->srp_timer, 6000 /* 6 secs */ );
  62114. +}
  62115. +
  62116. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if)
  62117. +{
  62118. + uint32_t *addr = (uint32_t *) & (core_if->core_global_regs->gotgctl);
  62119. + gotgctl_data_t mem;
  62120. + gotgctl_data_t val;
  62121. +
  62122. + val.d32 = DWC_READ_REG32(addr);
  62123. + if (val.b.sesreq) {
  62124. + DWC_ERROR("Session Request Already active!\n");
  62125. + return;
  62126. + }
  62127. +
  62128. + DWC_INFO("Session Request Initated\n"); //NOTICE
  62129. + mem.d32 = DWC_READ_REG32(addr);
  62130. + mem.b.sesreq = 1;
  62131. + DWC_WRITE_REG32(addr, mem.d32);
  62132. +
  62133. + /* Start the SRP timer */
  62134. + dwc_otg_pcd_start_srp_timer(core_if);
  62135. + return;
  62136. +}
  62137. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h
  62138. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil.h 1970-01-01 01:00:00.000000000 +0100
  62139. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil.h 2014-06-11 21:03:43.000000000 +0200
  62140. @@ -0,0 +1,1464 @@
  62141. +/* ==========================================================================
  62142. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil.h $
  62143. + * $Revision: #123 $
  62144. + * $Date: 2012/08/10 $
  62145. + * $Change: 2047372 $
  62146. + *
  62147. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  62148. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  62149. + * otherwise expressly agreed to in writing between Synopsys and you.
  62150. + *
  62151. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  62152. + * any End User Software License Agreement or Agreement for Licensed Product
  62153. + * with Synopsys or any supplement thereto. You are permitted to use and
  62154. + * redistribute this Software in source and binary forms, with or without
  62155. + * modification, provided that redistributions of source code must retain this
  62156. + * notice. You may not view, use, disclose, copy or distribute this file or
  62157. + * any information contained herein except pursuant to this license grant from
  62158. + * Synopsys. If you do not agree with this notice, including the disclaimer
  62159. + * below, then you are not authorized to use the Software.
  62160. + *
  62161. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  62162. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  62163. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62164. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  62165. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  62166. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  62167. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  62168. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  62169. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  62170. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  62171. + * DAMAGE.
  62172. + * ========================================================================== */
  62173. +
  62174. +#if !defined(__DWC_CIL_H__)
  62175. +#define __DWC_CIL_H__
  62176. +
  62177. +#include "dwc_list.h"
  62178. +#include "dwc_otg_dbg.h"
  62179. +#include "dwc_otg_regs.h"
  62180. +
  62181. +#include "dwc_otg_core_if.h"
  62182. +#include "dwc_otg_adp.h"
  62183. +
  62184. +/**
  62185. + * @file
  62186. + * This file contains the interface to the Core Interface Layer.
  62187. + */
  62188. +
  62189. +#ifdef DWC_UTE_CFI
  62190. +
  62191. +#define MAX_DMA_DESCS_PER_EP 256
  62192. +
  62193. +/**
  62194. + * Enumeration for the data buffer mode
  62195. + */
  62196. +typedef enum _data_buffer_mode {
  62197. + BM_STANDARD = 0, /* data buffer is in normal mode */
  62198. + BM_SG = 1, /* data buffer uses the scatter/gather mode */
  62199. + BM_CONCAT = 2, /* data buffer uses the concatenation mode */
  62200. + BM_CIRCULAR = 3, /* data buffer uses the circular DMA mode */
  62201. + BM_ALIGN = 4 /* data buffer is in buffer alignment mode */
  62202. +} data_buffer_mode_e;
  62203. +#endif //DWC_UTE_CFI
  62204. +
  62205. +/** Macros defined for DWC OTG HW Release version */
  62206. +
  62207. +#define OTG_CORE_REV_2_60a 0x4F54260A
  62208. +#define OTG_CORE_REV_2_71a 0x4F54271A
  62209. +#define OTG_CORE_REV_2_72a 0x4F54272A
  62210. +#define OTG_CORE_REV_2_80a 0x4F54280A
  62211. +#define OTG_CORE_REV_2_81a 0x4F54281A
  62212. +#define OTG_CORE_REV_2_90a 0x4F54290A
  62213. +#define OTG_CORE_REV_2_91a 0x4F54291A
  62214. +#define OTG_CORE_REV_2_92a 0x4F54292A
  62215. +#define OTG_CORE_REV_2_93a 0x4F54293A
  62216. +#define OTG_CORE_REV_2_94a 0x4F54294A
  62217. +#define OTG_CORE_REV_3_00a 0x4F54300A
  62218. +
  62219. +/**
  62220. + * Information for each ISOC packet.
  62221. + */
  62222. +typedef struct iso_pkt_info {
  62223. + uint32_t offset;
  62224. + uint32_t length;
  62225. + int32_t status;
  62226. +} iso_pkt_info_t;
  62227. +
  62228. +/**
  62229. + * The <code>dwc_ep</code> structure represents the state of a single
  62230. + * endpoint when acting in device mode. It contains the data items
  62231. + * needed for an endpoint to be activated and transfer packets.
  62232. + */
  62233. +typedef struct dwc_ep {
  62234. + /** EP number used for register address lookup */
  62235. + uint8_t num;
  62236. + /** EP direction 0 = OUT */
  62237. + unsigned is_in:1;
  62238. + /** EP active. */
  62239. + unsigned active:1;
  62240. +
  62241. + /**
  62242. + * Periodic Tx FIFO # for IN EPs For INTR EP set to 0 to use non-periodic
  62243. + * Tx FIFO. If dedicated Tx FIFOs are enabled Tx FIFO # FOR IN EPs*/
  62244. + unsigned tx_fifo_num:4;
  62245. + /** EP type: 0 - Control, 1 - ISOC, 2 - BULK, 3 - INTR */
  62246. + unsigned type:2;
  62247. +#define DWC_OTG_EP_TYPE_CONTROL 0
  62248. +#define DWC_OTG_EP_TYPE_ISOC 1
  62249. +#define DWC_OTG_EP_TYPE_BULK 2
  62250. +#define DWC_OTG_EP_TYPE_INTR 3
  62251. +
  62252. + /** DATA start PID for INTR and BULK EP */
  62253. + unsigned data_pid_start:1;
  62254. + /** Frame (even/odd) for ISOC EP */
  62255. + unsigned even_odd_frame:1;
  62256. + /** Max Packet bytes */
  62257. + unsigned maxpacket:11;
  62258. +
  62259. + /** Max Transfer size */
  62260. + uint32_t maxxfer;
  62261. +
  62262. + /** @name Transfer state */
  62263. + /** @{ */
  62264. +
  62265. + /**
  62266. + * Pointer to the beginning of the transfer buffer -- do not modify
  62267. + * during transfer.
  62268. + */
  62269. +
  62270. + dwc_dma_t dma_addr;
  62271. +
  62272. + dwc_dma_t dma_desc_addr;
  62273. + dwc_otg_dev_dma_desc_t *desc_addr;
  62274. +
  62275. + uint8_t *start_xfer_buff;
  62276. + /** pointer to the transfer buffer */
  62277. + uint8_t *xfer_buff;
  62278. + /** Number of bytes to transfer */
  62279. + unsigned xfer_len:19;
  62280. + /** Number of bytes transferred. */
  62281. + unsigned xfer_count:19;
  62282. + /** Sent ZLP */
  62283. + unsigned sent_zlp:1;
  62284. + /** Total len for control transfer */
  62285. + unsigned total_len:19;
  62286. +
  62287. + /** stall clear flag */
  62288. + unsigned stall_clear_flag:1;
  62289. +
  62290. + /** SETUP pkt cnt rollover flag for EP0 out*/
  62291. + unsigned stp_rollover;
  62292. +
  62293. +#ifdef DWC_UTE_CFI
  62294. + /* The buffer mode */
  62295. + data_buffer_mode_e buff_mode;
  62296. +
  62297. + /* The chain of DMA descriptors.
  62298. + * MAX_DMA_DESCS_PER_EP will be allocated for each active EP.
  62299. + */
  62300. + dwc_otg_dma_desc_t *descs;
  62301. +
  62302. + /* The DMA address of the descriptors chain start */
  62303. + dma_addr_t descs_dma_addr;
  62304. + /** This variable stores the length of the last enqueued request */
  62305. + uint32_t cfi_req_len;
  62306. +#endif //DWC_UTE_CFI
  62307. +
  62308. +/** Max DMA Descriptor count for any EP */
  62309. +#define MAX_DMA_DESC_CNT 256
  62310. + /** Allocated DMA Desc count */
  62311. + uint32_t desc_cnt;
  62312. +
  62313. + /** bInterval */
  62314. + uint32_t bInterval;
  62315. + /** Next frame num to setup next ISOC transfer */
  62316. + uint32_t frame_num;
  62317. + /** Indicates SOF number overrun in DSTS */
  62318. + uint8_t frm_overrun;
  62319. +
  62320. +#ifdef DWC_UTE_PER_IO
  62321. + /** Next frame num for which will be setup DMA Desc */
  62322. + uint32_t xiso_frame_num;
  62323. + /** bInterval */
  62324. + uint32_t xiso_bInterval;
  62325. + /** Count of currently active transfers - shall be either 0 or 1 */
  62326. + int xiso_active_xfers;
  62327. + int xiso_queued_xfers;
  62328. +#endif
  62329. +#ifdef DWC_EN_ISOC
  62330. + /**
  62331. + * Variables specific for ISOC EPs
  62332. + *
  62333. + */
  62334. + /** DMA addresses of ISOC buffers */
  62335. + dwc_dma_t dma_addr0;
  62336. + dwc_dma_t dma_addr1;
  62337. +
  62338. + dwc_dma_t iso_dma_desc_addr;
  62339. + dwc_otg_dev_dma_desc_t *iso_desc_addr;
  62340. +
  62341. + /** pointer to the transfer buffers */
  62342. + uint8_t *xfer_buff0;
  62343. + uint8_t *xfer_buff1;
  62344. +
  62345. + /** number of ISOC Buffer is processing */
  62346. + uint32_t proc_buf_num;
  62347. + /** Interval of ISOC Buffer processing */
  62348. + uint32_t buf_proc_intrvl;
  62349. + /** Data size for regular frame */
  62350. + uint32_t data_per_frame;
  62351. +
  62352. + /* todo - pattern data support is to be implemented in the future */
  62353. + /** Data size for pattern frame */
  62354. + uint32_t data_pattern_frame;
  62355. + /** Frame number of pattern data */
  62356. + uint32_t sync_frame;
  62357. +
  62358. + /** bInterval */
  62359. + uint32_t bInterval;
  62360. + /** ISO Packet number per frame */
  62361. + uint32_t pkt_per_frm;
  62362. + /** Next frame num for which will be setup DMA Desc */
  62363. + uint32_t next_frame;
  62364. + /** Number of packets per buffer processing */
  62365. + uint32_t pkt_cnt;
  62366. + /** Info for all isoc packets */
  62367. + iso_pkt_info_t *pkt_info;
  62368. + /** current pkt number */
  62369. + uint32_t cur_pkt;
  62370. + /** current pkt number */
  62371. + uint8_t *cur_pkt_addr;
  62372. + /** current pkt number */
  62373. + uint32_t cur_pkt_dma_addr;
  62374. +#endif /* DWC_EN_ISOC */
  62375. +
  62376. +/** @} */
  62377. +} dwc_ep_t;
  62378. +
  62379. +/*
  62380. + * Reasons for halting a host channel.
  62381. + */
  62382. +typedef enum dwc_otg_halt_status {
  62383. + DWC_OTG_HC_XFER_NO_HALT_STATUS,
  62384. + DWC_OTG_HC_XFER_COMPLETE,
  62385. + DWC_OTG_HC_XFER_URB_COMPLETE,
  62386. + DWC_OTG_HC_XFER_ACK,
  62387. + DWC_OTG_HC_XFER_NAK,
  62388. + DWC_OTG_HC_XFER_NYET,
  62389. + DWC_OTG_HC_XFER_STALL,
  62390. + DWC_OTG_HC_XFER_XACT_ERR,
  62391. + DWC_OTG_HC_XFER_FRAME_OVERRUN,
  62392. + DWC_OTG_HC_XFER_BABBLE_ERR,
  62393. + DWC_OTG_HC_XFER_DATA_TOGGLE_ERR,
  62394. + DWC_OTG_HC_XFER_AHB_ERR,
  62395. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE,
  62396. + DWC_OTG_HC_XFER_URB_DEQUEUE
  62397. +} dwc_otg_halt_status_e;
  62398. +
  62399. +/**
  62400. + * Host channel descriptor. This structure represents the state of a single
  62401. + * host channel when acting in host mode. It contains the data items needed to
  62402. + * transfer packets to an endpoint via a host channel.
  62403. + */
  62404. +typedef struct dwc_hc {
  62405. + /** Host channel number used for register address lookup */
  62406. + uint8_t hc_num;
  62407. +
  62408. + /** Device to access */
  62409. + unsigned dev_addr:7;
  62410. +
  62411. + /** EP to access */
  62412. + unsigned ep_num:4;
  62413. +
  62414. + /** EP direction. 0: OUT, 1: IN */
  62415. + unsigned ep_is_in:1;
  62416. +
  62417. + /**
  62418. + * EP speed.
  62419. + * One of the following values:
  62420. + * - DWC_OTG_EP_SPEED_LOW
  62421. + * - DWC_OTG_EP_SPEED_FULL
  62422. + * - DWC_OTG_EP_SPEED_HIGH
  62423. + */
  62424. + unsigned speed:2;
  62425. +#define DWC_OTG_EP_SPEED_LOW 0
  62426. +#define DWC_OTG_EP_SPEED_FULL 1
  62427. +#define DWC_OTG_EP_SPEED_HIGH 2
  62428. +
  62429. + /**
  62430. + * Endpoint type.
  62431. + * One of the following values:
  62432. + * - DWC_OTG_EP_TYPE_CONTROL: 0
  62433. + * - DWC_OTG_EP_TYPE_ISOC: 1
  62434. + * - DWC_OTG_EP_TYPE_BULK: 2
  62435. + * - DWC_OTG_EP_TYPE_INTR: 3
  62436. + */
  62437. + unsigned ep_type:2;
  62438. +
  62439. + /** Max packet size in bytes */
  62440. + unsigned max_packet:11;
  62441. +
  62442. + /**
  62443. + * PID for initial transaction.
  62444. + * 0: DATA0,<br>
  62445. + * 1: DATA2,<br>
  62446. + * 2: DATA1,<br>
  62447. + * 3: MDATA (non-Control EP),
  62448. + * SETUP (Control EP)
  62449. + */
  62450. + unsigned data_pid_start:2;
  62451. +#define DWC_OTG_HC_PID_DATA0 0
  62452. +#define DWC_OTG_HC_PID_DATA2 1
  62453. +#define DWC_OTG_HC_PID_DATA1 2
  62454. +#define DWC_OTG_HC_PID_MDATA 3
  62455. +#define DWC_OTG_HC_PID_SETUP 3
  62456. +
  62457. + /** Number of periodic transactions per (micro)frame */
  62458. + unsigned multi_count:2;
  62459. +
  62460. + /** @name Transfer State */
  62461. + /** @{ */
  62462. +
  62463. + /** Pointer to the current transfer buffer position. */
  62464. + uint8_t *xfer_buff;
  62465. + /**
  62466. + * In Buffer DMA mode this buffer will be used
  62467. + * if xfer_buff is not DWORD aligned.
  62468. + */
  62469. + dwc_dma_t align_buff;
  62470. + /** Total number of bytes to transfer. */
  62471. + uint32_t xfer_len;
  62472. + /** Number of bytes transferred so far. */
  62473. + uint32_t xfer_count;
  62474. + /** Packet count at start of transfer.*/
  62475. + uint16_t start_pkt_count;
  62476. +
  62477. + /**
  62478. + * Flag to indicate whether the transfer has been started. Set to 1 if
  62479. + * it has been started, 0 otherwise.
  62480. + */
  62481. + uint8_t xfer_started;
  62482. +
  62483. + /**
  62484. + * Set to 1 to indicate that a PING request should be issued on this
  62485. + * channel. If 0, process normally.
  62486. + */
  62487. + uint8_t do_ping;
  62488. +
  62489. + /**
  62490. + * Set to 1 to indicate that the error count for this transaction is
  62491. + * non-zero. Set to 0 if the error count is 0.
  62492. + */
  62493. + uint8_t error_state;
  62494. +
  62495. + /**
  62496. + * Set to 1 to indicate that this channel should be halted the next
  62497. + * time a request is queued for the channel. This is necessary in
  62498. + * slave mode if no request queue space is available when an attempt
  62499. + * is made to halt the channel.
  62500. + */
  62501. + uint8_t halt_on_queue;
  62502. +
  62503. + /**
  62504. + * Set to 1 if the host channel has been halted, but the core is not
  62505. + * finished flushing queued requests. Otherwise 0.
  62506. + */
  62507. + uint8_t halt_pending;
  62508. +
  62509. + /**
  62510. + * Reason for halting the host channel.
  62511. + */
  62512. + dwc_otg_halt_status_e halt_status;
  62513. +
  62514. + /*
  62515. + * Split settings for the host channel
  62516. + */
  62517. + uint8_t do_split; /**< Enable split for the channel */
  62518. + uint8_t complete_split; /**< Enable complete split */
  62519. + uint8_t hub_addr; /**< Address of high speed hub */
  62520. +
  62521. + uint8_t port_addr; /**< Port of the low/full speed device */
  62522. + /** Split transaction position
  62523. + * One of the following values:
  62524. + * - DWC_HCSPLIT_XACTPOS_MID
  62525. + * - DWC_HCSPLIT_XACTPOS_BEGIN
  62526. + * - DWC_HCSPLIT_XACTPOS_END
  62527. + * - DWC_HCSPLIT_XACTPOS_ALL */
  62528. + uint8_t xact_pos;
  62529. +
  62530. + /** Set when the host channel does a short read. */
  62531. + uint8_t short_read;
  62532. +
  62533. + /**
  62534. + * Number of requests issued for this channel since it was assigned to
  62535. + * the current transfer (not counting PINGs).
  62536. + */
  62537. + uint8_t requests;
  62538. +
  62539. + /**
  62540. + * Queue Head for the transfer being processed by this channel.
  62541. + */
  62542. + struct dwc_otg_qh *qh;
  62543. +
  62544. + /** @} */
  62545. +
  62546. + /** Entry in list of host channels. */
  62547. + DWC_CIRCLEQ_ENTRY(dwc_hc) hc_list_entry;
  62548. +
  62549. + /** @name Descriptor DMA support */
  62550. + /** @{ */
  62551. +
  62552. + /** Number of Transfer Descriptors */
  62553. + uint16_t ntd;
  62554. +
  62555. + /** Descriptor List DMA address */
  62556. + dwc_dma_t desc_list_addr;
  62557. +
  62558. + /** Scheduling micro-frame bitmap. */
  62559. + uint8_t schinfo;
  62560. +
  62561. + /** @} */
  62562. +} dwc_hc_t;
  62563. +
  62564. +/**
  62565. + * The following parameters may be specified when starting the module. These
  62566. + * parameters define how the DWC_otg controller should be configured.
  62567. + */
  62568. +typedef struct dwc_otg_core_params {
  62569. + int32_t opt;
  62570. +
  62571. + /**
  62572. + * Specifies the OTG capabilities. The driver will automatically
  62573. + * detect the value for this parameter if none is specified.
  62574. + * 0 - HNP and SRP capable (default)
  62575. + * 1 - SRP Only capable
  62576. + * 2 - No HNP/SRP capable
  62577. + */
  62578. + int32_t otg_cap;
  62579. +
  62580. + /**
  62581. + * Specifies whether to use slave or DMA mode for accessing the data
  62582. + * FIFOs. The driver will automatically detect the value for this
  62583. + * parameter if none is specified.
  62584. + * 0 - Slave
  62585. + * 1 - DMA (default, if available)
  62586. + */
  62587. + int32_t dma_enable;
  62588. +
  62589. + /**
  62590. + * When DMA mode is enabled specifies whether to use address DMA or DMA
  62591. + * Descriptor mode for accessing the data FIFOs in device mode. The driver
  62592. + * will automatically detect the value for this if none is specified.
  62593. + * 0 - address DMA
  62594. + * 1 - DMA Descriptor(default, if available)
  62595. + */
  62596. + int32_t dma_desc_enable;
  62597. + /** The DMA Burst size (applicable only for External DMA
  62598. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  62599. + */
  62600. + int32_t dma_burst_size; /* Translate this to GAHBCFG values */
  62601. +
  62602. + /**
  62603. + * Specifies the maximum speed of operation in host and device mode.
  62604. + * The actual speed depends on the speed of the attached device and
  62605. + * the value of phy_type. The actual speed depends on the speed of the
  62606. + * attached device.
  62607. + * 0 - High Speed (default)
  62608. + * 1 - Full Speed
  62609. + */
  62610. + int32_t speed;
  62611. + /** Specifies whether low power mode is supported when attached
  62612. + * to a Full Speed or Low Speed device in host mode.
  62613. + * 0 - Don't support low power mode (default)
  62614. + * 1 - Support low power mode
  62615. + */
  62616. + int32_t host_support_fs_ls_low_power;
  62617. +
  62618. + /** Specifies the PHY clock rate in low power mode when connected to a
  62619. + * Low Speed device in host mode. This parameter is applicable only if
  62620. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  62621. + * then defaults to 6 MHZ otherwise 48 MHZ.
  62622. + *
  62623. + * 0 - 48 MHz
  62624. + * 1 - 6 MHz
  62625. + */
  62626. + int32_t host_ls_low_power_phy_clk;
  62627. +
  62628. + /**
  62629. + * 0 - Use cC FIFO size parameters
  62630. + * 1 - Allow dynamic FIFO sizing (default)
  62631. + */
  62632. + int32_t enable_dynamic_fifo;
  62633. +
  62634. + /** Total number of 4-byte words in the data FIFO memory. This
  62635. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  62636. + * Tx FIFOs.
  62637. + * 32 to 32768 (default 8192)
  62638. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  62639. + */
  62640. + int32_t data_fifo_size;
  62641. +
  62642. + /** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  62643. + * FIFO sizing is enabled.
  62644. + * 16 to 32768 (default 1064)
  62645. + */
  62646. + int32_t dev_rx_fifo_size;
  62647. +
  62648. + /** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  62649. + * when dynamic FIFO sizing is enabled.
  62650. + * 16 to 32768 (default 1024)
  62651. + */
  62652. + int32_t dev_nperio_tx_fifo_size;
  62653. +
  62654. + /** Number of 4-byte words in each of the periodic Tx FIFOs in device
  62655. + * mode when dynamic FIFO sizing is enabled.
  62656. + * 4 to 768 (default 256)
  62657. + */
  62658. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  62659. +
  62660. + /** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  62661. + * FIFO sizing is enabled.
  62662. + * 16 to 32768 (default 1024)
  62663. + */
  62664. + int32_t host_rx_fifo_size;
  62665. +
  62666. + /** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  62667. + * when Dynamic FIFO sizing is enabled in the core.
  62668. + * 16 to 32768 (default 1024)
  62669. + */
  62670. + int32_t host_nperio_tx_fifo_size;
  62671. +
  62672. + /** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  62673. + * FIFO sizing is enabled.
  62674. + * 16 to 32768 (default 1024)
  62675. + */
  62676. + int32_t host_perio_tx_fifo_size;
  62677. +
  62678. + /** The maximum transfer size supported in bytes.
  62679. + * 2047 to 65,535 (default 65,535)
  62680. + */
  62681. + int32_t max_transfer_size;
  62682. +
  62683. + /** The maximum number of packets in a transfer.
  62684. + * 15 to 511 (default 511)
  62685. + */
  62686. + int32_t max_packet_count;
  62687. +
  62688. + /** The number of host channel registers to use.
  62689. + * 1 to 16 (default 12)
  62690. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  62691. + */
  62692. + int32_t host_channels;
  62693. +
  62694. + /** The number of endpoints in addition to EP0 available for device
  62695. + * mode operations.
  62696. + * 1 to 15 (default 6 IN and OUT)
  62697. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  62698. + * endpoints in addition to EP0.
  62699. + */
  62700. + int32_t dev_endpoints;
  62701. +
  62702. + /**
  62703. + * Specifies the type of PHY interface to use. By default, the driver
  62704. + * will automatically detect the phy_type.
  62705. + *
  62706. + * 0 - Full Speed PHY
  62707. + * 1 - UTMI+ (default)
  62708. + * 2 - ULPI
  62709. + */
  62710. + int32_t phy_type;
  62711. +
  62712. + /**
  62713. + * Specifies the UTMI+ Data Width. This parameter is
  62714. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  62715. + * PHY_TYPE, this parameter indicates the data width between
  62716. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  62717. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  62718. + * to "8 and 16 bits", meaning that the core has been
  62719. + * configured to work at either data path width.
  62720. + *
  62721. + * 8 or 16 bits (default 16)
  62722. + */
  62723. + int32_t phy_utmi_width;
  62724. +
  62725. + /**
  62726. + * Specifies whether the ULPI operates at double or single
  62727. + * data rate. This parameter is only applicable if PHY_TYPE is
  62728. + * ULPI.
  62729. + *
  62730. + * 0 - single data rate ULPI interface with 8 bit wide data
  62731. + * bus (default)
  62732. + * 1 - double data rate ULPI interface with 4 bit wide data
  62733. + * bus
  62734. + */
  62735. + int32_t phy_ulpi_ddr;
  62736. +
  62737. + /**
  62738. + * Specifies whether to use the internal or external supply to
  62739. + * drive the vbus with a ULPI phy.
  62740. + */
  62741. + int32_t phy_ulpi_ext_vbus;
  62742. +
  62743. + /**
  62744. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  62745. + * parameter is only applicable if PHY_TYPE is FS.
  62746. + * 0 - No (default)
  62747. + * 1 - Yes
  62748. + */
  62749. + int32_t i2c_enable;
  62750. +
  62751. + int32_t ulpi_fs_ls;
  62752. +
  62753. + int32_t ts_dline;
  62754. +
  62755. + /**
  62756. + * Specifies whether dedicated transmit FIFOs are
  62757. + * enabled for non periodic IN endpoints in device mode
  62758. + * 0 - No
  62759. + * 1 - Yes
  62760. + */
  62761. + int32_t en_multiple_tx_fifo;
  62762. +
  62763. + /** Number of 4-byte words in each of the Tx FIFOs in device
  62764. + * mode when dynamic FIFO sizing is enabled.
  62765. + * 4 to 768 (default 256)
  62766. + */
  62767. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  62768. +
  62769. + /** Thresholding enable flag-
  62770. + * bit 0 - enable non-ISO Tx thresholding
  62771. + * bit 1 - enable ISO Tx thresholding
  62772. + * bit 2 - enable Rx thresholding
  62773. + */
  62774. + uint32_t thr_ctl;
  62775. +
  62776. + /** Thresholding length for Tx
  62777. + * FIFOs in 32 bit DWORDs
  62778. + */
  62779. + uint32_t tx_thr_length;
  62780. +
  62781. + /** Thresholding length for Rx
  62782. + * FIFOs in 32 bit DWORDs
  62783. + */
  62784. + uint32_t rx_thr_length;
  62785. +
  62786. + /**
  62787. + * Specifies whether LPM (Link Power Management) support is enabled
  62788. + */
  62789. + int32_t lpm_enable;
  62790. +
  62791. + /** Per Transfer Interrupt
  62792. + * mode enable flag
  62793. + * 1 - Enabled
  62794. + * 0 - Disabled
  62795. + */
  62796. + int32_t pti_enable;
  62797. +
  62798. + /** Multi Processor Interrupt
  62799. + * mode enable flag
  62800. + * 1 - Enabled
  62801. + * 0 - Disabled
  62802. + */
  62803. + int32_t mpi_enable;
  62804. +
  62805. + /** IS_USB Capability
  62806. + * 1 - Enabled
  62807. + * 0 - Disabled
  62808. + */
  62809. + int32_t ic_usb_cap;
  62810. +
  62811. + /** AHB Threshold Ratio
  62812. + * 2'b00 AHB Threshold = MAC Threshold
  62813. + * 2'b01 AHB Threshold = 1/2 MAC Threshold
  62814. + * 2'b10 AHB Threshold = 1/4 MAC Threshold
  62815. + * 2'b11 AHB Threshold = 1/8 MAC Threshold
  62816. + */
  62817. + int32_t ahb_thr_ratio;
  62818. +
  62819. + /** ADP Support
  62820. + * 1 - Enabled
  62821. + * 0 - Disabled
  62822. + */
  62823. + int32_t adp_supp_enable;
  62824. +
  62825. + /** HFIR Reload Control
  62826. + * 0 - The HFIR cannot be reloaded dynamically.
  62827. + * 1 - Allow dynamic reloading of the HFIR register during runtime.
  62828. + */
  62829. + int32_t reload_ctl;
  62830. +
  62831. + /** DCFG: Enable device Out NAK
  62832. + * 0 - The core does not set NAK after Bulk Out transfer complete.
  62833. + * 1 - The core sets NAK after Bulk OUT transfer complete.
  62834. + */
  62835. + int32_t dev_out_nak;
  62836. +
  62837. + /** DCFG: Enable Continue on BNA
  62838. + * After receiving BNA interrupt the core disables the endpoint,when the
  62839. + * endpoint is re-enabled by the application the core starts processing
  62840. + * 0 - from the DOEPDMA descriptor
  62841. + * 1 - from the descriptor which received the BNA.
  62842. + */
  62843. + int32_t cont_on_bna;
  62844. +
  62845. + /** GAHBCFG: AHB Single Support
  62846. + * This bit when programmed supports SINGLE transfers for remainder
  62847. + * data in a transfer for DMA mode of operation.
  62848. + * 0 - in this case the remainder data will be sent using INCR burst size.
  62849. + * 1 - in this case the remainder data will be sent using SINGLE burst size.
  62850. + */
  62851. + int32_t ahb_single;
  62852. +
  62853. + /** Core Power down mode
  62854. + * 0 - No Power Down is enabled
  62855. + * 1 - Reserved
  62856. + * 2 - Complete Power Down (Hibernation)
  62857. + */
  62858. + int32_t power_down;
  62859. +
  62860. + /** OTG revision supported
  62861. + * 0 - OTG 1.3 revision
  62862. + * 1 - OTG 2.0 revision
  62863. + */
  62864. + int32_t otg_ver;
  62865. +
  62866. +} dwc_otg_core_params_t;
  62867. +
  62868. +#ifdef DEBUG
  62869. +struct dwc_otg_core_if;
  62870. +typedef struct hc_xfer_info {
  62871. + struct dwc_otg_core_if *core_if;
  62872. + dwc_hc_t *hc;
  62873. +} hc_xfer_info_t;
  62874. +#endif
  62875. +
  62876. +typedef struct ep_xfer_info {
  62877. + struct dwc_otg_core_if *core_if;
  62878. + dwc_ep_t *ep;
  62879. + uint8_t state;
  62880. +} ep_xfer_info_t;
  62881. +/*
  62882. + * Device States
  62883. + */
  62884. +typedef enum dwc_otg_lx_state {
  62885. + /** On state */
  62886. + DWC_OTG_L0,
  62887. + /** LPM sleep state*/
  62888. + DWC_OTG_L1,
  62889. + /** USB suspend state*/
  62890. + DWC_OTG_L2,
  62891. + /** Off state*/
  62892. + DWC_OTG_L3
  62893. +} dwc_otg_lx_state_e;
  62894. +
  62895. +struct dwc_otg_global_regs_backup {
  62896. + uint32_t gotgctl_local;
  62897. + uint32_t gintmsk_local;
  62898. + uint32_t gahbcfg_local;
  62899. + uint32_t gusbcfg_local;
  62900. + uint32_t grxfsiz_local;
  62901. + uint32_t gnptxfsiz_local;
  62902. +#ifdef CONFIG_USB_DWC_OTG_LPM
  62903. + uint32_t glpmcfg_local;
  62904. +#endif
  62905. + uint32_t gi2cctl_local;
  62906. + uint32_t hptxfsiz_local;
  62907. + uint32_t pcgcctl_local;
  62908. + uint32_t gdfifocfg_local;
  62909. + uint32_t dtxfsiz_local[MAX_EPS_CHANNELS];
  62910. + uint32_t gpwrdn_local;
  62911. + uint32_t xhib_pcgcctl;
  62912. + uint32_t xhib_gpwrdn;
  62913. +};
  62914. +
  62915. +struct dwc_otg_host_regs_backup {
  62916. + uint32_t hcfg_local;
  62917. + uint32_t haintmsk_local;
  62918. + uint32_t hcintmsk_local[MAX_EPS_CHANNELS];
  62919. + uint32_t hprt0_local;
  62920. + uint32_t hfir_local;
  62921. +};
  62922. +
  62923. +struct dwc_otg_dev_regs_backup {
  62924. + uint32_t dcfg;
  62925. + uint32_t dctl;
  62926. + uint32_t daintmsk;
  62927. + uint32_t diepmsk;
  62928. + uint32_t doepmsk;
  62929. + uint32_t diepctl[MAX_EPS_CHANNELS];
  62930. + uint32_t dieptsiz[MAX_EPS_CHANNELS];
  62931. + uint32_t diepdma[MAX_EPS_CHANNELS];
  62932. +};
  62933. +/**
  62934. + * The <code>dwc_otg_core_if</code> structure contains information needed to manage
  62935. + * the DWC_otg controller acting in either host or device mode. It
  62936. + * represents the programming view of the controller as a whole.
  62937. + */
  62938. +struct dwc_otg_core_if {
  62939. + /** Parameters that define how the core should be configured.*/
  62940. + dwc_otg_core_params_t *core_params;
  62941. +
  62942. + /** Core Global registers starting at offset 000h. */
  62943. + dwc_otg_core_global_regs_t *core_global_regs;
  62944. +
  62945. + /** Device-specific information */
  62946. + dwc_otg_dev_if_t *dev_if;
  62947. + /** Host-specific information */
  62948. + dwc_otg_host_if_t *host_if;
  62949. +
  62950. + /** Value from SNPSID register */
  62951. + uint32_t snpsid;
  62952. +
  62953. + /*
  62954. + * Set to 1 if the core PHY interface bits in USBCFG have been
  62955. + * initialized.
  62956. + */
  62957. + uint8_t phy_init_done;
  62958. +
  62959. + /*
  62960. + * SRP Success flag, set by srp success interrupt in FS I2C mode
  62961. + */
  62962. + uint8_t srp_success;
  62963. + uint8_t srp_timer_started;
  62964. + /** Timer for SRP. If it expires before SRP is successful
  62965. + * clear the SRP. */
  62966. + dwc_timer_t *srp_timer;
  62967. +
  62968. +#ifdef DWC_DEV_SRPCAP
  62969. + /* This timer is needed to power on the hibernated host core if SRP is not
  62970. + * initiated on connected SRP capable device for limited period of time
  62971. + */
  62972. + uint8_t pwron_timer_started;
  62973. + dwc_timer_t *pwron_timer;
  62974. +#endif
  62975. + /* Common configuration information */
  62976. + /** Power and Clock Gating Control Register */
  62977. + volatile uint32_t *pcgcctl;
  62978. +#define DWC_OTG_PCGCCTL_OFFSET 0xE00
  62979. +
  62980. + /** Push/pop addresses for endpoints or host channels.*/
  62981. + uint32_t *data_fifo[MAX_EPS_CHANNELS];
  62982. +#define DWC_OTG_DATA_FIFO_OFFSET 0x1000
  62983. +#define DWC_OTG_DATA_FIFO_SIZE 0x1000
  62984. +
  62985. + /** Total RAM for FIFOs (Bytes) */
  62986. + uint16_t total_fifo_size;
  62987. + /** Size of Rx FIFO (Bytes) */
  62988. + uint16_t rx_fifo_size;
  62989. + /** Size of Non-periodic Tx FIFO (Bytes) */
  62990. + uint16_t nperio_tx_fifo_size;
  62991. +
  62992. + /** 1 if DMA is enabled, 0 otherwise. */
  62993. + uint8_t dma_enable;
  62994. +
  62995. + /** 1 if DMA descriptor is enabled, 0 otherwise. */
  62996. + uint8_t dma_desc_enable;
  62997. +
  62998. + /** 1 if PTI Enhancement mode is enabled, 0 otherwise. */
  62999. + uint8_t pti_enh_enable;
  63000. +
  63001. + /** 1 if MPI Enhancement mode is enabled, 0 otherwise. */
  63002. + uint8_t multiproc_int_enable;
  63003. +
  63004. + /** 1 if dedicated Tx FIFOs are enabled, 0 otherwise. */
  63005. + uint8_t en_multiple_tx_fifo;
  63006. +
  63007. + /** Set to 1 if multiple packets of a high-bandwidth transfer is in
  63008. + * process of being queued */
  63009. + uint8_t queuing_high_bandwidth;
  63010. +
  63011. + /** Hardware Configuration -- stored here for convenience.*/
  63012. + hwcfg1_data_t hwcfg1;
  63013. + hwcfg2_data_t hwcfg2;
  63014. + hwcfg3_data_t hwcfg3;
  63015. + hwcfg4_data_t hwcfg4;
  63016. + fifosize_data_t hptxfsiz;
  63017. +
  63018. + /** Host and Device Configuration -- stored here for convenience.*/
  63019. + hcfg_data_t hcfg;
  63020. + dcfg_data_t dcfg;
  63021. +
  63022. + /** The operational State, during transations
  63023. + * (a_host>>a_peripherial and b_device=>b_host) this may not
  63024. + * match the core but allows the software to determine
  63025. + * transitions.
  63026. + */
  63027. + uint8_t op_state;
  63028. +
  63029. + /**
  63030. + * Set to 1 if the HCD needs to be restarted on a session request
  63031. + * interrupt. This is required if no connector ID status change has
  63032. + * occurred since the HCD was last disconnected.
  63033. + */
  63034. + uint8_t restart_hcd_on_session_req;
  63035. +
  63036. + /** HCD callbacks */
  63037. + /** A-Device is a_host */
  63038. +#define A_HOST (1)
  63039. + /** A-Device is a_suspend */
  63040. +#define A_SUSPEND (2)
  63041. + /** A-Device is a_peripherial */
  63042. +#define A_PERIPHERAL (3)
  63043. + /** B-Device is operating as a Peripheral. */
  63044. +#define B_PERIPHERAL (4)
  63045. + /** B-Device is operating as a Host. */
  63046. +#define B_HOST (5)
  63047. +
  63048. + /** HCD callbacks */
  63049. + struct dwc_otg_cil_callbacks *hcd_cb;
  63050. + /** PCD callbacks */
  63051. + struct dwc_otg_cil_callbacks *pcd_cb;
  63052. +
  63053. + /** Device mode Periodic Tx FIFO Mask */
  63054. + uint32_t p_tx_msk;
  63055. + /** Device mode Periodic Tx FIFO Mask */
  63056. + uint32_t tx_msk;
  63057. +
  63058. + /** Workqueue object used for handling several interrupts */
  63059. + dwc_workq_t *wq_otg;
  63060. +
  63061. + /** Timer object used for handling "Wakeup Detected" Interrupt */
  63062. + dwc_timer_t *wkp_timer;
  63063. + /** This arrays used for debug purposes for DEV OUT NAK enhancement */
  63064. + uint32_t start_doeptsiz_val[MAX_EPS_CHANNELS];
  63065. + ep_xfer_info_t ep_xfer_info[MAX_EPS_CHANNELS];
  63066. + dwc_timer_t *ep_xfer_timer[MAX_EPS_CHANNELS];
  63067. +#ifdef DEBUG
  63068. + uint32_t start_hcchar_val[MAX_EPS_CHANNELS];
  63069. +
  63070. + hc_xfer_info_t hc_xfer_info[MAX_EPS_CHANNELS];
  63071. + dwc_timer_t *hc_xfer_timer[MAX_EPS_CHANNELS];
  63072. +
  63073. + uint32_t hfnum_7_samples;
  63074. + uint64_t hfnum_7_frrem_accum;
  63075. + uint32_t hfnum_0_samples;
  63076. + uint64_t hfnum_0_frrem_accum;
  63077. + uint32_t hfnum_other_samples;
  63078. + uint64_t hfnum_other_frrem_accum;
  63079. +#endif
  63080. +
  63081. +#ifdef DWC_UTE_CFI
  63082. + uint16_t pwron_rxfsiz;
  63083. + uint16_t pwron_gnptxfsiz;
  63084. + uint16_t pwron_txfsiz[15];
  63085. +
  63086. + uint16_t init_rxfsiz;
  63087. + uint16_t init_gnptxfsiz;
  63088. + uint16_t init_txfsiz[15];
  63089. +#endif
  63090. +
  63091. + /** Lx state of device */
  63092. + dwc_otg_lx_state_e lx_state;
  63093. +
  63094. + /** Saved Core Global registers */
  63095. + struct dwc_otg_global_regs_backup *gr_backup;
  63096. + /** Saved Host registers */
  63097. + struct dwc_otg_host_regs_backup *hr_backup;
  63098. + /** Saved Device registers */
  63099. + struct dwc_otg_dev_regs_backup *dr_backup;
  63100. +
  63101. + /** Power Down Enable */
  63102. + uint32_t power_down;
  63103. +
  63104. + /** ADP support Enable */
  63105. + uint32_t adp_enable;
  63106. +
  63107. + /** ADP structure object */
  63108. + dwc_otg_adp_t adp;
  63109. +
  63110. + /** hibernation/suspend flag */
  63111. + int hibernation_suspend;
  63112. +
  63113. + /** Device mode extended hibernation flag */
  63114. + int xhib;
  63115. +
  63116. + /** OTG revision supported */
  63117. + uint32_t otg_ver;
  63118. +
  63119. + /** OTG status flag used for HNP polling */
  63120. + uint8_t otg_sts;
  63121. +
  63122. + /** Pointer to either hcd->lock or pcd->lock */
  63123. + dwc_spinlock_t *lock;
  63124. +
  63125. + /** Start predict NextEP based on Learning Queue if equal 1,
  63126. + * also used as counter of disabled NP IN EP's */
  63127. + uint8_t start_predict;
  63128. +
  63129. + /** NextEp sequence, including EP0: nextep_seq[] = EP if non-periodic and
  63130. + * active, 0xff otherwise */
  63131. + uint8_t nextep_seq[MAX_EPS_CHANNELS];
  63132. +
  63133. + /** Index of fisrt EP in nextep_seq array which should be re-enabled **/
  63134. + uint8_t first_in_nextep_seq;
  63135. +
  63136. + /** Frame number while entering to ISR - needed for ISOCs **/
  63137. + uint32_t frame_num;
  63138. +
  63139. +};
  63140. +
  63141. +#ifdef DEBUG
  63142. +/*
  63143. + * This function is called when transfer is timed out.
  63144. + */
  63145. +extern void hc_xfer_timeout(void *ptr);
  63146. +#endif
  63147. +
  63148. +/*
  63149. + * This function is called when transfer is timed out on endpoint.
  63150. + */
  63151. +extern void ep_xfer_timeout(void *ptr);
  63152. +
  63153. +/*
  63154. + * The following functions are functions for works
  63155. + * using during handling some interrupts
  63156. + */
  63157. +extern void w_conn_id_status_change(void *p);
  63158. +
  63159. +extern void w_wakeup_detected(void *p);
  63160. +
  63161. +/** Saves global register values into system memory. */
  63162. +extern int dwc_otg_save_global_regs(dwc_otg_core_if_t * core_if);
  63163. +/** Saves device register values into system memory. */
  63164. +extern int dwc_otg_save_dev_regs(dwc_otg_core_if_t * core_if);
  63165. +/** Saves host register values into system memory. */
  63166. +extern int dwc_otg_save_host_regs(dwc_otg_core_if_t * core_if);
  63167. +/** Restore global register values. */
  63168. +extern int dwc_otg_restore_global_regs(dwc_otg_core_if_t * core_if);
  63169. +/** Restore host register values. */
  63170. +extern int dwc_otg_restore_host_regs(dwc_otg_core_if_t * core_if, int reset);
  63171. +/** Restore device register values. */
  63172. +extern int dwc_otg_restore_dev_regs(dwc_otg_core_if_t * core_if,
  63173. + int rem_wakeup);
  63174. +extern int restore_lpm_i2c_regs(dwc_otg_core_if_t * core_if);
  63175. +extern int restore_essential_regs(dwc_otg_core_if_t * core_if, int rmode,
  63176. + int is_host);
  63177. +
  63178. +extern int dwc_otg_host_hibernation_restore(dwc_otg_core_if_t * core_if,
  63179. + int restore_mode, int reset);
  63180. +extern int dwc_otg_device_hibernation_restore(dwc_otg_core_if_t * core_if,
  63181. + int rem_wakeup, int reset);
  63182. +
  63183. +/*
  63184. + * The following functions support initialization of the CIL driver component
  63185. + * and the DWC_otg controller.
  63186. + */
  63187. +extern void dwc_otg_core_host_init(dwc_otg_core_if_t * _core_if);
  63188. +extern void dwc_otg_core_dev_init(dwc_otg_core_if_t * _core_if);
  63189. +
  63190. +/** @name Device CIL Functions
  63191. + * The following functions support managing the DWC_otg controller in device
  63192. + * mode.
  63193. + */
  63194. +/**@{*/
  63195. +extern void dwc_otg_wakeup(dwc_otg_core_if_t * _core_if);
  63196. +extern void dwc_otg_read_setup_packet(dwc_otg_core_if_t * _core_if,
  63197. + uint32_t * _dest);
  63198. +extern uint32_t dwc_otg_get_frame_number(dwc_otg_core_if_t * _core_if);
  63199. +extern void dwc_otg_ep0_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63200. +extern void dwc_otg_ep_activate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63201. +extern void dwc_otg_ep_deactivate(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63202. +extern void dwc_otg_ep_start_transfer(dwc_otg_core_if_t * _core_if,
  63203. + dwc_ep_t * _ep);
  63204. +extern void dwc_otg_ep_start_zl_transfer(dwc_otg_core_if_t * _core_if,
  63205. + dwc_ep_t * _ep);
  63206. +extern void dwc_otg_ep0_start_transfer(dwc_otg_core_if_t * _core_if,
  63207. + dwc_ep_t * _ep);
  63208. +extern void dwc_otg_ep0_continue_transfer(dwc_otg_core_if_t * _core_if,
  63209. + dwc_ep_t * _ep);
  63210. +extern void dwc_otg_ep_write_packet(dwc_otg_core_if_t * _core_if,
  63211. + dwc_ep_t * _ep, int _dma);
  63212. +extern void dwc_otg_ep_set_stall(dwc_otg_core_if_t * _core_if, dwc_ep_t * _ep);
  63213. +extern void dwc_otg_ep_clear_stall(dwc_otg_core_if_t * _core_if,
  63214. + dwc_ep_t * _ep);
  63215. +extern void dwc_otg_enable_device_interrupts(dwc_otg_core_if_t * _core_if);
  63216. +
  63217. +#ifdef DWC_EN_ISOC
  63218. +extern void dwc_otg_iso_ep_start_frm_transfer(dwc_otg_core_if_t * core_if,
  63219. + dwc_ep_t * ep);
  63220. +extern void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  63221. + dwc_ep_t * ep);
  63222. +#endif /* DWC_EN_ISOC */
  63223. +/**@}*/
  63224. +
  63225. +/** @name Host CIL Functions
  63226. + * The following functions support managing the DWC_otg controller in host
  63227. + * mode.
  63228. + */
  63229. +/**@{*/
  63230. +extern void dwc_otg_hc_init(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63231. +extern void dwc_otg_hc_halt(dwc_otg_core_if_t * _core_if,
  63232. + dwc_hc_t * _hc, dwc_otg_halt_status_e _halt_status);
  63233. +extern void dwc_otg_hc_cleanup(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63234. +extern void dwc_otg_hc_start_transfer(dwc_otg_core_if_t * _core_if,
  63235. + dwc_hc_t * _hc);
  63236. +extern int dwc_otg_hc_continue_transfer(dwc_otg_core_if_t * _core_if,
  63237. + dwc_hc_t * _hc);
  63238. +extern void dwc_otg_hc_do_ping(dwc_otg_core_if_t * _core_if, dwc_hc_t * _hc);
  63239. +extern void dwc_otg_hc_write_packet(dwc_otg_core_if_t * _core_if,
  63240. + dwc_hc_t * _hc);
  63241. +extern void dwc_otg_enable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63242. +extern void dwc_otg_disable_host_interrupts(dwc_otg_core_if_t * _core_if);
  63243. +
  63244. +extern void dwc_otg_hc_start_transfer_ddma(dwc_otg_core_if_t * core_if,
  63245. + dwc_hc_t * hc);
  63246. +
  63247. +extern uint32_t calc_frame_interval(dwc_otg_core_if_t * core_if);
  63248. +
  63249. +/* Macro used to clear one channel interrupt */
  63250. +#define clear_hc_int(_hc_regs_, _intr_) \
  63251. +do { \
  63252. + hcint_data_t hcint_clear = {.d32 = 0}; \
  63253. + hcint_clear.b._intr_ = 1; \
  63254. + DWC_WRITE_REG32(&(_hc_regs_)->hcint, hcint_clear.d32); \
  63255. +} while (0)
  63256. +
  63257. +/*
  63258. + * Macro used to disable one channel interrupt. Channel interrupts are
  63259. + * disabled when the channel is halted or released by the interrupt handler.
  63260. + * There is no need to handle further interrupts of that type until the
  63261. + * channel is re-assigned. In fact, subsequent handling may cause crashes
  63262. + * because the channel structures are cleaned up when the channel is released.
  63263. + */
  63264. +#define disable_hc_int(_hc_regs_, _intr_) \
  63265. +do { \
  63266. + hcintmsk_data_t hcintmsk = {.d32 = 0}; \
  63267. + hcintmsk.b._intr_ = 1; \
  63268. + DWC_MODIFY_REG32(&(_hc_regs_)->hcintmsk, hcintmsk.d32, 0); \
  63269. +} while (0)
  63270. +
  63271. +/**
  63272. + * This function Reads HPRT0 in preparation to modify. It keeps the
  63273. + * WC bits 0 so that if they are read as 1, they won't clear when you
  63274. + * write it back
  63275. + */
  63276. +static inline uint32_t dwc_otg_read_hprt0(dwc_otg_core_if_t * _core_if)
  63277. +{
  63278. + hprt0_data_t hprt0;
  63279. + hprt0.d32 = DWC_READ_REG32(_core_if->host_if->hprt0);
  63280. + hprt0.b.prtena = 0;
  63281. + hprt0.b.prtconndet = 0;
  63282. + hprt0.b.prtenchng = 0;
  63283. + hprt0.b.prtovrcurrchng = 0;
  63284. + return hprt0.d32;
  63285. +}
  63286. +
  63287. +/**@}*/
  63288. +
  63289. +/** @name Common CIL Functions
  63290. + * The following functions support managing the DWC_otg controller in either
  63291. + * device or host mode.
  63292. + */
  63293. +/**@{*/
  63294. +
  63295. +extern void dwc_otg_read_packet(dwc_otg_core_if_t * core_if,
  63296. + uint8_t * dest, uint16_t bytes);
  63297. +
  63298. +extern void dwc_otg_flush_tx_fifo(dwc_otg_core_if_t * _core_if, const int _num);
  63299. +extern void dwc_otg_flush_rx_fifo(dwc_otg_core_if_t * _core_if);
  63300. +extern void dwc_otg_core_reset(dwc_otg_core_if_t * _core_if);
  63301. +
  63302. +/**
  63303. + * This function returns the Core Interrupt register.
  63304. + */
  63305. +static inline uint32_t dwc_otg_read_core_intr(dwc_otg_core_if_t * core_if)
  63306. +{
  63307. + return (DWC_READ_REG32(&core_if->core_global_regs->gintsts) &
  63308. + DWC_READ_REG32(&core_if->core_global_regs->gintmsk));
  63309. +}
  63310. +
  63311. +/**
  63312. + * This function returns the OTG Interrupt register.
  63313. + */
  63314. +static inline uint32_t dwc_otg_read_otg_intr(dwc_otg_core_if_t * core_if)
  63315. +{
  63316. + return (DWC_READ_REG32(&core_if->core_global_regs->gotgint));
  63317. +}
  63318. +
  63319. +/**
  63320. + * This function reads the Device All Endpoints Interrupt register and
  63321. + * returns the IN endpoint interrupt bits.
  63322. + */
  63323. +static inline uint32_t dwc_otg_read_dev_all_in_ep_intr(dwc_otg_core_if_t *
  63324. + core_if)
  63325. +{
  63326. +
  63327. + uint32_t v;
  63328. +
  63329. + if (core_if->multiproc_int_enable) {
  63330. + v = DWC_READ_REG32(&core_if->dev_if->
  63331. + dev_global_regs->deachint) &
  63332. + DWC_READ_REG32(&core_if->
  63333. + dev_if->dev_global_regs->deachintmsk);
  63334. + } else {
  63335. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63336. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63337. + }
  63338. + return (v & 0xffff);
  63339. +}
  63340. +
  63341. +/**
  63342. + * This function reads the Device All Endpoints Interrupt register and
  63343. + * returns the OUT endpoint interrupt bits.
  63344. + */
  63345. +static inline uint32_t dwc_otg_read_dev_all_out_ep_intr(dwc_otg_core_if_t *
  63346. + core_if)
  63347. +{
  63348. + uint32_t v;
  63349. +
  63350. + if (core_if->multiproc_int_enable) {
  63351. + v = DWC_READ_REG32(&core_if->dev_if->
  63352. + dev_global_regs->deachint) &
  63353. + DWC_READ_REG32(&core_if->
  63354. + dev_if->dev_global_regs->deachintmsk);
  63355. + } else {
  63356. + v = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daint) &
  63357. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->daintmsk);
  63358. + }
  63359. +
  63360. + return ((v & 0xffff0000) >> 16);
  63361. +}
  63362. +
  63363. +/**
  63364. + * This function returns the Device IN EP Interrupt register
  63365. + */
  63366. +static inline uint32_t dwc_otg_read_dev_in_ep_intr(dwc_otg_core_if_t * core_if,
  63367. + dwc_ep_t * ep)
  63368. +{
  63369. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  63370. + uint32_t v, msk, emp;
  63371. +
  63372. + if (core_if->multiproc_int_enable) {
  63373. + msk =
  63374. + DWC_READ_REG32(&dev_if->
  63375. + dev_global_regs->diepeachintmsk[ep->num]);
  63376. + emp =
  63377. + DWC_READ_REG32(&dev_if->
  63378. + dev_global_regs->dtknqr4_fifoemptymsk);
  63379. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63380. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63381. + } else {
  63382. + msk = DWC_READ_REG32(&dev_if->dev_global_regs->diepmsk);
  63383. + emp =
  63384. + DWC_READ_REG32(&dev_if->
  63385. + dev_global_regs->dtknqr4_fifoemptymsk);
  63386. + msk |= ((emp >> ep->num) & 0x1) << 7;
  63387. + v = DWC_READ_REG32(&dev_if->in_ep_regs[ep->num]->diepint) & msk;
  63388. + }
  63389. +
  63390. + return v;
  63391. +}
  63392. +
  63393. +/**
  63394. + * This function returns the Device OUT EP Interrupt register
  63395. + */
  63396. +static inline uint32_t dwc_otg_read_dev_out_ep_intr(dwc_otg_core_if_t *
  63397. + _core_if, dwc_ep_t * _ep)
  63398. +{
  63399. + dwc_otg_dev_if_t *dev_if = _core_if->dev_if;
  63400. + uint32_t v;
  63401. + doepmsk_data_t msk = {.d32 = 0 };
  63402. +
  63403. + if (_core_if->multiproc_int_enable) {
  63404. + msk.d32 =
  63405. + DWC_READ_REG32(&dev_if->
  63406. + dev_global_regs->doepeachintmsk[_ep->num]);
  63407. + if (_core_if->pti_enh_enable) {
  63408. + msk.b.pktdrpsts = 1;
  63409. + }
  63410. + v = DWC_READ_REG32(&dev_if->
  63411. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63412. + } else {
  63413. + msk.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->doepmsk);
  63414. + if (_core_if->pti_enh_enable) {
  63415. + msk.b.pktdrpsts = 1;
  63416. + }
  63417. + v = DWC_READ_REG32(&dev_if->
  63418. + out_ep_regs[_ep->num]->doepint) & msk.d32;
  63419. + }
  63420. + return v;
  63421. +}
  63422. +
  63423. +/**
  63424. + * This function returns the Host All Channel Interrupt register
  63425. + */
  63426. +static inline uint32_t dwc_otg_read_host_all_channels_intr(dwc_otg_core_if_t *
  63427. + _core_if)
  63428. +{
  63429. + return (DWC_READ_REG32(&_core_if->host_if->host_global_regs->haint));
  63430. +}
  63431. +
  63432. +static inline uint32_t dwc_otg_read_host_channel_intr(dwc_otg_core_if_t *
  63433. + _core_if, dwc_hc_t * _hc)
  63434. +{
  63435. + return (DWC_READ_REG32
  63436. + (&_core_if->host_if->hc_regs[_hc->hc_num]->hcint));
  63437. +}
  63438. +
  63439. +/**
  63440. + * This function returns the mode of the operation, host or device.
  63441. + *
  63442. + * @return 0 - Device Mode, 1 - Host Mode
  63443. + */
  63444. +static inline uint32_t dwc_otg_mode(dwc_otg_core_if_t * _core_if)
  63445. +{
  63446. + return (DWC_READ_REG32(&_core_if->core_global_regs->gintsts) & 0x1);
  63447. +}
  63448. +
  63449. +/**@}*/
  63450. +
  63451. +/**
  63452. + * DWC_otg CIL callback structure. This structure allows the HCD and
  63453. + * PCD to register functions used for starting and stopping the PCD
  63454. + * and HCD for role change on for a DRD.
  63455. + */
  63456. +typedef struct dwc_otg_cil_callbacks {
  63457. + /** Start function for role change */
  63458. + int (*start) (void *_p);
  63459. + /** Stop Function for role change */
  63460. + int (*stop) (void *_p);
  63461. + /** Disconnect Function for role change */
  63462. + int (*disconnect) (void *_p);
  63463. + /** Resume/Remote wakeup Function */
  63464. + int (*resume_wakeup) (void *_p);
  63465. + /** Suspend function */
  63466. + int (*suspend) (void *_p);
  63467. + /** Session Start (SRP) */
  63468. + int (*session_start) (void *_p);
  63469. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63470. + /** Sleep (switch to L0 state) */
  63471. + int (*sleep) (void *_p);
  63472. +#endif
  63473. + /** Pointer passed to start() and stop() */
  63474. + void *p;
  63475. +} dwc_otg_cil_callbacks_t;
  63476. +
  63477. +extern void dwc_otg_cil_register_pcd_callbacks(dwc_otg_core_if_t * _core_if,
  63478. + dwc_otg_cil_callbacks_t * _cb,
  63479. + void *_p);
  63480. +extern void dwc_otg_cil_register_hcd_callbacks(dwc_otg_core_if_t * _core_if,
  63481. + dwc_otg_cil_callbacks_t * _cb,
  63482. + void *_p);
  63483. +
  63484. +void dwc_otg_initiate_srp(dwc_otg_core_if_t * core_if);
  63485. +
  63486. +//////////////////////////////////////////////////////////////////////
  63487. +/** Start the HCD. Helper function for using the HCD callbacks.
  63488. + *
  63489. + * @param core_if Programming view of DWC_otg controller.
  63490. + */
  63491. +static inline void cil_hcd_start(dwc_otg_core_if_t * core_if)
  63492. +{
  63493. + if (core_if->hcd_cb && core_if->hcd_cb->start) {
  63494. + core_if->hcd_cb->start(core_if->hcd_cb->p);
  63495. + }
  63496. +}
  63497. +
  63498. +/** Stop the HCD. Helper function for using the HCD callbacks.
  63499. + *
  63500. + * @param core_if Programming view of DWC_otg controller.
  63501. + */
  63502. +static inline void cil_hcd_stop(dwc_otg_core_if_t * core_if)
  63503. +{
  63504. + if (core_if->hcd_cb && core_if->hcd_cb->stop) {
  63505. + core_if->hcd_cb->stop(core_if->hcd_cb->p);
  63506. + }
  63507. +}
  63508. +
  63509. +/** Disconnect the HCD. Helper function for using the HCD callbacks.
  63510. + *
  63511. + * @param core_if Programming view of DWC_otg controller.
  63512. + */
  63513. +static inline void cil_hcd_disconnect(dwc_otg_core_if_t * core_if)
  63514. +{
  63515. + if (core_if->hcd_cb && core_if->hcd_cb->disconnect) {
  63516. + core_if->hcd_cb->disconnect(core_if->hcd_cb->p);
  63517. + }
  63518. +}
  63519. +
  63520. +/** Inform the HCD the a New Session has begun. Helper function for
  63521. + * using the HCD callbacks.
  63522. + *
  63523. + * @param core_if Programming view of DWC_otg controller.
  63524. + */
  63525. +static inline void cil_hcd_session_start(dwc_otg_core_if_t * core_if)
  63526. +{
  63527. + if (core_if->hcd_cb && core_if->hcd_cb->session_start) {
  63528. + core_if->hcd_cb->session_start(core_if->hcd_cb->p);
  63529. + }
  63530. +}
  63531. +
  63532. +#ifdef CONFIG_USB_DWC_OTG_LPM
  63533. +/**
  63534. + * Inform the HCD about LPM sleep.
  63535. + * Helper function for using the HCD callbacks.
  63536. + *
  63537. + * @param core_if Programming view of DWC_otg controller.
  63538. + */
  63539. +static inline void cil_hcd_sleep(dwc_otg_core_if_t * core_if)
  63540. +{
  63541. + if (core_if->hcd_cb && core_if->hcd_cb->sleep) {
  63542. + core_if->hcd_cb->sleep(core_if->hcd_cb->p);
  63543. + }
  63544. +}
  63545. +#endif
  63546. +
  63547. +/** Resume the HCD. Helper function for using the HCD callbacks.
  63548. + *
  63549. + * @param core_if Programming view of DWC_otg controller.
  63550. + */
  63551. +static inline void cil_hcd_resume(dwc_otg_core_if_t * core_if)
  63552. +{
  63553. + if (core_if->hcd_cb && core_if->hcd_cb->resume_wakeup) {
  63554. + core_if->hcd_cb->resume_wakeup(core_if->hcd_cb->p);
  63555. + }
  63556. +}
  63557. +
  63558. +/** Start the PCD. Helper function for using the PCD callbacks.
  63559. + *
  63560. + * @param core_if Programming view of DWC_otg controller.
  63561. + */
  63562. +static inline void cil_pcd_start(dwc_otg_core_if_t * core_if)
  63563. +{
  63564. + if (core_if->pcd_cb && core_if->pcd_cb->start) {
  63565. + core_if->pcd_cb->start(core_if->pcd_cb->p);
  63566. + }
  63567. +}
  63568. +
  63569. +/** Stop the PCD. Helper function for using the PCD callbacks.
  63570. + *
  63571. + * @param core_if Programming view of DWC_otg controller.
  63572. + */
  63573. +static inline void cil_pcd_stop(dwc_otg_core_if_t * core_if)
  63574. +{
  63575. + if (core_if->pcd_cb && core_if->pcd_cb->stop) {
  63576. + core_if->pcd_cb->stop(core_if->pcd_cb->p);
  63577. + }
  63578. +}
  63579. +
  63580. +/** Suspend the PCD. Helper function for using the PCD callbacks.
  63581. + *
  63582. + * @param core_if Programming view of DWC_otg controller.
  63583. + */
  63584. +static inline void cil_pcd_suspend(dwc_otg_core_if_t * core_if)
  63585. +{
  63586. + if (core_if->pcd_cb && core_if->pcd_cb->suspend) {
  63587. + core_if->pcd_cb->suspend(core_if->pcd_cb->p);
  63588. + }
  63589. +}
  63590. +
  63591. +/** Resume the PCD. Helper function for using the PCD callbacks.
  63592. + *
  63593. + * @param core_if Programming view of DWC_otg controller.
  63594. + */
  63595. +static inline void cil_pcd_resume(dwc_otg_core_if_t * core_if)
  63596. +{
  63597. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  63598. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  63599. + }
  63600. +}
  63601. +
  63602. +//////////////////////////////////////////////////////////////////////
  63603. +
  63604. +#endif
  63605. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c
  63606. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 1970-01-01 01:00:00.000000000 +0100
  63607. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_cil_intr.c 2014-06-11 21:03:43.000000000 +0200
  63608. @@ -0,0 +1,1595 @@
  63609. +/* ==========================================================================
  63610. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_cil_intr.c $
  63611. + * $Revision: #32 $
  63612. + * $Date: 2012/08/10 $
  63613. + * $Change: 2047372 $
  63614. + *
  63615. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  63616. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  63617. + * otherwise expressly agreed to in writing between Synopsys and you.
  63618. + *
  63619. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  63620. + * any End User Software License Agreement or Agreement for Licensed Product
  63621. + * with Synopsys or any supplement thereto. You are permitted to use and
  63622. + * redistribute this Software in source and binary forms, with or without
  63623. + * modification, provided that redistributions of source code must retain this
  63624. + * notice. You may not view, use, disclose, copy or distribute this file or
  63625. + * any information contained herein except pursuant to this license grant from
  63626. + * Synopsys. If you do not agree with this notice, including the disclaimer
  63627. + * below, then you are not authorized to use the Software.
  63628. + *
  63629. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  63630. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  63631. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  63632. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  63633. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  63634. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  63635. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  63636. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  63637. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  63638. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  63639. + * DAMAGE.
  63640. + * ========================================================================== */
  63641. +
  63642. +/** @file
  63643. + *
  63644. + * The Core Interface Layer provides basic services for accessing and
  63645. + * managing the DWC_otg hardware. These services are used by both the
  63646. + * Host Controller Driver and the Peripheral Controller Driver.
  63647. + *
  63648. + * This file contains the Common Interrupt handlers.
  63649. + */
  63650. +#include "dwc_os.h"
  63651. +#include "dwc_otg_regs.h"
  63652. +#include "dwc_otg_cil.h"
  63653. +#include "dwc_otg_driver.h"
  63654. +#include "dwc_otg_pcd.h"
  63655. +#include "dwc_otg_hcd.h"
  63656. +
  63657. +#ifdef DEBUG
  63658. +inline const char *op_state_str(dwc_otg_core_if_t * core_if)
  63659. +{
  63660. + return (core_if->op_state == A_HOST ? "a_host" :
  63661. + (core_if->op_state == A_SUSPEND ? "a_suspend" :
  63662. + (core_if->op_state == A_PERIPHERAL ? "a_peripheral" :
  63663. + (core_if->op_state == B_PERIPHERAL ? "b_peripheral" :
  63664. + (core_if->op_state == B_HOST ? "b_host" : "unknown")))));
  63665. +}
  63666. +#endif
  63667. +
  63668. +/** This function will log a debug message
  63669. + *
  63670. + * @param core_if Programming view of DWC_otg controller.
  63671. + */
  63672. +int32_t dwc_otg_handle_mode_mismatch_intr(dwc_otg_core_if_t * core_if)
  63673. +{
  63674. + gintsts_data_t gintsts;
  63675. + DWC_WARN("Mode Mismatch Interrupt: currently in %s mode\n",
  63676. + dwc_otg_mode(core_if) ? "Host" : "Device");
  63677. +
  63678. + /* Clear interrupt */
  63679. + gintsts.d32 = 0;
  63680. + gintsts.b.modemismatch = 1;
  63681. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63682. + return 1;
  63683. +}
  63684. +
  63685. +/**
  63686. + * This function handles the OTG Interrupts. It reads the OTG
  63687. + * Interrupt Register (GOTGINT) to determine what interrupt has
  63688. + * occurred.
  63689. + *
  63690. + * @param core_if Programming view of DWC_otg controller.
  63691. + */
  63692. +int32_t dwc_otg_handle_otg_intr(dwc_otg_core_if_t * core_if)
  63693. +{
  63694. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  63695. + gotgint_data_t gotgint;
  63696. + gotgctl_data_t gotgctl;
  63697. + gintmsk_data_t gintmsk;
  63698. + gpwrdn_data_t gpwrdn;
  63699. +
  63700. + gotgint.d32 = DWC_READ_REG32(&global_regs->gotgint);
  63701. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63702. + DWC_DEBUGPL(DBG_CIL, "++OTG Interrupt gotgint=%0x [%s]\n", gotgint.d32,
  63703. + op_state_str(core_if));
  63704. +
  63705. + if (gotgint.b.sesenddet) {
  63706. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63707. + "Session End Detected++ (%s)\n",
  63708. + op_state_str(core_if));
  63709. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63710. +
  63711. + if (core_if->op_state == B_HOST) {
  63712. + cil_pcd_start(core_if);
  63713. + core_if->op_state = B_PERIPHERAL;
  63714. + } else {
  63715. + /* If not B_HOST and Device HNP still set. HNP
  63716. + * Did not succeed!*/
  63717. + if (gotgctl.b.devhnpen) {
  63718. + DWC_DEBUGPL(DBG_ANY, "Session End Detected\n");
  63719. + __DWC_ERROR("Device Not Connected/Responding!\n");
  63720. + }
  63721. +
  63722. + /* If Session End Detected the B-Cable has
  63723. + * been disconnected. */
  63724. + /* Reset PCD and Gadget driver to a
  63725. + * clean state. */
  63726. + core_if->lx_state = DWC_OTG_L0;
  63727. + DWC_SPINUNLOCK(core_if->lock);
  63728. + cil_pcd_stop(core_if);
  63729. + DWC_SPINLOCK(core_if->lock);
  63730. +
  63731. + if (core_if->adp_enable) {
  63732. + if (core_if->power_down == 2) {
  63733. + gpwrdn.d32 = 0;
  63734. + gpwrdn.b.pwrdnswtch = 1;
  63735. + DWC_MODIFY_REG32(&core_if->
  63736. + core_global_regs->
  63737. + gpwrdn, gpwrdn.d32, 0);
  63738. + }
  63739. +
  63740. + gpwrdn.d32 = 0;
  63741. + gpwrdn.b.pmuintsel = 1;
  63742. + gpwrdn.b.pmuactv = 1;
  63743. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  63744. + gpwrdn, 0, gpwrdn.d32);
  63745. +
  63746. + dwc_otg_adp_sense_start(core_if);
  63747. + }
  63748. + }
  63749. +
  63750. + gotgctl.d32 = 0;
  63751. + gotgctl.b.devhnpen = 1;
  63752. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63753. + }
  63754. + if (gotgint.b.sesreqsucstschng) {
  63755. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63756. + "Session Reqeust Success Status Change++\n");
  63757. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63758. + if (gotgctl.b.sesreqscs) {
  63759. +
  63760. + if ((core_if->core_params->phy_type ==
  63761. + DWC_PHY_TYPE_PARAM_FS) && (core_if->core_params->i2c_enable)) {
  63762. + core_if->srp_success = 1;
  63763. + } else {
  63764. + DWC_SPINUNLOCK(core_if->lock);
  63765. + cil_pcd_resume(core_if);
  63766. + DWC_SPINLOCK(core_if->lock);
  63767. + /* Clear Session Request */
  63768. + gotgctl.d32 = 0;
  63769. + gotgctl.b.sesreq = 1;
  63770. + DWC_MODIFY_REG32(&global_regs->gotgctl,
  63771. + gotgctl.d32, 0);
  63772. + }
  63773. + }
  63774. + }
  63775. + if (gotgint.b.hstnegsucstschng) {
  63776. + /* Print statements during the HNP interrupt handling
  63777. + * can cause it to fail.*/
  63778. + gotgctl.d32 = DWC_READ_REG32(&global_regs->gotgctl);
  63779. + /* WA for 3.00a- HW is not setting cur_mode, even sometimes
  63780. + * this does not help*/
  63781. + if (core_if->snpsid >= OTG_CORE_REV_3_00a)
  63782. + dwc_udelay(100);
  63783. + if (gotgctl.b.hstnegscs) {
  63784. + if (dwc_otg_is_host_mode(core_if)) {
  63785. + core_if->op_state = B_HOST;
  63786. + /*
  63787. + * Need to disable SOF interrupt immediately.
  63788. + * When switching from device to host, the PCD
  63789. + * interrupt handler won't handle the
  63790. + * interrupt if host mode is already set. The
  63791. + * HCD interrupt handler won't get called if
  63792. + * the HCD state is HALT. This means that the
  63793. + * interrupt does not get handled and Linux
  63794. + * complains loudly.
  63795. + */
  63796. + gintmsk.d32 = 0;
  63797. + gintmsk.b.sofintr = 1;
  63798. + DWC_MODIFY_REG32(&global_regs->gintmsk,
  63799. + gintmsk.d32, 0);
  63800. + /* Call callback function with spin lock released */
  63801. + DWC_SPINUNLOCK(core_if->lock);
  63802. + cil_pcd_stop(core_if);
  63803. + /*
  63804. + * Initialize the Core for Host mode.
  63805. + */
  63806. + cil_hcd_start(core_if);
  63807. + DWC_SPINLOCK(core_if->lock);
  63808. + core_if->op_state = B_HOST;
  63809. + }
  63810. + } else {
  63811. + gotgctl.d32 = 0;
  63812. + gotgctl.b.hnpreq = 1;
  63813. + gotgctl.b.devhnpen = 1;
  63814. + DWC_MODIFY_REG32(&global_regs->gotgctl, gotgctl.d32, 0);
  63815. + DWC_DEBUGPL(DBG_ANY, "HNP Failed\n");
  63816. + __DWC_ERROR("Device Not Connected/Responding\n");
  63817. + }
  63818. + }
  63819. + if (gotgint.b.hstnegdet) {
  63820. + /* The disconnect interrupt is set at the same time as
  63821. + * Host Negotiation Detected. During the mode
  63822. + * switch all interrupts are cleared so the disconnect
  63823. + * interrupt handler will not get executed.
  63824. + */
  63825. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63826. + "Host Negotiation Detected++ (%s)\n",
  63827. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63828. + "Device"));
  63829. + if (dwc_otg_is_device_mode(core_if)) {
  63830. + DWC_DEBUGPL(DBG_ANY, "a_suspend->a_peripheral (%d)\n",
  63831. + core_if->op_state);
  63832. + DWC_SPINUNLOCK(core_if->lock);
  63833. + cil_hcd_disconnect(core_if);
  63834. + cil_pcd_start(core_if);
  63835. + DWC_SPINLOCK(core_if->lock);
  63836. + core_if->op_state = A_PERIPHERAL;
  63837. + } else {
  63838. + /*
  63839. + * Need to disable SOF interrupt immediately. When
  63840. + * switching from device to host, the PCD interrupt
  63841. + * handler won't handle the interrupt if host mode is
  63842. + * already set. The HCD interrupt handler won't get
  63843. + * called if the HCD state is HALT. This means that
  63844. + * the interrupt does not get handled and Linux
  63845. + * complains loudly.
  63846. + */
  63847. + gintmsk.d32 = 0;
  63848. + gintmsk.b.sofintr = 1;
  63849. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmsk.d32, 0);
  63850. + DWC_SPINUNLOCK(core_if->lock);
  63851. + cil_pcd_stop(core_if);
  63852. + cil_hcd_start(core_if);
  63853. + DWC_SPINLOCK(core_if->lock);
  63854. + core_if->op_state = A_HOST;
  63855. + }
  63856. + }
  63857. + if (gotgint.b.adevtoutchng) {
  63858. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: "
  63859. + "A-Device Timeout Change++\n");
  63860. + }
  63861. + if (gotgint.b.debdone) {
  63862. + DWC_DEBUGPL(DBG_ANY, " ++OTG Interrupt: " "Debounce Done++\n");
  63863. + }
  63864. +
  63865. + /* Clear GOTGINT */
  63866. + DWC_WRITE_REG32(&core_if->core_global_regs->gotgint, gotgint.d32);
  63867. +
  63868. + return 1;
  63869. +}
  63870. +
  63871. +void w_conn_id_status_change(void *p)
  63872. +{
  63873. + dwc_otg_core_if_t *core_if = p;
  63874. + uint32_t count = 0;
  63875. + gotgctl_data_t gotgctl = {.d32 = 0 };
  63876. +
  63877. + gotgctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  63878. + DWC_DEBUGPL(DBG_CIL, "gotgctl=%0x\n", gotgctl.d32);
  63879. + DWC_DEBUGPL(DBG_CIL, "gotgctl.b.conidsts=%d\n", gotgctl.b.conidsts);
  63880. +
  63881. + /* B-Device connector (Device Mode) */
  63882. + if (gotgctl.b.conidsts) {
  63883. + /* Wait for switch to device mode. */
  63884. + while (!dwc_otg_is_device_mode(core_if)) {
  63885. + DWC_PRINTF("Waiting for Peripheral Mode, Mode=%s\n",
  63886. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63887. + "Peripheral"));
  63888. + dwc_mdelay(100);
  63889. + if (++count > 10000)
  63890. + break;
  63891. + }
  63892. + DWC_ASSERT(++count < 10000,
  63893. + "Connection id status change timed out");
  63894. + core_if->op_state = B_PERIPHERAL;
  63895. + dwc_otg_core_init(core_if);
  63896. + dwc_otg_enable_global_interrupts(core_if);
  63897. + cil_pcd_start(core_if);
  63898. + } else {
  63899. + /* A-Device connector (Host Mode) */
  63900. + while (!dwc_otg_is_host_mode(core_if)) {
  63901. + DWC_PRINTF("Waiting for Host Mode, Mode=%s\n",
  63902. + (dwc_otg_is_host_mode(core_if) ? "Host" :
  63903. + "Peripheral"));
  63904. + dwc_mdelay(100);
  63905. + if (++count > 10000)
  63906. + break;
  63907. + }
  63908. + DWC_ASSERT(++count < 10000,
  63909. + "Connection id status change timed out");
  63910. + core_if->op_state = A_HOST;
  63911. + /*
  63912. + * Initialize the Core for Host mode.
  63913. + */
  63914. + dwc_otg_core_init(core_if);
  63915. + dwc_otg_enable_global_interrupts(core_if);
  63916. + cil_hcd_start(core_if);
  63917. + }
  63918. +}
  63919. +
  63920. +/**
  63921. + * This function handles the Connector ID Status Change Interrupt. It
  63922. + * reads the OTG Interrupt Register (GOTCTL) to determine whether this
  63923. + * is a Device to Host Mode transition or a Host Mode to Device
  63924. + * Transition.
  63925. + *
  63926. + * This only occurs when the cable is connected/removed from the PHY
  63927. + * connector.
  63928. + *
  63929. + * @param core_if Programming view of DWC_otg controller.
  63930. + */
  63931. +int32_t dwc_otg_handle_conn_id_status_change_intr(dwc_otg_core_if_t * core_if)
  63932. +{
  63933. +
  63934. + /*
  63935. + * Need to disable SOF interrupt immediately. If switching from device
  63936. + * to host, the PCD interrupt handler won't handle the interrupt if
  63937. + * host mode is already set. The HCD interrupt handler won't get
  63938. + * called if the HCD state is HALT. This means that the interrupt does
  63939. + * not get handled and Linux complains loudly.
  63940. + */
  63941. + gintmsk_data_t gintmsk = {.d32 = 0 };
  63942. + gintsts_data_t gintsts = {.d32 = 0 };
  63943. +
  63944. + gintmsk.b.sofintr = 1;
  63945. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  63946. +
  63947. + DWC_DEBUGPL(DBG_CIL,
  63948. + " ++Connector ID Status Change Interrupt++ (%s)\n",
  63949. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"));
  63950. +
  63951. + DWC_SPINUNLOCK(core_if->lock);
  63952. +
  63953. + /*
  63954. + * Need to schedule a work, as there are possible DELAY function calls
  63955. + * Release lock before scheduling workq as it holds spinlock during scheduling
  63956. + */
  63957. +
  63958. + DWC_WORKQ_SCHEDULE(core_if->wq_otg, w_conn_id_status_change,
  63959. + core_if, "connection id status change");
  63960. + DWC_SPINLOCK(core_if->lock);
  63961. +
  63962. + /* Set flag and clear interrupt */
  63963. + gintsts.b.conidstschng = 1;
  63964. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  63965. +
  63966. + return 1;
  63967. +}
  63968. +
  63969. +/**
  63970. + * This interrupt indicates that a device is initiating the Session
  63971. + * Request Protocol to request the host to turn on bus power so a new
  63972. + * session can begin. The handler responds by turning on bus power. If
  63973. + * the DWC_otg controller is in low power mode, the handler brings the
  63974. + * controller out of low power mode before turning on bus power.
  63975. + *
  63976. + * @param core_if Programming view of DWC_otg controller.
  63977. + */
  63978. +int32_t dwc_otg_handle_session_req_intr(dwc_otg_core_if_t * core_if)
  63979. +{
  63980. + gintsts_data_t gintsts;
  63981. +
  63982. +#ifndef DWC_HOST_ONLY
  63983. + DWC_DEBUGPL(DBG_ANY, "++Session Request Interrupt++\n");
  63984. +
  63985. + if (dwc_otg_is_device_mode(core_if)) {
  63986. + DWC_PRINTF("SRP: Device mode\n");
  63987. + } else {
  63988. + hprt0_data_t hprt0;
  63989. + DWC_PRINTF("SRP: Host mode\n");
  63990. +
  63991. + /* Turn on the port power bit. */
  63992. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  63993. + hprt0.b.prtpwr = 1;
  63994. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  63995. +
  63996. + /* Start the Connection timer. So a message can be displayed
  63997. + * if connect does not occur within 10 seconds. */
  63998. + cil_hcd_session_start(core_if);
  63999. + }
  64000. +#endif
  64001. +
  64002. + /* Clear interrupt */
  64003. + gintsts.d32 = 0;
  64004. + gintsts.b.sessreqintr = 1;
  64005. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64006. +
  64007. + return 1;
  64008. +}
  64009. +
  64010. +void w_wakeup_detected(void *p)
  64011. +{
  64012. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) p;
  64013. + /*
  64014. + * Clear the Resume after 70ms. (Need 20 ms minimum. Use 70 ms
  64015. + * so that OPT tests pass with all PHYs).
  64016. + */
  64017. + hprt0_data_t hprt0 = {.d32 = 0 };
  64018. +#if 0
  64019. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64020. + /* Restart the Phy Clock */
  64021. + pcgcctl.b.stoppclk = 1;
  64022. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64023. + dwc_udelay(10);
  64024. +#endif //0
  64025. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  64026. + DWC_DEBUGPL(DBG_ANY, "Resume: HPRT0=%0x\n", hprt0.d32);
  64027. +// dwc_mdelay(70);
  64028. + hprt0.b.prtres = 0; /* Resume */
  64029. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  64030. + DWC_DEBUGPL(DBG_ANY, "Clear Resume: HPRT0=%0x\n",
  64031. + DWC_READ_REG32(core_if->host_if->hprt0));
  64032. +
  64033. + cil_hcd_resume(core_if);
  64034. +
  64035. + /** Change to L0 state*/
  64036. + core_if->lx_state = DWC_OTG_L0;
  64037. +}
  64038. +
  64039. +/**
  64040. + * This interrupt indicates that the DWC_otg controller has detected a
  64041. + * resume or remote wakeup sequence. If the DWC_otg controller is in
  64042. + * low power mode, the handler must brings the controller out of low
  64043. + * power mode. The controller automatically begins resume
  64044. + * signaling. The handler schedules a time to stop resume signaling.
  64045. + */
  64046. +int32_t dwc_otg_handle_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64047. +{
  64048. + gintsts_data_t gintsts;
  64049. +
  64050. + DWC_DEBUGPL(DBG_ANY,
  64051. + "++Resume and Remote Wakeup Detected Interrupt++\n");
  64052. +
  64053. + DWC_PRINTF("%s lxstate = %d\n", __func__, core_if->lx_state);
  64054. +
  64055. + if (dwc_otg_is_device_mode(core_if)) {
  64056. + dctl_data_t dctl = {.d32 = 0 };
  64057. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n",
  64058. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->
  64059. + dsts));
  64060. + if (core_if->lx_state == DWC_OTG_L2) {
  64061. +#ifdef PARTIAL_POWER_DOWN
  64062. + if (core_if->hwcfg4.b.power_optimiz) {
  64063. + pcgcctl_data_t power = {.d32 = 0 };
  64064. +
  64065. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64066. + DWC_DEBUGPL(DBG_CIL, "PCGCCTL=%0x\n",
  64067. + power.d32);
  64068. +
  64069. + power.b.stoppclk = 0;
  64070. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64071. +
  64072. + power.b.pwrclmp = 0;
  64073. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64074. +
  64075. + power.b.rstpdwnmodule = 0;
  64076. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64077. + }
  64078. +#endif
  64079. + /* Clear the Remote Wakeup Signaling */
  64080. + dctl.b.rmtwkupsig = 1;
  64081. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  64082. + dctl, dctl.d32, 0);
  64083. +
  64084. + DWC_SPINUNLOCK(core_if->lock);
  64085. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  64086. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  64087. + }
  64088. + DWC_SPINLOCK(core_if->lock);
  64089. + } else {
  64090. + glpmcfg_data_t lpmcfg;
  64091. + lpmcfg.d32 =
  64092. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64093. + lpmcfg.b.hird_thres &= (~(1 << 4));
  64094. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64095. + lpmcfg.d32);
  64096. + }
  64097. + /** Change to L0 state*/
  64098. + core_if->lx_state = DWC_OTG_L0;
  64099. + } else {
  64100. + if (core_if->lx_state != DWC_OTG_L1) {
  64101. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64102. +
  64103. + /* Restart the Phy Clock */
  64104. + pcgcctl.b.stoppclk = 1;
  64105. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  64106. + DWC_TIMER_SCHEDULE(core_if->wkp_timer, 71);
  64107. + } else {
  64108. + /** Change to L0 state*/
  64109. + core_if->lx_state = DWC_OTG_L0;
  64110. + }
  64111. + }
  64112. +
  64113. + /* Clear interrupt */
  64114. + gintsts.d32 = 0;
  64115. + gintsts.b.wkupintr = 1;
  64116. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64117. +
  64118. + return 1;
  64119. +}
  64120. +
  64121. +/**
  64122. + * This interrupt indicates that the Wakeup Logic has detected a
  64123. + * Device disconnect.
  64124. + */
  64125. +static int32_t dwc_otg_handle_pwrdn_disconnect_intr(dwc_otg_core_if_t *core_if)
  64126. +{
  64127. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64128. + gpwrdn_data_t gpwrdn_temp = { .d32 = 0 };
  64129. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64130. +
  64131. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64132. +
  64133. + if (!core_if->hibernation_suspend) {
  64134. + DWC_PRINTF("Already exited from Hibernation\n");
  64135. + return 1;
  64136. + }
  64137. +
  64138. + /* Switch on the voltage to the core */
  64139. + gpwrdn.b.pwrdnswtch = 1;
  64140. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64141. + dwc_udelay(10);
  64142. +
  64143. + /* Reset the core */
  64144. + gpwrdn.d32 = 0;
  64145. + gpwrdn.b.pwrdnrstn = 1;
  64146. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64147. + dwc_udelay(10);
  64148. +
  64149. + /* Disable power clamps*/
  64150. + gpwrdn.d32 = 0;
  64151. + gpwrdn.b.pwrdnclmp = 1;
  64152. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64153. +
  64154. + /* Remove reset the core signal */
  64155. + gpwrdn.d32 = 0;
  64156. + gpwrdn.b.pwrdnrstn = 1;
  64157. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64158. + dwc_udelay(10);
  64159. +
  64160. + /* Disable PMU interrupt */
  64161. + gpwrdn.d32 = 0;
  64162. + gpwrdn.b.pmuintsel = 1;
  64163. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64164. +
  64165. + core_if->hibernation_suspend = 0;
  64166. +
  64167. + /* Disable PMU */
  64168. + gpwrdn.d32 = 0;
  64169. + gpwrdn.b.pmuactv = 1;
  64170. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64171. + dwc_udelay(10);
  64172. +
  64173. + if (gpwrdn_temp.b.idsts) {
  64174. + core_if->op_state = B_PERIPHERAL;
  64175. + dwc_otg_core_init(core_if);
  64176. + dwc_otg_enable_global_interrupts(core_if);
  64177. + cil_pcd_start(core_if);
  64178. + } else {
  64179. + core_if->op_state = A_HOST;
  64180. + dwc_otg_core_init(core_if);
  64181. + dwc_otg_enable_global_interrupts(core_if);
  64182. + cil_hcd_start(core_if);
  64183. + }
  64184. +
  64185. + return 1;
  64186. +}
  64187. +
  64188. +/**
  64189. + * This interrupt indicates that the Wakeup Logic has detected a
  64190. + * remote wakeup sequence.
  64191. + */
  64192. +static int32_t dwc_otg_handle_pwrdn_wakeup_detected_intr(dwc_otg_core_if_t * core_if)
  64193. +{
  64194. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64195. + DWC_DEBUGPL(DBG_ANY,
  64196. + "++Powerdown Remote Wakeup Detected Interrupt++\n");
  64197. +
  64198. + if (!core_if->hibernation_suspend) {
  64199. + DWC_PRINTF("Already exited from Hibernation\n");
  64200. + return 1;
  64201. + }
  64202. +
  64203. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64204. + if (gpwrdn.b.idsts) { // Device Mode
  64205. + if ((core_if->power_down == 2)
  64206. + && (core_if->hibernation_suspend == 1)) {
  64207. + dwc_otg_device_hibernation_restore(core_if, 0, 0);
  64208. + }
  64209. + } else {
  64210. + if ((core_if->power_down == 2)
  64211. + && (core_if->hibernation_suspend == 1)) {
  64212. + dwc_otg_host_hibernation_restore(core_if, 1, 0);
  64213. + }
  64214. + }
  64215. + return 1;
  64216. +}
  64217. +
  64218. +static int32_t dwc_otg_handle_pwrdn_idsts_change(dwc_otg_device_t *otg_dev)
  64219. +{
  64220. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64221. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64222. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64223. +
  64224. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64225. + gpwrdn_temp.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64226. + if (core_if->power_down == 2) {
  64227. + if (!core_if->hibernation_suspend) {
  64228. + DWC_PRINTF("Already exited from Hibernation\n");
  64229. + return 1;
  64230. + }
  64231. + DWC_DEBUGPL(DBG_ANY, "Exit from hibernation on ID sts change\n");
  64232. + /* Switch on the voltage to the core */
  64233. + gpwrdn.b.pwrdnswtch = 1;
  64234. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64235. + dwc_udelay(10);
  64236. +
  64237. + /* Reset the core */
  64238. + gpwrdn.d32 = 0;
  64239. + gpwrdn.b.pwrdnrstn = 1;
  64240. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64241. + dwc_udelay(10);
  64242. +
  64243. + /* Disable power clamps */
  64244. + gpwrdn.d32 = 0;
  64245. + gpwrdn.b.pwrdnclmp = 1;
  64246. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64247. +
  64248. + /* Remove reset the core signal */
  64249. + gpwrdn.d32 = 0;
  64250. + gpwrdn.b.pwrdnrstn = 1;
  64251. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64252. + dwc_udelay(10);
  64253. +
  64254. + /* Disable PMU interrupt */
  64255. + gpwrdn.d32 = 0;
  64256. + gpwrdn.b.pmuintsel = 1;
  64257. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64258. +
  64259. + /*Indicates that we are exiting from hibernation */
  64260. + core_if->hibernation_suspend = 0;
  64261. +
  64262. + /* Disable PMU */
  64263. + gpwrdn.d32 = 0;
  64264. + gpwrdn.b.pmuactv = 1;
  64265. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64266. + dwc_udelay(10);
  64267. +
  64268. + gpwrdn.d32 = core_if->gr_backup->gpwrdn_local;
  64269. + if (gpwrdn.b.dis_vbus == 1) {
  64270. + gpwrdn.d32 = 0;
  64271. + gpwrdn.b.dis_vbus = 1;
  64272. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64273. + }
  64274. +
  64275. + if (gpwrdn_temp.b.idsts) {
  64276. + core_if->op_state = B_PERIPHERAL;
  64277. + dwc_otg_core_init(core_if);
  64278. + dwc_otg_enable_global_interrupts(core_if);
  64279. + cil_pcd_start(core_if);
  64280. + } else {
  64281. + core_if->op_state = A_HOST;
  64282. + dwc_otg_core_init(core_if);
  64283. + dwc_otg_enable_global_interrupts(core_if);
  64284. + cil_hcd_start(core_if);
  64285. + }
  64286. + }
  64287. +
  64288. + if (core_if->adp_enable) {
  64289. + uint8_t is_host = 0;
  64290. + DWC_SPINUNLOCK(core_if->lock);
  64291. + /* Change the core_if's lock to hcd/pcd lock depend on mode? */
  64292. +#ifndef DWC_HOST_ONLY
  64293. + if (gpwrdn_temp.b.idsts)
  64294. + core_if->lock = otg_dev->pcd->lock;
  64295. +#endif
  64296. +#ifndef DWC_DEVICE_ONLY
  64297. + if (!gpwrdn_temp.b.idsts) {
  64298. + core_if->lock = otg_dev->hcd->lock;
  64299. + is_host = 1;
  64300. + }
  64301. +#endif
  64302. + DWC_PRINTF("RESTART ADP\n");
  64303. + if (core_if->adp.probe_enabled)
  64304. + dwc_otg_adp_probe_stop(core_if);
  64305. + if (core_if->adp.sense_enabled)
  64306. + dwc_otg_adp_sense_stop(core_if);
  64307. + if (core_if->adp.sense_timer_started)
  64308. + DWC_TIMER_CANCEL(core_if->adp.sense_timer);
  64309. + if (core_if->adp.vbuson_timer_started)
  64310. + DWC_TIMER_CANCEL(core_if->adp.vbuson_timer);
  64311. + core_if->adp.probe_timer_values[0] = -1;
  64312. + core_if->adp.probe_timer_values[1] = -1;
  64313. + core_if->adp.sense_timer_started = 0;
  64314. + core_if->adp.vbuson_timer_started = 0;
  64315. + core_if->adp.probe_counter = 0;
  64316. + core_if->adp.gpwrdn = 0;
  64317. +
  64318. + /* Disable PMU and restart ADP */
  64319. + gpwrdn_temp.d32 = 0;
  64320. + gpwrdn_temp.b.pmuactv = 1;
  64321. + gpwrdn_temp.b.pmuintsel = 1;
  64322. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64323. + DWC_PRINTF("Check point 1\n");
  64324. + dwc_mdelay(110);
  64325. + dwc_otg_adp_start(core_if, is_host);
  64326. + DWC_SPINLOCK(core_if->lock);
  64327. + }
  64328. +
  64329. +
  64330. + return 1;
  64331. +}
  64332. +
  64333. +static int32_t dwc_otg_handle_pwrdn_session_change(dwc_otg_core_if_t * core_if)
  64334. +{
  64335. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64336. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  64337. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64338. +
  64339. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64340. + if (core_if->power_down == 2) {
  64341. + if (!core_if->hibernation_suspend) {
  64342. + DWC_PRINTF("Already exited from Hibernation\n");
  64343. + return 1;
  64344. + }
  64345. +
  64346. + if ((otg_cap_param != DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64347. + otg_cap_param != DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) &&
  64348. + gpwrdn.b.bsessvld == 0) {
  64349. + /* Save gpwrdn register for further usage if stschng interrupt */
  64350. + core_if->gr_backup->gpwrdn_local =
  64351. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64352. + /*Exit from ISR and wait for stschng interrupt with bsessvld = 1 */
  64353. + return 1;
  64354. + }
  64355. +
  64356. + /* Switch on the voltage to the core */
  64357. + gpwrdn.d32 = 0;
  64358. + gpwrdn.b.pwrdnswtch = 1;
  64359. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64360. + dwc_udelay(10);
  64361. +
  64362. + /* Reset the core */
  64363. + gpwrdn.d32 = 0;
  64364. + gpwrdn.b.pwrdnrstn = 1;
  64365. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64366. + dwc_udelay(10);
  64367. +
  64368. + /* Disable power clamps */
  64369. + gpwrdn.d32 = 0;
  64370. + gpwrdn.b.pwrdnclmp = 1;
  64371. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64372. +
  64373. + /* Remove reset the core signal */
  64374. + gpwrdn.d32 = 0;
  64375. + gpwrdn.b.pwrdnrstn = 1;
  64376. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64377. + dwc_udelay(10);
  64378. +
  64379. + /* Disable PMU interrupt */
  64380. + gpwrdn.d32 = 0;
  64381. + gpwrdn.b.pmuintsel = 1;
  64382. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64383. + dwc_udelay(10);
  64384. +
  64385. + /*Indicates that we are exiting from hibernation */
  64386. + core_if->hibernation_suspend = 0;
  64387. +
  64388. + /* Disable PMU */
  64389. + gpwrdn.d32 = 0;
  64390. + gpwrdn.b.pmuactv = 1;
  64391. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64392. + dwc_udelay(10);
  64393. +
  64394. + core_if->op_state = B_PERIPHERAL;
  64395. + dwc_otg_core_init(core_if);
  64396. + dwc_otg_enable_global_interrupts(core_if);
  64397. + cil_pcd_start(core_if);
  64398. +
  64399. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE ||
  64400. + otg_cap_param == DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE) {
  64401. + /*
  64402. + * Initiate SRP after initial ADP probe.
  64403. + */
  64404. + dwc_otg_initiate_srp(core_if);
  64405. + }
  64406. + }
  64407. +
  64408. + return 1;
  64409. +}
  64410. +/**
  64411. + * This interrupt indicates that the Wakeup Logic has detected a
  64412. + * status change either on IDDIG or BSessVld.
  64413. + */
  64414. +static uint32_t dwc_otg_handle_pwrdn_stschng_intr(dwc_otg_device_t *otg_dev)
  64415. +{
  64416. + int retval;
  64417. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64418. + gpwrdn_data_t gpwrdn_temp = {.d32 = 0 };
  64419. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  64420. +
  64421. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64422. +
  64423. + if (core_if->power_down == 2) {
  64424. + if (core_if->hibernation_suspend <= 0) {
  64425. + DWC_PRINTF("Already exited from Hibernation\n");
  64426. + return 1;
  64427. + } else
  64428. + gpwrdn_temp.d32 = core_if->gr_backup->gpwrdn_local;
  64429. +
  64430. + } else {
  64431. + gpwrdn_temp.d32 = core_if->adp.gpwrdn;
  64432. + }
  64433. +
  64434. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64435. +
  64436. + if (gpwrdn.b.idsts ^ gpwrdn_temp.b.idsts) {
  64437. + retval = dwc_otg_handle_pwrdn_idsts_change(otg_dev);
  64438. + } else if (gpwrdn.b.bsessvld ^ gpwrdn_temp.b.bsessvld) {
  64439. + retval = dwc_otg_handle_pwrdn_session_change(core_if);
  64440. + }
  64441. +
  64442. + return retval;
  64443. +}
  64444. +
  64445. +/**
  64446. + * This interrupt indicates that the Wakeup Logic has detected a
  64447. + * SRP.
  64448. + */
  64449. +static int32_t dwc_otg_handle_pwrdn_srp_intr(dwc_otg_core_if_t * core_if)
  64450. +{
  64451. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64452. +
  64453. + DWC_PRINTF("%s called\n", __FUNCTION__);
  64454. +
  64455. + if (!core_if->hibernation_suspend) {
  64456. + DWC_PRINTF("Already exited from Hibernation\n");
  64457. + return 1;
  64458. + }
  64459. +#ifdef DWC_DEV_SRPCAP
  64460. + if (core_if->pwron_timer_started) {
  64461. + core_if->pwron_timer_started = 0;
  64462. + DWC_TIMER_CANCEL(core_if->pwron_timer);
  64463. + }
  64464. +#endif
  64465. +
  64466. + /* Switch on the voltage to the core */
  64467. + gpwrdn.b.pwrdnswtch = 1;
  64468. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64469. + dwc_udelay(10);
  64470. +
  64471. + /* Reset the core */
  64472. + gpwrdn.d32 = 0;
  64473. + gpwrdn.b.pwrdnrstn = 1;
  64474. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64475. + dwc_udelay(10);
  64476. +
  64477. + /* Disable power clamps */
  64478. + gpwrdn.d32 = 0;
  64479. + gpwrdn.b.pwrdnclmp = 1;
  64480. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64481. +
  64482. + /* Remove reset the core signal */
  64483. + gpwrdn.d32 = 0;
  64484. + gpwrdn.b.pwrdnrstn = 1;
  64485. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  64486. + dwc_udelay(10);
  64487. +
  64488. + /* Disable PMU interrupt */
  64489. + gpwrdn.d32 = 0;
  64490. + gpwrdn.b.pmuintsel = 1;
  64491. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64492. +
  64493. + /* Indicates that we are exiting from hibernation */
  64494. + core_if->hibernation_suspend = 0;
  64495. +
  64496. + /* Disable PMU */
  64497. + gpwrdn.d32 = 0;
  64498. + gpwrdn.b.pmuactv = 1;
  64499. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64500. + dwc_udelay(10);
  64501. +
  64502. + /* Programm Disable VBUS to 0 */
  64503. + gpwrdn.d32 = 0;
  64504. + gpwrdn.b.dis_vbus = 1;
  64505. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  64506. +
  64507. + /*Initialize the core as Host */
  64508. + core_if->op_state = A_HOST;
  64509. + dwc_otg_core_init(core_if);
  64510. + dwc_otg_enable_global_interrupts(core_if);
  64511. + cil_hcd_start(core_if);
  64512. +
  64513. + return 1;
  64514. +}
  64515. +
  64516. +/** This interrupt indicates that restore command after Hibernation
  64517. + * was completed by the core. */
  64518. +int32_t dwc_otg_handle_restore_done_intr(dwc_otg_core_if_t * core_if)
  64519. +{
  64520. + pcgcctl_data_t pcgcctl;
  64521. + DWC_DEBUGPL(DBG_ANY, "++Restore Done Interrupt++\n");
  64522. +
  64523. + //TODO De-assert restore signal. 8.a
  64524. + pcgcctl.d32 = DWC_READ_REG32(core_if->pcgcctl);
  64525. + if (pcgcctl.b.restoremode == 1) {
  64526. + gintmsk_data_t gintmsk = {.d32 = 0 };
  64527. + /*
  64528. + * If restore mode is Remote Wakeup,
  64529. + * unmask Remote Wakeup interrupt.
  64530. + */
  64531. + gintmsk.b.wkupintr = 1;
  64532. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  64533. + 0, gintmsk.d32);
  64534. + }
  64535. +
  64536. + return 1;
  64537. +}
  64538. +
  64539. +/**
  64540. + * This interrupt indicates that a device has been disconnected from
  64541. + * the root port.
  64542. + */
  64543. +int32_t dwc_otg_handle_disconnect_intr(dwc_otg_core_if_t * core_if)
  64544. +{
  64545. + gintsts_data_t gintsts;
  64546. +
  64547. + DWC_DEBUGPL(DBG_ANY, "++Disconnect Detected Interrupt++ (%s) %s\n",
  64548. + (dwc_otg_is_host_mode(core_if) ? "Host" : "Device"),
  64549. + op_state_str(core_if));
  64550. +
  64551. +/** @todo Consolidate this if statement. */
  64552. +#ifndef DWC_HOST_ONLY
  64553. + if (core_if->op_state == B_HOST) {
  64554. + /* If in device mode Disconnect and stop the HCD, then
  64555. + * start the PCD. */
  64556. + DWC_SPINUNLOCK(core_if->lock);
  64557. + cil_hcd_disconnect(core_if);
  64558. + cil_pcd_start(core_if);
  64559. + DWC_SPINLOCK(core_if->lock);
  64560. + core_if->op_state = B_PERIPHERAL;
  64561. + } else if (dwc_otg_is_device_mode(core_if)) {
  64562. + gotgctl_data_t gotgctl = {.d32 = 0 };
  64563. + gotgctl.d32 =
  64564. + DWC_READ_REG32(&core_if->core_global_regs->gotgctl);
  64565. + if (gotgctl.b.hstsethnpen == 1) {
  64566. + /* Do nothing, if HNP in process the OTG
  64567. + * interrupt "Host Negotiation Detected"
  64568. + * interrupt will do the mode switch.
  64569. + */
  64570. + } else if (gotgctl.b.devhnpen == 0) {
  64571. + /* If in device mode Disconnect and stop the HCD, then
  64572. + * start the PCD. */
  64573. + DWC_SPINUNLOCK(core_if->lock);
  64574. + cil_hcd_disconnect(core_if);
  64575. + cil_pcd_start(core_if);
  64576. + DWC_SPINLOCK(core_if->lock);
  64577. + core_if->op_state = B_PERIPHERAL;
  64578. + } else {
  64579. + DWC_DEBUGPL(DBG_ANY, "!a_peripheral && !devhnpen\n");
  64580. + }
  64581. + } else {
  64582. + if (core_if->op_state == A_HOST) {
  64583. + /* A-Cable still connected but device disconnected. */
  64584. + cil_hcd_disconnect(core_if);
  64585. + if (core_if->adp_enable) {
  64586. + gpwrdn_data_t gpwrdn = { .d32 = 0 };
  64587. + cil_hcd_stop(core_if);
  64588. + /* Enable Power Down Logic */
  64589. + gpwrdn.b.pmuintsel = 1;
  64590. + gpwrdn.b.pmuactv = 1;
  64591. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64592. + gpwrdn, 0, gpwrdn.d32);
  64593. + dwc_otg_adp_probe_start(core_if);
  64594. +
  64595. + /* Power off the core */
  64596. + if (core_if->power_down == 2) {
  64597. + gpwrdn.d32 = 0;
  64598. + gpwrdn.b.pwrdnswtch = 1;
  64599. + DWC_MODIFY_REG32
  64600. + (&core_if->core_global_regs->gpwrdn,
  64601. + gpwrdn.d32, 0);
  64602. + }
  64603. + }
  64604. + }
  64605. + }
  64606. +#endif
  64607. + /* Change to L3(OFF) state */
  64608. + core_if->lx_state = DWC_OTG_L3;
  64609. +
  64610. + gintsts.d32 = 0;
  64611. + gintsts.b.disconnect = 1;
  64612. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64613. + return 1;
  64614. +}
  64615. +
  64616. +/**
  64617. + * This interrupt indicates that SUSPEND state has been detected on
  64618. + * the USB.
  64619. + *
  64620. + * For HNP the USB Suspend interrupt signals the change from
  64621. + * "a_peripheral" to "a_host".
  64622. + *
  64623. + * When power management is enabled the core will be put in low power
  64624. + * mode.
  64625. + */
  64626. +int32_t dwc_otg_handle_usb_suspend_intr(dwc_otg_core_if_t * core_if)
  64627. +{
  64628. + dsts_data_t dsts;
  64629. + gintsts_data_t gintsts;
  64630. + dcfg_data_t dcfg;
  64631. +
  64632. + DWC_DEBUGPL(DBG_ANY, "USB SUSPEND\n");
  64633. +
  64634. + if (dwc_otg_is_device_mode(core_if)) {
  64635. + /* Check the Device status register to determine if the Suspend
  64636. + * state is active. */
  64637. + dsts.d32 =
  64638. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  64639. + DWC_DEBUGPL(DBG_PCD, "DSTS=0x%0x\n", dsts.d32);
  64640. + DWC_DEBUGPL(DBG_PCD, "DSTS.Suspend Status=%d "
  64641. + "HWCFG4.power Optimize=%d\n",
  64642. + dsts.b.suspsts, core_if->hwcfg4.b.power_optimiz);
  64643. +
  64644. +#ifdef PARTIAL_POWER_DOWN
  64645. +/** @todo Add a module parameter for power management. */
  64646. +
  64647. + if (dsts.b.suspsts && core_if->hwcfg4.b.power_optimiz) {
  64648. + pcgcctl_data_t power = {.d32 = 0 };
  64649. + DWC_DEBUGPL(DBG_CIL, "suspend\n");
  64650. +
  64651. + power.b.pwrclmp = 1;
  64652. + DWC_WRITE_REG32(core_if->pcgcctl, power.d32);
  64653. +
  64654. + power.b.rstpdwnmodule = 1;
  64655. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64656. +
  64657. + power.b.stoppclk = 1;
  64658. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, power.d32);
  64659. +
  64660. + } else {
  64661. + DWC_DEBUGPL(DBG_ANY, "disconnect?\n");
  64662. + }
  64663. +#endif
  64664. + /* PCD callback for suspend. Release the lock inside of callback function */
  64665. + cil_pcd_suspend(core_if);
  64666. + if (core_if->power_down == 2)
  64667. + {
  64668. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64669. + DWC_DEBUGPL(DBG_ANY,"lx_state = %08x\n",core_if->lx_state);
  64670. + DWC_DEBUGPL(DBG_ANY," device address = %08d\n",dcfg.b.devaddr);
  64671. +
  64672. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64673. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64674. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64675. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  64676. +
  64677. + /* Change to L2(suspend) state */
  64678. + core_if->lx_state = DWC_OTG_L2;
  64679. +
  64680. + /* Clear interrupt in gintsts */
  64681. + gintsts.d32 = 0;
  64682. + gintsts.b.usbsuspend = 1;
  64683. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64684. + gintsts, gintsts.d32);
  64685. + DWC_PRINTF("Start of hibernation completed\n");
  64686. + dwc_otg_save_global_regs(core_if);
  64687. + dwc_otg_save_dev_regs(core_if);
  64688. +
  64689. + gusbcfg.d32 =
  64690. + DWC_READ_REG32(&core_if->core_global_regs->
  64691. + gusbcfg);
  64692. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  64693. + /* ULPI interface */
  64694. + /* Suspend the Phy Clock */
  64695. + pcgcctl.d32 = 0;
  64696. + pcgcctl.b.stoppclk = 1;
  64697. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64698. + pcgcctl.d32);
  64699. + dwc_udelay(10);
  64700. + gpwrdn.b.pmuactv = 1;
  64701. + DWC_MODIFY_REG32(&core_if->
  64702. + core_global_regs->
  64703. + gpwrdn, 0, gpwrdn.d32);
  64704. + } else {
  64705. + /* UTMI+ Interface */
  64706. + gpwrdn.b.pmuactv = 1;
  64707. + DWC_MODIFY_REG32(&core_if->
  64708. + core_global_regs->
  64709. + gpwrdn, 0, gpwrdn.d32);
  64710. + dwc_udelay(10);
  64711. + pcgcctl.b.stoppclk = 1;
  64712. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  64713. + pcgcctl.d32);
  64714. + dwc_udelay(10);
  64715. + }
  64716. +
  64717. + /* Set flag to indicate that we are in hibernation */
  64718. + core_if->hibernation_suspend = 1;
  64719. + /* Enable interrupts from wake up logic */
  64720. + gpwrdn.d32 = 0;
  64721. + gpwrdn.b.pmuintsel = 1;
  64722. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64723. + gpwrdn, 0, gpwrdn.d32);
  64724. + dwc_udelay(10);
  64725. +
  64726. + /* Unmask device mode interrupts in GPWRDN */
  64727. + gpwrdn.d32 = 0;
  64728. + gpwrdn.b.rst_det_msk = 1;
  64729. + gpwrdn.b.lnstchng_msk = 1;
  64730. + gpwrdn.b.sts_chngint_msk = 1;
  64731. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64732. + gpwrdn, 0, gpwrdn.d32);
  64733. + dwc_udelay(10);
  64734. +
  64735. + /* Enable Power Down Clamp */
  64736. + gpwrdn.d32 = 0;
  64737. + gpwrdn.b.pwrdnclmp = 1;
  64738. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64739. + gpwrdn, 0, gpwrdn.d32);
  64740. + dwc_udelay(10);
  64741. +
  64742. + /* Switch off VDD */
  64743. + gpwrdn.d32 = 0;
  64744. + gpwrdn.b.pwrdnswtch = 1;
  64745. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  64746. + gpwrdn, 0, gpwrdn.d32);
  64747. +
  64748. + /* Save gpwrdn register for further usage if stschng interrupt */
  64749. + core_if->gr_backup->gpwrdn_local =
  64750. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64751. + DWC_PRINTF("Hibernation completed\n");
  64752. +
  64753. + return 1;
  64754. + }
  64755. + } else if (core_if->power_down == 3) {
  64756. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64757. + dcfg.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dcfg);
  64758. + DWC_DEBUGPL(DBG_ANY, "lx_state = %08x\n",core_if->lx_state);
  64759. + DWC_DEBUGPL(DBG_ANY, " device address = %08d\n",dcfg.b.devaddr);
  64760. +
  64761. + if (core_if->lx_state != DWC_OTG_L3 && dcfg.b.devaddr) {
  64762. + DWC_DEBUGPL(DBG_ANY, "Start entering to extended hibernation\n");
  64763. + core_if->xhib = 1;
  64764. +
  64765. + /* Clear interrupt in gintsts */
  64766. + gintsts.d32 = 0;
  64767. + gintsts.b.usbsuspend = 1;
  64768. + DWC_WRITE_REG32(&core_if->core_global_regs->
  64769. + gintsts, gintsts.d32);
  64770. +
  64771. + dwc_otg_save_global_regs(core_if);
  64772. + dwc_otg_save_dev_regs(core_if);
  64773. +
  64774. + /* Wait for 10 PHY clocks */
  64775. + dwc_udelay(10);
  64776. +
  64777. + /* Program GPIO register while entering to xHib */
  64778. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x1);
  64779. +
  64780. + pcgcctl.b.enbl_extnd_hiber = 1;
  64781. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64782. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64783. +
  64784. + pcgcctl.d32 = 0;
  64785. + pcgcctl.b.extnd_hiber_pwrclmp = 1;
  64786. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64787. +
  64788. + pcgcctl.d32 = 0;
  64789. + pcgcctl.b.extnd_hiber_switch = 1;
  64790. + core_if->gr_backup->xhib_gpwrdn = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  64791. + core_if->gr_backup->xhib_pcgcctl = DWC_READ_REG32(core_if->pcgcctl) | pcgcctl.d32;
  64792. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  64793. +
  64794. + DWC_DEBUGPL(DBG_ANY, "Finished entering to extended hibernation\n");
  64795. +
  64796. + return 1;
  64797. + }
  64798. + }
  64799. + } else {
  64800. + if (core_if->op_state == A_PERIPHERAL) {
  64801. + DWC_DEBUGPL(DBG_ANY, "a_peripheral->a_host\n");
  64802. + /* Clear the a_peripheral flag, back to a_host. */
  64803. + DWC_SPINUNLOCK(core_if->lock);
  64804. + cil_pcd_stop(core_if);
  64805. + cil_hcd_start(core_if);
  64806. + DWC_SPINLOCK(core_if->lock);
  64807. + core_if->op_state = A_HOST;
  64808. + }
  64809. + }
  64810. +
  64811. + /* Change to L2(suspend) state */
  64812. + core_if->lx_state = DWC_OTG_L2;
  64813. +
  64814. + /* Clear interrupt */
  64815. + gintsts.d32 = 0;
  64816. + gintsts.b.usbsuspend = 1;
  64817. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64818. +
  64819. + return 1;
  64820. +}
  64821. +
  64822. +static int32_t dwc_otg_handle_xhib_exit_intr(dwc_otg_core_if_t * core_if)
  64823. +{
  64824. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  64825. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  64826. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64827. +
  64828. + dwc_udelay(10);
  64829. +
  64830. + /* Program GPIO register while entering to xHib */
  64831. + DWC_WRITE_REG32(&core_if->core_global_regs->ggpio, 0x0);
  64832. +
  64833. + pcgcctl.d32 = core_if->gr_backup->xhib_pcgcctl;
  64834. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64835. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64836. + dwc_udelay(10);
  64837. +
  64838. + gpwrdn.d32 = core_if->gr_backup->xhib_gpwrdn;
  64839. + gpwrdn.b.restore = 1;
  64840. + DWC_WRITE_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32);
  64841. + dwc_udelay(10);
  64842. +
  64843. + restore_lpm_i2c_regs(core_if);
  64844. +
  64845. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64846. + pcgcctl.b.max_xcvrselect = 1;
  64847. + pcgcctl.b.ess_reg_restored = 0;
  64848. + pcgcctl.b.extnd_hiber_switch = 0;
  64849. + pcgcctl.b.extnd_hiber_pwrclmp = 0;
  64850. + pcgcctl.b.enbl_extnd_hiber = 1;
  64851. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64852. +
  64853. + gahbcfg.d32 = core_if->gr_backup->gahbcfg_local;
  64854. + gahbcfg.b.glblintrmsk = 1;
  64855. + DWC_WRITE_REG32(&core_if->core_global_regs->gahbcfg, gahbcfg.d32);
  64856. +
  64857. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, 0xFFFFFFFF);
  64858. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, 0x1 << 16);
  64859. +
  64860. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg,
  64861. + core_if->gr_backup->gusbcfg_local);
  64862. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg,
  64863. + core_if->dr_backup->dcfg);
  64864. +
  64865. + pcgcctl.d32 = 0;
  64866. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64867. + pcgcctl.b.max_xcvrselect = 1;
  64868. + pcgcctl.d32 |= 0x608;
  64869. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64870. + dwc_udelay(10);
  64871. +
  64872. + pcgcctl.d32 = 0;
  64873. + pcgcctl.d32 = core_if->gr_backup->pcgcctl_local & (0x3FFFF << 14);
  64874. + pcgcctl.b.max_xcvrselect = 1;
  64875. + pcgcctl.b.ess_reg_restored = 1;
  64876. + pcgcctl.b.enbl_extnd_hiber = 1;
  64877. + pcgcctl.b.rstpdwnmodule = 1;
  64878. + pcgcctl.b.restoremode = 1;
  64879. + DWC_WRITE_REG32(core_if->pcgcctl, pcgcctl.d32);
  64880. +
  64881. + DWC_DEBUGPL(DBG_ANY, "%s called\n", __FUNCTION__);
  64882. +
  64883. + return 1;
  64884. +}
  64885. +
  64886. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64887. +/**
  64888. + * This function hadles LPM transaction received interrupt.
  64889. + */
  64890. +static int32_t dwc_otg_handle_lpm_intr(dwc_otg_core_if_t * core_if)
  64891. +{
  64892. + glpmcfg_data_t lpmcfg;
  64893. + gintsts_data_t gintsts;
  64894. +
  64895. + if (!core_if->core_params->lpm_enable) {
  64896. + DWC_PRINTF("Unexpected LPM interrupt\n");
  64897. + }
  64898. +
  64899. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64900. + DWC_PRINTF("LPM config register = 0x%08x\n", lpmcfg.d32);
  64901. +
  64902. + if (dwc_otg_is_host_mode(core_if)) {
  64903. + cil_hcd_sleep(core_if);
  64904. + } else {
  64905. + lpmcfg.b.hird_thres |= (1 << 4);
  64906. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg,
  64907. + lpmcfg.d32);
  64908. + }
  64909. +
  64910. + /* Examine prt_sleep_sts after TL1TokenTetry period max (10 us) */
  64911. + dwc_udelay(10);
  64912. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  64913. + if (lpmcfg.b.prt_sleep_sts) {
  64914. + /* Save the current state */
  64915. + core_if->lx_state = DWC_OTG_L1;
  64916. + }
  64917. +
  64918. + /* Clear interrupt */
  64919. + gintsts.d32 = 0;
  64920. + gintsts.b.lpmtranrcvd = 1;
  64921. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  64922. + return 1;
  64923. +}
  64924. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  64925. +
  64926. +/**
  64927. + * This function returns the Core Interrupt register.
  64928. + */
  64929. +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)
  64930. +{
  64931. + gahbcfg_data_t gahbcfg = {.d32 = 0 };
  64932. + gintsts_data_t gintsts;
  64933. + gintmsk_data_t gintmsk;
  64934. + gintmsk_data_t gintmsk_common = {.d32 = 0 };
  64935. + gintmsk_common.b.wkupintr = 1;
  64936. + gintmsk_common.b.sessreqintr = 1;
  64937. + gintmsk_common.b.conidstschng = 1;
  64938. + gintmsk_common.b.otgintr = 1;
  64939. + gintmsk_common.b.modemismatch = 1;
  64940. + gintmsk_common.b.disconnect = 1;
  64941. + gintmsk_common.b.usbsuspend = 1;
  64942. +#ifdef CONFIG_USB_DWC_OTG_LPM
  64943. + gintmsk_common.b.lpmtranrcvd = 1;
  64944. +#endif
  64945. + gintmsk_common.b.restoredone = 1;
  64946. + if(dwc_otg_is_device_mode(core_if))
  64947. + {
  64948. + /** @todo: The port interrupt occurs while in device
  64949. + * mode. Added code to CIL to clear the interrupt for now!
  64950. + */
  64951. + gintmsk_common.b.portintr = 1;
  64952. + }
  64953. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  64954. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  64955. + if(fiq_enable) {
  64956. + local_fiq_disable();
  64957. + /* Pull in the interrupts that the FIQ has masked */
  64958. + gintmsk.d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  64959. + /* for the upstairs function to reenable - have to read it here in case FIQ triggers again */
  64960. + reenable_gintmsk->d32 |= gintmsk.d32;
  64961. + reenable_gintmsk->d32 |= ~(hcd->fiq_state->gintmsk_saved.d32);
  64962. + reenable_gintmsk->d32 &= gintmsk_common.d32;
  64963. + local_fiq_enable();
  64964. + }
  64965. +
  64966. + gahbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gahbcfg);
  64967. +
  64968. +#ifdef DEBUG
  64969. + /* if any common interrupts set */
  64970. + if (gintsts.d32 & gintmsk_common.d32) {
  64971. + DWC_DEBUGPL(DBG_ANY, "common_intr: gintsts=%08x gintmsk=%08x\n",
  64972. + gintsts.d32, gintmsk.d32);
  64973. + }
  64974. +#endif
  64975. + if (!fiq_enable){
  64976. + if (gahbcfg.b.glblintrmsk)
  64977. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  64978. + else
  64979. + return 0;
  64980. + } else {
  64981. + /* Our IRQ kicker is no longer the USB hardware, it's the MPHI interface.
  64982. + * Can't trust the global interrupt mask bit in this case.
  64983. + */
  64984. + return ((gintsts.d32 & gintmsk.d32) & gintmsk_common.d32);
  64985. + }
  64986. +
  64987. +}
  64988. +
  64989. +/* MACRO for clearing interupt bits in GPWRDN register */
  64990. +#define CLEAR_GPWRDN_INTR(__core_if,__intr) \
  64991. +do { \
  64992. + gpwrdn_data_t gpwrdn = {.d32=0}; \
  64993. + gpwrdn.b.__intr = 1; \
  64994. + DWC_MODIFY_REG32(&__core_if->core_global_regs->gpwrdn, \
  64995. + 0, gpwrdn.d32); \
  64996. +} while (0)
  64997. +
  64998. +/**
  64999. + * Common interrupt handler.
  65000. + *
  65001. + * The common interrupts are those that occur in both Host and Device mode.
  65002. + * This handler handles the following interrupts:
  65003. + * - Mode Mismatch Interrupt
  65004. + * - Disconnect Interrupt
  65005. + * - OTG Interrupt
  65006. + * - Connector ID Status Change Interrupt
  65007. + * - Session Request Interrupt.
  65008. + * - Resume / Remote Wakeup Detected Interrupt.
  65009. + * - LPM Transaction Received Interrupt
  65010. + * - ADP Transaction Received Interrupt
  65011. + *
  65012. + */
  65013. +int32_t dwc_otg_handle_common_intr(void *dev)
  65014. +{
  65015. + int retval = 0;
  65016. + gintsts_data_t gintsts;
  65017. + gintmsk_data_t gintmsk_reenable = { .d32 = 0 };
  65018. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65019. + dwc_otg_device_t *otg_dev = dev;
  65020. + dwc_otg_core_if_t *core_if = otg_dev->core_if;
  65021. + gpwrdn.d32 = DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  65022. + if (dwc_otg_is_device_mode(core_if))
  65023. + core_if->frame_num = dwc_otg_get_frame_number(core_if);
  65024. +
  65025. + if (core_if->lock)
  65026. + DWC_SPINLOCK(core_if->lock);
  65027. +
  65028. + if (core_if->power_down == 3 && core_if->xhib == 1) {
  65029. + DWC_DEBUGPL(DBG_ANY, "Exiting from xHIB state\n");
  65030. + retval |= dwc_otg_handle_xhib_exit_intr(core_if);
  65031. + core_if->xhib = 2;
  65032. + if (core_if->lock)
  65033. + DWC_SPINUNLOCK(core_if->lock);
  65034. +
  65035. + return retval;
  65036. + }
  65037. +
  65038. + if (core_if->hibernation_suspend <= 0) {
  65039. + /* read_common will have to poke the FIQ's saved mask. We must then clear this mask at the end
  65040. + * of this handler - god only knows why it's done like this
  65041. + */
  65042. + gintsts.d32 = dwc_otg_read_common_intr(core_if, &gintmsk_reenable, otg_dev->hcd);
  65043. +
  65044. + if (gintsts.b.modemismatch) {
  65045. + retval |= dwc_otg_handle_mode_mismatch_intr(core_if);
  65046. + }
  65047. + if (gintsts.b.otgintr) {
  65048. + retval |= dwc_otg_handle_otg_intr(core_if);
  65049. + }
  65050. + if (gintsts.b.conidstschng) {
  65051. + retval |=
  65052. + dwc_otg_handle_conn_id_status_change_intr(core_if);
  65053. + }
  65054. + if (gintsts.b.disconnect) {
  65055. + retval |= dwc_otg_handle_disconnect_intr(core_if);
  65056. + }
  65057. + if (gintsts.b.sessreqintr) {
  65058. + retval |= dwc_otg_handle_session_req_intr(core_if);
  65059. + }
  65060. + if (gintsts.b.wkupintr) {
  65061. + retval |= dwc_otg_handle_wakeup_detected_intr(core_if);
  65062. + }
  65063. + if (gintsts.b.usbsuspend) {
  65064. + retval |= dwc_otg_handle_usb_suspend_intr(core_if);
  65065. + }
  65066. +#ifdef CONFIG_USB_DWC_OTG_LPM
  65067. + if (gintsts.b.lpmtranrcvd) {
  65068. + retval |= dwc_otg_handle_lpm_intr(core_if);
  65069. + }
  65070. +#endif
  65071. + if (gintsts.b.restoredone) {
  65072. + gintsts.d32 = 0;
  65073. + if (core_if->power_down == 2)
  65074. + core_if->hibernation_suspend = -1;
  65075. + else if (core_if->power_down == 3 && core_if->xhib == 2) {
  65076. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  65077. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  65078. + dctl_data_t dctl = {.d32 = 0 };
  65079. +
  65080. + DWC_WRITE_REG32(&core_if->core_global_regs->
  65081. + gintsts, 0xFFFFFFFF);
  65082. +
  65083. + DWC_DEBUGPL(DBG_ANY,
  65084. + "RESTORE DONE generated\n");
  65085. +
  65086. + gpwrdn.b.restore = 1;
  65087. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  65088. + dwc_udelay(10);
  65089. +
  65090. + pcgcctl.b.rstpdwnmodule = 1;
  65091. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65092. +
  65093. + DWC_WRITE_REG32(&core_if->core_global_regs->gusbcfg, core_if->gr_backup->gusbcfg_local);
  65094. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dcfg, core_if->dr_backup->dcfg);
  65095. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, core_if->dr_backup->dctl);
  65096. + dwc_udelay(50);
  65097. +
  65098. + dctl.b.pwronprgdone = 1;
  65099. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  65100. + dwc_udelay(10);
  65101. +
  65102. + dwc_otg_restore_global_regs(core_if);
  65103. + dwc_otg_restore_dev_regs(core_if, 0);
  65104. +
  65105. + dctl.d32 = 0;
  65106. + dctl.b.pwronprgdone = 1;
  65107. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  65108. + dwc_udelay(10);
  65109. +
  65110. + pcgcctl.d32 = 0;
  65111. + pcgcctl.b.enbl_extnd_hiber = 1;
  65112. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  65113. +
  65114. + /* The core will be in ON STATE */
  65115. + core_if->lx_state = DWC_OTG_L0;
  65116. + core_if->xhib = 0;
  65117. +
  65118. + DWC_SPINUNLOCK(core_if->lock);
  65119. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  65120. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  65121. + }
  65122. + DWC_SPINLOCK(core_if->lock);
  65123. +
  65124. + }
  65125. +
  65126. + gintsts.b.restoredone = 1;
  65127. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65128. + DWC_PRINTF(" --Restore done interrupt received-- \n");
  65129. + retval |= 1;
  65130. + }
  65131. + if (gintsts.b.portintr && dwc_otg_is_device_mode(core_if)) {
  65132. + /* The port interrupt occurs while in device mode with HPRT0
  65133. + * Port Enable/Disable.
  65134. + */
  65135. + gintsts.d32 = 0;
  65136. + gintsts.b.portintr = 1;
  65137. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts,gintsts.d32);
  65138. + retval |= 1;
  65139. + gintmsk_reenable.b.portintr = 1;
  65140. +
  65141. + }
  65142. + /* Did we actually handle anything? if so, unmask the interrupt */
  65143. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "CILOUT %1d", retval);
  65144. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintsts.d32);
  65145. +// fiq_print(FIQDBG_INT, otg_dev->hcd->fiq_state, "%08x", gintmsk_reenable.d32);
  65146. + if (retval) {
  65147. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_reenable.d32);
  65148. + }
  65149. +
  65150. + } else {
  65151. + DWC_DEBUGPL(DBG_ANY, "gpwrdn=%08x\n", gpwrdn.d32);
  65152. +
  65153. + if (gpwrdn.b.disconn_det && gpwrdn.b.disconn_det_msk) {
  65154. + CLEAR_GPWRDN_INTR(core_if, disconn_det);
  65155. + if (gpwrdn.b.linestate == 0) {
  65156. + dwc_otg_handle_pwrdn_disconnect_intr(core_if);
  65157. + } else {
  65158. + DWC_PRINTF("Disconnect detected while linestate is not 0\n");
  65159. + }
  65160. +
  65161. + retval |= 1;
  65162. + }
  65163. + if (gpwrdn.b.lnstschng && gpwrdn.b.lnstchng_msk) {
  65164. + CLEAR_GPWRDN_INTR(core_if, lnstschng);
  65165. + /* remote wakeup from hibernation */
  65166. + if (gpwrdn.b.linestate == 2 || gpwrdn.b.linestate == 1) {
  65167. + dwc_otg_handle_pwrdn_wakeup_detected_intr(core_if);
  65168. + } else {
  65169. + DWC_PRINTF("gpwrdn.linestate = %d\n", gpwrdn.b.linestate);
  65170. + }
  65171. + retval |= 1;
  65172. + }
  65173. + if (gpwrdn.b.rst_det && gpwrdn.b.rst_det_msk) {
  65174. + CLEAR_GPWRDN_INTR(core_if, rst_det);
  65175. + if (gpwrdn.b.linestate == 0) {
  65176. + DWC_PRINTF("Reset detected\n");
  65177. + retval |= dwc_otg_device_hibernation_restore(core_if, 0, 1);
  65178. + }
  65179. + }
  65180. + if (gpwrdn.b.srp_det && gpwrdn.b.srp_det_msk) {
  65181. + CLEAR_GPWRDN_INTR(core_if, srp_det);
  65182. + dwc_otg_handle_pwrdn_srp_intr(core_if);
  65183. + retval |= 1;
  65184. + }
  65185. + }
  65186. + /* Handle ADP interrupt here */
  65187. + if (gpwrdn.b.adp_int) {
  65188. + DWC_PRINTF("ADP interrupt\n");
  65189. + CLEAR_GPWRDN_INTR(core_if, adp_int);
  65190. + dwc_otg_adp_handle_intr(core_if);
  65191. + retval |= 1;
  65192. + }
  65193. + if (gpwrdn.b.sts_chngint && gpwrdn.b.sts_chngint_msk) {
  65194. + DWC_PRINTF("STS CHNG interrupt asserted\n");
  65195. + CLEAR_GPWRDN_INTR(core_if, sts_chngint);
  65196. + dwc_otg_handle_pwrdn_stschng_intr(otg_dev);
  65197. +
  65198. + retval |= 1;
  65199. + }
  65200. + if (core_if->lock)
  65201. + DWC_SPINUNLOCK(core_if->lock);
  65202. + return retval;
  65203. +}
  65204. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_core_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h
  65205. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 1970-01-01 01:00:00.000000000 +0100
  65206. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_core_if.h 2014-06-11 21:03:43.000000000 +0200
  65207. @@ -0,0 +1,705 @@
  65208. +/* ==========================================================================
  65209. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_core_if.h $
  65210. + * $Revision: #13 $
  65211. + * $Date: 2012/08/10 $
  65212. + * $Change: 2047372 $
  65213. + *
  65214. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65215. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65216. + * otherwise expressly agreed to in writing between Synopsys and you.
  65217. + *
  65218. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65219. + * any End User Software License Agreement or Agreement for Licensed Product
  65220. + * with Synopsys or any supplement thereto. You are permitted to use and
  65221. + * redistribute this Software in source and binary forms, with or without
  65222. + * modification, provided that redistributions of source code must retain this
  65223. + * notice. You may not view, use, disclose, copy or distribute this file or
  65224. + * any information contained herein except pursuant to this license grant from
  65225. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65226. + * below, then you are not authorized to use the Software.
  65227. + *
  65228. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65229. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65230. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65231. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65232. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65233. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65234. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65235. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65236. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65237. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65238. + * DAMAGE.
  65239. + * ========================================================================== */
  65240. +#if !defined(__DWC_CORE_IF_H__)
  65241. +#define __DWC_CORE_IF_H__
  65242. +
  65243. +#include "dwc_os.h"
  65244. +
  65245. +/** @file
  65246. + * This file defines DWC_OTG Core API
  65247. + */
  65248. +
  65249. +struct dwc_otg_core_if;
  65250. +typedef struct dwc_otg_core_if dwc_otg_core_if_t;
  65251. +
  65252. +/** Maximum number of Periodic FIFOs */
  65253. +#define MAX_PERIO_FIFOS 15
  65254. +/** Maximum number of Periodic FIFOs */
  65255. +#define MAX_TX_FIFOS 15
  65256. +
  65257. +/** Maximum number of Endpoints/HostChannels */
  65258. +#define MAX_EPS_CHANNELS 16
  65259. +
  65260. +extern dwc_otg_core_if_t *dwc_otg_cil_init(const uint32_t * _reg_base_addr);
  65261. +extern void dwc_otg_core_init(dwc_otg_core_if_t * _core_if);
  65262. +extern void dwc_otg_cil_remove(dwc_otg_core_if_t * _core_if);
  65263. +
  65264. +extern void dwc_otg_enable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65265. +extern void dwc_otg_disable_global_interrupts(dwc_otg_core_if_t * _core_if);
  65266. +
  65267. +extern uint8_t dwc_otg_is_device_mode(dwc_otg_core_if_t * _core_if);
  65268. +extern uint8_t dwc_otg_is_host_mode(dwc_otg_core_if_t * _core_if);
  65269. +
  65270. +extern uint8_t dwc_otg_is_dma_enable(dwc_otg_core_if_t * core_if);
  65271. +
  65272. +/** This function should be called on every hardware interrupt. */
  65273. +extern int32_t dwc_otg_handle_common_intr(void *otg_dev);
  65274. +
  65275. +/** @name OTG Core Parameters */
  65276. +/** @{ */
  65277. +
  65278. +/**
  65279. + * Specifies the OTG capabilities. The driver will automatically
  65280. + * detect the value for this parameter if none is specified.
  65281. + * 0 - HNP and SRP capable (default)
  65282. + * 1 - SRP Only capable
  65283. + * 2 - No HNP/SRP capable
  65284. + */
  65285. +extern int dwc_otg_set_param_otg_cap(dwc_otg_core_if_t * core_if, int32_t val);
  65286. +extern int32_t dwc_otg_get_param_otg_cap(dwc_otg_core_if_t * core_if);
  65287. +#define DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE 0
  65288. +#define DWC_OTG_CAP_PARAM_SRP_ONLY_CAPABLE 1
  65289. +#define DWC_OTG_CAP_PARAM_NO_HNP_SRP_CAPABLE 2
  65290. +#define dwc_param_otg_cap_default DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE
  65291. +
  65292. +extern int dwc_otg_set_param_opt(dwc_otg_core_if_t * core_if, int32_t val);
  65293. +extern int32_t dwc_otg_get_param_opt(dwc_otg_core_if_t * core_if);
  65294. +#define dwc_param_opt_default 1
  65295. +
  65296. +/**
  65297. + * Specifies whether to use slave or DMA mode for accessing the data
  65298. + * FIFOs. The driver will automatically detect the value for this
  65299. + * parameter if none is specified.
  65300. + * 0 - Slave
  65301. + * 1 - DMA (default, if available)
  65302. + */
  65303. +extern int dwc_otg_set_param_dma_enable(dwc_otg_core_if_t * core_if,
  65304. + int32_t val);
  65305. +extern int32_t dwc_otg_get_param_dma_enable(dwc_otg_core_if_t * core_if);
  65306. +#define dwc_param_dma_enable_default 1
  65307. +
  65308. +/**
  65309. + * When DMA mode is enabled specifies whether to use
  65310. + * address DMA or DMA Descritor mode for accessing the data
  65311. + * FIFOs in device mode. The driver will automatically detect
  65312. + * the value for this parameter if none is specified.
  65313. + * 0 - address DMA
  65314. + * 1 - DMA Descriptor(default, if available)
  65315. + */
  65316. +extern int dwc_otg_set_param_dma_desc_enable(dwc_otg_core_if_t * core_if,
  65317. + int32_t val);
  65318. +extern int32_t dwc_otg_get_param_dma_desc_enable(dwc_otg_core_if_t * core_if);
  65319. +//#define dwc_param_dma_desc_enable_default 1
  65320. +#define dwc_param_dma_desc_enable_default 0 // Broadcom BCM2708
  65321. +
  65322. +/** The DMA Burst size (applicable only for External DMA
  65323. + * Mode). 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  65324. + */
  65325. +extern int dwc_otg_set_param_dma_burst_size(dwc_otg_core_if_t * core_if,
  65326. + int32_t val);
  65327. +extern int32_t dwc_otg_get_param_dma_burst_size(dwc_otg_core_if_t * core_if);
  65328. +#define dwc_param_dma_burst_size_default 32
  65329. +
  65330. +/**
  65331. + * Specifies the maximum speed of operation in host and device mode.
  65332. + * The actual speed depends on the speed of the attached device and
  65333. + * the value of phy_type. The actual speed depends on the speed of the
  65334. + * attached device.
  65335. + * 0 - High Speed (default)
  65336. + * 1 - Full Speed
  65337. + */
  65338. +extern int dwc_otg_set_param_speed(dwc_otg_core_if_t * core_if, int32_t val);
  65339. +extern int32_t dwc_otg_get_param_speed(dwc_otg_core_if_t * core_if);
  65340. +#define dwc_param_speed_default 0
  65341. +#define DWC_SPEED_PARAM_HIGH 0
  65342. +#define DWC_SPEED_PARAM_FULL 1
  65343. +
  65344. +/** Specifies whether low power mode is supported when attached
  65345. + * to a Full Speed or Low Speed device in host mode.
  65346. + * 0 - Don't support low power mode (default)
  65347. + * 1 - Support low power mode
  65348. + */
  65349. +extern int dwc_otg_set_param_host_support_fs_ls_low_power(dwc_otg_core_if_t *
  65350. + core_if, int32_t val);
  65351. +extern int32_t dwc_otg_get_param_host_support_fs_ls_low_power(dwc_otg_core_if_t
  65352. + * core_if);
  65353. +#define dwc_param_host_support_fs_ls_low_power_default 0
  65354. +
  65355. +/** Specifies the PHY clock rate in low power mode when connected to a
  65356. + * Low Speed device in host mode. This parameter is applicable only if
  65357. + * HOST_SUPPORT_FS_LS_LOW_POWER is enabled. If PHY_TYPE is set to FS
  65358. + * then defaults to 6 MHZ otherwise 48 MHZ.
  65359. + *
  65360. + * 0 - 48 MHz
  65361. + * 1 - 6 MHz
  65362. + */
  65363. +extern int dwc_otg_set_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65364. + core_if, int32_t val);
  65365. +extern int32_t dwc_otg_get_param_host_ls_low_power_phy_clk(dwc_otg_core_if_t *
  65366. + core_if);
  65367. +#define dwc_param_host_ls_low_power_phy_clk_default 0
  65368. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_48MHZ 0
  65369. +#define DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ 1
  65370. +
  65371. +/**
  65372. + * 0 - Use cC FIFO size parameters
  65373. + * 1 - Allow dynamic FIFO sizing (default)
  65374. + */
  65375. +extern int dwc_otg_set_param_enable_dynamic_fifo(dwc_otg_core_if_t * core_if,
  65376. + int32_t val);
  65377. +extern int32_t dwc_otg_get_param_enable_dynamic_fifo(dwc_otg_core_if_t *
  65378. + core_if);
  65379. +#define dwc_param_enable_dynamic_fifo_default 1
  65380. +
  65381. +/** Total number of 4-byte words in the data FIFO memory. This
  65382. + * memory includes the Rx FIFO, non-periodic Tx FIFO, and periodic
  65383. + * Tx FIFOs.
  65384. + * 32 to 32768 (default 8192)
  65385. + * Note: The total FIFO memory depth in the FPGA configuration is 8192.
  65386. + */
  65387. +extern int dwc_otg_set_param_data_fifo_size(dwc_otg_core_if_t * core_if,
  65388. + int32_t val);
  65389. +extern int32_t dwc_otg_get_param_data_fifo_size(dwc_otg_core_if_t * core_if);
  65390. +//#define dwc_param_data_fifo_size_default 8192
  65391. +#define dwc_param_data_fifo_size_default 0xFF0 // Broadcom BCM2708
  65392. +
  65393. +/** Number of 4-byte words in the Rx FIFO in device mode when dynamic
  65394. + * FIFO sizing is enabled.
  65395. + * 16 to 32768 (default 1064)
  65396. + */
  65397. +extern int dwc_otg_set_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65398. + int32_t val);
  65399. +extern int32_t dwc_otg_get_param_dev_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65400. +#define dwc_param_dev_rx_fifo_size_default 1064
  65401. +
  65402. +/** Number of 4-byte words in the non-periodic Tx FIFO in device mode
  65403. + * when dynamic FIFO sizing is enabled.
  65404. + * 16 to 32768 (default 1024)
  65405. + */
  65406. +extern int dwc_otg_set_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65407. + core_if, int32_t val);
  65408. +extern int32_t dwc_otg_get_param_dev_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65409. + core_if);
  65410. +#define dwc_param_dev_nperio_tx_fifo_size_default 1024
  65411. +
  65412. +/** Number of 4-byte words in each of the periodic Tx FIFOs in device
  65413. + * mode when dynamic FIFO sizing is enabled.
  65414. + * 4 to 768 (default 256)
  65415. + */
  65416. +extern int dwc_otg_set_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65417. + int32_t val, int fifo_num);
  65418. +extern int32_t dwc_otg_get_param_dev_perio_tx_fifo_size(dwc_otg_core_if_t *
  65419. + core_if, int fifo_num);
  65420. +#define dwc_param_dev_perio_tx_fifo_size_default 256
  65421. +
  65422. +/** Number of 4-byte words in the Rx FIFO in host mode when dynamic
  65423. + * FIFO sizing is enabled.
  65424. + * 16 to 32768 (default 1024)
  65425. + */
  65426. +extern int dwc_otg_set_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if,
  65427. + int32_t val);
  65428. +extern int32_t dwc_otg_get_param_host_rx_fifo_size(dwc_otg_core_if_t * core_if);
  65429. +//#define dwc_param_host_rx_fifo_size_default 1024
  65430. +#define dwc_param_host_rx_fifo_size_default 774 // Broadcom BCM2708
  65431. +
  65432. +/** Number of 4-byte words in the non-periodic Tx FIFO in host mode
  65433. + * when Dynamic FIFO sizing is enabled in the core.
  65434. + * 16 to 32768 (default 1024)
  65435. + */
  65436. +extern int dwc_otg_set_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65437. + core_if, int32_t val);
  65438. +extern int32_t dwc_otg_get_param_host_nperio_tx_fifo_size(dwc_otg_core_if_t *
  65439. + core_if);
  65440. +//#define dwc_param_host_nperio_tx_fifo_size_default 1024
  65441. +#define dwc_param_host_nperio_tx_fifo_size_default 0x100 // Broadcom BCM2708
  65442. +
  65443. +/** Number of 4-byte words in the host periodic Tx FIFO when dynamic
  65444. + * FIFO sizing is enabled.
  65445. + * 16 to 32768 (default 1024)
  65446. + */
  65447. +extern int dwc_otg_set_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65448. + core_if, int32_t val);
  65449. +extern int32_t dwc_otg_get_param_host_perio_tx_fifo_size(dwc_otg_core_if_t *
  65450. + core_if);
  65451. +//#define dwc_param_host_perio_tx_fifo_size_default 1024
  65452. +#define dwc_param_host_perio_tx_fifo_size_default 0x200 // Broadcom BCM2708
  65453. +
  65454. +/** The maximum transfer size supported in bytes.
  65455. + * 2047 to 65,535 (default 65,535)
  65456. + */
  65457. +extern int dwc_otg_set_param_max_transfer_size(dwc_otg_core_if_t * core_if,
  65458. + int32_t val);
  65459. +extern int32_t dwc_otg_get_param_max_transfer_size(dwc_otg_core_if_t * core_if);
  65460. +#define dwc_param_max_transfer_size_default 65535
  65461. +
  65462. +/** The maximum number of packets in a transfer.
  65463. + * 15 to 511 (default 511)
  65464. + */
  65465. +extern int dwc_otg_set_param_max_packet_count(dwc_otg_core_if_t * core_if,
  65466. + int32_t val);
  65467. +extern int32_t dwc_otg_get_param_max_packet_count(dwc_otg_core_if_t * core_if);
  65468. +#define dwc_param_max_packet_count_default 511
  65469. +
  65470. +/** The number of host channel registers to use.
  65471. + * 1 to 16 (default 12)
  65472. + * Note: The FPGA configuration supports a maximum of 12 host channels.
  65473. + */
  65474. +extern int dwc_otg_set_param_host_channels(dwc_otg_core_if_t * core_if,
  65475. + int32_t val);
  65476. +extern int32_t dwc_otg_get_param_host_channels(dwc_otg_core_if_t * core_if);
  65477. +//#define dwc_param_host_channels_default 12
  65478. +#define dwc_param_host_channels_default 8 // Broadcom BCM2708
  65479. +
  65480. +/** The number of endpoints in addition to EP0 available for device
  65481. + * mode operations.
  65482. + * 1 to 15 (default 6 IN and OUT)
  65483. + * Note: The FPGA configuration supports a maximum of 6 IN and OUT
  65484. + * endpoints in addition to EP0.
  65485. + */
  65486. +extern int dwc_otg_set_param_dev_endpoints(dwc_otg_core_if_t * core_if,
  65487. + int32_t val);
  65488. +extern int32_t dwc_otg_get_param_dev_endpoints(dwc_otg_core_if_t * core_if);
  65489. +#define dwc_param_dev_endpoints_default 6
  65490. +
  65491. +/**
  65492. + * Specifies the type of PHY interface to use. By default, the driver
  65493. + * will automatically detect the phy_type.
  65494. + *
  65495. + * 0 - Full Speed PHY
  65496. + * 1 - UTMI+ (default)
  65497. + * 2 - ULPI
  65498. + */
  65499. +extern int dwc_otg_set_param_phy_type(dwc_otg_core_if_t * core_if, int32_t val);
  65500. +extern int32_t dwc_otg_get_param_phy_type(dwc_otg_core_if_t * core_if);
  65501. +#define DWC_PHY_TYPE_PARAM_FS 0
  65502. +#define DWC_PHY_TYPE_PARAM_UTMI 1
  65503. +#define DWC_PHY_TYPE_PARAM_ULPI 2
  65504. +#define dwc_param_phy_type_default DWC_PHY_TYPE_PARAM_UTMI
  65505. +
  65506. +/**
  65507. + * Specifies the UTMI+ Data Width. This parameter is
  65508. + * applicable for a PHY_TYPE of UTMI+ or ULPI. (For a ULPI
  65509. + * PHY_TYPE, this parameter indicates the data width between
  65510. + * the MAC and the ULPI Wrapper.) Also, this parameter is
  65511. + * applicable only if the OTG_HSPHY_WIDTH cC parameter was set
  65512. + * to "8 and 16 bits", meaning that the core has been
  65513. + * configured to work at either data path width.
  65514. + *
  65515. + * 8 or 16 bits (default 16)
  65516. + */
  65517. +extern int dwc_otg_set_param_phy_utmi_width(dwc_otg_core_if_t * core_if,
  65518. + int32_t val);
  65519. +extern int32_t dwc_otg_get_param_phy_utmi_width(dwc_otg_core_if_t * core_if);
  65520. +//#define dwc_param_phy_utmi_width_default 16
  65521. +#define dwc_param_phy_utmi_width_default 8 // Broadcom BCM2708
  65522. +
  65523. +/**
  65524. + * Specifies whether the ULPI operates at double or single
  65525. + * data rate. This parameter is only applicable if PHY_TYPE is
  65526. + * ULPI.
  65527. + *
  65528. + * 0 - single data rate ULPI interface with 8 bit wide data
  65529. + * bus (default)
  65530. + * 1 - double data rate ULPI interface with 4 bit wide data
  65531. + * bus
  65532. + */
  65533. +extern int dwc_otg_set_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if,
  65534. + int32_t val);
  65535. +extern int32_t dwc_otg_get_param_phy_ulpi_ddr(dwc_otg_core_if_t * core_if);
  65536. +#define dwc_param_phy_ulpi_ddr_default 0
  65537. +
  65538. +/**
  65539. + * Specifies whether to use the internal or external supply to
  65540. + * drive the vbus with a ULPI phy.
  65541. + */
  65542. +extern int dwc_otg_set_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if,
  65543. + int32_t val);
  65544. +extern int32_t dwc_otg_get_param_phy_ulpi_ext_vbus(dwc_otg_core_if_t * core_if);
  65545. +#define DWC_PHY_ULPI_INTERNAL_VBUS 0
  65546. +#define DWC_PHY_ULPI_EXTERNAL_VBUS 1
  65547. +#define dwc_param_phy_ulpi_ext_vbus_default DWC_PHY_ULPI_INTERNAL_VBUS
  65548. +
  65549. +/**
  65550. + * Specifies whether to use the I2Cinterface for full speed PHY. This
  65551. + * parameter is only applicable if PHY_TYPE is FS.
  65552. + * 0 - No (default)
  65553. + * 1 - Yes
  65554. + */
  65555. +extern int dwc_otg_set_param_i2c_enable(dwc_otg_core_if_t * core_if,
  65556. + int32_t val);
  65557. +extern int32_t dwc_otg_get_param_i2c_enable(dwc_otg_core_if_t * core_if);
  65558. +#define dwc_param_i2c_enable_default 0
  65559. +
  65560. +extern int dwc_otg_set_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if,
  65561. + int32_t val);
  65562. +extern int32_t dwc_otg_get_param_ulpi_fs_ls(dwc_otg_core_if_t * core_if);
  65563. +#define dwc_param_ulpi_fs_ls_default 0
  65564. +
  65565. +extern int dwc_otg_set_param_ts_dline(dwc_otg_core_if_t * core_if, int32_t val);
  65566. +extern int32_t dwc_otg_get_param_ts_dline(dwc_otg_core_if_t * core_if);
  65567. +#define dwc_param_ts_dline_default 0
  65568. +
  65569. +/**
  65570. + * Specifies whether dedicated transmit FIFOs are
  65571. + * enabled for non periodic IN endpoints in device mode
  65572. + * 0 - No
  65573. + * 1 - Yes
  65574. + */
  65575. +extern int dwc_otg_set_param_en_multiple_tx_fifo(dwc_otg_core_if_t * core_if,
  65576. + int32_t val);
  65577. +extern int32_t dwc_otg_get_param_en_multiple_tx_fifo(dwc_otg_core_if_t *
  65578. + core_if);
  65579. +#define dwc_param_en_multiple_tx_fifo_default 1
  65580. +
  65581. +/** Number of 4-byte words in each of the Tx FIFOs in device
  65582. + * mode when dynamic FIFO sizing is enabled.
  65583. + * 4 to 768 (default 256)
  65584. + */
  65585. +extern int dwc_otg_set_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65586. + int fifo_num, int32_t val);
  65587. +extern int32_t dwc_otg_get_param_dev_tx_fifo_size(dwc_otg_core_if_t * core_if,
  65588. + int fifo_num);
  65589. +#define dwc_param_dev_tx_fifo_size_default 768
  65590. +
  65591. +/** Thresholding enable flag-
  65592. + * bit 0 - enable non-ISO Tx thresholding
  65593. + * bit 1 - enable ISO Tx thresholding
  65594. + * bit 2 - enable Rx thresholding
  65595. + */
  65596. +extern int dwc_otg_set_param_thr_ctl(dwc_otg_core_if_t * core_if, int32_t val);
  65597. +extern int32_t dwc_otg_get_thr_ctl(dwc_otg_core_if_t * core_if, int fifo_num);
  65598. +#define dwc_param_thr_ctl_default 0
  65599. +
  65600. +/** Thresholding length for Tx
  65601. + * FIFOs in 32 bit DWORDs
  65602. + */
  65603. +extern int dwc_otg_set_param_tx_thr_length(dwc_otg_core_if_t * core_if,
  65604. + int32_t val);
  65605. +extern int32_t dwc_otg_get_tx_thr_length(dwc_otg_core_if_t * core_if);
  65606. +#define dwc_param_tx_thr_length_default 64
  65607. +
  65608. +/** Thresholding length for Rx
  65609. + * FIFOs in 32 bit DWORDs
  65610. + */
  65611. +extern int dwc_otg_set_param_rx_thr_length(dwc_otg_core_if_t * core_if,
  65612. + int32_t val);
  65613. +extern int32_t dwc_otg_get_rx_thr_length(dwc_otg_core_if_t * core_if);
  65614. +#define dwc_param_rx_thr_length_default 64
  65615. +
  65616. +/**
  65617. + * Specifies whether LPM (Link Power Management) support is enabled
  65618. + */
  65619. +extern int dwc_otg_set_param_lpm_enable(dwc_otg_core_if_t * core_if,
  65620. + int32_t val);
  65621. +extern int32_t dwc_otg_get_param_lpm_enable(dwc_otg_core_if_t * core_if);
  65622. +#define dwc_param_lpm_enable_default 1
  65623. +
  65624. +/**
  65625. + * Specifies whether PTI enhancement is enabled
  65626. + */
  65627. +extern int dwc_otg_set_param_pti_enable(dwc_otg_core_if_t * core_if,
  65628. + int32_t val);
  65629. +extern int32_t dwc_otg_get_param_pti_enable(dwc_otg_core_if_t * core_if);
  65630. +#define dwc_param_pti_enable_default 0
  65631. +
  65632. +/**
  65633. + * Specifies whether MPI enhancement is enabled
  65634. + */
  65635. +extern int dwc_otg_set_param_mpi_enable(dwc_otg_core_if_t * core_if,
  65636. + int32_t val);
  65637. +extern int32_t dwc_otg_get_param_mpi_enable(dwc_otg_core_if_t * core_if);
  65638. +#define dwc_param_mpi_enable_default 0
  65639. +
  65640. +/**
  65641. + * Specifies whether ADP capability is enabled
  65642. + */
  65643. +extern int dwc_otg_set_param_adp_enable(dwc_otg_core_if_t * core_if,
  65644. + int32_t val);
  65645. +extern int32_t dwc_otg_get_param_adp_enable(dwc_otg_core_if_t * core_if);
  65646. +#define dwc_param_adp_enable_default 0
  65647. +
  65648. +/**
  65649. + * Specifies whether IC_USB capability is enabled
  65650. + */
  65651. +
  65652. +extern int dwc_otg_set_param_ic_usb_cap(dwc_otg_core_if_t * core_if,
  65653. + int32_t val);
  65654. +extern int32_t dwc_otg_get_param_ic_usb_cap(dwc_otg_core_if_t * core_if);
  65655. +#define dwc_param_ic_usb_cap_default 0
  65656. +
  65657. +extern int dwc_otg_set_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if,
  65658. + int32_t val);
  65659. +extern int32_t dwc_otg_get_param_ahb_thr_ratio(dwc_otg_core_if_t * core_if);
  65660. +#define dwc_param_ahb_thr_ratio_default 0
  65661. +
  65662. +extern int dwc_otg_set_param_power_down(dwc_otg_core_if_t * core_if,
  65663. + int32_t val);
  65664. +extern int32_t dwc_otg_get_param_power_down(dwc_otg_core_if_t * core_if);
  65665. +#define dwc_param_power_down_default 0
  65666. +
  65667. +extern int dwc_otg_set_param_reload_ctl(dwc_otg_core_if_t * core_if,
  65668. + int32_t val);
  65669. +extern int32_t dwc_otg_get_param_reload_ctl(dwc_otg_core_if_t * core_if);
  65670. +#define dwc_param_reload_ctl_default 0
  65671. +
  65672. +extern int dwc_otg_set_param_dev_out_nak(dwc_otg_core_if_t * core_if,
  65673. + int32_t val);
  65674. +extern int32_t dwc_otg_get_param_dev_out_nak(dwc_otg_core_if_t * core_if);
  65675. +#define dwc_param_dev_out_nak_default 0
  65676. +
  65677. +extern int dwc_otg_set_param_cont_on_bna(dwc_otg_core_if_t * core_if,
  65678. + int32_t val);
  65679. +extern int32_t dwc_otg_get_param_cont_on_bna(dwc_otg_core_if_t * core_if);
  65680. +#define dwc_param_cont_on_bna_default 0
  65681. +
  65682. +extern int dwc_otg_set_param_ahb_single(dwc_otg_core_if_t * core_if,
  65683. + int32_t val);
  65684. +extern int32_t dwc_otg_get_param_ahb_single(dwc_otg_core_if_t * core_if);
  65685. +#define dwc_param_ahb_single_default 0
  65686. +
  65687. +extern int dwc_otg_set_param_otg_ver(dwc_otg_core_if_t * core_if, int32_t val);
  65688. +extern int32_t dwc_otg_get_param_otg_ver(dwc_otg_core_if_t * core_if);
  65689. +#define dwc_param_otg_ver_default 0
  65690. +
  65691. +/** @} */
  65692. +
  65693. +/** @name Access to registers and bit-fields */
  65694. +
  65695. +/**
  65696. + * Dump core registers and SPRAM
  65697. + */
  65698. +extern void dwc_otg_dump_dev_registers(dwc_otg_core_if_t * _core_if);
  65699. +extern void dwc_otg_dump_spram(dwc_otg_core_if_t * _core_if);
  65700. +extern void dwc_otg_dump_host_registers(dwc_otg_core_if_t * _core_if);
  65701. +extern void dwc_otg_dump_global_registers(dwc_otg_core_if_t * _core_if);
  65702. +
  65703. +/**
  65704. + * Get host negotiation status.
  65705. + */
  65706. +extern uint32_t dwc_otg_get_hnpstatus(dwc_otg_core_if_t * core_if);
  65707. +
  65708. +/**
  65709. + * Get srp status
  65710. + */
  65711. +extern uint32_t dwc_otg_get_srpstatus(dwc_otg_core_if_t * core_if);
  65712. +
  65713. +/**
  65714. + * Set hnpreq bit in the GOTGCTL register.
  65715. + */
  65716. +extern void dwc_otg_set_hnpreq(dwc_otg_core_if_t * core_if, uint32_t val);
  65717. +
  65718. +/**
  65719. + * Get Content of SNPSID register.
  65720. + */
  65721. +extern uint32_t dwc_otg_get_gsnpsid(dwc_otg_core_if_t * core_if);
  65722. +
  65723. +/**
  65724. + * Get current mode.
  65725. + * Returns 0 if in device mode, and 1 if in host mode.
  65726. + */
  65727. +extern uint32_t dwc_otg_get_mode(dwc_otg_core_if_t * core_if);
  65728. +
  65729. +/**
  65730. + * Get value of hnpcapable field in the GUSBCFG register
  65731. + */
  65732. +extern uint32_t dwc_otg_get_hnpcapable(dwc_otg_core_if_t * core_if);
  65733. +/**
  65734. + * Set value of hnpcapable field in the GUSBCFG register
  65735. + */
  65736. +extern void dwc_otg_set_hnpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65737. +
  65738. +/**
  65739. + * Get value of srpcapable field in the GUSBCFG register
  65740. + */
  65741. +extern uint32_t dwc_otg_get_srpcapable(dwc_otg_core_if_t * core_if);
  65742. +/**
  65743. + * Set value of srpcapable field in the GUSBCFG register
  65744. + */
  65745. +extern void dwc_otg_set_srpcapable(dwc_otg_core_if_t * core_if, uint32_t val);
  65746. +
  65747. +/**
  65748. + * Get value of devspeed field in the DCFG register
  65749. + */
  65750. +extern uint32_t dwc_otg_get_devspeed(dwc_otg_core_if_t * core_if);
  65751. +/**
  65752. + * Set value of devspeed field in the DCFG register
  65753. + */
  65754. +extern void dwc_otg_set_devspeed(dwc_otg_core_if_t * core_if, uint32_t val);
  65755. +
  65756. +/**
  65757. + * Get the value of busconnected field from the HPRT0 register
  65758. + */
  65759. +extern uint32_t dwc_otg_get_busconnected(dwc_otg_core_if_t * core_if);
  65760. +
  65761. +/**
  65762. + * Gets the device enumeration Speed.
  65763. + */
  65764. +extern uint32_t dwc_otg_get_enumspeed(dwc_otg_core_if_t * core_if);
  65765. +
  65766. +/**
  65767. + * Get value of prtpwr field from the HPRT0 register
  65768. + */
  65769. +extern uint32_t dwc_otg_get_prtpower(dwc_otg_core_if_t * core_if);
  65770. +
  65771. +/**
  65772. + * Get value of flag indicating core state - hibernated or not
  65773. + */
  65774. +extern uint32_t dwc_otg_get_core_state(dwc_otg_core_if_t * core_if);
  65775. +
  65776. +/**
  65777. + * Set value of prtpwr field from the HPRT0 register
  65778. + */
  65779. +extern void dwc_otg_set_prtpower(dwc_otg_core_if_t * core_if, uint32_t val);
  65780. +
  65781. +/**
  65782. + * Get value of prtsusp field from the HPRT0 regsiter
  65783. + */
  65784. +extern uint32_t dwc_otg_get_prtsuspend(dwc_otg_core_if_t * core_if);
  65785. +/**
  65786. + * Set value of prtpwr field from the HPRT0 register
  65787. + */
  65788. +extern void dwc_otg_set_prtsuspend(dwc_otg_core_if_t * core_if, uint32_t val);
  65789. +
  65790. +/**
  65791. + * Get value of ModeChTimEn field from the HCFG regsiter
  65792. + */
  65793. +extern uint32_t dwc_otg_get_mode_ch_tim(dwc_otg_core_if_t * core_if);
  65794. +/**
  65795. + * Set value of ModeChTimEn field from the HCFG regsiter
  65796. + */
  65797. +extern void dwc_otg_set_mode_ch_tim(dwc_otg_core_if_t * core_if, uint32_t val);
  65798. +
  65799. +/**
  65800. + * Get value of Fram Interval field from the HFIR regsiter
  65801. + */
  65802. +extern uint32_t dwc_otg_get_fr_interval(dwc_otg_core_if_t * core_if);
  65803. +/**
  65804. + * Set value of Frame Interval field from the HFIR regsiter
  65805. + */
  65806. +extern void dwc_otg_set_fr_interval(dwc_otg_core_if_t * core_if, uint32_t val);
  65807. +
  65808. +/**
  65809. + * Set value of prtres field from the HPRT0 register
  65810. + *FIXME Remove?
  65811. + */
  65812. +extern void dwc_otg_set_prtresume(dwc_otg_core_if_t * core_if, uint32_t val);
  65813. +
  65814. +/**
  65815. + * Get value of rmtwkupsig bit in DCTL register
  65816. + */
  65817. +extern uint32_t dwc_otg_get_remotewakesig(dwc_otg_core_if_t * core_if);
  65818. +
  65819. +/**
  65820. + * Get value of prt_sleep_sts field from the GLPMCFG register
  65821. + */
  65822. +extern uint32_t dwc_otg_get_lpm_portsleepstatus(dwc_otg_core_if_t * core_if);
  65823. +
  65824. +/**
  65825. + * Get value of rem_wkup_en field from the GLPMCFG register
  65826. + */
  65827. +extern uint32_t dwc_otg_get_lpm_remotewakeenabled(dwc_otg_core_if_t * core_if);
  65828. +
  65829. +/**
  65830. + * Get value of appl_resp field from the GLPMCFG register
  65831. + */
  65832. +extern uint32_t dwc_otg_get_lpmresponse(dwc_otg_core_if_t * core_if);
  65833. +/**
  65834. + * Set value of appl_resp field from the GLPMCFG register
  65835. + */
  65836. +extern void dwc_otg_set_lpmresponse(dwc_otg_core_if_t * core_if, uint32_t val);
  65837. +
  65838. +/**
  65839. + * Get value of hsic_connect field from the GLPMCFG register
  65840. + */
  65841. +extern uint32_t dwc_otg_get_hsic_connect(dwc_otg_core_if_t * core_if);
  65842. +/**
  65843. + * Set value of hsic_connect field from the GLPMCFG register
  65844. + */
  65845. +extern void dwc_otg_set_hsic_connect(dwc_otg_core_if_t * core_if, uint32_t val);
  65846. +
  65847. +/**
  65848. + * Get value of inv_sel_hsic field from the GLPMCFG register.
  65849. + */
  65850. +extern uint32_t dwc_otg_get_inv_sel_hsic(dwc_otg_core_if_t * core_if);
  65851. +/**
  65852. + * Set value of inv_sel_hsic field from the GLPMFG register.
  65853. + */
  65854. +extern void dwc_otg_set_inv_sel_hsic(dwc_otg_core_if_t * core_if, uint32_t val);
  65855. +
  65856. +/*
  65857. + * Some functions for accessing registers
  65858. + */
  65859. +
  65860. +/**
  65861. + * GOTGCTL register
  65862. + */
  65863. +extern uint32_t dwc_otg_get_gotgctl(dwc_otg_core_if_t * core_if);
  65864. +extern void dwc_otg_set_gotgctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65865. +
  65866. +/**
  65867. + * GUSBCFG register
  65868. + */
  65869. +extern uint32_t dwc_otg_get_gusbcfg(dwc_otg_core_if_t * core_if);
  65870. +extern void dwc_otg_set_gusbcfg(dwc_otg_core_if_t * core_if, uint32_t val);
  65871. +
  65872. +/**
  65873. + * GRXFSIZ register
  65874. + */
  65875. +extern uint32_t dwc_otg_get_grxfsiz(dwc_otg_core_if_t * core_if);
  65876. +extern void dwc_otg_set_grxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65877. +
  65878. +/**
  65879. + * GNPTXFSIZ register
  65880. + */
  65881. +extern uint32_t dwc_otg_get_gnptxfsiz(dwc_otg_core_if_t * core_if);
  65882. +extern void dwc_otg_set_gnptxfsiz(dwc_otg_core_if_t * core_if, uint32_t val);
  65883. +
  65884. +extern uint32_t dwc_otg_get_gpvndctl(dwc_otg_core_if_t * core_if);
  65885. +extern void dwc_otg_set_gpvndctl(dwc_otg_core_if_t * core_if, uint32_t val);
  65886. +
  65887. +/**
  65888. + * GGPIO register
  65889. + */
  65890. +extern uint32_t dwc_otg_get_ggpio(dwc_otg_core_if_t * core_if);
  65891. +extern void dwc_otg_set_ggpio(dwc_otg_core_if_t * core_if, uint32_t val);
  65892. +
  65893. +/**
  65894. + * GUID register
  65895. + */
  65896. +extern uint32_t dwc_otg_get_guid(dwc_otg_core_if_t * core_if);
  65897. +extern void dwc_otg_set_guid(dwc_otg_core_if_t * core_if, uint32_t val);
  65898. +
  65899. +/**
  65900. + * HPRT0 register
  65901. + */
  65902. +extern uint32_t dwc_otg_get_hprt0(dwc_otg_core_if_t * core_if);
  65903. +extern void dwc_otg_set_hprt0(dwc_otg_core_if_t * core_if, uint32_t val);
  65904. +
  65905. +/**
  65906. + * GHPTXFSIZE
  65907. + */
  65908. +extern uint32_t dwc_otg_get_hptxfsiz(dwc_otg_core_if_t * core_if);
  65909. +
  65910. +/** @} */
  65911. +
  65912. +#endif /* __DWC_CORE_IF_H__ */
  65913. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_dbg.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h
  65914. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 1970-01-01 01:00:00.000000000 +0100
  65915. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_dbg.h 2014-06-11 21:03:43.000000000 +0200
  65916. @@ -0,0 +1,117 @@
  65917. +/* ==========================================================================
  65918. + *
  65919. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  65920. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  65921. + * otherwise expressly agreed to in writing between Synopsys and you.
  65922. + *
  65923. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  65924. + * any End User Software License Agreement or Agreement for Licensed Product
  65925. + * with Synopsys or any supplement thereto. You are permitted to use and
  65926. + * redistribute this Software in source and binary forms, with or without
  65927. + * modification, provided that redistributions of source code must retain this
  65928. + * notice. You may not view, use, disclose, copy or distribute this file or
  65929. + * any information contained herein except pursuant to this license grant from
  65930. + * Synopsys. If you do not agree with this notice, including the disclaimer
  65931. + * below, then you are not authorized to use the Software.
  65932. + *
  65933. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  65934. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  65935. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  65936. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  65937. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  65938. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  65939. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  65940. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  65941. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  65942. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  65943. + * DAMAGE.
  65944. + * ========================================================================== */
  65945. +
  65946. +#ifndef __DWC_OTG_DBG_H__
  65947. +#define __DWC_OTG_DBG_H__
  65948. +
  65949. +/** @file
  65950. + * This file defines debug levels.
  65951. + * Debugging support vanishes in non-debug builds.
  65952. + */
  65953. +
  65954. +/**
  65955. + * The Debug Level bit-mask variable.
  65956. + */
  65957. +extern uint32_t g_dbg_lvl;
  65958. +/**
  65959. + * Set the Debug Level variable.
  65960. + */
  65961. +static inline uint32_t SET_DEBUG_LEVEL(const uint32_t new)
  65962. +{
  65963. + uint32_t old = g_dbg_lvl;
  65964. + g_dbg_lvl = new;
  65965. + return old;
  65966. +}
  65967. +
  65968. +#define DBG_USER (0x1)
  65969. +/** When debug level has the DBG_CIL bit set, display CIL Debug messages. */
  65970. +#define DBG_CIL (0x2)
  65971. +/** When debug level has the DBG_CILV bit set, display CIL Verbose debug
  65972. + * messages */
  65973. +#define DBG_CILV (0x20)
  65974. +/** When debug level has the DBG_PCD bit set, display PCD (Device) debug
  65975. + * messages */
  65976. +#define DBG_PCD (0x4)
  65977. +/** When debug level has the DBG_PCDV set, display PCD (Device) Verbose debug
  65978. + * messages */
  65979. +#define DBG_PCDV (0x40)
  65980. +/** When debug level has the DBG_HCD bit set, display Host debug messages */
  65981. +#define DBG_HCD (0x8)
  65982. +/** When debug level has the DBG_HCDV bit set, display Verbose Host debug
  65983. + * messages */
  65984. +#define DBG_HCDV (0x80)
  65985. +/** When debug level has the DBG_HCD_URB bit set, display enqueued URBs in host
  65986. + * mode. */
  65987. +#define DBG_HCD_URB (0x800)
  65988. +/** When debug level has the DBG_HCDI bit set, display host interrupt
  65989. + * messages. */
  65990. +#define DBG_HCDI (0x1000)
  65991. +
  65992. +/** When debug level has any bit set, display debug messages */
  65993. +#define DBG_ANY (0xFF)
  65994. +
  65995. +/** All debug messages off */
  65996. +#define DBG_OFF 0
  65997. +
  65998. +/** Prefix string for DWC_DEBUG print macros. */
  65999. +#define USB_DWC "DWC_otg: "
  66000. +
  66001. +/**
  66002. + * Print a debug message when the Global debug level variable contains
  66003. + * the bit defined in <code>lvl</code>.
  66004. + *
  66005. + * @param[in] lvl - Debug level, use one of the DBG_ constants above.
  66006. + * @param[in] x - like printf
  66007. + *
  66008. + * Example:<p>
  66009. + * <code>
  66010. + * DWC_DEBUGPL( DBG_ANY, "%s(%p)\n", __func__, _reg_base_addr);
  66011. + * </code>
  66012. + * <br>
  66013. + * results in:<br>
  66014. + * <code>
  66015. + * usb-DWC_otg: dwc_otg_cil_init(ca867000)
  66016. + * </code>
  66017. + */
  66018. +#ifdef DEBUG
  66019. +
  66020. +# define DWC_DEBUGPL(lvl, x...) do{ if ((lvl)&g_dbg_lvl)__DWC_DEBUG(USB_DWC x ); }while(0)
  66021. +# define DWC_DEBUGP(x...) DWC_DEBUGPL(DBG_ANY, x )
  66022. +
  66023. +# define CHK_DEBUG_LEVEL(level) ((level) & g_dbg_lvl)
  66024. +
  66025. +#else
  66026. +
  66027. +# define DWC_DEBUGPL(lvl, x...) do{}while(0)
  66028. +# define DWC_DEBUGP(x...)
  66029. +
  66030. +# define CHK_DEBUG_LEVEL(level) (0)
  66031. +
  66032. +#endif /*DEBUG*/
  66033. +#endif
  66034. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_driver.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c
  66035. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_driver.c 1970-01-01 01:00:00.000000000 +0100
  66036. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.c 2014-06-11 21:03:43.000000000 +0200
  66037. @@ -0,0 +1,1749 @@
  66038. +/* ==========================================================================
  66039. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.c $
  66040. + * $Revision: #92 $
  66041. + * $Date: 2012/08/10 $
  66042. + * $Change: 2047372 $
  66043. + *
  66044. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  66045. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  66046. + * otherwise expressly agreed to in writing between Synopsys and you.
  66047. + *
  66048. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  66049. + * any End User Software License Agreement or Agreement for Licensed Product
  66050. + * with Synopsys or any supplement thereto. You are permitted to use and
  66051. + * redistribute this Software in source and binary forms, with or without
  66052. + * modification, provided that redistributions of source code must retain this
  66053. + * notice. You may not view, use, disclose, copy or distribute this file or
  66054. + * any information contained herein except pursuant to this license grant from
  66055. + * Synopsys. If you do not agree with this notice, including the disclaimer
  66056. + * below, then you are not authorized to use the Software.
  66057. + *
  66058. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  66059. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66060. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  66061. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  66062. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  66063. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  66064. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  66065. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66066. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  66067. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  66068. + * DAMAGE.
  66069. + * ========================================================================== */
  66070. +
  66071. +/** @file
  66072. + * The dwc_otg_driver module provides the initialization and cleanup entry
  66073. + * points for the DWC_otg driver. This module will be dynamically installed
  66074. + * after Linux is booted using the insmod command. When the module is
  66075. + * installed, the dwc_otg_driver_init function is called. When the module is
  66076. + * removed (using rmmod), the dwc_otg_driver_cleanup function is called.
  66077. + *
  66078. + * This module also defines a data structure for the dwc_otg_driver, which is
  66079. + * used in conjunction with the standard ARM lm_device structure. These
  66080. + * structures allow the OTG driver to comply with the standard Linux driver
  66081. + * model in which devices and drivers are registered with a bus driver. This
  66082. + * has the benefit that Linux can expose attributes of the driver and device
  66083. + * in its special sysfs file system. Users can then read or write files in
  66084. + * this file system to perform diagnostics on the driver components or the
  66085. + * device.
  66086. + */
  66087. +
  66088. +#include "dwc_otg_os_dep.h"
  66089. +#include "dwc_os.h"
  66090. +#include "dwc_otg_dbg.h"
  66091. +#include "dwc_otg_driver.h"
  66092. +#include "dwc_otg_attr.h"
  66093. +#include "dwc_otg_core_if.h"
  66094. +#include "dwc_otg_pcd_if.h"
  66095. +#include "dwc_otg_hcd_if.h"
  66096. +#include "dwc_otg_fiq_fsm.h"
  66097. +
  66098. +#define DWC_DRIVER_VERSION "3.00a 10-AUG-2012"
  66099. +#define DWC_DRIVER_DESC "HS OTG USB Controller driver"
  66100. +
  66101. +bool microframe_schedule=true;
  66102. +
  66103. +static const char dwc_driver_name[] = "dwc_otg";
  66104. +
  66105. +
  66106. +extern int pcd_init(
  66107. +#ifdef LM_INTERFACE
  66108. + struct lm_device *_dev
  66109. +#elif defined(PCI_INTERFACE)
  66110. + struct pci_dev *_dev
  66111. +#elif defined(PLATFORM_INTERFACE)
  66112. + struct platform_device *dev
  66113. +#endif
  66114. + );
  66115. +extern int hcd_init(
  66116. +#ifdef LM_INTERFACE
  66117. + struct lm_device *_dev
  66118. +#elif defined(PCI_INTERFACE)
  66119. + struct pci_dev *_dev
  66120. +#elif defined(PLATFORM_INTERFACE)
  66121. + struct platform_device *dev
  66122. +#endif
  66123. + );
  66124. +
  66125. +extern int pcd_remove(
  66126. +#ifdef LM_INTERFACE
  66127. + struct lm_device *_dev
  66128. +#elif defined(PCI_INTERFACE)
  66129. + struct pci_dev *_dev
  66130. +#elif defined(PLATFORM_INTERFACE)
  66131. + struct platform_device *_dev
  66132. +#endif
  66133. + );
  66134. +
  66135. +extern void hcd_remove(
  66136. +#ifdef LM_INTERFACE
  66137. + struct lm_device *_dev
  66138. +#elif defined(PCI_INTERFACE)
  66139. + struct pci_dev *_dev
  66140. +#elif defined(PLATFORM_INTERFACE)
  66141. + struct platform_device *_dev
  66142. +#endif
  66143. + );
  66144. +
  66145. +extern void dwc_otg_adp_start(dwc_otg_core_if_t * core_if, uint8_t is_host);
  66146. +
  66147. +/*-------------------------------------------------------------------------*/
  66148. +/* Encapsulate the module parameter settings */
  66149. +
  66150. +struct dwc_otg_driver_module_params {
  66151. + int32_t opt;
  66152. + int32_t otg_cap;
  66153. + int32_t dma_enable;
  66154. + int32_t dma_desc_enable;
  66155. + int32_t dma_burst_size;
  66156. + int32_t speed;
  66157. + int32_t host_support_fs_ls_low_power;
  66158. + int32_t host_ls_low_power_phy_clk;
  66159. + int32_t enable_dynamic_fifo;
  66160. + int32_t data_fifo_size;
  66161. + int32_t dev_rx_fifo_size;
  66162. + int32_t dev_nperio_tx_fifo_size;
  66163. + uint32_t dev_perio_tx_fifo_size[MAX_PERIO_FIFOS];
  66164. + int32_t host_rx_fifo_size;
  66165. + int32_t host_nperio_tx_fifo_size;
  66166. + int32_t host_perio_tx_fifo_size;
  66167. + int32_t max_transfer_size;
  66168. + int32_t max_packet_count;
  66169. + int32_t host_channels;
  66170. + int32_t dev_endpoints;
  66171. + int32_t phy_type;
  66172. + int32_t phy_utmi_width;
  66173. + int32_t phy_ulpi_ddr;
  66174. + int32_t phy_ulpi_ext_vbus;
  66175. + int32_t i2c_enable;
  66176. + int32_t ulpi_fs_ls;
  66177. + int32_t ts_dline;
  66178. + int32_t en_multiple_tx_fifo;
  66179. + uint32_t dev_tx_fifo_size[MAX_TX_FIFOS];
  66180. + uint32_t thr_ctl;
  66181. + uint32_t tx_thr_length;
  66182. + uint32_t rx_thr_length;
  66183. + int32_t pti_enable;
  66184. + int32_t mpi_enable;
  66185. + int32_t lpm_enable;
  66186. + int32_t ic_usb_cap;
  66187. + int32_t ahb_thr_ratio;
  66188. + int32_t power_down;
  66189. + int32_t reload_ctl;
  66190. + int32_t dev_out_nak;
  66191. + int32_t cont_on_bna;
  66192. + int32_t ahb_single;
  66193. + int32_t otg_ver;
  66194. + int32_t adp_enable;
  66195. +};
  66196. +
  66197. +static struct dwc_otg_driver_module_params dwc_otg_module_params = {
  66198. + .opt = -1,
  66199. + .otg_cap = -1,
  66200. + .dma_enable = -1,
  66201. + .dma_desc_enable = -1,
  66202. + .dma_burst_size = -1,
  66203. + .speed = -1,
  66204. + .host_support_fs_ls_low_power = -1,
  66205. + .host_ls_low_power_phy_clk = -1,
  66206. + .enable_dynamic_fifo = -1,
  66207. + .data_fifo_size = -1,
  66208. + .dev_rx_fifo_size = -1,
  66209. + .dev_nperio_tx_fifo_size = -1,
  66210. + .dev_perio_tx_fifo_size = {
  66211. + /* dev_perio_tx_fifo_size_1 */
  66212. + -1,
  66213. + -1,
  66214. + -1,
  66215. + -1,
  66216. + -1,
  66217. + -1,
  66218. + -1,
  66219. + -1,
  66220. + -1,
  66221. + -1,
  66222. + -1,
  66223. + -1,
  66224. + -1,
  66225. + -1,
  66226. + -1
  66227. + /* 15 */
  66228. + },
  66229. + .host_rx_fifo_size = -1,
  66230. + .host_nperio_tx_fifo_size = -1,
  66231. + .host_perio_tx_fifo_size = -1,
  66232. + .max_transfer_size = -1,
  66233. + .max_packet_count = -1,
  66234. + .host_channels = -1,
  66235. + .dev_endpoints = -1,
  66236. + .phy_type = -1,
  66237. + .phy_utmi_width = -1,
  66238. + .phy_ulpi_ddr = -1,
  66239. + .phy_ulpi_ext_vbus = -1,
  66240. + .i2c_enable = -1,
  66241. + .ulpi_fs_ls = -1,
  66242. + .ts_dline = -1,
  66243. + .en_multiple_tx_fifo = -1,
  66244. + .dev_tx_fifo_size = {
  66245. + /* dev_tx_fifo_size */
  66246. + -1,
  66247. + -1,
  66248. + -1,
  66249. + -1,
  66250. + -1,
  66251. + -1,
  66252. + -1,
  66253. + -1,
  66254. + -1,
  66255. + -1,
  66256. + -1,
  66257. + -1,
  66258. + -1,
  66259. + -1,
  66260. + -1
  66261. + /* 15 */
  66262. + },
  66263. + .thr_ctl = -1,
  66264. + .tx_thr_length = -1,
  66265. + .rx_thr_length = -1,
  66266. + .pti_enable = -1,
  66267. + .mpi_enable = -1,
  66268. + .lpm_enable = 0,
  66269. + .ic_usb_cap = -1,
  66270. + .ahb_thr_ratio = -1,
  66271. + .power_down = -1,
  66272. + .reload_ctl = -1,
  66273. + .dev_out_nak = -1,
  66274. + .cont_on_bna = -1,
  66275. + .ahb_single = -1,
  66276. + .otg_ver = -1,
  66277. + .adp_enable = -1,
  66278. +};
  66279. +
  66280. +//Global variable to switch the fiq fix on or off
  66281. +bool fiq_enable = 1;
  66282. +// Global variable to enable the split transaction fix
  66283. +bool fiq_fsm_enable = true;
  66284. +//Bulk split-transaction NAK holdoff in microframes
  66285. +uint16_t nak_holdoff = 8;
  66286. +
  66287. +unsigned short fiq_fsm_mask = 0x07;
  66288. +
  66289. +/**
  66290. + * This function shows the Driver Version.
  66291. + */
  66292. +static ssize_t version_show(struct device_driver *dev, char *buf)
  66293. +{
  66294. + return snprintf(buf, sizeof(DWC_DRIVER_VERSION) + 2, "%s\n",
  66295. + DWC_DRIVER_VERSION);
  66296. +}
  66297. +
  66298. +static DRIVER_ATTR(version, S_IRUGO, version_show, NULL);
  66299. +
  66300. +/**
  66301. + * Global Debug Level Mask.
  66302. + */
  66303. +uint32_t g_dbg_lvl = 0; /* OFF */
  66304. +
  66305. +/**
  66306. + * This function shows the driver Debug Level.
  66307. + */
  66308. +static ssize_t dbg_level_show(struct device_driver *drv, char *buf)
  66309. +{
  66310. + return sprintf(buf, "0x%0x\n", g_dbg_lvl);
  66311. +}
  66312. +
  66313. +/**
  66314. + * This function stores the driver Debug Level.
  66315. + */
  66316. +static ssize_t dbg_level_store(struct device_driver *drv, const char *buf,
  66317. + size_t count)
  66318. +{
  66319. + g_dbg_lvl = simple_strtoul(buf, NULL, 16);
  66320. + return count;
  66321. +}
  66322. +
  66323. +static DRIVER_ATTR(debuglevel, S_IRUGO | S_IWUSR, dbg_level_show,
  66324. + dbg_level_store);
  66325. +
  66326. +/**
  66327. + * This function is called during module intialization
  66328. + * to pass module parameters to the DWC_OTG CORE.
  66329. + */
  66330. +static int set_parameters(dwc_otg_core_if_t * core_if)
  66331. +{
  66332. + int retval = 0;
  66333. + int i;
  66334. +
  66335. + if (dwc_otg_module_params.otg_cap != -1) {
  66336. + retval +=
  66337. + dwc_otg_set_param_otg_cap(core_if,
  66338. + dwc_otg_module_params.otg_cap);
  66339. + }
  66340. + if (dwc_otg_module_params.dma_enable != -1) {
  66341. + retval +=
  66342. + dwc_otg_set_param_dma_enable(core_if,
  66343. + dwc_otg_module_params.
  66344. + dma_enable);
  66345. + }
  66346. + if (dwc_otg_module_params.dma_desc_enable != -1) {
  66347. + retval +=
  66348. + dwc_otg_set_param_dma_desc_enable(core_if,
  66349. + dwc_otg_module_params.
  66350. + dma_desc_enable);
  66351. + }
  66352. + if (dwc_otg_module_params.opt != -1) {
  66353. + retval +=
  66354. + dwc_otg_set_param_opt(core_if, dwc_otg_module_params.opt);
  66355. + }
  66356. + if (dwc_otg_module_params.dma_burst_size != -1) {
  66357. + retval +=
  66358. + dwc_otg_set_param_dma_burst_size(core_if,
  66359. + dwc_otg_module_params.
  66360. + dma_burst_size);
  66361. + }
  66362. + if (dwc_otg_module_params.host_support_fs_ls_low_power != -1) {
  66363. + retval +=
  66364. + dwc_otg_set_param_host_support_fs_ls_low_power(core_if,
  66365. + dwc_otg_module_params.
  66366. + host_support_fs_ls_low_power);
  66367. + }
  66368. + if (dwc_otg_module_params.enable_dynamic_fifo != -1) {
  66369. + retval +=
  66370. + dwc_otg_set_param_enable_dynamic_fifo(core_if,
  66371. + dwc_otg_module_params.
  66372. + enable_dynamic_fifo);
  66373. + }
  66374. + if (dwc_otg_module_params.data_fifo_size != -1) {
  66375. + retval +=
  66376. + dwc_otg_set_param_data_fifo_size(core_if,
  66377. + dwc_otg_module_params.
  66378. + data_fifo_size);
  66379. + }
  66380. + if (dwc_otg_module_params.dev_rx_fifo_size != -1) {
  66381. + retval +=
  66382. + dwc_otg_set_param_dev_rx_fifo_size(core_if,
  66383. + dwc_otg_module_params.
  66384. + dev_rx_fifo_size);
  66385. + }
  66386. + if (dwc_otg_module_params.dev_nperio_tx_fifo_size != -1) {
  66387. + retval +=
  66388. + dwc_otg_set_param_dev_nperio_tx_fifo_size(core_if,
  66389. + dwc_otg_module_params.
  66390. + dev_nperio_tx_fifo_size);
  66391. + }
  66392. + if (dwc_otg_module_params.host_rx_fifo_size != -1) {
  66393. + retval +=
  66394. + dwc_otg_set_param_host_rx_fifo_size(core_if,
  66395. + dwc_otg_module_params.host_rx_fifo_size);
  66396. + }
  66397. + if (dwc_otg_module_params.host_nperio_tx_fifo_size != -1) {
  66398. + retval +=
  66399. + dwc_otg_set_param_host_nperio_tx_fifo_size(core_if,
  66400. + dwc_otg_module_params.
  66401. + host_nperio_tx_fifo_size);
  66402. + }
  66403. + if (dwc_otg_module_params.host_perio_tx_fifo_size != -1) {
  66404. + retval +=
  66405. + dwc_otg_set_param_host_perio_tx_fifo_size(core_if,
  66406. + dwc_otg_module_params.
  66407. + host_perio_tx_fifo_size);
  66408. + }
  66409. + if (dwc_otg_module_params.max_transfer_size != -1) {
  66410. + retval +=
  66411. + dwc_otg_set_param_max_transfer_size(core_if,
  66412. + dwc_otg_module_params.
  66413. + max_transfer_size);
  66414. + }
  66415. + if (dwc_otg_module_params.max_packet_count != -1) {
  66416. + retval +=
  66417. + dwc_otg_set_param_max_packet_count(core_if,
  66418. + dwc_otg_module_params.
  66419. + max_packet_count);
  66420. + }
  66421. + if (dwc_otg_module_params.host_channels != -1) {
  66422. + retval +=
  66423. + dwc_otg_set_param_host_channels(core_if,
  66424. + dwc_otg_module_params.
  66425. + host_channels);
  66426. + }
  66427. + if (dwc_otg_module_params.dev_endpoints != -1) {
  66428. + retval +=
  66429. + dwc_otg_set_param_dev_endpoints(core_if,
  66430. + dwc_otg_module_params.
  66431. + dev_endpoints);
  66432. + }
  66433. + if (dwc_otg_module_params.phy_type != -1) {
  66434. + retval +=
  66435. + dwc_otg_set_param_phy_type(core_if,
  66436. + dwc_otg_module_params.phy_type);
  66437. + }
  66438. + if (dwc_otg_module_params.speed != -1) {
  66439. + retval +=
  66440. + dwc_otg_set_param_speed(core_if,
  66441. + dwc_otg_module_params.speed);
  66442. + }
  66443. + if (dwc_otg_module_params.host_ls_low_power_phy_clk != -1) {
  66444. + retval +=
  66445. + dwc_otg_set_param_host_ls_low_power_phy_clk(core_if,
  66446. + dwc_otg_module_params.
  66447. + host_ls_low_power_phy_clk);
  66448. + }
  66449. + if (dwc_otg_module_params.phy_ulpi_ddr != -1) {
  66450. + retval +=
  66451. + dwc_otg_set_param_phy_ulpi_ddr(core_if,
  66452. + dwc_otg_module_params.
  66453. + phy_ulpi_ddr);
  66454. + }
  66455. + if (dwc_otg_module_params.phy_ulpi_ext_vbus != -1) {
  66456. + retval +=
  66457. + dwc_otg_set_param_phy_ulpi_ext_vbus(core_if,
  66458. + dwc_otg_module_params.
  66459. + phy_ulpi_ext_vbus);
  66460. + }
  66461. + if (dwc_otg_module_params.phy_utmi_width != -1) {
  66462. + retval +=
  66463. + dwc_otg_set_param_phy_utmi_width(core_if,
  66464. + dwc_otg_module_params.
  66465. + phy_utmi_width);
  66466. + }
  66467. + if (dwc_otg_module_params.ulpi_fs_ls != -1) {
  66468. + retval +=
  66469. + dwc_otg_set_param_ulpi_fs_ls(core_if,
  66470. + dwc_otg_module_params.ulpi_fs_ls);
  66471. + }
  66472. + if (dwc_otg_module_params.ts_dline != -1) {
  66473. + retval +=
  66474. + dwc_otg_set_param_ts_dline(core_if,
  66475. + dwc_otg_module_params.ts_dline);
  66476. + }
  66477. + if (dwc_otg_module_params.i2c_enable != -1) {
  66478. + retval +=
  66479. + dwc_otg_set_param_i2c_enable(core_if,
  66480. + dwc_otg_module_params.
  66481. + i2c_enable);
  66482. + }
  66483. + if (dwc_otg_module_params.en_multiple_tx_fifo != -1) {
  66484. + retval +=
  66485. + dwc_otg_set_param_en_multiple_tx_fifo(core_if,
  66486. + dwc_otg_module_params.
  66487. + en_multiple_tx_fifo);
  66488. + }
  66489. + for (i = 0; i < 15; i++) {
  66490. + if (dwc_otg_module_params.dev_perio_tx_fifo_size[i] != -1) {
  66491. + retval +=
  66492. + dwc_otg_set_param_dev_perio_tx_fifo_size(core_if,
  66493. + dwc_otg_module_params.
  66494. + dev_perio_tx_fifo_size
  66495. + [i], i);
  66496. + }
  66497. + }
  66498. +
  66499. + for (i = 0; i < 15; i++) {
  66500. + if (dwc_otg_module_params.dev_tx_fifo_size[i] != -1) {
  66501. + retval += dwc_otg_set_param_dev_tx_fifo_size(core_if,
  66502. + dwc_otg_module_params.
  66503. + dev_tx_fifo_size
  66504. + [i], i);
  66505. + }
  66506. + }
  66507. + if (dwc_otg_module_params.thr_ctl != -1) {
  66508. + retval +=
  66509. + dwc_otg_set_param_thr_ctl(core_if,
  66510. + dwc_otg_module_params.thr_ctl);
  66511. + }
  66512. + if (dwc_otg_module_params.mpi_enable != -1) {
  66513. + retval +=
  66514. + dwc_otg_set_param_mpi_enable(core_if,
  66515. + dwc_otg_module_params.
  66516. + mpi_enable);
  66517. + }
  66518. + if (dwc_otg_module_params.pti_enable != -1) {
  66519. + retval +=
  66520. + dwc_otg_set_param_pti_enable(core_if,
  66521. + dwc_otg_module_params.
  66522. + pti_enable);
  66523. + }
  66524. + if (dwc_otg_module_params.lpm_enable != -1) {
  66525. + retval +=
  66526. + dwc_otg_set_param_lpm_enable(core_if,
  66527. + dwc_otg_module_params.
  66528. + lpm_enable);
  66529. + }
  66530. + if (dwc_otg_module_params.ic_usb_cap != -1) {
  66531. + retval +=
  66532. + dwc_otg_set_param_ic_usb_cap(core_if,
  66533. + dwc_otg_module_params.
  66534. + ic_usb_cap);
  66535. + }
  66536. + if (dwc_otg_module_params.tx_thr_length != -1) {
  66537. + retval +=
  66538. + dwc_otg_set_param_tx_thr_length(core_if,
  66539. + dwc_otg_module_params.tx_thr_length);
  66540. + }
  66541. + if (dwc_otg_module_params.rx_thr_length != -1) {
  66542. + retval +=
  66543. + dwc_otg_set_param_rx_thr_length(core_if,
  66544. + dwc_otg_module_params.
  66545. + rx_thr_length);
  66546. + }
  66547. + if (dwc_otg_module_params.ahb_thr_ratio != -1) {
  66548. + retval +=
  66549. + dwc_otg_set_param_ahb_thr_ratio(core_if,
  66550. + dwc_otg_module_params.ahb_thr_ratio);
  66551. + }
  66552. + if (dwc_otg_module_params.power_down != -1) {
  66553. + retval +=
  66554. + dwc_otg_set_param_power_down(core_if,
  66555. + dwc_otg_module_params.power_down);
  66556. + }
  66557. + if (dwc_otg_module_params.reload_ctl != -1) {
  66558. + retval +=
  66559. + dwc_otg_set_param_reload_ctl(core_if,
  66560. + dwc_otg_module_params.reload_ctl);
  66561. + }
  66562. +
  66563. + if (dwc_otg_module_params.dev_out_nak != -1) {
  66564. + retval +=
  66565. + dwc_otg_set_param_dev_out_nak(core_if,
  66566. + dwc_otg_module_params.dev_out_nak);
  66567. + }
  66568. +
  66569. + if (dwc_otg_module_params.cont_on_bna != -1) {
  66570. + retval +=
  66571. + dwc_otg_set_param_cont_on_bna(core_if,
  66572. + dwc_otg_module_params.cont_on_bna);
  66573. + }
  66574. +
  66575. + if (dwc_otg_module_params.ahb_single != -1) {
  66576. + retval +=
  66577. + dwc_otg_set_param_ahb_single(core_if,
  66578. + dwc_otg_module_params.ahb_single);
  66579. + }
  66580. +
  66581. + if (dwc_otg_module_params.otg_ver != -1) {
  66582. + retval +=
  66583. + dwc_otg_set_param_otg_ver(core_if,
  66584. + dwc_otg_module_params.otg_ver);
  66585. + }
  66586. + if (dwc_otg_module_params.adp_enable != -1) {
  66587. + retval +=
  66588. + dwc_otg_set_param_adp_enable(core_if,
  66589. + dwc_otg_module_params.
  66590. + adp_enable);
  66591. + }
  66592. + return retval;
  66593. +}
  66594. +
  66595. +/**
  66596. + * This function is the top level interrupt handler for the Common
  66597. + * (Device and host modes) interrupts.
  66598. + */
  66599. +static irqreturn_t dwc_otg_common_irq(int irq, void *dev)
  66600. +{
  66601. + int32_t retval = IRQ_NONE;
  66602. +
  66603. + retval = dwc_otg_handle_common_intr(dev);
  66604. + if (retval != 0) {
  66605. + S3C2410X_CLEAR_EINTPEND();
  66606. + }
  66607. + return IRQ_RETVAL(retval);
  66608. +}
  66609. +
  66610. +/**
  66611. + * This function is called when a lm_device is unregistered with the
  66612. + * dwc_otg_driver. This happens, for example, when the rmmod command is
  66613. + * executed. The device may or may not be electrically present. If it is
  66614. + * present, the driver stops device processing. Any resources used on behalf
  66615. + * of this device are freed.
  66616. + *
  66617. + * @param _dev
  66618. + */
  66619. +#ifdef LM_INTERFACE
  66620. +#define REM_RETVAL(n)
  66621. +static void dwc_otg_driver_remove( struct lm_device *_dev )
  66622. +{ dwc_otg_device_t *otg_dev = lm_get_drvdata(_dev);
  66623. +#elif defined(PCI_INTERFACE)
  66624. +#define REM_RETVAL(n)
  66625. +static void dwc_otg_driver_remove( struct pci_dev *_dev )
  66626. +{ dwc_otg_device_t *otg_dev = pci_get_drvdata(_dev);
  66627. +#elif defined(PLATFORM_INTERFACE)
  66628. +#define REM_RETVAL(n) n
  66629. +static int dwc_otg_driver_remove( struct platform_device *_dev )
  66630. +{ dwc_otg_device_t *otg_dev = platform_get_drvdata(_dev);
  66631. +#endif
  66632. +
  66633. + DWC_DEBUGPL(DBG_ANY, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  66634. +
  66635. + if (!otg_dev) {
  66636. + /* Memory allocation for the dwc_otg_device failed. */
  66637. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  66638. + return REM_RETVAL(-ENOMEM);
  66639. + }
  66640. +#ifndef DWC_DEVICE_ONLY
  66641. + if (otg_dev->hcd) {
  66642. + hcd_remove(_dev);
  66643. + } else {
  66644. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  66645. + return REM_RETVAL(-EINVAL);
  66646. + }
  66647. +#endif
  66648. +
  66649. +#ifndef DWC_HOST_ONLY
  66650. + if (otg_dev->pcd) {
  66651. + pcd_remove(_dev);
  66652. + } else {
  66653. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->pcd NULL!\n", __func__);
  66654. + return REM_RETVAL(-EINVAL);
  66655. + }
  66656. +#endif
  66657. + /*
  66658. + * Free the IRQ
  66659. + */
  66660. + if (otg_dev->common_irq_installed) {
  66661. +#ifdef PLATFORM_INTERFACE
  66662. + free_irq(platform_get_irq(_dev, 0), otg_dev);
  66663. +#else
  66664. + free_irq(_dev->irq, otg_dev);
  66665. +#endif
  66666. + } else {
  66667. + DWC_DEBUGPL(DBG_ANY, "%s: There is no installed irq!\n", __func__);
  66668. + return REM_RETVAL(-ENXIO);
  66669. + }
  66670. +
  66671. + if (otg_dev->core_if) {
  66672. + dwc_otg_cil_remove(otg_dev->core_if);
  66673. + } else {
  66674. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->core_if NULL!\n", __func__);
  66675. + return REM_RETVAL(-ENXIO);
  66676. + }
  66677. +
  66678. + /*
  66679. + * Remove the device attributes
  66680. + */
  66681. + dwc_otg_attr_remove(_dev);
  66682. +
  66683. + /*
  66684. + * Return the memory.
  66685. + */
  66686. + if (otg_dev->os_dep.base) {
  66687. + iounmap(otg_dev->os_dep.base);
  66688. + }
  66689. + DWC_FREE(otg_dev);
  66690. +
  66691. + /*
  66692. + * Clear the drvdata pointer.
  66693. + */
  66694. +#ifdef LM_INTERFACE
  66695. + lm_set_drvdata(_dev, 0);
  66696. +#elif defined(PCI_INTERFACE)
  66697. + release_mem_region(otg_dev->os_dep.rsrc_start,
  66698. + otg_dev->os_dep.rsrc_len);
  66699. + pci_set_drvdata(_dev, 0);
  66700. +#elif defined(PLATFORM_INTERFACE)
  66701. + platform_set_drvdata(_dev, 0);
  66702. +#endif
  66703. + return REM_RETVAL(0);
  66704. +}
  66705. +
  66706. +/**
  66707. + * This function is called when an lm_device is bound to a
  66708. + * dwc_otg_driver. It creates the driver components required to
  66709. + * control the device (CIL, HCD, and PCD) and it initializes the
  66710. + * device. The driver components are stored in a dwc_otg_device
  66711. + * structure. A reference to the dwc_otg_device is saved in the
  66712. + * lm_device. This allows the driver to access the dwc_otg_device
  66713. + * structure on subsequent calls to driver methods for this device.
  66714. + *
  66715. + * @param _dev Bus device
  66716. + */
  66717. +static int dwc_otg_driver_probe(
  66718. +#ifdef LM_INTERFACE
  66719. + struct lm_device *_dev
  66720. +#elif defined(PCI_INTERFACE)
  66721. + struct pci_dev *_dev,
  66722. + const struct pci_device_id *id
  66723. +#elif defined(PLATFORM_INTERFACE)
  66724. + struct platform_device *_dev
  66725. +#endif
  66726. + )
  66727. +{
  66728. + int retval = 0;
  66729. + dwc_otg_device_t *dwc_otg_device;
  66730. + int devirq;
  66731. +
  66732. + dev_dbg(&_dev->dev, "dwc_otg_driver_probe(%p)\n", _dev);
  66733. +#ifdef LM_INTERFACE
  66734. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)_dev->resource.start);
  66735. +#elif defined(PCI_INTERFACE)
  66736. + if (!id) {
  66737. + DWC_ERROR("Invalid pci_device_id %p", id);
  66738. + return -EINVAL;
  66739. + }
  66740. +
  66741. + if (!_dev || (pci_enable_device(_dev) < 0)) {
  66742. + DWC_ERROR("Invalid pci_device %p", _dev);
  66743. + return -ENODEV;
  66744. + }
  66745. + dev_dbg(&_dev->dev, "start=0x%08x\n", (unsigned)pci_resource_start(_dev,0));
  66746. + /* other stuff needed as well? */
  66747. +
  66748. +#elif defined(PLATFORM_INTERFACE)
  66749. + dev_dbg(&_dev->dev, "start=0x%08x (len 0x%x)\n",
  66750. + (unsigned)_dev->resource->start,
  66751. + (unsigned)(_dev->resource->end - _dev->resource->start));
  66752. +#endif
  66753. +
  66754. + dwc_otg_device = DWC_ALLOC(sizeof(dwc_otg_device_t));
  66755. +
  66756. + if (!dwc_otg_device) {
  66757. + dev_err(&_dev->dev, "kmalloc of dwc_otg_device failed\n");
  66758. + return -ENOMEM;
  66759. + }
  66760. +
  66761. + memset(dwc_otg_device, 0, sizeof(*dwc_otg_device));
  66762. + dwc_otg_device->os_dep.reg_offset = 0xFFFFFFFF;
  66763. +
  66764. + /*
  66765. + * Map the DWC_otg Core memory into virtual address space.
  66766. + */
  66767. +#ifdef LM_INTERFACE
  66768. + dwc_otg_device->os_dep.base = ioremap(_dev->resource.start, SZ_256K);
  66769. +
  66770. + if (!dwc_otg_device->os_dep.base) {
  66771. + dev_err(&_dev->dev, "ioremap() failed\n");
  66772. + DWC_FREE(dwc_otg_device);
  66773. + return -ENOMEM;
  66774. + }
  66775. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66776. + (unsigned)dwc_otg_device->os_dep.base);
  66777. +#elif defined(PCI_INTERFACE)
  66778. + _dev->current_state = PCI_D0;
  66779. + _dev->dev.power.power_state = PMSG_ON;
  66780. +
  66781. + if (!_dev->irq) {
  66782. + DWC_ERROR("Found HC with no IRQ. Check BIOS/PCI %s setup!",
  66783. + pci_name(_dev));
  66784. + iounmap(dwc_otg_device->os_dep.base);
  66785. + DWC_FREE(dwc_otg_device);
  66786. + return -ENODEV;
  66787. + }
  66788. +
  66789. + dwc_otg_device->os_dep.rsrc_start = pci_resource_start(_dev, 0);
  66790. + dwc_otg_device->os_dep.rsrc_len = pci_resource_len(_dev, 0);
  66791. + DWC_DEBUGPL(DBG_ANY, "PCI resource: start=%08x, len=%08x\n",
  66792. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66793. + (unsigned)dwc_otg_device->os_dep.rsrc_len);
  66794. + if (!request_mem_region
  66795. + (dwc_otg_device->os_dep.rsrc_start, dwc_otg_device->os_dep.rsrc_len,
  66796. + "dwc_otg")) {
  66797. + dev_dbg(&_dev->dev, "error requesting memory\n");
  66798. + iounmap(dwc_otg_device->os_dep.base);
  66799. + DWC_FREE(dwc_otg_device);
  66800. + return -EFAULT;
  66801. + }
  66802. +
  66803. + dwc_otg_device->os_dep.base =
  66804. + ioremap_nocache(dwc_otg_device->os_dep.rsrc_start,
  66805. + dwc_otg_device->os_dep.rsrc_len);
  66806. + if (dwc_otg_device->os_dep.base == NULL) {
  66807. + dev_dbg(&_dev->dev, "error mapping memory\n");
  66808. + release_mem_region(dwc_otg_device->os_dep.rsrc_start,
  66809. + dwc_otg_device->os_dep.rsrc_len);
  66810. + iounmap(dwc_otg_device->os_dep.base);
  66811. + DWC_FREE(dwc_otg_device);
  66812. + return -EFAULT;
  66813. + }
  66814. + dev_dbg(&_dev->dev, "base=0x%p (before adjust) \n",
  66815. + dwc_otg_device->os_dep.base);
  66816. + dwc_otg_device->os_dep.base = (char *)dwc_otg_device->os_dep.base;
  66817. + dev_dbg(&_dev->dev, "base=0x%p (after adjust) \n",
  66818. + dwc_otg_device->os_dep.base);
  66819. + dev_dbg(&_dev->dev, "%s: mapped PA 0x%x to VA 0x%p\n", __func__,
  66820. + (unsigned)dwc_otg_device->os_dep.rsrc_start,
  66821. + dwc_otg_device->os_dep.base);
  66822. +
  66823. + pci_set_master(_dev);
  66824. + pci_set_drvdata(_dev, dwc_otg_device);
  66825. +#elif defined(PLATFORM_INTERFACE)
  66826. + DWC_DEBUGPL(DBG_ANY,"Platform resource: start=%08x, len=%08x\n",
  66827. + _dev->resource->start,
  66828. + _dev->resource->end - _dev->resource->start + 1);
  66829. +#if 1
  66830. + if (!request_mem_region(_dev->resource[0].start,
  66831. + _dev->resource[0].end - _dev->resource[0].start + 1,
  66832. + "dwc_otg")) {
  66833. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66834. + retval = -EFAULT;
  66835. + goto fail;
  66836. + }
  66837. +
  66838. + dwc_otg_device->os_dep.base = ioremap_nocache(_dev->resource[0].start,
  66839. + _dev->resource[0].end -
  66840. + _dev->resource[0].start+1);
  66841. + if (fiq_enable)
  66842. + {
  66843. + if (!request_mem_region(_dev->resource[1].start,
  66844. + _dev->resource[1].end - _dev->resource[1].start + 1,
  66845. + "dwc_otg")) {
  66846. + dev_dbg(&_dev->dev, "error reserving mapped memory\n");
  66847. + retval = -EFAULT;
  66848. + goto fail;
  66849. + }
  66850. +
  66851. + dwc_otg_device->os_dep.mphi_base = ioremap_nocache(_dev->resource[1].start,
  66852. + _dev->resource[1].end -
  66853. + _dev->resource[1].start + 1);
  66854. + }
  66855. +
  66856. +#else
  66857. + {
  66858. + struct map_desc desc = {
  66859. + .virtual = IO_ADDRESS((unsigned)_dev->resource->start),
  66860. + .pfn = __phys_to_pfn((unsigned)_dev->resource->start),
  66861. + .length = SZ_128K,
  66862. + .type = MT_DEVICE
  66863. + };
  66864. + iotable_init(&desc, 1);
  66865. + dwc_otg_device->os_dep.base = (void *)desc.virtual;
  66866. + }
  66867. +#endif
  66868. + if (!dwc_otg_device->os_dep.base) {
  66869. + dev_err(&_dev->dev, "ioremap() failed\n");
  66870. + retval = -ENOMEM;
  66871. + goto fail;
  66872. + }
  66873. + dev_dbg(&_dev->dev, "base=0x%08x\n",
  66874. + (unsigned)dwc_otg_device->os_dep.base);
  66875. +#endif
  66876. +
  66877. + /*
  66878. + * Initialize driver data to point to the global DWC_otg
  66879. + * Device structure.
  66880. + */
  66881. +#ifdef LM_INTERFACE
  66882. + lm_set_drvdata(_dev, dwc_otg_device);
  66883. +#elif defined(PLATFORM_INTERFACE)
  66884. + platform_set_drvdata(_dev, dwc_otg_device);
  66885. +#endif
  66886. + dev_dbg(&_dev->dev, "dwc_otg_device=0x%p\n", dwc_otg_device);
  66887. +
  66888. + dwc_otg_device->core_if = dwc_otg_cil_init(dwc_otg_device->os_dep.base);
  66889. + DWC_DEBUGPL(DBG_HCDV, "probe of device %p given core_if %p\n",
  66890. + dwc_otg_device, dwc_otg_device->core_if);//GRAYG
  66891. +
  66892. + if (!dwc_otg_device->core_if) {
  66893. + dev_err(&_dev->dev, "CIL initialization failed!\n");
  66894. + retval = -ENOMEM;
  66895. + goto fail;
  66896. + }
  66897. +
  66898. + dev_dbg(&_dev->dev, "Calling get_gsnpsid\n");
  66899. + /*
  66900. + * Attempt to ensure this device is really a DWC_otg Controller.
  66901. + * Read and verify the SNPSID register contents. The value should be
  66902. + * 0x45F42XXX or 0x45F42XXX, which corresponds to either "OT2" or "OTG3",
  66903. + * as in "OTG version 2.XX" or "OTG version 3.XX".
  66904. + */
  66905. +
  66906. + if (((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F542000) &&
  66907. + ((dwc_otg_get_gsnpsid(dwc_otg_device->core_if) & 0xFFFFF000) != 0x4F543000)) {
  66908. + dev_err(&_dev->dev, "Bad value for SNPSID: 0x%08x\n",
  66909. + dwc_otg_get_gsnpsid(dwc_otg_device->core_if));
  66910. + retval = -EINVAL;
  66911. + goto fail;
  66912. + }
  66913. +
  66914. + /*
  66915. + * Validate parameter values.
  66916. + */
  66917. + dev_dbg(&_dev->dev, "Calling set_parameters\n");
  66918. + if (set_parameters(dwc_otg_device->core_if)) {
  66919. + retval = -EINVAL;
  66920. + goto fail;
  66921. + }
  66922. +
  66923. + /*
  66924. + * Create Device Attributes in sysfs
  66925. + */
  66926. + dev_dbg(&_dev->dev, "Calling attr_create\n");
  66927. + dwc_otg_attr_create(_dev);
  66928. +
  66929. + /*
  66930. + * Disable the global interrupt until all the interrupt
  66931. + * handlers are installed.
  66932. + */
  66933. + dev_dbg(&_dev->dev, "Calling disable_global_interrupts\n");
  66934. + dwc_otg_disable_global_interrupts(dwc_otg_device->core_if);
  66935. +
  66936. + /*
  66937. + * Install the interrupt handler for the common interrupts before
  66938. + * enabling common interrupts in core_init below.
  66939. + */
  66940. +
  66941. +#if defined(PLATFORM_INTERFACE)
  66942. + devirq = platform_get_irq(_dev, fiq_enable ? 0 : 1);
  66943. +#else
  66944. + devirq = _dev->irq;
  66945. +#endif
  66946. + DWC_DEBUGPL(DBG_CIL, "registering (common) handler for irq%d\n",
  66947. + devirq);
  66948. + dev_dbg(&_dev->dev, "Calling request_irq(%d)\n", devirq);
  66949. + retval = request_irq(devirq, dwc_otg_common_irq,
  66950. + IRQF_SHARED,
  66951. + "dwc_otg", dwc_otg_device);
  66952. + if (retval) {
  66953. + DWC_ERROR("request of irq%d failed\n", devirq);
  66954. + retval = -EBUSY;
  66955. + goto fail;
  66956. + } else {
  66957. + dwc_otg_device->common_irq_installed = 1;
  66958. + }
  66959. +
  66960. +#ifndef IRQF_TRIGGER_LOW
  66961. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  66962. + dev_dbg(&_dev->dev, "Calling set_irq_type\n");
  66963. + set_irq_type(devirq,
  66964. +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  66965. + IRQT_LOW
  66966. +#else
  66967. + IRQ_TYPE_LEVEL_LOW
  66968. +#endif
  66969. + );
  66970. +#endif
  66971. +#endif /*IRQF_TRIGGER_LOW*/
  66972. +
  66973. + /*
  66974. + * Initialize the DWC_otg core.
  66975. + */
  66976. + dev_dbg(&_dev->dev, "Calling dwc_otg_core_init\n");
  66977. + dwc_otg_core_init(dwc_otg_device->core_if);
  66978. +
  66979. +#ifndef DWC_HOST_ONLY
  66980. + /*
  66981. + * Initialize the PCD
  66982. + */
  66983. + dev_dbg(&_dev->dev, "Calling pcd_init\n");
  66984. + retval = pcd_init(_dev);
  66985. + if (retval != 0) {
  66986. + DWC_ERROR("pcd_init failed\n");
  66987. + dwc_otg_device->pcd = NULL;
  66988. + goto fail;
  66989. + }
  66990. +#endif
  66991. +#ifndef DWC_DEVICE_ONLY
  66992. + /*
  66993. + * Initialize the HCD
  66994. + */
  66995. + dev_dbg(&_dev->dev, "Calling hcd_init\n");
  66996. + retval = hcd_init(_dev);
  66997. + if (retval != 0) {
  66998. + DWC_ERROR("hcd_init failed\n");
  66999. + dwc_otg_device->hcd = NULL;
  67000. + goto fail;
  67001. + }
  67002. +#endif
  67003. + /* Recover from drvdata having been overwritten by hcd_init() */
  67004. +#ifdef LM_INTERFACE
  67005. + lm_set_drvdata(_dev, dwc_otg_device);
  67006. +#elif defined(PLATFORM_INTERFACE)
  67007. + platform_set_drvdata(_dev, dwc_otg_device);
  67008. +#elif defined(PCI_INTERFACE)
  67009. + pci_set_drvdata(_dev, dwc_otg_device);
  67010. + dwc_otg_device->os_dep.pcidev = _dev;
  67011. +#endif
  67012. +
  67013. + /*
  67014. + * Enable the global interrupt after all the interrupt
  67015. + * handlers are installed if there is no ADP support else
  67016. + * perform initial actions required for Internal ADP logic.
  67017. + */
  67018. + if (!dwc_otg_get_param_adp_enable(dwc_otg_device->core_if)) {
  67019. + dev_dbg(&_dev->dev, "Calling enable_global_interrupts\n");
  67020. + dwc_otg_enable_global_interrupts(dwc_otg_device->core_if);
  67021. + dev_dbg(&_dev->dev, "Done\n");
  67022. + } else
  67023. + dwc_otg_adp_start(dwc_otg_device->core_if,
  67024. + dwc_otg_is_host_mode(dwc_otg_device->core_if));
  67025. +
  67026. + return 0;
  67027. +
  67028. +fail:
  67029. + dwc_otg_driver_remove(_dev);
  67030. + return retval;
  67031. +}
  67032. +
  67033. +/**
  67034. + * This structure defines the methods to be called by a bus driver
  67035. + * during the lifecycle of a device on that bus. Both drivers and
  67036. + * devices are registered with a bus driver. The bus driver matches
  67037. + * devices to drivers based on information in the device and driver
  67038. + * structures.
  67039. + *
  67040. + * The probe function is called when the bus driver matches a device
  67041. + * to this driver. The remove function is called when a device is
  67042. + * unregistered with the bus driver.
  67043. + */
  67044. +#ifdef LM_INTERFACE
  67045. +static struct lm_driver dwc_otg_driver = {
  67046. + .drv = {.name = (char *)dwc_driver_name,},
  67047. + .probe = dwc_otg_driver_probe,
  67048. + .remove = dwc_otg_driver_remove,
  67049. + // 'suspend' and 'resume' absent
  67050. +};
  67051. +#elif defined(PCI_INTERFACE)
  67052. +static const struct pci_device_id pci_ids[] = { {
  67053. + PCI_DEVICE(0x16c3, 0xabcd),
  67054. + .driver_data =
  67055. + (unsigned long)0xdeadbeef,
  67056. + }, { /* end: all zeroes */ }
  67057. +};
  67058. +
  67059. +MODULE_DEVICE_TABLE(pci, pci_ids);
  67060. +
  67061. +/* pci driver glue; this is a "new style" PCI driver module */
  67062. +static struct pci_driver dwc_otg_driver = {
  67063. + .name = "dwc_otg",
  67064. + .id_table = pci_ids,
  67065. +
  67066. + .probe = dwc_otg_driver_probe,
  67067. + .remove = dwc_otg_driver_remove,
  67068. +
  67069. + .driver = {
  67070. + .name = (char *)dwc_driver_name,
  67071. + },
  67072. +};
  67073. +#elif defined(PLATFORM_INTERFACE)
  67074. +static struct platform_device_id platform_ids[] = {
  67075. + {
  67076. + .name = "bcm2708_usb",
  67077. + .driver_data = (kernel_ulong_t) 0xdeadbeef,
  67078. + },
  67079. + { /* end: all zeroes */ }
  67080. +};
  67081. +MODULE_DEVICE_TABLE(platform, platform_ids);
  67082. +
  67083. +static struct platform_driver dwc_otg_driver = {
  67084. + .driver = {
  67085. + .name = (char *)dwc_driver_name,
  67086. + },
  67087. + .id_table = platform_ids,
  67088. +
  67089. + .probe = dwc_otg_driver_probe,
  67090. + .remove = dwc_otg_driver_remove,
  67091. + // no 'shutdown', 'suspend', 'resume', 'suspend_late' or 'resume_early'
  67092. +};
  67093. +#endif
  67094. +
  67095. +/**
  67096. + * This function is called when the dwc_otg_driver is installed with the
  67097. + * insmod command. It registers the dwc_otg_driver structure with the
  67098. + * appropriate bus driver. This will cause the dwc_otg_driver_probe function
  67099. + * to be called. In addition, the bus driver will automatically expose
  67100. + * attributes defined for the device and driver in the special sysfs file
  67101. + * system.
  67102. + *
  67103. + * @return
  67104. + */
  67105. +static int __init dwc_otg_driver_init(void)
  67106. +{
  67107. + int retval = 0;
  67108. + int error;
  67109. + struct device_driver *drv;
  67110. +
  67111. + if(fiq_fsm_enable && !fiq_enable) {
  67112. + printk(KERN_WARNING "dwc_otg: fiq_fsm_enable was set without fiq_enable! Correcting.\n");
  67113. + fiq_enable = 1;
  67114. + }
  67115. +
  67116. + printk(KERN_INFO "%s: version %s (%s bus)\n", dwc_driver_name,
  67117. + DWC_DRIVER_VERSION,
  67118. +#ifdef LM_INTERFACE
  67119. + "logicmodule");
  67120. + retval = lm_driver_register(&dwc_otg_driver);
  67121. + drv = &dwc_otg_driver.drv;
  67122. +#elif defined(PCI_INTERFACE)
  67123. + "pci");
  67124. + retval = pci_register_driver(&dwc_otg_driver);
  67125. + drv = &dwc_otg_driver.driver;
  67126. +#elif defined(PLATFORM_INTERFACE)
  67127. + "platform");
  67128. + retval = platform_driver_register(&dwc_otg_driver);
  67129. + drv = &dwc_otg_driver.driver;
  67130. +#endif
  67131. + if (retval < 0) {
  67132. + printk(KERN_ERR "%s retval=%d\n", __func__, retval);
  67133. + return retval;
  67134. + }
  67135. + printk(KERN_DEBUG "dwc_otg: FIQ %s\n", fiq_enable ? "enabled":"disabled");
  67136. + printk(KERN_DEBUG "dwc_otg: NAK holdoff %s\n", nak_holdoff ? "enabled":"disabled");
  67137. + printk(KERN_DEBUG "dwc_otg: FIQ split-transaction FSM %s\n", fiq_fsm_enable ? "enabled":"disabled");
  67138. +
  67139. + error = driver_create_file(drv, &driver_attr_version);
  67140. +#ifdef DEBUG
  67141. + error = driver_create_file(drv, &driver_attr_debuglevel);
  67142. +#endif
  67143. + return retval;
  67144. +}
  67145. +
  67146. +module_init(dwc_otg_driver_init);
  67147. +
  67148. +/**
  67149. + * This function is called when the driver is removed from the kernel
  67150. + * with the rmmod command. The driver unregisters itself with its bus
  67151. + * driver.
  67152. + *
  67153. + */
  67154. +static void __exit dwc_otg_driver_cleanup(void)
  67155. +{
  67156. + printk(KERN_DEBUG "dwc_otg_driver_cleanup()\n");
  67157. +
  67158. +#ifdef LM_INTERFACE
  67159. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_debuglevel);
  67160. + driver_remove_file(&dwc_otg_driver.drv, &driver_attr_version);
  67161. + lm_driver_unregister(&dwc_otg_driver);
  67162. +#elif defined(PCI_INTERFACE)
  67163. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67164. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67165. + pci_unregister_driver(&dwc_otg_driver);
  67166. +#elif defined(PLATFORM_INTERFACE)
  67167. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_debuglevel);
  67168. + driver_remove_file(&dwc_otg_driver.driver, &driver_attr_version);
  67169. + platform_driver_unregister(&dwc_otg_driver);
  67170. +#endif
  67171. +
  67172. + printk(KERN_INFO "%s module removed\n", dwc_driver_name);
  67173. +}
  67174. +
  67175. +module_exit(dwc_otg_driver_cleanup);
  67176. +
  67177. +MODULE_DESCRIPTION(DWC_DRIVER_DESC);
  67178. +MODULE_AUTHOR("Synopsys Inc.");
  67179. +MODULE_LICENSE("GPL");
  67180. +
  67181. +module_param_named(otg_cap, dwc_otg_module_params.otg_cap, int, 0444);
  67182. +MODULE_PARM_DESC(otg_cap, "OTG Capabilities 0=HNP&SRP 1=SRP Only 2=None");
  67183. +module_param_named(opt, dwc_otg_module_params.opt, int, 0444);
  67184. +MODULE_PARM_DESC(opt, "OPT Mode");
  67185. +module_param_named(dma_enable, dwc_otg_module_params.dma_enable, int, 0444);
  67186. +MODULE_PARM_DESC(dma_enable, "DMA Mode 0=Slave 1=DMA enabled");
  67187. +
  67188. +module_param_named(dma_desc_enable, dwc_otg_module_params.dma_desc_enable, int,
  67189. + 0444);
  67190. +MODULE_PARM_DESC(dma_desc_enable,
  67191. + "DMA Desc Mode 0=Address DMA 1=DMA Descriptor enabled");
  67192. +
  67193. +module_param_named(dma_burst_size, dwc_otg_module_params.dma_burst_size, int,
  67194. + 0444);
  67195. +MODULE_PARM_DESC(dma_burst_size,
  67196. + "DMA Burst Size 1, 4, 8, 16, 32, 64, 128, 256");
  67197. +module_param_named(speed, dwc_otg_module_params.speed, int, 0444);
  67198. +MODULE_PARM_DESC(speed, "Speed 0=High Speed 1=Full Speed");
  67199. +module_param_named(host_support_fs_ls_low_power,
  67200. + dwc_otg_module_params.host_support_fs_ls_low_power, int,
  67201. + 0444);
  67202. +MODULE_PARM_DESC(host_support_fs_ls_low_power,
  67203. + "Support Low Power w/FS or LS 0=Support 1=Don't Support");
  67204. +module_param_named(host_ls_low_power_phy_clk,
  67205. + dwc_otg_module_params.host_ls_low_power_phy_clk, int, 0444);
  67206. +MODULE_PARM_DESC(host_ls_low_power_phy_clk,
  67207. + "Low Speed Low Power Clock 0=48Mhz 1=6Mhz");
  67208. +module_param_named(enable_dynamic_fifo,
  67209. + dwc_otg_module_params.enable_dynamic_fifo, int, 0444);
  67210. +MODULE_PARM_DESC(enable_dynamic_fifo, "0=cC Setting 1=Allow Dynamic Sizing");
  67211. +module_param_named(data_fifo_size, dwc_otg_module_params.data_fifo_size, int,
  67212. + 0444);
  67213. +MODULE_PARM_DESC(data_fifo_size,
  67214. + "Total number of words in the data FIFO memory 32-32768");
  67215. +module_param_named(dev_rx_fifo_size, dwc_otg_module_params.dev_rx_fifo_size,
  67216. + int, 0444);
  67217. +MODULE_PARM_DESC(dev_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67218. +module_param_named(dev_nperio_tx_fifo_size,
  67219. + dwc_otg_module_params.dev_nperio_tx_fifo_size, int, 0444);
  67220. +MODULE_PARM_DESC(dev_nperio_tx_fifo_size,
  67221. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67222. +module_param_named(dev_perio_tx_fifo_size_1,
  67223. + dwc_otg_module_params.dev_perio_tx_fifo_size[0], int, 0444);
  67224. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_1,
  67225. + "Number of words in the periodic Tx FIFO 4-768");
  67226. +module_param_named(dev_perio_tx_fifo_size_2,
  67227. + dwc_otg_module_params.dev_perio_tx_fifo_size[1], int, 0444);
  67228. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_2,
  67229. + "Number of words in the periodic Tx FIFO 4-768");
  67230. +module_param_named(dev_perio_tx_fifo_size_3,
  67231. + dwc_otg_module_params.dev_perio_tx_fifo_size[2], int, 0444);
  67232. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_3,
  67233. + "Number of words in the periodic Tx FIFO 4-768");
  67234. +module_param_named(dev_perio_tx_fifo_size_4,
  67235. + dwc_otg_module_params.dev_perio_tx_fifo_size[3], int, 0444);
  67236. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_4,
  67237. + "Number of words in the periodic Tx FIFO 4-768");
  67238. +module_param_named(dev_perio_tx_fifo_size_5,
  67239. + dwc_otg_module_params.dev_perio_tx_fifo_size[4], int, 0444);
  67240. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_5,
  67241. + "Number of words in the periodic Tx FIFO 4-768");
  67242. +module_param_named(dev_perio_tx_fifo_size_6,
  67243. + dwc_otg_module_params.dev_perio_tx_fifo_size[5], int, 0444);
  67244. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_6,
  67245. + "Number of words in the periodic Tx FIFO 4-768");
  67246. +module_param_named(dev_perio_tx_fifo_size_7,
  67247. + dwc_otg_module_params.dev_perio_tx_fifo_size[6], int, 0444);
  67248. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_7,
  67249. + "Number of words in the periodic Tx FIFO 4-768");
  67250. +module_param_named(dev_perio_tx_fifo_size_8,
  67251. + dwc_otg_module_params.dev_perio_tx_fifo_size[7], int, 0444);
  67252. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_8,
  67253. + "Number of words in the periodic Tx FIFO 4-768");
  67254. +module_param_named(dev_perio_tx_fifo_size_9,
  67255. + dwc_otg_module_params.dev_perio_tx_fifo_size[8], int, 0444);
  67256. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_9,
  67257. + "Number of words in the periodic Tx FIFO 4-768");
  67258. +module_param_named(dev_perio_tx_fifo_size_10,
  67259. + dwc_otg_module_params.dev_perio_tx_fifo_size[9], int, 0444);
  67260. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_10,
  67261. + "Number of words in the periodic Tx FIFO 4-768");
  67262. +module_param_named(dev_perio_tx_fifo_size_11,
  67263. + dwc_otg_module_params.dev_perio_tx_fifo_size[10], int, 0444);
  67264. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_11,
  67265. + "Number of words in the periodic Tx FIFO 4-768");
  67266. +module_param_named(dev_perio_tx_fifo_size_12,
  67267. + dwc_otg_module_params.dev_perio_tx_fifo_size[11], int, 0444);
  67268. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_12,
  67269. + "Number of words in the periodic Tx FIFO 4-768");
  67270. +module_param_named(dev_perio_tx_fifo_size_13,
  67271. + dwc_otg_module_params.dev_perio_tx_fifo_size[12], int, 0444);
  67272. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_13,
  67273. + "Number of words in the periodic Tx FIFO 4-768");
  67274. +module_param_named(dev_perio_tx_fifo_size_14,
  67275. + dwc_otg_module_params.dev_perio_tx_fifo_size[13], int, 0444);
  67276. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_14,
  67277. + "Number of words in the periodic Tx FIFO 4-768");
  67278. +module_param_named(dev_perio_tx_fifo_size_15,
  67279. + dwc_otg_module_params.dev_perio_tx_fifo_size[14], int, 0444);
  67280. +MODULE_PARM_DESC(dev_perio_tx_fifo_size_15,
  67281. + "Number of words in the periodic Tx FIFO 4-768");
  67282. +module_param_named(host_rx_fifo_size, dwc_otg_module_params.host_rx_fifo_size,
  67283. + int, 0444);
  67284. +MODULE_PARM_DESC(host_rx_fifo_size, "Number of words in the Rx FIFO 16-32768");
  67285. +module_param_named(host_nperio_tx_fifo_size,
  67286. + dwc_otg_module_params.host_nperio_tx_fifo_size, int, 0444);
  67287. +MODULE_PARM_DESC(host_nperio_tx_fifo_size,
  67288. + "Number of words in the non-periodic Tx FIFO 16-32768");
  67289. +module_param_named(host_perio_tx_fifo_size,
  67290. + dwc_otg_module_params.host_perio_tx_fifo_size, int, 0444);
  67291. +MODULE_PARM_DESC(host_perio_tx_fifo_size,
  67292. + "Number of words in the host periodic Tx FIFO 16-32768");
  67293. +module_param_named(max_transfer_size, dwc_otg_module_params.max_transfer_size,
  67294. + int, 0444);
  67295. +/** @todo Set the max to 512K, modify checks */
  67296. +MODULE_PARM_DESC(max_transfer_size,
  67297. + "The maximum transfer size supported in bytes 2047-65535");
  67298. +module_param_named(max_packet_count, dwc_otg_module_params.max_packet_count,
  67299. + int, 0444);
  67300. +MODULE_PARM_DESC(max_packet_count,
  67301. + "The maximum number of packets in a transfer 15-511");
  67302. +module_param_named(host_channels, dwc_otg_module_params.host_channels, int,
  67303. + 0444);
  67304. +MODULE_PARM_DESC(host_channels,
  67305. + "The number of host channel registers to use 1-16");
  67306. +module_param_named(dev_endpoints, dwc_otg_module_params.dev_endpoints, int,
  67307. + 0444);
  67308. +MODULE_PARM_DESC(dev_endpoints,
  67309. + "The number of endpoints in addition to EP0 available for device mode 1-15");
  67310. +module_param_named(phy_type, dwc_otg_module_params.phy_type, int, 0444);
  67311. +MODULE_PARM_DESC(phy_type, "0=Reserved 1=UTMI+ 2=ULPI");
  67312. +module_param_named(phy_utmi_width, dwc_otg_module_params.phy_utmi_width, int,
  67313. + 0444);
  67314. +MODULE_PARM_DESC(phy_utmi_width, "Specifies the UTMI+ Data Width 8 or 16 bits");
  67315. +module_param_named(phy_ulpi_ddr, dwc_otg_module_params.phy_ulpi_ddr, int, 0444);
  67316. +MODULE_PARM_DESC(phy_ulpi_ddr,
  67317. + "ULPI at double or single data rate 0=Single 1=Double");
  67318. +module_param_named(phy_ulpi_ext_vbus, dwc_otg_module_params.phy_ulpi_ext_vbus,
  67319. + int, 0444);
  67320. +MODULE_PARM_DESC(phy_ulpi_ext_vbus,
  67321. + "ULPI PHY using internal or external vbus 0=Internal");
  67322. +module_param_named(i2c_enable, dwc_otg_module_params.i2c_enable, int, 0444);
  67323. +MODULE_PARM_DESC(i2c_enable, "FS PHY Interface");
  67324. +module_param_named(ulpi_fs_ls, dwc_otg_module_params.ulpi_fs_ls, int, 0444);
  67325. +MODULE_PARM_DESC(ulpi_fs_ls, "ULPI PHY FS/LS mode only");
  67326. +module_param_named(ts_dline, dwc_otg_module_params.ts_dline, int, 0444);
  67327. +MODULE_PARM_DESC(ts_dline, "Term select Dline pulsing for all PHYs");
  67328. +module_param_named(debug, g_dbg_lvl, int, 0444);
  67329. +MODULE_PARM_DESC(debug, "");
  67330. +
  67331. +module_param_named(en_multiple_tx_fifo,
  67332. + dwc_otg_module_params.en_multiple_tx_fifo, int, 0444);
  67333. +MODULE_PARM_DESC(en_multiple_tx_fifo,
  67334. + "Dedicated Non Periodic Tx FIFOs 0=disabled 1=enabled");
  67335. +module_param_named(dev_tx_fifo_size_1,
  67336. + dwc_otg_module_params.dev_tx_fifo_size[0], int, 0444);
  67337. +MODULE_PARM_DESC(dev_tx_fifo_size_1, "Number of words in the Tx FIFO 4-768");
  67338. +module_param_named(dev_tx_fifo_size_2,
  67339. + dwc_otg_module_params.dev_tx_fifo_size[1], int, 0444);
  67340. +MODULE_PARM_DESC(dev_tx_fifo_size_2, "Number of words in the Tx FIFO 4-768");
  67341. +module_param_named(dev_tx_fifo_size_3,
  67342. + dwc_otg_module_params.dev_tx_fifo_size[2], int, 0444);
  67343. +MODULE_PARM_DESC(dev_tx_fifo_size_3, "Number of words in the Tx FIFO 4-768");
  67344. +module_param_named(dev_tx_fifo_size_4,
  67345. + dwc_otg_module_params.dev_tx_fifo_size[3], int, 0444);
  67346. +MODULE_PARM_DESC(dev_tx_fifo_size_4, "Number of words in the Tx FIFO 4-768");
  67347. +module_param_named(dev_tx_fifo_size_5,
  67348. + dwc_otg_module_params.dev_tx_fifo_size[4], int, 0444);
  67349. +MODULE_PARM_DESC(dev_tx_fifo_size_5, "Number of words in the Tx FIFO 4-768");
  67350. +module_param_named(dev_tx_fifo_size_6,
  67351. + dwc_otg_module_params.dev_tx_fifo_size[5], int, 0444);
  67352. +MODULE_PARM_DESC(dev_tx_fifo_size_6, "Number of words in the Tx FIFO 4-768");
  67353. +module_param_named(dev_tx_fifo_size_7,
  67354. + dwc_otg_module_params.dev_tx_fifo_size[6], int, 0444);
  67355. +MODULE_PARM_DESC(dev_tx_fifo_size_7, "Number of words in the Tx FIFO 4-768");
  67356. +module_param_named(dev_tx_fifo_size_8,
  67357. + dwc_otg_module_params.dev_tx_fifo_size[7], int, 0444);
  67358. +MODULE_PARM_DESC(dev_tx_fifo_size_8, "Number of words in the Tx FIFO 4-768");
  67359. +module_param_named(dev_tx_fifo_size_9,
  67360. + dwc_otg_module_params.dev_tx_fifo_size[8], int, 0444);
  67361. +MODULE_PARM_DESC(dev_tx_fifo_size_9, "Number of words in the Tx FIFO 4-768");
  67362. +module_param_named(dev_tx_fifo_size_10,
  67363. + dwc_otg_module_params.dev_tx_fifo_size[9], int, 0444);
  67364. +MODULE_PARM_DESC(dev_tx_fifo_size_10, "Number of words in the Tx FIFO 4-768");
  67365. +module_param_named(dev_tx_fifo_size_11,
  67366. + dwc_otg_module_params.dev_tx_fifo_size[10], int, 0444);
  67367. +MODULE_PARM_DESC(dev_tx_fifo_size_11, "Number of words in the Tx FIFO 4-768");
  67368. +module_param_named(dev_tx_fifo_size_12,
  67369. + dwc_otg_module_params.dev_tx_fifo_size[11], int, 0444);
  67370. +MODULE_PARM_DESC(dev_tx_fifo_size_12, "Number of words in the Tx FIFO 4-768");
  67371. +module_param_named(dev_tx_fifo_size_13,
  67372. + dwc_otg_module_params.dev_tx_fifo_size[12], int, 0444);
  67373. +MODULE_PARM_DESC(dev_tx_fifo_size_13, "Number of words in the Tx FIFO 4-768");
  67374. +module_param_named(dev_tx_fifo_size_14,
  67375. + dwc_otg_module_params.dev_tx_fifo_size[13], int, 0444);
  67376. +MODULE_PARM_DESC(dev_tx_fifo_size_14, "Number of words in the Tx FIFO 4-768");
  67377. +module_param_named(dev_tx_fifo_size_15,
  67378. + dwc_otg_module_params.dev_tx_fifo_size[14], int, 0444);
  67379. +MODULE_PARM_DESC(dev_tx_fifo_size_15, "Number of words in the Tx FIFO 4-768");
  67380. +
  67381. +module_param_named(thr_ctl, dwc_otg_module_params.thr_ctl, int, 0444);
  67382. +MODULE_PARM_DESC(thr_ctl,
  67383. + "Thresholding enable flag bit 0 - non ISO Tx thr., 1 - ISO Tx thr., 2 - Rx thr.- bit 0=disabled 1=enabled");
  67384. +module_param_named(tx_thr_length, dwc_otg_module_params.tx_thr_length, int,
  67385. + 0444);
  67386. +MODULE_PARM_DESC(tx_thr_length, "Tx Threshold length in 32 bit DWORDs");
  67387. +module_param_named(rx_thr_length, dwc_otg_module_params.rx_thr_length, int,
  67388. + 0444);
  67389. +MODULE_PARM_DESC(rx_thr_length, "Rx Threshold length in 32 bit DWORDs");
  67390. +
  67391. +module_param_named(pti_enable, dwc_otg_module_params.pti_enable, int, 0444);
  67392. +module_param_named(mpi_enable, dwc_otg_module_params.mpi_enable, int, 0444);
  67393. +module_param_named(lpm_enable, dwc_otg_module_params.lpm_enable, int, 0444);
  67394. +MODULE_PARM_DESC(lpm_enable, "LPM Enable 0=LPM Disabled 1=LPM Enabled");
  67395. +module_param_named(ic_usb_cap, dwc_otg_module_params.ic_usb_cap, int, 0444);
  67396. +MODULE_PARM_DESC(ic_usb_cap,
  67397. + "IC_USB Capability 0=IC_USB Disabled 1=IC_USB Enabled");
  67398. +module_param_named(ahb_thr_ratio, dwc_otg_module_params.ahb_thr_ratio, int,
  67399. + 0444);
  67400. +MODULE_PARM_DESC(ahb_thr_ratio, "AHB Threshold Ratio");
  67401. +module_param_named(power_down, dwc_otg_module_params.power_down, int, 0444);
  67402. +MODULE_PARM_DESC(power_down, "Power Down Mode");
  67403. +module_param_named(reload_ctl, dwc_otg_module_params.reload_ctl, int, 0444);
  67404. +MODULE_PARM_DESC(reload_ctl, "HFIR Reload Control");
  67405. +module_param_named(dev_out_nak, dwc_otg_module_params.dev_out_nak, int, 0444);
  67406. +MODULE_PARM_DESC(dev_out_nak, "Enable Device OUT NAK");
  67407. +module_param_named(cont_on_bna, dwc_otg_module_params.cont_on_bna, int, 0444);
  67408. +MODULE_PARM_DESC(cont_on_bna, "Enable Enable Continue on BNA");
  67409. +module_param_named(ahb_single, dwc_otg_module_params.ahb_single, int, 0444);
  67410. +MODULE_PARM_DESC(ahb_single, "Enable AHB Single Support");
  67411. +module_param_named(adp_enable, dwc_otg_module_params.adp_enable, int, 0444);
  67412. +MODULE_PARM_DESC(adp_enable, "ADP Enable 0=ADP Disabled 1=ADP Enabled");
  67413. +module_param_named(otg_ver, dwc_otg_module_params.otg_ver, int, 0444);
  67414. +MODULE_PARM_DESC(otg_ver, "OTG revision supported 0=OTG 1.3 1=OTG 2.0");
  67415. +module_param(microframe_schedule, bool, 0444);
  67416. +MODULE_PARM_DESC(microframe_schedule, "Enable the microframe scheduler");
  67417. +
  67418. +module_param(fiq_enable, bool, 0444);
  67419. +MODULE_PARM_DESC(fiq_enable, "Enable the FIQ");
  67420. +module_param(nak_holdoff, ushort, 0644);
  67421. +MODULE_PARM_DESC(nak_holdoff, "Throttle duration for bulk split-transaction endpoints on a NAK. Default 8");
  67422. +module_param(fiq_fsm_enable, bool, 0444);
  67423. +MODULE_PARM_DESC(fiq_fsm_enable, "Enable the FIQ to perform split transactions as defined by fiq_fsm_mask");
  67424. +module_param(fiq_fsm_mask, ushort, 0444);
  67425. +MODULE_PARM_DESC(fiq_fsm_mask, "Bitmask of transactions to perform in the FIQ.\n"
  67426. + "Bit 0 : Non-periodic split transactions\n"
  67427. + "Bit 1 : Periodic split transactions\n"
  67428. + "Bit 2 : High-speed multi-transfer isochronous\n"
  67429. + "All other bits should be set 0.");
  67430. +
  67431. +
  67432. +/** @page "Module Parameters"
  67433. + *
  67434. + * The following parameters may be specified when starting the module.
  67435. + * These parameters define how the DWC_otg controller should be
  67436. + * configured. Parameter values are passed to the CIL initialization
  67437. + * function dwc_otg_cil_init
  67438. + *
  67439. + * Example: <code>modprobe dwc_otg speed=1 otg_cap=1</code>
  67440. + *
  67441. +
  67442. + <table>
  67443. + <tr><td>Parameter Name</td><td>Meaning</td></tr>
  67444. +
  67445. + <tr>
  67446. + <td>otg_cap</td>
  67447. + <td>Specifies the OTG capabilities. The driver will automatically detect the
  67448. + value for this parameter if none is specified.
  67449. + - 0: HNP and SRP capable (default, if available)
  67450. + - 1: SRP Only capable
  67451. + - 2: No HNP/SRP capable
  67452. + </td></tr>
  67453. +
  67454. + <tr>
  67455. + <td>dma_enable</td>
  67456. + <td>Specifies whether to use slave or DMA mode for accessing the data FIFOs.
  67457. + The driver will automatically detect the value for this parameter if none is
  67458. + specified.
  67459. + - 0: Slave
  67460. + - 1: DMA (default, if available)
  67461. + </td></tr>
  67462. +
  67463. + <tr>
  67464. + <td>dma_burst_size</td>
  67465. + <td>The DMA Burst size (applicable only for External DMA Mode).
  67466. + - Values: 1, 4, 8 16, 32, 64, 128, 256 (default 32)
  67467. + </td></tr>
  67468. +
  67469. + <tr>
  67470. + <td>speed</td>
  67471. + <td>Specifies the maximum speed of operation in host and device mode. The
  67472. + actual speed depends on the speed of the attached device and the value of
  67473. + phy_type.
  67474. + - 0: High Speed (default)
  67475. + - 1: Full Speed
  67476. + </td></tr>
  67477. +
  67478. + <tr>
  67479. + <td>host_support_fs_ls_low_power</td>
  67480. + <td>Specifies whether low power mode is supported when attached to a Full
  67481. + Speed or Low Speed device in host mode.
  67482. + - 0: Don't support low power mode (default)
  67483. + - 1: Support low power mode
  67484. + </td></tr>
  67485. +
  67486. + <tr>
  67487. + <td>host_ls_low_power_phy_clk</td>
  67488. + <td>Specifies the PHY clock rate in low power mode when connected to a Low
  67489. + Speed device in host mode. This parameter is applicable only if
  67490. + HOST_SUPPORT_FS_LS_LOW_POWER is enabled.
  67491. + - 0: 48 MHz (default)
  67492. + - 1: 6 MHz
  67493. + </td></tr>
  67494. +
  67495. + <tr>
  67496. + <td>enable_dynamic_fifo</td>
  67497. + <td> Specifies whether FIFOs may be resized by the driver software.
  67498. + - 0: Use cC FIFO size parameters
  67499. + - 1: Allow dynamic FIFO sizing (default)
  67500. + </td></tr>
  67501. +
  67502. + <tr>
  67503. + <td>data_fifo_size</td>
  67504. + <td>Total number of 4-byte words in the data FIFO memory. This memory
  67505. + includes the Rx FIFO, non-periodic Tx FIFO, and periodic Tx FIFOs.
  67506. + - Values: 32 to 32768 (default 8192)
  67507. +
  67508. + Note: The total FIFO memory depth in the FPGA configuration is 8192.
  67509. + </td></tr>
  67510. +
  67511. + <tr>
  67512. + <td>dev_rx_fifo_size</td>
  67513. + <td>Number of 4-byte words in the Rx FIFO in device mode when dynamic
  67514. + FIFO sizing is enabled.
  67515. + - Values: 16 to 32768 (default 1064)
  67516. + </td></tr>
  67517. +
  67518. + <tr>
  67519. + <td>dev_nperio_tx_fifo_size</td>
  67520. + <td>Number of 4-byte words in the non-periodic Tx FIFO in device mode when
  67521. + dynamic FIFO sizing is enabled.
  67522. + - Values: 16 to 32768 (default 1024)
  67523. + </td></tr>
  67524. +
  67525. + <tr>
  67526. + <td>dev_perio_tx_fifo_size_n (n = 1 to 15)</td>
  67527. + <td>Number of 4-byte words in each of the periodic Tx FIFOs in device mode
  67528. + when dynamic FIFO sizing is enabled.
  67529. + - Values: 4 to 768 (default 256)
  67530. + </td></tr>
  67531. +
  67532. + <tr>
  67533. + <td>host_rx_fifo_size</td>
  67534. + <td>Number of 4-byte words in the Rx FIFO in host mode when dynamic FIFO
  67535. + sizing is enabled.
  67536. + - Values: 16 to 32768 (default 1024)
  67537. + </td></tr>
  67538. +
  67539. + <tr>
  67540. + <td>host_nperio_tx_fifo_size</td>
  67541. + <td>Number of 4-byte words in the non-periodic Tx FIFO in host mode when
  67542. + dynamic FIFO sizing is enabled in the core.
  67543. + - Values: 16 to 32768 (default 1024)
  67544. + </td></tr>
  67545. +
  67546. + <tr>
  67547. + <td>host_perio_tx_fifo_size</td>
  67548. + <td>Number of 4-byte words in the host periodic Tx FIFO when dynamic FIFO
  67549. + sizing is enabled.
  67550. + - Values: 16 to 32768 (default 1024)
  67551. + </td></tr>
  67552. +
  67553. + <tr>
  67554. + <td>max_transfer_size</td>
  67555. + <td>The maximum transfer size supported in bytes.
  67556. + - Values: 2047 to 65,535 (default 65,535)
  67557. + </td></tr>
  67558. +
  67559. + <tr>
  67560. + <td>max_packet_count</td>
  67561. + <td>The maximum number of packets in a transfer.
  67562. + - Values: 15 to 511 (default 511)
  67563. + </td></tr>
  67564. +
  67565. + <tr>
  67566. + <td>host_channels</td>
  67567. + <td>The number of host channel registers to use.
  67568. + - Values: 1 to 16 (default 12)
  67569. +
  67570. + Note: The FPGA configuration supports a maximum of 12 host channels.
  67571. + </td></tr>
  67572. +
  67573. + <tr>
  67574. + <td>dev_endpoints</td>
  67575. + <td>The number of endpoints in addition to EP0 available for device mode
  67576. + operations.
  67577. + - Values: 1 to 15 (default 6 IN and OUT)
  67578. +
  67579. + Note: The FPGA configuration supports a maximum of 6 IN and OUT endpoints in
  67580. + addition to EP0.
  67581. + </td></tr>
  67582. +
  67583. + <tr>
  67584. + <td>phy_type</td>
  67585. + <td>Specifies the type of PHY interface to use. By default, the driver will
  67586. + automatically detect the phy_type.
  67587. + - 0: Full Speed
  67588. + - 1: UTMI+ (default, if available)
  67589. + - 2: ULPI
  67590. + </td></tr>
  67591. +
  67592. + <tr>
  67593. + <td>phy_utmi_width</td>
  67594. + <td>Specifies the UTMI+ Data Width. This parameter is applicable for a
  67595. + phy_type of UTMI+. Also, this parameter is applicable only if the
  67596. + OTG_HSPHY_WIDTH cC parameter was set to "8 and 16 bits", meaning that the
  67597. + core has been configured to work at either data path width.
  67598. + - Values: 8 or 16 bits (default 16)
  67599. + </td></tr>
  67600. +
  67601. + <tr>
  67602. + <td>phy_ulpi_ddr</td>
  67603. + <td>Specifies whether the ULPI operates at double or single data rate. This
  67604. + parameter is only applicable if phy_type is ULPI.
  67605. + - 0: single data rate ULPI interface with 8 bit wide data bus (default)
  67606. + - 1: double data rate ULPI interface with 4 bit wide data bus
  67607. + </td></tr>
  67608. +
  67609. + <tr>
  67610. + <td>i2c_enable</td>
  67611. + <td>Specifies whether to use the I2C interface for full speed PHY. This
  67612. + parameter is only applicable if PHY_TYPE is FS.
  67613. + - 0: Disabled (default)
  67614. + - 1: Enabled
  67615. + </td></tr>
  67616. +
  67617. + <tr>
  67618. + <td>ulpi_fs_ls</td>
  67619. + <td>Specifies whether to use ULPI FS/LS mode only.
  67620. + - 0: Disabled (default)
  67621. + - 1: Enabled
  67622. + </td></tr>
  67623. +
  67624. + <tr>
  67625. + <td>ts_dline</td>
  67626. + <td>Specifies whether term select D-Line pulsing for all PHYs is enabled.
  67627. + - 0: Disabled (default)
  67628. + - 1: Enabled
  67629. + </td></tr>
  67630. +
  67631. + <tr>
  67632. + <td>en_multiple_tx_fifo</td>
  67633. + <td>Specifies whether dedicatedto tx fifos are enabled for non periodic IN EPs.
  67634. + The driver will automatically detect the value for this parameter if none is
  67635. + specified.
  67636. + - 0: Disabled
  67637. + - 1: Enabled (default, if available)
  67638. + </td></tr>
  67639. +
  67640. + <tr>
  67641. + <td>dev_tx_fifo_size_n (n = 1 to 15)</td>
  67642. + <td>Number of 4-byte words in each of the Tx FIFOs in device mode
  67643. + when dynamic FIFO sizing is enabled.
  67644. + - Values: 4 to 768 (default 256)
  67645. + </td></tr>
  67646. +
  67647. + <tr>
  67648. + <td>tx_thr_length</td>
  67649. + <td>Transmit Threshold length in 32 bit double words
  67650. + - Values: 8 to 128 (default 64)
  67651. + </td></tr>
  67652. +
  67653. + <tr>
  67654. + <td>rx_thr_length</td>
  67655. + <td>Receive Threshold length in 32 bit double words
  67656. + - Values: 8 to 128 (default 64)
  67657. + </td></tr>
  67658. +
  67659. +<tr>
  67660. + <td>thr_ctl</td>
  67661. + <td>Specifies whether to enable Thresholding for Device mode. Bits 0, 1, 2 of
  67662. + this parmater specifies if thresholding is enabled for non-Iso Tx, Iso Tx and
  67663. + Rx transfers accordingly.
  67664. + The driver will automatically detect the value for this parameter if none is
  67665. + specified.
  67666. + - Values: 0 to 7 (default 0)
  67667. + Bit values indicate:
  67668. + - 0: Thresholding disabled
  67669. + - 1: Thresholding enabled
  67670. + </td></tr>
  67671. +
  67672. +<tr>
  67673. + <td>dma_desc_enable</td>
  67674. + <td>Specifies whether to enable Descriptor DMA mode.
  67675. + The driver will automatically detect the value for this parameter if none is
  67676. + specified.
  67677. + - 0: Descriptor DMA disabled
  67678. + - 1: Descriptor DMA (default, if available)
  67679. + </td></tr>
  67680. +
  67681. +<tr>
  67682. + <td>mpi_enable</td>
  67683. + <td>Specifies whether to enable MPI enhancement mode.
  67684. + The driver will automatically detect the value for this parameter if none is
  67685. + specified.
  67686. + - 0: MPI disabled (default)
  67687. + - 1: MPI enable
  67688. + </td></tr>
  67689. +
  67690. +<tr>
  67691. + <td>pti_enable</td>
  67692. + <td>Specifies whether to enable PTI enhancement support.
  67693. + The driver will automatically detect the value for this parameter if none is
  67694. + specified.
  67695. + - 0: PTI disabled (default)
  67696. + - 1: PTI enable
  67697. + </td></tr>
  67698. +
  67699. +<tr>
  67700. + <td>lpm_enable</td>
  67701. + <td>Specifies whether to enable LPM support.
  67702. + The driver will automatically detect the value for this parameter if none is
  67703. + specified.
  67704. + - 0: LPM disabled
  67705. + - 1: LPM enable (default, if available)
  67706. + </td></tr>
  67707. +
  67708. +<tr>
  67709. + <td>ic_usb_cap</td>
  67710. + <td>Specifies whether to enable IC_USB capability.
  67711. + The driver will automatically detect the value for this parameter if none is
  67712. + specified.
  67713. + - 0: IC_USB disabled (default, if available)
  67714. + - 1: IC_USB enable
  67715. + </td></tr>
  67716. +
  67717. +<tr>
  67718. + <td>ahb_thr_ratio</td>
  67719. + <td>Specifies AHB Threshold ratio.
  67720. + - Values: 0 to 3 (default 0)
  67721. + </td></tr>
  67722. +
  67723. +<tr>
  67724. + <td>power_down</td>
  67725. + <td>Specifies Power Down(Hibernation) Mode.
  67726. + The driver will automatically detect the value for this parameter if none is
  67727. + specified.
  67728. + - 0: Power Down disabled (default)
  67729. + - 2: Power Down enabled
  67730. + </td></tr>
  67731. +
  67732. + <tr>
  67733. + <td>reload_ctl</td>
  67734. + <td>Specifies whether dynamic reloading of the HFIR register is allowed during
  67735. + run time. The driver will automatically detect the value for this parameter if
  67736. + none is specified. In case the HFIR value is reloaded when HFIR.RldCtrl == 1'b0
  67737. + the core might misbehave.
  67738. + - 0: Reload Control disabled (default)
  67739. + - 1: Reload Control enabled
  67740. + </td></tr>
  67741. +
  67742. + <tr>
  67743. + <td>dev_out_nak</td>
  67744. + <td>Specifies whether Device OUT NAK enhancement enabled or no.
  67745. + The driver will automatically detect the value for this parameter if
  67746. + none is specified. This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67747. + - 0: The core does not set NAK after Bulk OUT transfer complete (default)
  67748. + - 1: The core sets NAK after Bulk OUT transfer complete
  67749. + </td></tr>
  67750. +
  67751. + <tr>
  67752. + <td>cont_on_bna</td>
  67753. + <td>Specifies whether Enable Continue on BNA enabled or no.
  67754. + After receiving BNA interrupt the core disables the endpoint,when the
  67755. + endpoint is re-enabled by the application the
  67756. + - 0: Core starts processing from the DOEPDMA descriptor (default)
  67757. + - 1: Core starts processing from the descriptor which received the BNA.
  67758. + This parameter is valid only when OTG_EN_DESC_DMA == 1b1.
  67759. + </td></tr>
  67760. +
  67761. + <tr>
  67762. + <td>ahb_single</td>
  67763. + <td>This bit when programmed supports SINGLE transfers for remainder data
  67764. + in a transfer for DMA mode of operation.
  67765. + - 0: The remainder data will be sent using INCR burst size (default)
  67766. + - 1: The remainder data will be sent using SINGLE burst size.
  67767. + </td></tr>
  67768. +
  67769. +<tr>
  67770. + <td>adp_enable</td>
  67771. + <td>Specifies whether ADP feature is enabled.
  67772. + The driver will automatically detect the value for this parameter if none is
  67773. + specified.
  67774. + - 0: ADP feature disabled (default)
  67775. + - 1: ADP feature enabled
  67776. + </td></tr>
  67777. +
  67778. + <tr>
  67779. + <td>otg_ver</td>
  67780. + <td>Specifies whether OTG is performing as USB OTG Revision 2.0 or Revision 1.3
  67781. + USB OTG device.
  67782. + - 0: OTG 2.0 support disabled (default)
  67783. + - 1: OTG 2.0 support enabled
  67784. + </td></tr>
  67785. +
  67786. +*/
  67787. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_driver.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h
  67788. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_driver.h 1970-01-01 01:00:00.000000000 +0100
  67789. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_driver.h 2014-06-11 21:03:43.000000000 +0200
  67790. @@ -0,0 +1,86 @@
  67791. +/* ==========================================================================
  67792. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_driver.h $
  67793. + * $Revision: #19 $
  67794. + * $Date: 2010/11/15 $
  67795. + * $Change: 1627671 $
  67796. + *
  67797. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  67798. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  67799. + * otherwise expressly agreed to in writing between Synopsys and you.
  67800. + *
  67801. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  67802. + * any End User Software License Agreement or Agreement for Licensed Product
  67803. + * with Synopsys or any supplement thereto. You are permitted to use and
  67804. + * redistribute this Software in source and binary forms, with or without
  67805. + * modification, provided that redistributions of source code must retain this
  67806. + * notice. You may not view, use, disclose, copy or distribute this file or
  67807. + * any information contained herein except pursuant to this license grant from
  67808. + * Synopsys. If you do not agree with this notice, including the disclaimer
  67809. + * below, then you are not authorized to use the Software.
  67810. + *
  67811. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  67812. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67813. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67814. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  67815. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67816. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  67817. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  67818. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67819. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67820. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  67821. + * DAMAGE.
  67822. + * ========================================================================== */
  67823. +
  67824. +#ifndef __DWC_OTG_DRIVER_H__
  67825. +#define __DWC_OTG_DRIVER_H__
  67826. +
  67827. +/** @file
  67828. + * This file contains the interface to the Linux driver.
  67829. + */
  67830. +#include "dwc_otg_os_dep.h"
  67831. +#include "dwc_otg_core_if.h"
  67832. +
  67833. +/* Type declarations */
  67834. +struct dwc_otg_pcd;
  67835. +struct dwc_otg_hcd;
  67836. +
  67837. +/**
  67838. + * This structure is a wrapper that encapsulates the driver components used to
  67839. + * manage a single DWC_otg controller.
  67840. + */
  67841. +typedef struct dwc_otg_device {
  67842. + /** Structure containing OS-dependent stuff. KEEP THIS STRUCT AT THE
  67843. + * VERY BEGINNING OF THE DEVICE STRUCT. OSes such as FreeBSD and NetBSD
  67844. + * require this. */
  67845. + struct os_dependent os_dep;
  67846. +
  67847. + /** Pointer to the core interface structure. */
  67848. + dwc_otg_core_if_t *core_if;
  67849. +
  67850. + /** Pointer to the PCD structure. */
  67851. + struct dwc_otg_pcd *pcd;
  67852. +
  67853. + /** Pointer to the HCD structure. */
  67854. + struct dwc_otg_hcd *hcd;
  67855. +
  67856. + /** Flag to indicate whether the common IRQ handler is installed. */
  67857. + uint8_t common_irq_installed;
  67858. +
  67859. +} dwc_otg_device_t;
  67860. +
  67861. +/*We must clear S3C24XX_EINTPEND external interrupt register
  67862. + * because after clearing in this register trigerred IRQ from
  67863. + * H/W core in kernel interrupt can be occured again before OTG
  67864. + * handlers clear all IRQ sources of Core registers because of
  67865. + * timing latencies and Low Level IRQ Type.
  67866. + */
  67867. +#ifdef CONFIG_MACH_IPMATE
  67868. +#define S3C2410X_CLEAR_EINTPEND() \
  67869. +do { \
  67870. + __raw_writel(1UL << 11,S3C24XX_EINTPEND); \
  67871. +} while (0)
  67872. +#else
  67873. +#define S3C2410X_CLEAR_EINTPEND() do { } while (0)
  67874. +#endif
  67875. +
  67876. +#endif
  67877. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c
  67878. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 1970-01-01 01:00:00.000000000 +0100
  67879. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.c 2014-06-11 21:03:43.000000000 +0200
  67880. @@ -0,0 +1,1290 @@
  67881. +/*
  67882. + * dwc_otg_fiq_fsm.c - The finite state machine FIQ
  67883. + *
  67884. + * Copyright (c) 2013 Raspberry Pi Foundation
  67885. + *
  67886. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  67887. + * All rights reserved.
  67888. + *
  67889. + * Redistribution and use in source and binary forms, with or without
  67890. + * modification, are permitted provided that the following conditions are met:
  67891. + * * Redistributions of source code must retain the above copyright
  67892. + * notice, this list of conditions and the following disclaimer.
  67893. + * * Redistributions in binary form must reproduce the above copyright
  67894. + * notice, this list of conditions and the following disclaimer in the
  67895. + * documentation and/or other materials provided with the distribution.
  67896. + * * Neither the name of Raspberry Pi nor the
  67897. + * names of its contributors may be used to endorse or promote products
  67898. + * derived from this software without specific prior written permission.
  67899. + *
  67900. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  67901. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  67902. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  67903. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  67904. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  67905. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  67906. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  67907. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  67908. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  67909. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  67910. + *
  67911. + * This FIQ implements functionality that performs split transactions on
  67912. + * the dwc_otg hardware without any outside intervention. A split transaction
  67913. + * is "queued" by nominating a specific host channel to perform the entirety
  67914. + * of a split transaction. This FIQ will then perform the microframe-precise
  67915. + * scheduling required in each phase of the transaction until completion.
  67916. + *
  67917. + * The FIQ functionality is glued into the Synopsys driver via the entry point
  67918. + * in the FSM enqueue function, and at the exit point in handling a HC interrupt
  67919. + * for a FSM-enabled channel.
  67920. + *
  67921. + * NB: Large parts of this implementation have architecture-specific code.
  67922. + * For porting this functionality to other ARM machines, the minimum is required:
  67923. + * - An interrupt controller allowing the top-level dwc USB interrupt to be routed
  67924. + * to the FIQ
  67925. + * - A method of forcing a software generated interrupt from FIQ mode that then
  67926. + * triggers an IRQ entry (with the dwc USB handler called by this IRQ number)
  67927. + * - Guaranteed interrupt routing such that both the FIQ and SGI occur on the same
  67928. + * processor core - there is no locking between the FIQ and IRQ (aside from
  67929. + * local_fiq_disable)
  67930. + *
  67931. + */
  67932. +
  67933. +#include "dwc_otg_fiq_fsm.h"
  67934. +
  67935. +
  67936. +char buffer[1000*16];
  67937. +int wptr;
  67938. +void notrace _fiq_print(enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...)
  67939. +{
  67940. + enum fiq_debug_level dbg_lvl_req = FIQDBG_ERR;
  67941. + va_list args;
  67942. + char text[17];
  67943. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + 0x408) };
  67944. +
  67945. + if((dbg_lvl & dbg_lvl_req) || dbg_lvl == FIQDBG_ERR)
  67946. + {
  67947. + snprintf(text, 9, " %4d:%1u ", hfnum.b.frnum/8, hfnum.b.frnum & 7);
  67948. + va_start(args, fmt);
  67949. + vsnprintf(text+8, 9, fmt, args);
  67950. + va_end(args);
  67951. +
  67952. + memcpy(buffer + wptr, text, 16);
  67953. + wptr = (wptr + 16) % sizeof(buffer);
  67954. + }
  67955. +}
  67956. +
  67957. +/**
  67958. + * fiq_fsm_restart_channel() - Poke channel enable bit for a split transaction
  67959. + * @channel: channel to re-enable
  67960. + */
  67961. +static void fiq_fsm_restart_channel(struct fiq_state *st, int n, int force)
  67962. +{
  67963. + hcchar_data_t hcchar = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR) };
  67964. +
  67965. + hcchar.b.chen = 0;
  67966. + if (st->channel[n].hcchar_copy.b.eptype & 0x1) {
  67967. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  67968. + /* Hardware bug workaround: update the ssplit index */
  67969. + if (st->channel[n].hcsplt_copy.b.spltena)
  67970. + st->channel[n].expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  67971. +
  67972. + hcchar.b.oddfrm = (hfnum.b.frnum & 0x1) ? 0 : 1;
  67973. + }
  67974. +
  67975. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  67976. + hcchar.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  67977. + hcchar.b.chen = 1;
  67978. +
  67979. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, hcchar.d32);
  67980. + fiq_print(FIQDBG_INT, st, "HCGO %01d %01d", n, force);
  67981. +}
  67982. +
  67983. +/**
  67984. + * fiq_fsm_setup_csplit() - Prepare a host channel for a CSplit transaction stage
  67985. + * @st: Pointer to the channel's state
  67986. + * @n : channel number
  67987. + *
  67988. + * Change host channel registers to perform a complete-split transaction. Being mindful of the
  67989. + * endpoint direction, set control regs up correctly.
  67990. + */
  67991. +static void notrace fiq_fsm_setup_csplit(struct fiq_state *st, int n)
  67992. +{
  67993. + hcsplt_data_t hcsplt = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT) };
  67994. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  67995. +
  67996. + hcsplt.b.compsplt = 1;
  67997. + if (st->channel[n].hcchar_copy.b.epdir == 1) {
  67998. + // If IN, the CSPLIT result contains the data or a hub handshake. hctsiz = maxpacket.
  67999. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  68000. + } else {
  68001. + // If OUT, the CSPLIT result contains handshake only.
  68002. + hctsiz.b.xfersize = 0;
  68003. + }
  68004. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  68005. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68006. + mb();
  68007. +}
  68008. +
  68009. +static inline int notrace fiq_get_xfer_len(struct fiq_state *st, int n)
  68010. +{
  68011. + /* The xfersize register is a bit wonky. For IN transfers, it decrements by the packet size. */
  68012. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68013. +
  68014. + if (st->channel[n].hcchar_copy.b.epdir == 0) {
  68015. + return st->channel[n].hctsiz_copy.b.xfersize;
  68016. + } else {
  68017. + return st->channel[n].hctsiz_copy.b.xfersize - hctsiz.b.xfersize;
  68018. + }
  68019. +
  68020. +}
  68021. +
  68022. +
  68023. +/**
  68024. + * fiq_increment_dma_buf() - update DMA address for bounce buffers after a CSPLIT
  68025. + *
  68026. + * Of use only for IN periodic transfers.
  68027. + */
  68028. +static int notrace fiq_increment_dma_buf(struct fiq_state *st, int num_channels, int n)
  68029. +{
  68030. + hcdma_data_t hcdma;
  68031. + int i = st->channel[n].dma_info.index;
  68032. + int len;
  68033. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  68034. +
  68035. + len = fiq_get_xfer_len(st, n);
  68036. + fiq_print(FIQDBG_INT, st, "LEN: %03d", len);
  68037. + st->channel[n].dma_info.slot_len[i] = len;
  68038. + i++;
  68039. + if (i > 6)
  68040. + BUG();
  68041. +
  68042. + hcdma.d32 = (dma_addr_t) &blob->channel[n].index[i].buf[0];
  68043. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68044. + st->channel[n].dma_info.index = i;
  68045. + return 0;
  68046. +}
  68047. +
  68048. +/**
  68049. + * fiq_reload_hctsiz() - for IN transactions, reset HCTSIZ
  68050. + */
  68051. +static void notrace fiq_fsm_reload_hctsiz(struct fiq_state *st, int n)
  68052. +{
  68053. + hctsiz_data_t hctsiz = { .d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ) };
  68054. + hctsiz.b.xfersize = st->channel[n].hctsiz_copy.b.xfersize;
  68055. + hctsiz.b.pktcnt = 1;
  68056. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68057. +}
  68058. +
  68059. +/**
  68060. + * fiq_iso_out_advance() - update DMA address and split position bits
  68061. + * for isochronous OUT transactions.
  68062. + *
  68063. + * Returns 1 if this is the last packet queued, 0 otherwise. Split-ALL and
  68064. + * Split-BEGIN states are not handled - this is done when the transaction was queued.
  68065. + *
  68066. + * This function must only be called from the FIQ_ISO_OUT_ACTIVE state.
  68067. + */
  68068. +static int notrace fiq_iso_out_advance(struct fiq_state *st, int num_channels, int n)
  68069. +{
  68070. + hcsplt_data_t hcsplt;
  68071. + hctsiz_data_t hctsiz;
  68072. + hcdma_data_t hcdma;
  68073. + struct fiq_dma_blob *blob = (struct fiq_dma_blob *) st->dma_base;
  68074. + int last = 0;
  68075. + int i = st->channel[n].dma_info.index;
  68076. +
  68077. + fiq_print(FIQDBG_INT, st, "ADV %01d %01d ", n, i);
  68078. + i++;
  68079. + if (i == 4)
  68080. + last = 1;
  68081. + if (st->channel[n].dma_info.slot_len[i+1] == 255)
  68082. + last = 1;
  68083. +
  68084. + /* New DMA address - address of bounce buffer referred to in index */
  68085. + hcdma.d32 = (uint32_t) &blob->channel[n].index[i].buf[0];
  68086. + //hcdma.d32 = FIQ_READ(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n));
  68087. + //hcdma.d32 += st->channel[n].dma_info.slot_len[i];
  68088. + fiq_print(FIQDBG_INT, st, "LAST: %01d ", last);
  68089. + fiq_print(FIQDBG_INT, st, "LEN: %03d", st->channel[n].dma_info.slot_len[i]);
  68090. + hcsplt.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT);
  68091. + hctsiz.d32 = FIQ_READ(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ);
  68092. + hcsplt.b.xactpos = (last) ? ISOC_XACTPOS_END : ISOC_XACTPOS_MID;
  68093. + /* Set up new packet length */
  68094. + hctsiz.b.pktcnt = 1;
  68095. + hctsiz.b.xfersize = st->channel[n].dma_info.slot_len[i];
  68096. + fiq_print(FIQDBG_INT, st, "%08x", hctsiz.d32);
  68097. +
  68098. + st->channel[n].dma_info.index++;
  68099. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCSPLT, hcsplt.d32);
  68100. + FIQ_WRITE(st->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, hctsiz.d32);
  68101. + FIQ_WRITE(st->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68102. + return last;
  68103. +}
  68104. +
  68105. +/**
  68106. + * fiq_fsm_tt_next_isoc() - queue next pending isochronous out start-split on a TT
  68107. + *
  68108. + * Despite the limitations of the DWC core, we can force a microframe pipeline of
  68109. + * isochronous OUT start-split transactions while waiting for a corresponding other-type
  68110. + * of endpoint to finish its CSPLITs. TTs have big periodic buffers therefore it
  68111. + * is very unlikely that filling the start-split FIFO will cause data loss.
  68112. + * This allows much better interleaving of transactions in an order-independent way-
  68113. + * there is no requirement to prioritise isochronous, just a state-space search has
  68114. + * to be performed on each periodic start-split complete interrupt.
  68115. + */
  68116. +static int notrace fiq_fsm_tt_next_isoc(struct fiq_state *st, int num_channels, int n)
  68117. +{
  68118. + int hub_addr = st->channel[n].hub_addr;
  68119. + int port_addr = st->channel[n].port_addr;
  68120. + int i, poked = 0;
  68121. + for (i = 0; i < num_channels; i++) {
  68122. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  68123. + continue;
  68124. + if (st->channel[i].hub_addr == hub_addr &&
  68125. + st->channel[i].port_addr == port_addr) {
  68126. + switch (st->channel[i].fsm) {
  68127. + case FIQ_PER_ISO_OUT_PENDING:
  68128. + if (st->channel[i].nrpackets == 1) {
  68129. + st->channel[i].fsm = FIQ_PER_ISO_OUT_LAST;
  68130. + } else {
  68131. + st->channel[i].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68132. + }
  68133. + fiq_fsm_restart_channel(st, i, 0);
  68134. + poked = 1;
  68135. + break;
  68136. +
  68137. + default:
  68138. + break;
  68139. + }
  68140. + }
  68141. + if (poked)
  68142. + break;
  68143. + }
  68144. + return poked;
  68145. +}
  68146. +
  68147. +/**
  68148. + * fiq_fsm_tt_in_use() - search for host channels using this TT
  68149. + * @n: Channel to use as reference
  68150. + *
  68151. + */
  68152. +int notrace noinline fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n)
  68153. +{
  68154. + int hub_addr = st->channel[n].hub_addr;
  68155. + int port_addr = st->channel[n].port_addr;
  68156. + int i, in_use = 0;
  68157. + for (i = 0; i < num_channels; i++) {
  68158. + if (i == n || st->channel[i].fsm == FIQ_PASSTHROUGH)
  68159. + continue;
  68160. + switch (st->channel[i].fsm) {
  68161. + /* TT is reserved for channels that are in the middle of a periodic
  68162. + * split transaction.
  68163. + */
  68164. + case FIQ_PER_SSPLIT_STARTED:
  68165. + case FIQ_PER_CSPLIT_WAIT:
  68166. + case FIQ_PER_CSPLIT_NYET1:
  68167. + //case FIQ_PER_CSPLIT_POLL:
  68168. + case FIQ_PER_ISO_OUT_ACTIVE:
  68169. + case FIQ_PER_ISO_OUT_LAST:
  68170. + if (st->channel[i].hub_addr == hub_addr &&
  68171. + st->channel[i].port_addr == port_addr) {
  68172. + in_use = 1;
  68173. + }
  68174. + break;
  68175. + default:
  68176. + break;
  68177. + }
  68178. + if (in_use)
  68179. + break;
  68180. + }
  68181. + return in_use;
  68182. +}
  68183. +
  68184. +/**
  68185. + * fiq_fsm_more_csplits() - determine whether additional CSPLITs need
  68186. + * to be issued for this IN transaction.
  68187. + *
  68188. + * We cannot tell the inbound PID of a data packet due to hardware limitations.
  68189. + * we need to make an educated guess as to whether we need to queue another CSPLIT
  68190. + * or not. A no-brainer is when we have received enough data to fill the endpoint
  68191. + * size, but for endpoints that give variable-length data then we have to resort
  68192. + * to heuristics.
  68193. + *
  68194. + * We also return whether this is the last CSPLIT to be queued, again based on
  68195. + * heuristics. This is to allow a 1-uframe overlap of periodic split transactions.
  68196. + * Note: requires at least 1 CSPLIT to have been performed prior to being called.
  68197. + */
  68198. +
  68199. +/*
  68200. + * We need some way of guaranteeing if a returned periodic packet of size X
  68201. + * has a DATA0 PID.
  68202. + * The heuristic value of 144 bytes assumes that the received data has maximal
  68203. + * bit-stuffing and the clock frequency of the transmitting device is at the lowest
  68204. + * permissible limit. If the transfer length results in a final packet size
  68205. + * 144 < p <= 188, then an erroneous CSPLIT will be issued.
  68206. + * Also used to ensure that an endpoint will nominally only return a single
  68207. + * complete-split worth of data.
  68208. + */
  68209. +#define DATA0_PID_HEURISTIC 144
  68210. +
  68211. +static int notrace noinline fiq_fsm_more_csplits(struct fiq_state *state, int n, int *probably_last)
  68212. +{
  68213. +
  68214. + int i;
  68215. + int total_len = 0;
  68216. + int more_needed = 1;
  68217. + struct fiq_channel_state *st = &state->channel[n];
  68218. +
  68219. + for (i = 0; i < st->dma_info.index; i++) {
  68220. + total_len += st->dma_info.slot_len[i];
  68221. + }
  68222. +
  68223. + *probably_last = 0;
  68224. +
  68225. + if (st->hcchar_copy.b.eptype == 0x3) {
  68226. + /*
  68227. + * An interrupt endpoint will take max 2 CSPLITs. if we are receiving data
  68228. + * then this is definitely the last CSPLIT.
  68229. + */
  68230. + *probably_last = 1;
  68231. + } else {
  68232. + /* Isoc IN. This is a bit risky if we are the first transaction:
  68233. + * we may have been held off slightly. */
  68234. + if (i > 1 && st->dma_info.slot_len[st->dma_info.index-1] <= DATA0_PID_HEURISTIC) {
  68235. + more_needed = 0;
  68236. + }
  68237. + /* If in the next uframe we will receive enough data to fill the endpoint,
  68238. + * then only issue 1 more csplit.
  68239. + */
  68240. + if (st->hctsiz_copy.b.xfersize - total_len <= DATA0_PID_HEURISTIC)
  68241. + *probably_last = 1;
  68242. + }
  68243. +
  68244. + if (total_len >= st->hctsiz_copy.b.xfersize ||
  68245. + i == 6 || total_len == 0)
  68246. + /* Note: due to bit stuffing it is possible to have > 6 CSPLITs for
  68247. + * a single endpoint. Accepting more would completely break our scheduling mechanism though
  68248. + * - in these extreme cases we will pass through a truncated packet.
  68249. + */
  68250. + more_needed = 0;
  68251. +
  68252. + return more_needed;
  68253. +}
  68254. +
  68255. +/**
  68256. + * fiq_fsm_too_late() - Test transaction for lateness
  68257. + *
  68258. + * If a SSPLIT for a large IN transaction is issued too late in a frame,
  68259. + * the hub will disable the port to the device and respond with ERR handshakes.
  68260. + * The hub status endpoint will not reflect this change.
  68261. + * Returns 1 if we will issue a SSPLIT that will result in a device babble.
  68262. + */
  68263. +int notrace fiq_fsm_too_late(struct fiq_state *st, int n)
  68264. +{
  68265. + int uframe;
  68266. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  68267. + uframe = hfnum.b.frnum & 0x7;
  68268. + if ((uframe < 6) && (st->channel[n].nrpackets + 1 + uframe > 7)) {
  68269. + return 1;
  68270. + } else {
  68271. + return 0;
  68272. + }
  68273. +}
  68274. +
  68275. +
  68276. +/**
  68277. + * fiq_fsm_start_next_periodic() - A half-arsed attempt at a microframe pipeline
  68278. + *
  68279. + * Search pending transactions in the start-split pending state and queue them.
  68280. + * Don't queue packets in uframe .5 (comes out in .6) (USB2.0 11.18.4).
  68281. + * Note: we specifically don't do isochronous OUT transactions first because better
  68282. + * use of the TT's start-split fifo can be achieved by pipelining an IN before an OUT.
  68283. + */
  68284. +static void notrace noinline fiq_fsm_start_next_periodic(struct fiq_state *st, int num_channels)
  68285. +{
  68286. + int n;
  68287. + hfnum_data_t hfnum = { .d32 = FIQ_READ(st->dwc_regs_base + HFNUM) };
  68288. + if ((hfnum.b.frnum & 0x7) == 5)
  68289. + return;
  68290. + for (n = 0; n < num_channels; n++) {
  68291. + if (st->channel[n].fsm == FIQ_PER_SSPLIT_QUEUED) {
  68292. + /* Check to see if any other transactions are using this TT */
  68293. + if(!fiq_fsm_tt_in_use(st, num_channels, n)) {
  68294. + if (!fiq_fsm_too_late(st, n)) {
  68295. + st->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  68296. + fiq_print(FIQDBG_INT, st, "NEXTPER ");
  68297. + fiq_fsm_restart_channel(st, n, 0);
  68298. + } else {
  68299. + st->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  68300. + }
  68301. + break;
  68302. + }
  68303. + }
  68304. + }
  68305. + for (n = 0; n < num_channels; n++) {
  68306. + if (st->channel[n].fsm == FIQ_PER_ISO_OUT_PENDING) {
  68307. + if (!fiq_fsm_tt_in_use(st, num_channels, n)) {
  68308. + fiq_print(FIQDBG_INT, st, "NEXTISO ");
  68309. + st->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68310. + fiq_fsm_restart_channel(st, n, 0);
  68311. + break;
  68312. + }
  68313. + }
  68314. + }
  68315. +}
  68316. +
  68317. +/**
  68318. + * fiq_fsm_update_hs_isoc() - update isochronous frame and transfer data
  68319. + * @state: Pointer to fiq_state
  68320. + * @n: Channel transaction is active on
  68321. + * @hcint: Copy of host channel interrupt register
  68322. + *
  68323. + * Returns 0 if there are no more transactions for this HC to do, 1
  68324. + * otherwise.
  68325. + */
  68326. +static int notrace noinline fiq_fsm_update_hs_isoc(struct fiq_state *state, int n, hcint_data_t hcint)
  68327. +{
  68328. + struct fiq_channel_state *st = &state->channel[n];
  68329. + int xfer_len = 0, nrpackets = 0;
  68330. + hcdma_data_t hcdma;
  68331. + fiq_print(FIQDBG_INT, state, "HSISO %02d", n);
  68332. +
  68333. + xfer_len = fiq_get_xfer_len(state, n);
  68334. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].actual_length = xfer_len;
  68335. +
  68336. + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].status = hcint.d32;
  68337. +
  68338. + st->hs_isoc_info.index++;
  68339. + if (st->hs_isoc_info.index == st->hs_isoc_info.nrframes) {
  68340. + return 0;
  68341. + }
  68342. +
  68343. + /* grab the next DMA address offset from the array */
  68344. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].offset;
  68345. + FIQ_WRITE(state->dwc_regs_base + HC_DMA + (HC_OFFSET * n), hcdma.d32);
  68346. +
  68347. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  68348. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  68349. + * this is always set to the maximum size of the endpoint. */
  68350. + xfer_len = st->hs_isoc_info.iso_desc[st->hs_isoc_info.index].length;
  68351. + /* Integer divide in a FIQ: fun. FIXME: make this not suck */
  68352. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  68353. + if (nrpackets == 0)
  68354. + nrpackets = 1;
  68355. + st->hcchar_copy.b.multicnt = nrpackets;
  68356. + st->hctsiz_copy.b.pktcnt = nrpackets;
  68357. +
  68358. + /* Initial PID also needs to be set */
  68359. + if (st->hcchar_copy.b.epdir == 0) {
  68360. + st->hctsiz_copy.b.xfersize = xfer_len;
  68361. + switch (st->hcchar_copy.b.multicnt) {
  68362. + case 1:
  68363. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  68364. + break;
  68365. + case 2:
  68366. + case 3:
  68367. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  68368. + break;
  68369. + }
  68370. +
  68371. + } else {
  68372. + switch (st->hcchar_copy.b.multicnt) {
  68373. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  68374. + case 1:
  68375. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  68376. + break;
  68377. + case 2:
  68378. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  68379. + break;
  68380. + case 3:
  68381. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  68382. + break;
  68383. + }
  68384. + }
  68385. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCTSIZ, st->hctsiz_copy.d32);
  68386. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR, st->hcchar_copy.d32);
  68387. + /* Channel is enabled on hcint handler exit */
  68388. + fiq_print(FIQDBG_INT, state, "HSISOOUT");
  68389. + return 1;
  68390. +}
  68391. +
  68392. +
  68393. +/**
  68394. + * fiq_fsm_do_sof() - FSM start-of-frame interrupt handler
  68395. + * @state: Pointer to the state struct passed from banked FIQ mode registers.
  68396. + * @num_channels: set according to the DWC hardware configuration
  68397. + *
  68398. + * The SOF handler in FSM mode has two functions
  68399. + * 1. Hold off SOF from causing schedule advancement in IRQ context if there's
  68400. + * nothing to do
  68401. + * 2. Advance certain FSM states that require either a microframe delay, or a microframe
  68402. + * of holdoff.
  68403. + *
  68404. + * The second part is architecture-specific to mach-bcm2835 -
  68405. + * a sane interrupt controller would have a mask register for ARM interrupt sources
  68406. + * to be promoted to the nFIQ line, but it doesn't. Instead a single interrupt
  68407. + * number (USB) can be enabled. This means that certain parts of the USB specification
  68408. + * that require "wait a little while, then issue another packet" cannot be fulfilled with
  68409. + * the timing granularity required to achieve optimal throughout. The workaround is to use
  68410. + * the SOF "timer" (125uS) to perform this task.
  68411. + */
  68412. +static int notrace noinline fiq_fsm_do_sof(struct fiq_state *state, int num_channels)
  68413. +{
  68414. + hfnum_data_t hfnum = { .d32 = FIQ_READ(state->dwc_regs_base + HFNUM) };
  68415. + int n;
  68416. + int kick_irq = 0;
  68417. +
  68418. + if ((hfnum.b.frnum & 0x7) == 1) {
  68419. + /* We cannot issue csplits for transactions in the last frame past (n+1).1
  68420. + * Check to see if there are any transactions that are stale.
  68421. + * Boot them out.
  68422. + */
  68423. + for (n = 0; n < num_channels; n++) {
  68424. + switch (state->channel[n].fsm) {
  68425. + case FIQ_PER_CSPLIT_WAIT:
  68426. + case FIQ_PER_CSPLIT_NYET1:
  68427. + case FIQ_PER_CSPLIT_POLL:
  68428. + case FIQ_PER_CSPLIT_LAST:
  68429. + /* Check if we are no longer in the same full-speed frame. */
  68430. + if (((state->channel[n].expected_uframe & 0x3FFF) & ~0x7) <
  68431. + (hfnum.b.frnum & ~0x7))
  68432. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  68433. + break;
  68434. + default:
  68435. + break;
  68436. + }
  68437. + }
  68438. + }
  68439. +
  68440. + for (n = 0; n < num_channels; n++) {
  68441. + switch (state->channel[n].fsm) {
  68442. +
  68443. + case FIQ_NP_SSPLIT_RETRY:
  68444. + case FIQ_NP_IN_CSPLIT_RETRY:
  68445. + case FIQ_NP_OUT_CSPLIT_RETRY:
  68446. + fiq_fsm_restart_channel(state, n, 0);
  68447. + break;
  68448. +
  68449. + case FIQ_HS_ISOC_SLEEPING:
  68450. + state->channel[n].fsm = FIQ_HS_ISOC_TURBO;
  68451. + fiq_fsm_restart_channel(state, n, 0);
  68452. + break;
  68453. +
  68454. + case FIQ_PER_SSPLIT_QUEUED:
  68455. + if ((hfnum.b.frnum & 0x7) == 5)
  68456. + break;
  68457. + if(!fiq_fsm_tt_in_use(state, num_channels, n)) {
  68458. + if (!fiq_fsm_too_late(state, n)) {
  68459. + fiq_print(FIQDBG_INT, st, "SOF GO %01d", n);
  68460. + fiq_fsm_restart_channel(state, n, 0);
  68461. + state->channel[n].fsm = FIQ_PER_SSPLIT_STARTED;
  68462. + } else {
  68463. + /* Transaction cannot be started without risking a device babble error */
  68464. + state->channel[n].fsm = FIQ_PER_SPLIT_TIMEOUT;
  68465. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  68466. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  68467. + kick_irq |= 1;
  68468. + }
  68469. + }
  68470. + break;
  68471. +
  68472. + case FIQ_PER_ISO_OUT_PENDING:
  68473. + /* Ordinarily, this should be poked after the SSPLIT
  68474. + * complete interrupt for a competing transfer on the same
  68475. + * TT. Doesn't happen for aborted transactions though.
  68476. + */
  68477. + if ((hfnum.b.frnum & 0x7) >= 5)
  68478. + break;
  68479. + if (!fiq_fsm_tt_in_use(state, num_channels, n)) {
  68480. + /* Hardware bug. SOF can sometimes occur after the channel halt interrupt
  68481. + * that caused this.
  68482. + */
  68483. + fiq_fsm_restart_channel(state, n, 0);
  68484. + fiq_print(FIQDBG_INT, state, "SOF ISOC");
  68485. + if (state->channel[n].nrpackets == 1) {
  68486. + state->channel[n].fsm = FIQ_PER_ISO_OUT_LAST;
  68487. + } else {
  68488. + state->channel[n].fsm = FIQ_PER_ISO_OUT_ACTIVE;
  68489. + }
  68490. + }
  68491. + break;
  68492. +
  68493. + case FIQ_PER_CSPLIT_WAIT:
  68494. + /* we are guaranteed to be in this state if and only if the SSPLIT interrupt
  68495. + * occurred when the bus transaction occurred. The SOF interrupt reversal bug
  68496. + * will utterly bugger this up though.
  68497. + */
  68498. + if (hfnum.b.frnum != state->channel[n].expected_uframe) {
  68499. + fiq_print(FIQDBG_INT, state, "SOFCS %d ", n);
  68500. + state->channel[n].fsm = FIQ_PER_CSPLIT_POLL;
  68501. + fiq_fsm_restart_channel(state, n, 0);
  68502. + fiq_fsm_start_next_periodic(state, num_channels);
  68503. +
  68504. + }
  68505. + break;
  68506. +
  68507. + case FIQ_PER_SPLIT_TIMEOUT:
  68508. + case FIQ_DEQUEUE_ISSUED:
  68509. + /* Ugly: we have to force a HCD interrupt.
  68510. + * Poke the mask for the channel in question.
  68511. + * We will take a fake SOF because of this, but
  68512. + * that's OK.
  68513. + */
  68514. + state->haintmsk_saved.b2.chint &= ~(1 << n);
  68515. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, 0);
  68516. + kick_irq |= 1;
  68517. + break;
  68518. +
  68519. + default:
  68520. + break;
  68521. + }
  68522. + }
  68523. +
  68524. + if (state->kick_np_queues ||
  68525. + dwc_frame_num_le(state->next_sched_frame, hfnum.b.frnum))
  68526. + kick_irq |= 1;
  68527. +
  68528. + return !kick_irq;
  68529. +}
  68530. +
  68531. +
  68532. +/**
  68533. + * fiq_fsm_do_hcintr() - FSM host channel interrupt handler
  68534. + * @state: Pointer to the FIQ state struct
  68535. + * @num_channels: Number of channels as per hardware config
  68536. + * @n: channel for which HAINT(i) was raised
  68537. + *
  68538. + * An important property is that only the CHHLT interrupt is unmasked. Unfortunately, AHBerr is as well.
  68539. + */
  68540. +static int notrace noinline fiq_fsm_do_hcintr(struct fiq_state *state, int num_channels, int n)
  68541. +{
  68542. + hcint_data_t hcint;
  68543. + hcintmsk_data_t hcintmsk;
  68544. + hcint_data_t hcint_probe;
  68545. + hcchar_data_t hcchar;
  68546. + int handled = 0;
  68547. + int restart = 0;
  68548. + int last_csplit = 0;
  68549. + int start_next_periodic = 0;
  68550. + struct fiq_channel_state *st = &state->channel[n];
  68551. + hfnum_data_t hfnum;
  68552. +
  68553. + hcint.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT);
  68554. + hcintmsk.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK);
  68555. + hcint_probe.d32 = hcint.d32 & hcintmsk.d32;
  68556. +
  68557. + if (st->fsm != FIQ_PASSTHROUGH) {
  68558. + fiq_print(FIQDBG_INT, state, "HC%01d ST%02d", n, st->fsm);
  68559. + fiq_print(FIQDBG_INT, state, "%08x", hcint.d32);
  68560. + }
  68561. +
  68562. + switch (st->fsm) {
  68563. +
  68564. + case FIQ_PASSTHROUGH:
  68565. + case FIQ_DEQUEUE_ISSUED:
  68566. + /* doesn't belong to us, kick it upstairs */
  68567. + break;
  68568. +
  68569. + case FIQ_PASSTHROUGH_ERRORSTATE:
  68570. + /* We are here to emulate the error recovery mechanism of the dwc HCD.
  68571. + * Several interrupts are unmasked if a previous transaction failed - it's
  68572. + * death for the FIQ to attempt to handle them as the channel isn't halted.
  68573. + * Emulate what the HCD does in this situation: mask and continue.
  68574. + * The FSM has no other state setup so this has to be handled out-of-band.
  68575. + */
  68576. + fiq_print(FIQDBG_ERR, state, "ERRST %02d", n);
  68577. + if (hcint_probe.b.nak || hcint_probe.b.ack || hcint_probe.b.datatglerr) {
  68578. + fiq_print(FIQDBG_ERR, state, "RESET %02d", n);
  68579. + st->nr_errors = 0;
  68580. + hcintmsk.b.nak = 0;
  68581. + hcintmsk.b.ack = 0;
  68582. + hcintmsk.b.datatglerr = 0;
  68583. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINTMSK, hcintmsk.d32);
  68584. + return 1;
  68585. + }
  68586. + if (hcint_probe.b.chhltd) {
  68587. + fiq_print(FIQDBG_ERR, state, "CHHLT %02d", n);
  68588. + fiq_print(FIQDBG_ERR, state, "%08x", hcint.d32);
  68589. + return 0;
  68590. + }
  68591. + break;
  68592. +
  68593. + /* Non-periodic state groups */
  68594. + case FIQ_NP_SSPLIT_STARTED:
  68595. + case FIQ_NP_SSPLIT_RETRY:
  68596. + /* Got a HCINT for a NP SSPLIT. Expected ACK / NAK / fail */
  68597. + if (hcint.b.ack) {
  68598. + /* SSPLIT complete. For OUT, the data has been sent. For IN, the LS transaction
  68599. + * will start shortly. SOF needs to kick the transaction to prevent a NYET flood.
  68600. + */
  68601. + if(st->hcchar_copy.b.epdir == 1)
  68602. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  68603. + else
  68604. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68605. + st->nr_errors = 0;
  68606. + handled = 1;
  68607. + fiq_fsm_setup_csplit(state, n);
  68608. + } else if (hcint.b.nak) {
  68609. + // No buffer space in TT. Retry on a uframe boundary.
  68610. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  68611. + handled = 1;
  68612. + } else if (hcint.b.xacterr) {
  68613. + // The only other one we care about is xacterr. This implies HS bus error - retry.
  68614. + st->nr_errors++;
  68615. + st->fsm = FIQ_NP_SSPLIT_RETRY;
  68616. + if (st->nr_errors >= 3) {
  68617. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68618. + } else {
  68619. + handled = 1;
  68620. + restart = 1;
  68621. + }
  68622. + } else {
  68623. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68624. + handled = 0;
  68625. + restart = 0;
  68626. + }
  68627. + break;
  68628. +
  68629. + case FIQ_NP_IN_CSPLIT_RETRY:
  68630. + /* Received a CSPLIT done interrupt.
  68631. + * Expected Data/NAK/STALL/NYET for IN.
  68632. + */
  68633. + if (hcint.b.xfercomp) {
  68634. + /* For IN, data is present. */
  68635. + st->fsm = FIQ_NP_SPLIT_DONE;
  68636. + } else if (hcint.b.nak) {
  68637. + /* no endpoint data. Punt it upstairs */
  68638. + st->fsm = FIQ_NP_SPLIT_DONE;
  68639. + } else if (hcint.b.nyet) {
  68640. + /* CSPLIT NYET - retry on a uframe boundary. */
  68641. + handled = 1;
  68642. + st->nr_errors = 0;
  68643. + } else if (hcint.b.datatglerr) {
  68644. + /* data toggle errors do not set the xfercomp bit. */
  68645. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68646. + } else if (hcint.b.xacterr) {
  68647. + /* HS error. Retry immediate */
  68648. + st->fsm = FIQ_NP_IN_CSPLIT_RETRY;
  68649. + st->nr_errors++;
  68650. + if (st->nr_errors >= 3) {
  68651. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68652. + } else {
  68653. + handled = 1;
  68654. + restart = 1;
  68655. + }
  68656. + } else if (hcint.b.stall || hcint.b.bblerr) {
  68657. + /* A STALL implies either a LS bus error or a genuine STALL. */
  68658. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68659. + } else {
  68660. + /* Hardware bug. It's possible in some cases to
  68661. + * get a channel halt with nothing else set when
  68662. + * the response was a NYET. Treat as local 3-strikes retry.
  68663. + */
  68664. + hcint_data_t hcint_test = hcint;
  68665. + hcint_test.b.chhltd = 0;
  68666. + if (!hcint_test.d32) {
  68667. + st->nr_errors++;
  68668. + if (st->nr_errors >= 3) {
  68669. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68670. + } else {
  68671. + handled = 1;
  68672. + }
  68673. + } else {
  68674. + /* Bail out if something unexpected happened */
  68675. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68676. + }
  68677. + }
  68678. + break;
  68679. +
  68680. + case FIQ_NP_OUT_CSPLIT_RETRY:
  68681. + /* Received a CSPLIT done interrupt.
  68682. + * Expected ACK/NAK/STALL/NYET/XFERCOMP for OUT.*/
  68683. + if (hcint.b.xfercomp) {
  68684. + st->fsm = FIQ_NP_SPLIT_DONE;
  68685. + } else if (hcint.b.nak) {
  68686. + // The HCD will implement the holdoff on frame boundaries.
  68687. + st->fsm = FIQ_NP_SPLIT_DONE;
  68688. + } else if (hcint.b.nyet) {
  68689. + // Hub still processing.
  68690. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68691. + handled = 1;
  68692. + st->nr_errors = 0;
  68693. + //restart = 1;
  68694. + } else if (hcint.b.xacterr) {
  68695. + /* HS error. retry immediate */
  68696. + st->fsm = FIQ_NP_OUT_CSPLIT_RETRY;
  68697. + st->nr_errors++;
  68698. + if (st->nr_errors >= 3) {
  68699. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68700. + } else {
  68701. + handled = 1;
  68702. + restart = 1;
  68703. + }
  68704. + } else if (hcint.b.stall) {
  68705. + /* LS bus error or genuine stall */
  68706. + st->fsm = FIQ_NP_SPLIT_LS_ABORTED;
  68707. + } else {
  68708. + /*
  68709. + * Hardware bug. It's possible in some cases to get a
  68710. + * channel halt with nothing else set when the response was a NYET.
  68711. + * Treat as local 3-strikes retry.
  68712. + */
  68713. + hcint_data_t hcint_test = hcint;
  68714. + hcint_test.b.chhltd = 0;
  68715. + if (!hcint_test.d32) {
  68716. + st->nr_errors++;
  68717. + if (st->nr_errors >= 3) {
  68718. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68719. + } else {
  68720. + handled = 1;
  68721. + }
  68722. + } else {
  68723. + // Something unexpected happened. AHBerror or babble perhaps. Let the IRQ deal with it.
  68724. + st->fsm = FIQ_NP_SPLIT_HS_ABORTED;
  68725. + }
  68726. + }
  68727. + break;
  68728. +
  68729. + /* Periodic split states (except isoc out) */
  68730. + case FIQ_PER_SSPLIT_STARTED:
  68731. + /* Expect an ACK or failure for SSPLIT */
  68732. + if (hcint.b.ack) {
  68733. + /*
  68734. + * SSPLIT transfer complete interrupt - the generation of this interrupt is fraught with bugs.
  68735. + * For a packet queued in microframe n-3 to appear in n-2, if the channel is enabled near the EOF1
  68736. + * point for microframe n-3, the packet will not appear on the bus until microframe n.
  68737. + * Additionally, the generation of the actual interrupt is dodgy. For a packet appearing on the bus
  68738. + * in microframe n, sometimes the interrupt is generated immediately. Sometimes, it appears in n+1
  68739. + * coincident with SOF for n+1.
  68740. + * SOF is also buggy. It can sometimes be raised AFTER the first bus transaction has taken place.
  68741. + * These appear to be caused by timing/clock crossing bugs within the core itself.
  68742. + * State machine workaround.
  68743. + */
  68744. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68745. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68746. + fiq_fsm_setup_csplit(state, n);
  68747. + /* Poke the oddfrm bit. If we are equivalent, we received the interrupt at the correct
  68748. + * time. If not, then we're in the next SOF.
  68749. + */
  68750. + if ((hfnum.b.frnum & 0x1) == hcchar.b.oddfrm) {
  68751. + fiq_print(FIQDBG_INT, state, "CSWAIT %01d", n);
  68752. + st->expected_uframe = hfnum.b.frnum;
  68753. + st->fsm = FIQ_PER_CSPLIT_WAIT;
  68754. + } else {
  68755. + fiq_print(FIQDBG_INT, state, "CSPOL %01d", n);
  68756. + /* For isochronous IN endpoints,
  68757. + * we need to hold off if we are expecting a lot of data */
  68758. + if (st->hcchar_copy.b.mps < DATA0_PID_HEURISTIC) {
  68759. + start_next_periodic = 1;
  68760. + }
  68761. + /* Danger will robinson: we are in a broken state. If our first interrupt after
  68762. + * this is a NYET, it will be delayed by 1 uframe and result in an unrecoverable
  68763. + * lag. Unmask the NYET interrupt.
  68764. + */
  68765. + st->expected_uframe = (hfnum.b.frnum + 1) & 0x3FFF;
  68766. + st->fsm = FIQ_PER_CSPLIT_BROKEN_NYET1;
  68767. + restart = 1;
  68768. + }
  68769. + handled = 1;
  68770. + } else if (hcint.b.xacterr) {
  68771. + /* 3-strikes retry is enabled, we have hit our max nr_errors */
  68772. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68773. + start_next_periodic = 1;
  68774. + } else {
  68775. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68776. + start_next_periodic = 1;
  68777. + }
  68778. + /* We can now queue the next isochronous OUT transaction, if one is pending. */
  68779. + if(fiq_fsm_tt_next_isoc(state, num_channels, n)) {
  68780. + fiq_print(FIQDBG_INT, state, "NEXTISO ");
  68781. + }
  68782. + break;
  68783. +
  68784. + case FIQ_PER_CSPLIT_NYET1:
  68785. + /* First CSPLIT attempt was a NYET. If we get a subsequent NYET,
  68786. + * we are too late and the TT has dropped its CSPLIT fifo.
  68787. + */
  68788. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68789. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68790. + start_next_periodic = 1;
  68791. + if (hcint.b.nak) {
  68792. + st->fsm = FIQ_PER_SPLIT_DONE;
  68793. + } else if (hcint.b.xfercomp) {
  68794. + fiq_increment_dma_buf(state, num_channels, n);
  68795. + st->fsm = FIQ_PER_CSPLIT_POLL;
  68796. + st->nr_errors = 0;
  68797. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68798. + handled = 1;
  68799. + restart = 1;
  68800. + if (!last_csplit)
  68801. + start_next_periodic = 0;
  68802. + } else {
  68803. + st->fsm = FIQ_PER_SPLIT_DONE;
  68804. + }
  68805. + } else if (hcint.b.nyet) {
  68806. + /* Doh. Data lost. */
  68807. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68808. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  68809. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  68810. + } else {
  68811. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68812. + }
  68813. + break;
  68814. +
  68815. + case FIQ_PER_CSPLIT_BROKEN_NYET1:
  68816. + /*
  68817. + * we got here because our host channel is in the delayed-interrupt
  68818. + * state and we cannot take a NYET interrupt any later than when it
  68819. + * occurred. Disable then re-enable the channel if this happens to force
  68820. + * CSPLITs to occur at the right time.
  68821. + */
  68822. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68823. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68824. + fiq_print(FIQDBG_INT, state, "BROK: %01d ", n);
  68825. + if (hcint.b.nak) {
  68826. + st->fsm = FIQ_PER_SPLIT_DONE;
  68827. + start_next_periodic = 1;
  68828. + } else if (hcint.b.xfercomp) {
  68829. + fiq_increment_dma_buf(state, num_channels, n);
  68830. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68831. + st->fsm = FIQ_PER_CSPLIT_POLL;
  68832. + handled = 1;
  68833. + restart = 1;
  68834. + start_next_periodic = 1;
  68835. + /* Reload HCTSIZ for the next transfer */
  68836. + fiq_fsm_reload_hctsiz(state, n);
  68837. + if (!last_csplit)
  68838. + start_next_periodic = 0;
  68839. + } else {
  68840. + st->fsm = FIQ_PER_SPLIT_DONE;
  68841. + }
  68842. + } else if (hcint.b.nyet) {
  68843. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68844. + start_next_periodic = 1;
  68845. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  68846. + /* Local 3-strikes retry is handled by the core. This is a ERR response.*/
  68847. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  68848. + } else {
  68849. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68850. + }
  68851. + break;
  68852. +
  68853. + case FIQ_PER_CSPLIT_POLL:
  68854. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  68855. + hcchar.d32 = FIQ_READ(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCCHAR);
  68856. + start_next_periodic = 1;
  68857. + if (hcint.b.nak) {
  68858. + st->fsm = FIQ_PER_SPLIT_DONE;
  68859. + } else if (hcint.b.xfercomp) {
  68860. + fiq_increment_dma_buf(state, num_channels, n);
  68861. + if (fiq_fsm_more_csplits(state, n, &last_csplit)) {
  68862. + handled = 1;
  68863. + restart = 1;
  68864. + /* Reload HCTSIZ for the next transfer */
  68865. + fiq_fsm_reload_hctsiz(state, n);
  68866. + if (!last_csplit)
  68867. + start_next_periodic = 0;
  68868. + } else {
  68869. + st->fsm = FIQ_PER_SPLIT_DONE;
  68870. + }
  68871. + } else if (hcint.b.nyet) {
  68872. + /* Are we a NYET after the first data packet? */
  68873. + if (st->nrpackets == 0) {
  68874. + st->fsm = FIQ_PER_CSPLIT_NYET1;
  68875. + handled = 1;
  68876. + restart = 1;
  68877. + } else {
  68878. + /* We got a NYET when polling CSPLITs. Can happen
  68879. + * if our heuristic fails, or if someone disables us
  68880. + * for any significant length of time.
  68881. + */
  68882. + if (st->nr_errors >= 3) {
  68883. + st->fsm = FIQ_PER_SPLIT_NYET_ABORTED;
  68884. + } else {
  68885. + st->fsm = FIQ_PER_SPLIT_DONE;
  68886. + }
  68887. + }
  68888. + } else if (hcint.b.xacterr || hcint.b.stall || hcint.b.bblerr) {
  68889. + /* For xacterr, Local 3-strikes retry is handled by the core. This is a ERR response.*/
  68890. + st->fsm = FIQ_PER_SPLIT_LS_ABORTED;
  68891. + } else {
  68892. + st->fsm = FIQ_PER_SPLIT_HS_ABORTED;
  68893. + }
  68894. + break;
  68895. +
  68896. + case FIQ_HS_ISOC_TURBO:
  68897. + if (fiq_fsm_update_hs_isoc(state, n, hcint)) {
  68898. + /* more transactions to come */
  68899. + handled = 1;
  68900. + restart = 1;
  68901. + fiq_print(FIQDBG_INT, state, "HSISO M ");
  68902. + } else {
  68903. + st->fsm = FIQ_HS_ISOC_DONE;
  68904. + fiq_print(FIQDBG_INT, state, "HSISO F ");
  68905. + }
  68906. + break;
  68907. +
  68908. + case FIQ_HS_ISOC_ABORTED:
  68909. + /* This abort is called by the driver rewriting the state mid-transaction
  68910. + * which allows the dequeue mechanism to work more effectively.
  68911. + */
  68912. + break;
  68913. +
  68914. + case FIQ_PER_ISO_OUT_ACTIVE:
  68915. + if (hcint.b.ack) {
  68916. + if(fiq_iso_out_advance(state, num_channels, n)) {
  68917. + /* last OUT transfer */
  68918. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  68919. + /*
  68920. + * Assuming the periodic FIFO in the dwc core
  68921. + * actually does its job properly, we can queue
  68922. + * the next ssplit now and in theory, the wire
  68923. + * transactions will be in-order.
  68924. + */
  68925. + // No it doesn't. It appears to process requests in host channel order.
  68926. + //start_next_periodic = 1;
  68927. + }
  68928. + handled = 1;
  68929. + restart = 1;
  68930. + } else {
  68931. + /*
  68932. + * Isochronous transactions carry on regardless. Log the error
  68933. + * and continue.
  68934. + */
  68935. + //explode += 1;
  68936. + st->nr_errors++;
  68937. + if(fiq_iso_out_advance(state, num_channels, n)) {
  68938. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  68939. + //start_next_periodic = 1;
  68940. + }
  68941. + handled = 1;
  68942. + restart = 1;
  68943. + }
  68944. + break;
  68945. +
  68946. + case FIQ_PER_ISO_OUT_LAST:
  68947. + if (hcint.b.ack) {
  68948. + /* All done here */
  68949. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  68950. + } else {
  68951. + st->fsm = FIQ_PER_ISO_OUT_DONE;
  68952. + st->nr_errors++;
  68953. + }
  68954. + start_next_periodic = 1;
  68955. + break;
  68956. +
  68957. + case FIQ_PER_SPLIT_TIMEOUT:
  68958. + /* SOF kicked us because we overran. */
  68959. + start_next_periodic = 1;
  68960. + break;
  68961. +
  68962. + default:
  68963. + break;
  68964. + }
  68965. +
  68966. + if (handled) {
  68967. + FIQ_WRITE(state->dwc_regs_base + HC_START + (HC_OFFSET * n) + HCINT, hcint.d32);
  68968. + } else {
  68969. + /* Copy the regs into the state so the IRQ knows what to do */
  68970. + st->hcint_copy.d32 = hcint.d32;
  68971. + }
  68972. +
  68973. + if (restart) {
  68974. + /* Restart always implies handled. */
  68975. + if (restart == 2) {
  68976. + /* For complete-split INs, the show must go on.
  68977. + * Force a channel restart */
  68978. + fiq_fsm_restart_channel(state, n, 1);
  68979. + } else {
  68980. + fiq_fsm_restart_channel(state, n, 0);
  68981. + }
  68982. + }
  68983. + if (start_next_periodic) {
  68984. + fiq_fsm_start_next_periodic(state, num_channels);
  68985. + }
  68986. + if (st->fsm != FIQ_PASSTHROUGH)
  68987. + fiq_print(FIQDBG_INT, state, "FSMOUT%02d", st->fsm);
  68988. +
  68989. + return handled;
  68990. +}
  68991. +
  68992. +
  68993. +/**
  68994. + * dwc_otg_fiq_fsm() - Flying State Machine (monster) FIQ
  68995. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  68996. + * @num_channels: set according to the DWC hardware configuration
  68997. + * @dma: pointer to DMA bounce buffers for split transaction slots
  68998. + *
  68999. + * The FSM FIQ performs the low-level tasks that normally would be performed by the microcode
  69000. + * inside an EHCI or similar host controller regarding split transactions. The DWC core
  69001. + * interrupts each and every time a split transaction packet is received or sent successfully.
  69002. + * This results in either an interrupt storm when everything is working "properly", or
  69003. + * the interrupt latency of the system in general breaks time-sensitive periodic split
  69004. + * transactions. Pushing the low-level, but relatively easy state machine work into the FIQ
  69005. + * solves these problems.
  69006. + *
  69007. + * Return: void
  69008. + */
  69009. +void notrace dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels)
  69010. +{
  69011. + gintsts_data_t gintsts, gintsts_handled;
  69012. + gintmsk_data_t gintmsk;
  69013. + //hfnum_data_t hfnum;
  69014. + haint_data_t haint, haint_handled;
  69015. + haintmsk_data_t haintmsk;
  69016. + int kick_irq = 0;
  69017. +
  69018. + gintsts_handled.d32 = 0;
  69019. + haint_handled.d32 = 0;
  69020. +
  69021. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  69022. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  69023. + gintsts.d32 &= gintmsk.d32;
  69024. +
  69025. + if (gintsts.b.sofintr) {
  69026. + /* For FSM mode, SOF is required to keep the state machine advance for
  69027. + * certain stages of the periodic pipeline. It's death to mask this
  69028. + * interrupt in that case.
  69029. + */
  69030. +
  69031. + if (!fiq_fsm_do_sof(state, num_channels)) {
  69032. + /* Kick IRQ once. Queue advancement means that all pending transactions
  69033. + * will get serviced when the IRQ finally executes.
  69034. + */
  69035. + if (state->gintmsk_saved.b.sofintr == 1)
  69036. + kick_irq |= 1;
  69037. + state->gintmsk_saved.b.sofintr = 0;
  69038. + }
  69039. + gintsts_handled.b.sofintr = 1;
  69040. + }
  69041. +
  69042. + if (gintsts.b.hcintr) {
  69043. + int i;
  69044. + haint.d32 = FIQ_READ(state->dwc_regs_base + HAINT);
  69045. + haintmsk.d32 = FIQ_READ(state->dwc_regs_base + HAINTMSK);
  69046. + haint.d32 &= haintmsk.d32;
  69047. + haint_handled.d32 = 0;
  69048. + for (i=0; i<num_channels; i++) {
  69049. + if (haint.b2.chint & (1 << i)) {
  69050. + if(!fiq_fsm_do_hcintr(state, num_channels, i)) {
  69051. + /* HCINT was not handled in FIQ
  69052. + * HAINT is level-sensitive, leading to level-sensitive ginststs.b.hcint bit.
  69053. + * Mask HAINT(i) but keep top-level hcint unmasked.
  69054. + */
  69055. + state->haintmsk_saved.b2.chint &= ~(1 << i);
  69056. + } else {
  69057. + /* do_hcintr cleaned up after itself, but clear haint */
  69058. + haint_handled.b2.chint |= (1 << i);
  69059. + }
  69060. + }
  69061. + }
  69062. +
  69063. + if (haint_handled.b2.chint) {
  69064. + FIQ_WRITE(state->dwc_regs_base + HAINT, haint_handled.d32);
  69065. + }
  69066. +
  69067. + if (haintmsk.d32 != (haintmsk.d32 & state->haintmsk_saved.d32)) {
  69068. + /*
  69069. + * This is necessary to avoid multiple retriggers of the MPHI in the case
  69070. + * where interrupts are held off and HCINTs start to pile up.
  69071. + * Only wake up the IRQ if a new interrupt came in, was not handled and was
  69072. + * masked.
  69073. + */
  69074. + haintmsk.d32 &= state->haintmsk_saved.d32;
  69075. + FIQ_WRITE(state->dwc_regs_base + HAINTMSK, haintmsk.d32);
  69076. + kick_irq |= 1;
  69077. + }
  69078. + /* Top-Level interrupt - always handled because it's level-sensitive */
  69079. + gintsts_handled.b.hcintr = 1;
  69080. + }
  69081. +
  69082. +
  69083. + /* Clear the bits in the saved register that were not handled but were triggered. */
  69084. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  69085. +
  69086. + /* FIQ didn't handle something - mask has changed - write new mask */
  69087. + if (gintmsk.d32 != (gintmsk.d32 & state->gintmsk_saved.d32)) {
  69088. + gintmsk.d32 &= state->gintmsk_saved.d32;
  69089. + gintmsk.b.sofintr = 1;
  69090. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  69091. +// fiq_print(FIQDBG_INT, state, "KICKGINT");
  69092. +// fiq_print(FIQDBG_INT, state, "%08x", gintmsk.d32);
  69093. +// fiq_print(FIQDBG_INT, state, "%08x", state->gintmsk_saved.d32);
  69094. + kick_irq |= 1;
  69095. + }
  69096. +
  69097. + if (gintsts_handled.d32) {
  69098. + /* Only applies to edge-sensitive bits in GINTSTS */
  69099. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  69100. + }
  69101. +
  69102. + /* We got an interrupt, didn't handle it. */
  69103. + if (kick_irq) {
  69104. + state->mphi_int_count++;
  69105. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  69106. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  69107. +
  69108. + }
  69109. + state->fiq_done++;
  69110. + mb();
  69111. +}
  69112. +
  69113. +
  69114. +/**
  69115. + * dwc_otg_fiq_nop() - FIQ "lite"
  69116. + * @state: pointer to state struct passed from the banked FIQ mode registers.
  69117. + *
  69118. + * The "nop" handler does not intervene on any interrupts other than SOF.
  69119. + * It is limited in scope to deciding at each SOF if the IRQ SOF handler (which deals
  69120. + * with non-periodic/periodic queues) needs to be kicked.
  69121. + *
  69122. + * This is done to hold off the SOF interrupt, which occurs at a rate of 8000 per second.
  69123. + *
  69124. + * Return: void
  69125. + */
  69126. +void notrace dwc_otg_fiq_nop(struct fiq_state *state)
  69127. +{
  69128. + gintsts_data_t gintsts, gintsts_handled;
  69129. + gintmsk_data_t gintmsk;
  69130. + hfnum_data_t hfnum;
  69131. +
  69132. + hfnum.d32 = FIQ_READ(state->dwc_regs_base + HFNUM);
  69133. + gintsts.d32 = FIQ_READ(state->dwc_regs_base + GINTSTS);
  69134. + gintmsk.d32 = FIQ_READ(state->dwc_regs_base + GINTMSK);
  69135. + gintsts.d32 &= gintmsk.d32;
  69136. + gintsts_handled.d32 = 0;
  69137. +
  69138. + if (gintsts.b.sofintr) {
  69139. + if (!state->kick_np_queues &&
  69140. + dwc_frame_num_gt(state->next_sched_frame, hfnum.b.frnum)) {
  69141. + /* SOF handled, no work to do, just ACK interrupt */
  69142. + gintsts_handled.b.sofintr = 1;
  69143. + } else {
  69144. + /* Kick IRQ */
  69145. + state->gintmsk_saved.b.sofintr = 0;
  69146. + }
  69147. + }
  69148. +
  69149. + /* Reset handled interrupts */
  69150. + if(gintsts_handled.d32) {
  69151. + FIQ_WRITE(state->dwc_regs_base + GINTSTS, gintsts_handled.d32);
  69152. + }
  69153. +
  69154. + /* Clear the bits in the saved register that were not handled but were triggered. */
  69155. + state->gintmsk_saved.d32 &= ~(gintsts.d32 & ~gintsts_handled.d32);
  69156. +
  69157. + /* We got an interrupt, didn't handle it and want to mask it */
  69158. + if (~(state->gintmsk_saved.d32)) {
  69159. + state->mphi_int_count++;
  69160. + gintmsk.d32 &= state->gintmsk_saved.d32;
  69161. + FIQ_WRITE(state->dwc_regs_base + GINTMSK, gintmsk.d32);
  69162. + /* Force a clear before another dummy send */
  69163. + FIQ_WRITE(state->mphi_regs.intstat, (1<<29));
  69164. + FIQ_WRITE(state->mphi_regs.outdda, (int) state->dummy_send);
  69165. + FIQ_WRITE(state->mphi_regs.outddb, (1<<29));
  69166. +
  69167. + }
  69168. + state->fiq_done++;
  69169. + mb();
  69170. +}
  69171. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h
  69172. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 1970-01-01 01:00:00.000000000 +0100
  69173. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_fsm.h 2014-06-11 21:03:43.000000000 +0200
  69174. @@ -0,0 +1,353 @@
  69175. +/*
  69176. + * dwc_otg_fiq_fsm.h - Finite state machine FIQ header definitions
  69177. + *
  69178. + * Copyright (c) 2013 Raspberry Pi Foundation
  69179. + *
  69180. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  69181. + * All rights reserved.
  69182. + *
  69183. + * Redistribution and use in source and binary forms, with or without
  69184. + * modification, are permitted provided that the following conditions are met:
  69185. + * * Redistributions of source code must retain the above copyright
  69186. + * notice, this list of conditions and the following disclaimer.
  69187. + * * Redistributions in binary form must reproduce the above copyright
  69188. + * notice, this list of conditions and the following disclaimer in the
  69189. + * documentation and/or other materials provided with the distribution.
  69190. + * * Neither the name of Raspberry Pi nor the
  69191. + * names of its contributors may be used to endorse or promote products
  69192. + * derived from this software without specific prior written permission.
  69193. + *
  69194. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  69195. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  69196. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  69197. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  69198. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69199. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  69200. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  69201. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69202. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  69203. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69204. + *
  69205. + * This FIQ implements functionality that performs split transactions on
  69206. + * the dwc_otg hardware without any outside intervention. A split transaction
  69207. + * is "queued" by nominating a specific host channel to perform the entirety
  69208. + * of a split transaction. This FIQ will then perform the microframe-precise
  69209. + * scheduling required in each phase of the transaction until completion.
  69210. + *
  69211. + * The FIQ functionality has been surgically implanted into the Synopsys
  69212. + * vendor-provided driver.
  69213. + *
  69214. + */
  69215. +
  69216. +#ifndef DWC_OTG_FIQ_FSM_H_
  69217. +#define DWC_OTG_FIQ_FSM_H_
  69218. +
  69219. +#include "dwc_otg_regs.h"
  69220. +#include "dwc_otg_cil.h"
  69221. +#include "dwc_otg_hcd.h"
  69222. +#include <linux/kernel.h>
  69223. +#include <linux/irqflags.h>
  69224. +#include <linux/string.h>
  69225. +#include <asm/barrier.h>
  69226. +
  69227. +#if 0
  69228. +#define FLAME_ON(x) \
  69229. +do { \
  69230. + int gpioreg; \
  69231. + \
  69232. + gpioreg = readl(__io_address(0x20200000+0x8)); \
  69233. + gpioreg &= ~(7 << (x-20)*3); \
  69234. + gpioreg |= 0x1 << (x-20)*3; \
  69235. + writel(gpioreg, __io_address(0x20200000+0x8)); \
  69236. + \
  69237. + writel(1<<x, __io_address(0x20200000+(0x1C))); \
  69238. +} while (0)
  69239. +
  69240. +#define FLAME_OFF(x) \
  69241. +do { \
  69242. + writel(1<<x, __io_address(0x20200000+(0x28))); \
  69243. +} while (0)
  69244. +#else
  69245. +#define FLAME_ON(x) do { } while (0)
  69246. +#define FLAME_OFF(X) do { } while (0)
  69247. +#endif
  69248. +
  69249. +/* This is a quick-and-dirty arch-specific register read/write. We know that
  69250. + * writes to a peripheral on BCM2835 will always arrive in-order, also that
  69251. + * reads and writes are executed in-order therefore the need for memory barriers
  69252. + * is obviated if we're only talking to USB.
  69253. + */
  69254. +#define FIQ_WRITE(_addr_,_data_) (*(volatile unsigned int *) (_addr_) = (_data_))
  69255. +#define FIQ_READ(_addr_) (*(volatile unsigned int *) (_addr_))
  69256. +
  69257. +/* FIQ-ified register definitions. Offsets are from dwc_regs_base. */
  69258. +#define GINTSTS 0x014
  69259. +#define GINTMSK 0x018
  69260. +/* Debug register. Poll the top of the received packets FIFO. */
  69261. +#define GRXSTSR 0x01C
  69262. +#define HFNUM 0x408
  69263. +#define HAINT 0x414
  69264. +#define HAINTMSK 0x418
  69265. +#define HPRT0 0x440
  69266. +
  69267. +/* HC_regs start from an offset of 0x500 */
  69268. +#define HC_START 0x500
  69269. +#define HC_OFFSET 0x020
  69270. +
  69271. +#define HC_DMA 0x514
  69272. +
  69273. +#define HCCHAR 0x00
  69274. +#define HCSPLT 0x04
  69275. +#define HCINT 0x08
  69276. +#define HCINTMSK 0x0C
  69277. +#define HCTSIZ 0x10
  69278. +
  69279. +#define ISOC_XACTPOS_ALL 0b11
  69280. +#define ISOC_XACTPOS_BEGIN 0b10
  69281. +#define ISOC_XACTPOS_MID 0b00
  69282. +#define ISOC_XACTPOS_END 0b01
  69283. +
  69284. +#define DWC_PID_DATA2 0b01
  69285. +#define DWC_PID_MDATA 0b11
  69286. +#define DWC_PID_DATA1 0b10
  69287. +#define DWC_PID_DATA0 0b00
  69288. +
  69289. +typedef struct {
  69290. + volatile void* base;
  69291. + volatile void* ctrl;
  69292. + volatile void* outdda;
  69293. + volatile void* outddb;
  69294. + volatile void* intstat;
  69295. +} mphi_regs_t;
  69296. +
  69297. +
  69298. +enum fiq_debug_level {
  69299. + FIQDBG_SCHED = (1 << 0),
  69300. + FIQDBG_INT = (1 << 1),
  69301. + FIQDBG_ERR = (1 << 2),
  69302. + FIQDBG_PORTHUB = (1 << 3),
  69303. +};
  69304. +
  69305. +struct fiq_state;
  69306. +
  69307. +extern void _fiq_print (enum fiq_debug_level dbg_lvl, volatile struct fiq_state *state, char *fmt, ...);
  69308. +#if 0
  69309. +#define fiq_print _fiq_print
  69310. +#else
  69311. +#define fiq_print(x, y, ...)
  69312. +#endif
  69313. +
  69314. +extern bool fiq_enable, fiq_fsm_enable;
  69315. +extern ushort nak_holdoff;
  69316. +
  69317. +/**
  69318. + * enum fiq_fsm_state - The FIQ FSM states.
  69319. + *
  69320. + * This is the "core" of the FIQ FSM. Broadly, the FSM states follow the
  69321. + * USB2.0 specification for host responses to various transaction states.
  69322. + * There are modifications to this host state machine because of a variety of
  69323. + * quirks and limitations in the dwc_otg hardware.
  69324. + *
  69325. + * The fsm state is also used to communicate back to the driver on completion of
  69326. + * a split transaction. The end states are used in conjunction with the interrupts
  69327. + * raised by the final transaction.
  69328. + */
  69329. +enum fiq_fsm_state {
  69330. + /* FIQ isn't enabled for this host channel */
  69331. + FIQ_PASSTHROUGH = 0,
  69332. + /* For the first interrupt received for this channel,
  69333. + * the FIQ has to ack any interrupts indicating success. */
  69334. + FIQ_PASSTHROUGH_ERRORSTATE = 31,
  69335. + /* Nonperiodic state groups */
  69336. + FIQ_NP_SSPLIT_STARTED = 1,
  69337. + FIQ_NP_SSPLIT_RETRY = 2,
  69338. + FIQ_NP_OUT_CSPLIT_RETRY = 3,
  69339. + FIQ_NP_IN_CSPLIT_RETRY = 4,
  69340. + FIQ_NP_SPLIT_DONE = 5,
  69341. + FIQ_NP_SPLIT_LS_ABORTED = 6,
  69342. + /* This differentiates a HS transaction error from a LS one
  69343. + * (handling the hub state is different) */
  69344. + FIQ_NP_SPLIT_HS_ABORTED = 7,
  69345. +
  69346. + /* Periodic state groups */
  69347. + /* Periodic transactions are either started directly by the IRQ handler
  69348. + * or deferred if the TT is already in use.
  69349. + */
  69350. + FIQ_PER_SSPLIT_QUEUED = 8,
  69351. + FIQ_PER_SSPLIT_STARTED = 9,
  69352. + FIQ_PER_SSPLIT_LAST = 10,
  69353. +
  69354. +
  69355. + FIQ_PER_ISO_OUT_PENDING = 11,
  69356. + FIQ_PER_ISO_OUT_ACTIVE = 12,
  69357. + FIQ_PER_ISO_OUT_LAST = 13,
  69358. + FIQ_PER_ISO_OUT_DONE = 27,
  69359. +
  69360. + FIQ_PER_CSPLIT_WAIT = 14,
  69361. + FIQ_PER_CSPLIT_NYET1 = 15,
  69362. + FIQ_PER_CSPLIT_BROKEN_NYET1 = 28,
  69363. + FIQ_PER_CSPLIT_NYET_FAFF = 29,
  69364. + /* For multiple CSPLITs (large isoc IN, or delayed interrupt) */
  69365. + FIQ_PER_CSPLIT_POLL = 16,
  69366. + /* The last CSPLIT for a transaction has been issued, differentiates
  69367. + * for the state machine to queue the next packet.
  69368. + */
  69369. + FIQ_PER_CSPLIT_LAST = 17,
  69370. +
  69371. + FIQ_PER_SPLIT_DONE = 18,
  69372. + FIQ_PER_SPLIT_LS_ABORTED = 19,
  69373. + FIQ_PER_SPLIT_HS_ABORTED = 20,
  69374. + FIQ_PER_SPLIT_NYET_ABORTED = 21,
  69375. + /* Frame rollover has occurred without the transaction finishing. */
  69376. + FIQ_PER_SPLIT_TIMEOUT = 22,
  69377. +
  69378. + /* FIQ-accelerated HS Isochronous state groups */
  69379. + FIQ_HS_ISOC_TURBO = 23,
  69380. + /* For interval > 1, SOF wakes up the isochronous FSM */
  69381. + FIQ_HS_ISOC_SLEEPING = 24,
  69382. + FIQ_HS_ISOC_DONE = 25,
  69383. + FIQ_HS_ISOC_ABORTED = 26,
  69384. + FIQ_DEQUEUE_ISSUED = 30,
  69385. + FIQ_TEST = 32,
  69386. +};
  69387. +
  69388. +struct fiq_stack {
  69389. + int magic1;
  69390. + uint8_t stack[2048];
  69391. + int magic2;
  69392. +};
  69393. +
  69394. +
  69395. +/**
  69396. + * struct fiq_dma_info - DMA bounce buffer utilisation information (per-channel)
  69397. + * @index: Number of slots reported used for IN transactions / number of slots
  69398. + * transmitted for an OUT transaction
  69399. + * @slot_len[6]: Number of actual transfer bytes in each slot (255 if unused)
  69400. + *
  69401. + * Split transaction transfers can have variable length depending on other bus
  69402. + * traffic. The OTG core DMA engine requires 4-byte aligned addresses therefore
  69403. + * each transaction needs a guaranteed aligned address. A maximum of 6 split transfers
  69404. + * can happen per-frame.
  69405. + */
  69406. +struct fiq_dma_info {
  69407. + u8 index;
  69408. + u8 slot_len[6];
  69409. +};
  69410. +
  69411. +struct __attribute__((packed)) fiq_split_dma_slot {
  69412. + u8 buf[188];
  69413. +};
  69414. +
  69415. +struct fiq_dma_channel {
  69416. + struct __attribute__((packed)) fiq_split_dma_slot index[6];
  69417. +};
  69418. +
  69419. +struct fiq_dma_blob {
  69420. + struct __attribute__((packed)) fiq_dma_channel channel[0];
  69421. +};
  69422. +
  69423. +/**
  69424. + * struct fiq_hs_isoc_info - USB2.0 isochronous data
  69425. + * @iso_frame: Pointer to the array of OTG URB iso_frame_descs.
  69426. + * @nrframes: Total length of iso_frame_desc array
  69427. + * @index: Current index (FIQ-maintained)
  69428. + *
  69429. + */
  69430. +struct fiq_hs_isoc_info {
  69431. + struct dwc_otg_hcd_iso_packet_desc *iso_desc;
  69432. + unsigned int nrframes;
  69433. + unsigned int index;
  69434. +};
  69435. +
  69436. +/**
  69437. + * struct fiq_channel_state - FIQ state machine storage
  69438. + * @fsm: Current state of the channel as understood by the FIQ
  69439. + * @nr_errors: Number of transaction errors on this split-transaction
  69440. + * @hub_addr: SSPLIT/CSPLIT destination hub
  69441. + * @port_addr: SSPLIT/CSPLIT destination port - always 1 if single TT hub
  69442. + * @nrpackets: For isoc OUT, the number of split-OUT packets to transmit. For
  69443. + * split-IN, number of CSPLIT data packets that were received.
  69444. + * @hcchar_copy:
  69445. + * @hcsplt_copy:
  69446. + * @hcintmsk_copy:
  69447. + * @hctsiz_copy: Copies of the host channel registers.
  69448. + * For use as scratch, or for returning state.
  69449. + *
  69450. + * The fiq_channel_state is state storage between interrupts for a host channel. The
  69451. + * FSM state is stored here. Members of this structure must only be set up by the
  69452. + * driver prior to enabling the FIQ for this host channel, and not touched until the FIQ
  69453. + * has updated the state to either a COMPLETE state group or ABORT state group.
  69454. + */
  69455. +
  69456. +struct fiq_channel_state {
  69457. + enum fiq_fsm_state fsm;
  69458. + unsigned int nr_errors;
  69459. + unsigned int hub_addr;
  69460. + unsigned int port_addr;
  69461. + /* Hardware bug workaround: sometimes channel halt interrupts are
  69462. + * delayed until the next SOF. Keep track of when we expected to get interrupted. */
  69463. + unsigned int expected_uframe;
  69464. + /* in/out for communicating number of dma buffers used, or number of ISOC to do */
  69465. + unsigned int nrpackets;
  69466. + struct fiq_dma_info dma_info;
  69467. + struct fiq_hs_isoc_info hs_isoc_info;
  69468. + /* Copies of HC registers - in/out communication from/to IRQ handler
  69469. + * and for ease of channel setup. A bit of mungeing is performed - for
  69470. + * example the hctsiz.b.maxp is _always_ the max packet size of the endpoint.
  69471. + */
  69472. + hcchar_data_t hcchar_copy;
  69473. + hcsplt_data_t hcsplt_copy;
  69474. + hcint_data_t hcint_copy;
  69475. + hcintmsk_data_t hcintmsk_copy;
  69476. + hctsiz_data_t hctsiz_copy;
  69477. + hcdma_data_t hcdma_copy;
  69478. +};
  69479. +
  69480. +/**
  69481. + * struct fiq_state - top-level FIQ state machine storage
  69482. + * @mphi_regs: virtual address of the MPHI peripheral register file
  69483. + * @dwc_regs_base: virtual address of the base of the DWC core register file
  69484. + * @dma_base: physical address for the base of the DMA bounce buffers
  69485. + * @dummy_send: Scratch area for sending a fake message to the MPHI peripheral
  69486. + * @gintmsk_saved: Top-level mask of interrupts that the FIQ has not handled.
  69487. + * Used for determining which interrupts fired to set off the IRQ handler.
  69488. + * @haintmsk_saved: Mask of interrupts from host channels that the FIQ did not handle internally.
  69489. + * @np_count: Non-periodic transactions in the active queue
  69490. + * @np_sent: Count of non-periodic transactions that have completed
  69491. + * @next_sched_frame: For periodic transactions handled by the driver's SOF-driven queuing mechanism,
  69492. + * this is the next frame on which a SOF interrupt is required. Used to hold off
  69493. + * passing SOF through to the driver until necessary.
  69494. + * @channel[n]: Per-channel FIQ state. Allocated during init depending on the number of host
  69495. + * channels configured into the core logic.
  69496. + *
  69497. + * This is passed as the first argument to the dwc_otg_fiq_fsm top-level FIQ handler from the asm stub.
  69498. + * It contains top-level state information.
  69499. + */
  69500. +struct fiq_state {
  69501. + mphi_regs_t mphi_regs;
  69502. + void *dwc_regs_base;
  69503. + dma_addr_t dma_base;
  69504. + struct fiq_dma_blob *fiq_dmab;
  69505. + void *dummy_send;
  69506. + gintmsk_data_t gintmsk_saved;
  69507. + haintmsk_data_t haintmsk_saved;
  69508. + int mphi_int_count;
  69509. + unsigned int fiq_done;
  69510. + unsigned int kick_np_queues;
  69511. + unsigned int next_sched_frame;
  69512. +#ifdef FIQ_DEBUG
  69513. + char * buffer;
  69514. + unsigned int bufsiz;
  69515. +#endif
  69516. + struct fiq_channel_state channel[0];
  69517. +};
  69518. +
  69519. +extern int fiq_fsm_too_late(struct fiq_state *st, int n);
  69520. +
  69521. +extern int fiq_fsm_tt_in_use(struct fiq_state *st, int num_channels, int n);
  69522. +
  69523. +extern void dwc_otg_fiq_fsm(struct fiq_state *state, int num_channels);
  69524. +
  69525. +extern void dwc_otg_fiq_nop(struct fiq_state *state);
  69526. +
  69527. +#endif /* DWC_OTG_FIQ_FSM_H_ */
  69528. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S
  69529. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 1970-01-01 01:00:00.000000000 +0100
  69530. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_fiq_stub.S 2014-06-11 21:03:43.000000000 +0200
  69531. @@ -0,0 +1,81 @@
  69532. +/*
  69533. + * dwc_otg_fiq_fsm.S - assembly stub for the FSM FIQ
  69534. + *
  69535. + * Copyright (c) 2013 Raspberry Pi Foundation
  69536. + *
  69537. + * Author: Jonathan Bell <jonathan@raspberrypi.org>
  69538. + * All rights reserved.
  69539. + *
  69540. + * Redistribution and use in source and binary forms, with or without
  69541. + * modification, are permitted provided that the following conditions are met:
  69542. + * * Redistributions of source code must retain the above copyright
  69543. + * notice, this list of conditions and the following disclaimer.
  69544. + * * Redistributions in binary form must reproduce the above copyright
  69545. + * notice, this list of conditions and the following disclaimer in the
  69546. + * documentation and/or other materials provided with the distribution.
  69547. + * * Neither the name of Raspberry Pi nor the
  69548. + * names of its contributors may be used to endorse or promote products
  69549. + * derived from this software without specific prior written permission.
  69550. + *
  69551. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  69552. + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  69553. + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  69554. + * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  69555. + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69556. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  69557. + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  69558. + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  69559. + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  69560. + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  69561. + */
  69562. +
  69563. +
  69564. +#include <asm/assembler.h>
  69565. +#include <linux/linkage.h>
  69566. +
  69567. +
  69568. +.text
  69569. +
  69570. +.global _dwc_otg_fiq_stub_end;
  69571. +
  69572. +/**
  69573. + * _dwc_otg_fiq_stub() - entry copied to the FIQ vector page to allow
  69574. + * a C-style function call with arguments from the FIQ banked registers.
  69575. + * r0 = &hcd->fiq_state
  69576. + * r1 = &hcd->num_channels
  69577. + * r2 = &hcd->dma_buffers
  69578. + * Tramples: r0, r1, r2, r4, fp, ip
  69579. + */
  69580. +
  69581. +ENTRY(_dwc_otg_fiq_stub)
  69582. + /* Stash unbanked regs - SP will have been set up for us */
  69583. + mov ip, sp;
  69584. + stmdb sp!, {r0-r12, lr};
  69585. +#ifdef FIQ_DEBUG
  69586. + // Cycle profiling - read cycle counter at start
  69587. + mrc p15, 0, r5, c15, c12, 1;
  69588. +#endif
  69589. + /* r11 = fp, don't trample it */
  69590. + mov r4, fp;
  69591. + /* set EABI frame size */
  69592. + sub fp, ip, #512;
  69593. +
  69594. + /* for fiq NOP mode - just need state */
  69595. + mov r0, r8;
  69596. + /* r9 = num_channels */
  69597. + mov r1, r9;
  69598. + /* r10 = struct *dma_bufs */
  69599. +// mov r2, r10;
  69600. +
  69601. + /* r4 = &fiq_c_function */
  69602. + blx r4;
  69603. +#ifdef FIQ_DEBUG
  69604. + mrc p15, 0, r4, c15, c12, 1;
  69605. + subs r5, r5, r4;
  69606. + // r5 is now the cycle count time for executing the FIQ. Store it somewhere?
  69607. +#endif
  69608. + ldmia sp!, {r0-r12, lr};
  69609. + subs pc, lr, #4;
  69610. +_dwc_otg_fiq_stub_end:
  69611. +END(_dwc_otg_fiq_stub)
  69612. +
  69613. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c
  69614. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 1970-01-01 01:00:00.000000000 +0100
  69615. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.c 2014-06-11 21:03:43.000000000 +0200
  69616. @@ -0,0 +1,4192 @@
  69617. +
  69618. +/* ==========================================================================
  69619. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.c $
  69620. + * $Revision: #104 $
  69621. + * $Date: 2011/10/24 $
  69622. + * $Change: 1871159 $
  69623. + *
  69624. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  69625. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  69626. + * otherwise expressly agreed to in writing between Synopsys and you.
  69627. + *
  69628. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  69629. + * any End User Software License Agreement or Agreement for Licensed Product
  69630. + * with Synopsys or any supplement thereto. You are permitted to use and
  69631. + * redistribute this Software in source and binary forms, with or without
  69632. + * modification, provided that redistributions of source code must retain this
  69633. + * notice. You may not view, use, disclose, copy or distribute this file or
  69634. + * any information contained herein except pursuant to this license grant from
  69635. + * Synopsys. If you do not agree with this notice, including the disclaimer
  69636. + * below, then you are not authorized to use the Software.
  69637. + *
  69638. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  69639. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  69640. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  69641. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  69642. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  69643. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  69644. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  69645. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  69646. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  69647. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  69648. + * DAMAGE.
  69649. + * ========================================================================== */
  69650. +#ifndef DWC_DEVICE_ONLY
  69651. +
  69652. +/** @file
  69653. + * This file implements HCD Core. All code in this file is portable and doesn't
  69654. + * use any OS specific functions.
  69655. + * Interface provided by HCD Core is defined in <code><hcd_if.h></code>
  69656. + * header file.
  69657. + */
  69658. +
  69659. +#include <linux/usb.h>
  69660. +#include <linux/usb/hcd.h>
  69661. +
  69662. +#include "dwc_otg_hcd.h"
  69663. +#include "dwc_otg_regs.h"
  69664. +#include "dwc_otg_fiq_fsm.h"
  69665. +
  69666. +extern bool microframe_schedule;
  69667. +extern uint16_t fiq_fsm_mask, nak_holdoff;
  69668. +
  69669. +//#define DEBUG_HOST_CHANNELS
  69670. +#ifdef DEBUG_HOST_CHANNELS
  69671. +static int last_sel_trans_num_per_scheduled = 0;
  69672. +static int last_sel_trans_num_nonper_scheduled = 0;
  69673. +static int last_sel_trans_num_avail_hc_at_start = 0;
  69674. +static int last_sel_trans_num_avail_hc_at_end = 0;
  69675. +#endif /* DEBUG_HOST_CHANNELS */
  69676. +
  69677. +
  69678. +dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void)
  69679. +{
  69680. + return DWC_ALLOC(sizeof(dwc_otg_hcd_t));
  69681. +}
  69682. +
  69683. +/**
  69684. + * Connection timeout function. An OTG host is required to display a
  69685. + * message if the device does not connect within 10 seconds.
  69686. + */
  69687. +void dwc_otg_hcd_connect_timeout(void *ptr)
  69688. +{
  69689. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, ptr);
  69690. + DWC_PRINTF("Connect Timeout\n");
  69691. + __DWC_ERROR("Device Not Connected/Responding\n");
  69692. +}
  69693. +
  69694. +#if defined(DEBUG)
  69695. +static void dump_channel_info(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  69696. +{
  69697. + if (qh->channel != NULL) {
  69698. + dwc_hc_t *hc = qh->channel;
  69699. + dwc_list_link_t *item;
  69700. + dwc_otg_qh_t *qh_item;
  69701. + int num_channels = hcd->core_if->core_params->host_channels;
  69702. + int i;
  69703. +
  69704. + dwc_otg_hc_regs_t *hc_regs;
  69705. + hcchar_data_t hcchar;
  69706. + hcsplt_data_t hcsplt;
  69707. + hctsiz_data_t hctsiz;
  69708. + uint32_t hcdma;
  69709. +
  69710. + hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  69711. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69712. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  69713. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  69714. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  69715. +
  69716. + DWC_PRINTF(" Assigned to channel %p:\n", hc);
  69717. + DWC_PRINTF(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32,
  69718. + hcsplt.d32);
  69719. + DWC_PRINTF(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32,
  69720. + hcdma);
  69721. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  69722. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  69723. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  69724. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  69725. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  69726. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  69727. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  69728. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  69729. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  69730. + DWC_PRINTF(" qh: %p\n", hc->qh);
  69731. + DWC_PRINTF(" NP inactive sched:\n");
  69732. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_inactive) {
  69733. + qh_item =
  69734. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69735. + DWC_PRINTF(" %p\n", qh_item);
  69736. + }
  69737. + DWC_PRINTF(" NP active sched:\n");
  69738. + DWC_LIST_FOREACH(item, &hcd->non_periodic_sched_active) {
  69739. + qh_item =
  69740. + DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  69741. + DWC_PRINTF(" %p\n", qh_item);
  69742. + }
  69743. + DWC_PRINTF(" Channels: \n");
  69744. + for (i = 0; i < num_channels; i++) {
  69745. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  69746. + DWC_PRINTF(" %2d: %p\n", i, hc);
  69747. + }
  69748. + }
  69749. +}
  69750. +#else
  69751. +#define dump_channel_info(hcd, qh)
  69752. +#endif /* DEBUG */
  69753. +
  69754. +/**
  69755. + * Work queue function for starting the HCD when A-Cable is connected.
  69756. + * The hcd_start() must be called in a process context.
  69757. + */
  69758. +static void hcd_start_func(void *_vp)
  69759. +{
  69760. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) _vp;
  69761. +
  69762. + DWC_DEBUGPL(DBG_HCDV, "%s() %p\n", __func__, hcd);
  69763. + if (hcd) {
  69764. + hcd->fops->start(hcd);
  69765. + }
  69766. +}
  69767. +
  69768. +static void del_xfer_timers(dwc_otg_hcd_t * hcd)
  69769. +{
  69770. +#ifdef DEBUG
  69771. + int i;
  69772. + int num_channels = hcd->core_if->core_params->host_channels;
  69773. + for (i = 0; i < num_channels; i++) {
  69774. + DWC_TIMER_CANCEL(hcd->core_if->hc_xfer_timer[i]);
  69775. + }
  69776. +#endif
  69777. +}
  69778. +
  69779. +static void del_timers(dwc_otg_hcd_t * hcd)
  69780. +{
  69781. + del_xfer_timers(hcd);
  69782. + DWC_TIMER_CANCEL(hcd->conn_timer);
  69783. +}
  69784. +
  69785. +/**
  69786. + * Processes all the URBs in a single list of QHs. Completes them with
  69787. + * -ESHUTDOWN and frees the QTD.
  69788. + */
  69789. +static void kill_urbs_in_qh_list(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  69790. +{
  69791. + dwc_list_link_t *qh_item, *qh_tmp;
  69792. + dwc_otg_qh_t *qh;
  69793. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  69794. +
  69795. + DWC_LIST_FOREACH_SAFE(qh_item, qh_tmp, qh_list) {
  69796. + qh = DWC_LIST_ENTRY(qh_item, dwc_otg_qh_t, qh_list_entry);
  69797. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp,
  69798. + &qh->qtd_list, qtd_list_entry) {
  69799. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  69800. + if (qtd->urb != NULL) {
  69801. + hcd->fops->complete(hcd, qtd->urb->priv,
  69802. + qtd->urb, -DWC_E_SHUTDOWN);
  69803. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  69804. + }
  69805. +
  69806. + }
  69807. + if(qh->channel) {
  69808. + /* Using hcchar.chen == 1 is not a reliable test.
  69809. + * It is possible that the channel has already halted
  69810. + * but not yet been through the IRQ handler.
  69811. + */
  69812. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  69813. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  69814. + if(microframe_schedule)
  69815. + hcd->available_host_channels++;
  69816. + qh->channel = NULL;
  69817. + }
  69818. + dwc_otg_hcd_qh_remove(hcd, qh);
  69819. + }
  69820. +}
  69821. +
  69822. +/**
  69823. + * Responds with an error status of ESHUTDOWN to all URBs in the non-periodic
  69824. + * and periodic schedules. The QTD associated with each URB is removed from
  69825. + * the schedule and freed. This function may be called when a disconnect is
  69826. + * detected or when the HCD is being stopped.
  69827. + */
  69828. +static void kill_all_urbs(dwc_otg_hcd_t * hcd)
  69829. +{
  69830. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_inactive);
  69831. + kill_urbs_in_qh_list(hcd, &hcd->non_periodic_sched_active);
  69832. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_inactive);
  69833. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_ready);
  69834. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_assigned);
  69835. + kill_urbs_in_qh_list(hcd, &hcd->periodic_sched_queued);
  69836. +}
  69837. +
  69838. +/**
  69839. + * Start the connection timer. An OTG host is required to display a
  69840. + * message if the device does not connect within 10 seconds. The
  69841. + * timer is deleted if a port connect interrupt occurs before the
  69842. + * timer expires.
  69843. + */
  69844. +static void dwc_otg_hcd_start_connect_timer(dwc_otg_hcd_t * hcd)
  69845. +{
  69846. + DWC_TIMER_SCHEDULE(hcd->conn_timer, 10000 /* 10 secs */ );
  69847. +}
  69848. +
  69849. +/**
  69850. + * HCD Callback function for disconnect of the HCD.
  69851. + *
  69852. + * @param p void pointer to the <code>struct usb_hcd</code>
  69853. + */
  69854. +static int32_t dwc_otg_hcd_session_start_cb(void *p)
  69855. +{
  69856. + dwc_otg_hcd_t *dwc_otg_hcd;
  69857. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  69858. + dwc_otg_hcd = p;
  69859. + dwc_otg_hcd_start_connect_timer(dwc_otg_hcd);
  69860. + return 1;
  69861. +}
  69862. +
  69863. +/**
  69864. + * HCD Callback function for starting the HCD when A-Cable is
  69865. + * connected.
  69866. + *
  69867. + * @param p void pointer to the <code>struct usb_hcd</code>
  69868. + */
  69869. +static int32_t dwc_otg_hcd_start_cb(void *p)
  69870. +{
  69871. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69872. + dwc_otg_core_if_t *core_if;
  69873. + hprt0_data_t hprt0;
  69874. +
  69875. + core_if = dwc_otg_hcd->core_if;
  69876. +
  69877. + if (core_if->op_state == B_HOST) {
  69878. + /*
  69879. + * Reset the port. During a HNP mode switch the reset
  69880. + * needs to occur within 1ms and have a duration of at
  69881. + * least 50ms.
  69882. + */
  69883. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  69884. + hprt0.b.prtrst = 1;
  69885. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  69886. + }
  69887. + DWC_WORKQ_SCHEDULE_DELAYED(core_if->wq_otg,
  69888. + hcd_start_func, dwc_otg_hcd, 50,
  69889. + "start hcd");
  69890. +
  69891. + return 1;
  69892. +}
  69893. +
  69894. +/**
  69895. + * HCD Callback function for disconnect of the HCD.
  69896. + *
  69897. + * @param p void pointer to the <code>struct usb_hcd</code>
  69898. + */
  69899. +static int32_t dwc_otg_hcd_disconnect_cb(void *p)
  69900. +{
  69901. + gintsts_data_t intr;
  69902. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  69903. +
  69904. + /*
  69905. + * Set status flags for the hub driver.
  69906. + */
  69907. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  69908. + dwc_otg_hcd->flags.b.port_connect_status = 0;
  69909. + if(fiq_enable)
  69910. + local_fiq_disable();
  69911. + /*
  69912. + * Shutdown any transfers in process by clearing the Tx FIFO Empty
  69913. + * interrupt mask and status bits and disabling subsequent host
  69914. + * channel interrupts.
  69915. + */
  69916. + intr.d32 = 0;
  69917. + intr.b.nptxfempty = 1;
  69918. + intr.b.ptxfempty = 1;
  69919. + intr.b.hcintr = 1;
  69920. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintmsk,
  69921. + intr.d32, 0);
  69922. + DWC_MODIFY_REG32(&dwc_otg_hcd->core_if->core_global_regs->gintsts,
  69923. + intr.d32, 0);
  69924. +
  69925. + del_timers(dwc_otg_hcd);
  69926. +
  69927. + /*
  69928. + * Turn off the vbus power only if the core has transitioned to device
  69929. + * mode. If still in host mode, need to keep power on to detect a
  69930. + * reconnection.
  69931. + */
  69932. + if (dwc_otg_is_device_mode(dwc_otg_hcd->core_if)) {
  69933. + if (dwc_otg_hcd->core_if->op_state != A_SUSPEND) {
  69934. + hprt0_data_t hprt0 = {.d32 = 0 };
  69935. + DWC_PRINTF("Disconnect: PortPower off\n");
  69936. + hprt0.b.prtpwr = 0;
  69937. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0,
  69938. + hprt0.d32);
  69939. + }
  69940. +
  69941. + dwc_otg_disable_host_interrupts(dwc_otg_hcd->core_if);
  69942. + }
  69943. +
  69944. + /* Respond with an error status to all URBs in the schedule. */
  69945. + kill_all_urbs(dwc_otg_hcd);
  69946. +
  69947. + if (dwc_otg_is_host_mode(dwc_otg_hcd->core_if)) {
  69948. + /* Clean up any host channels that were in use. */
  69949. + int num_channels;
  69950. + int i;
  69951. + dwc_hc_t *channel;
  69952. + dwc_otg_hc_regs_t *hc_regs;
  69953. + hcchar_data_t hcchar;
  69954. +
  69955. + num_channels = dwc_otg_hcd->core_if->core_params->host_channels;
  69956. +
  69957. + if (!dwc_otg_hcd->core_if->dma_enable) {
  69958. + /* Flush out any channel requests in slave mode. */
  69959. + for (i = 0; i < num_channels; i++) {
  69960. + channel = dwc_otg_hcd->hc_ptr_array[i];
  69961. + if (DWC_CIRCLEQ_EMPTY_ENTRY
  69962. + (channel, hc_list_entry)) {
  69963. + hc_regs =
  69964. + dwc_otg_hcd->core_if->
  69965. + host_if->hc_regs[i];
  69966. + hcchar.d32 =
  69967. + DWC_READ_REG32(&hc_regs->hcchar);
  69968. + if (hcchar.b.chen) {
  69969. + hcchar.b.chen = 0;
  69970. + hcchar.b.chdis = 1;
  69971. + hcchar.b.epdir = 0;
  69972. + DWC_WRITE_REG32
  69973. + (&hc_regs->hcchar,
  69974. + hcchar.d32);
  69975. + }
  69976. + }
  69977. + }
  69978. + }
  69979. +
  69980. + for (i = 0; i < num_channels; i++) {
  69981. + channel = dwc_otg_hcd->hc_ptr_array[i];
  69982. + if (DWC_CIRCLEQ_EMPTY_ENTRY(channel, hc_list_entry)) {
  69983. + hc_regs =
  69984. + dwc_otg_hcd->core_if->host_if->hc_regs[i];
  69985. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  69986. + if (hcchar.b.chen) {
  69987. + /* Halt the channel. */
  69988. + hcchar.b.chdis = 1;
  69989. + DWC_WRITE_REG32(&hc_regs->hcchar,
  69990. + hcchar.d32);
  69991. + }
  69992. +
  69993. + dwc_otg_hc_cleanup(dwc_otg_hcd->core_if,
  69994. + channel);
  69995. + DWC_CIRCLEQ_INSERT_TAIL
  69996. + (&dwc_otg_hcd->free_hc_list, channel,
  69997. + hc_list_entry);
  69998. + /*
  69999. + * Added for Descriptor DMA to prevent channel double cleanup
  70000. + * in release_channel_ddma(). Which called from ep_disable
  70001. + * when device disconnect.
  70002. + */
  70003. + channel->qh = NULL;
  70004. + }
  70005. + }
  70006. + if(fiq_fsm_enable) {
  70007. + for(i=0; i < 128; i++) {
  70008. + dwc_otg_hcd->hub_port[i] = 0;
  70009. + }
  70010. + }
  70011. +
  70012. + }
  70013. +
  70014. + if(fiq_enable)
  70015. + local_fiq_enable();
  70016. +
  70017. + if (dwc_otg_hcd->fops->disconnect) {
  70018. + dwc_otg_hcd->fops->disconnect(dwc_otg_hcd);
  70019. + }
  70020. +
  70021. + return 1;
  70022. +}
  70023. +
  70024. +/**
  70025. + * HCD Callback function for stopping the HCD.
  70026. + *
  70027. + * @param p void pointer to the <code>struct usb_hcd</code>
  70028. + */
  70029. +static int32_t dwc_otg_hcd_stop_cb(void *p)
  70030. +{
  70031. + dwc_otg_hcd_t *dwc_otg_hcd = p;
  70032. +
  70033. + DWC_DEBUGPL(DBG_HCDV, "%s(%p)\n", __func__, p);
  70034. + dwc_otg_hcd_stop(dwc_otg_hcd);
  70035. + return 1;
  70036. +}
  70037. +
  70038. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70039. +/**
  70040. + * HCD Callback function for sleep of HCD.
  70041. + *
  70042. + * @param p void pointer to the <code>struct usb_hcd</code>
  70043. + */
  70044. +static int dwc_otg_hcd_sleep_cb(void *p)
  70045. +{
  70046. + dwc_otg_hcd_t *hcd = p;
  70047. +
  70048. + dwc_otg_hcd_free_hc_from_lpm(hcd);
  70049. +
  70050. + return 0;
  70051. +}
  70052. +#endif
  70053. +
  70054. +
  70055. +/**
  70056. + * HCD Callback function for Remote Wakeup.
  70057. + *
  70058. + * @param p void pointer to the <code>struct usb_hcd</code>
  70059. + */
  70060. +static int dwc_otg_hcd_rem_wakeup_cb(void *p)
  70061. +{
  70062. + dwc_otg_hcd_t *hcd = p;
  70063. +
  70064. + if (hcd->core_if->lx_state == DWC_OTG_L2) {
  70065. + hcd->flags.b.port_suspend_change = 1;
  70066. + }
  70067. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70068. + else {
  70069. + hcd->flags.b.port_l1_change = 1;
  70070. + }
  70071. +#endif
  70072. + return 0;
  70073. +}
  70074. +
  70075. +/**
  70076. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  70077. + * stopped.
  70078. + */
  70079. +void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd)
  70080. +{
  70081. + hprt0_data_t hprt0 = {.d32 = 0 };
  70082. +
  70083. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD STOP\n");
  70084. +
  70085. + /*
  70086. + * The root hub should be disconnected before this function is called.
  70087. + * The disconnect will clear the QTD lists (via ..._hcd_urb_dequeue)
  70088. + * and the QH lists (via ..._hcd_endpoint_disable).
  70089. + */
  70090. +
  70091. + /* Turn off all host-specific interrupts. */
  70092. + dwc_otg_disable_host_interrupts(hcd->core_if);
  70093. +
  70094. + /* Turn off the vbus power */
  70095. + DWC_PRINTF("PortPower off\n");
  70096. + hprt0.b.prtpwr = 0;
  70097. + DWC_WRITE_REG32(hcd->core_if->host_if->hprt0, hprt0.d32);
  70098. + dwc_mdelay(1);
  70099. +}
  70100. +
  70101. +int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * hcd,
  70102. + dwc_otg_hcd_urb_t * dwc_otg_urb, void **ep_handle,
  70103. + int atomic_alloc)
  70104. +{
  70105. + int retval = 0;
  70106. + uint8_t needs_scheduling = 0;
  70107. + dwc_otg_transaction_type_e tr_type;
  70108. + dwc_otg_qtd_t *qtd;
  70109. + gintmsk_data_t intr_mask = {.d32 = 0 };
  70110. + hprt0_data_t hprt0 = { .d32 = 0 };
  70111. +
  70112. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70113. + if (NULL == hcd->core_if) {
  70114. + DWC_ERROR("**** DWC OTG HCD URB Enqueue - HCD has NULL core_if\n");
  70115. + /* No longer connected. */
  70116. + return -DWC_E_INVALID;
  70117. + }
  70118. +#endif
  70119. + if (!hcd->flags.b.port_connect_status) {
  70120. + /* No longer connected. */
  70121. + DWC_ERROR("Not connected\n");
  70122. + return -DWC_E_NO_DEVICE;
  70123. + }
  70124. +
  70125. + /* Some core configurations cannot support LS traffic on a FS root port */
  70126. + if ((hcd->fops->speed(hcd, dwc_otg_urb->priv) == USB_SPEED_LOW) &&
  70127. + (hcd->core_if->hwcfg2.b.fs_phy_type == 1) &&
  70128. + (hcd->core_if->hwcfg2.b.hs_phy_type == 1)) {
  70129. + hprt0.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  70130. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_FULL_SPEED) {
  70131. + return -DWC_E_NO_DEVICE;
  70132. + }
  70133. + }
  70134. +
  70135. + qtd = dwc_otg_hcd_qtd_create(dwc_otg_urb, atomic_alloc);
  70136. + if (qtd == NULL) {
  70137. + DWC_ERROR("DWC OTG HCD URB Enqueue failed creating QTD\n");
  70138. + return -DWC_E_NO_MEMORY;
  70139. + }
  70140. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70141. + if (qtd->urb == NULL) {
  70142. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD with no URBs\n");
  70143. + return -DWC_E_NO_MEMORY;
  70144. + }
  70145. + if (qtd->urb->priv == NULL) {
  70146. + DWC_ERROR("**** DWC OTG HCD URB Enqueue created QTD URB with no URB handle\n");
  70147. + return -DWC_E_NO_MEMORY;
  70148. + }
  70149. +#endif
  70150. + intr_mask.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->gintmsk);
  70151. + if(!intr_mask.b.sofintr || fiq_enable) needs_scheduling = 1;
  70152. + if((((dwc_otg_qh_t *)ep_handle)->ep_type == UE_BULK) && !(qtd->urb->flags & URB_GIVEBACK_ASAP))
  70153. + /* Do not schedule SG transactions until qtd has URB_GIVEBACK_ASAP set */
  70154. + needs_scheduling = 0;
  70155. +
  70156. + retval = dwc_otg_hcd_qtd_add(qtd, hcd, (dwc_otg_qh_t **) ep_handle, atomic_alloc);
  70157. + // creates a new queue in ep_handle if it doesn't exist already
  70158. + if (retval < 0) {
  70159. + DWC_ERROR("DWC OTG HCD URB Enqueue failed adding QTD. "
  70160. + "Error status %d\n", retval);
  70161. + dwc_otg_hcd_qtd_free(qtd);
  70162. + return retval;
  70163. + }
  70164. +
  70165. + if(needs_scheduling) {
  70166. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  70167. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  70168. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  70169. + }
  70170. + }
  70171. + return retval;
  70172. +}
  70173. +
  70174. +int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * hcd,
  70175. + dwc_otg_hcd_urb_t * dwc_otg_urb)
  70176. +{
  70177. + dwc_otg_qh_t *qh;
  70178. + dwc_otg_qtd_t *urb_qtd;
  70179. + BUG_ON(!hcd);
  70180. + BUG_ON(!dwc_otg_urb);
  70181. +
  70182. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70183. +
  70184. + if (hcd == NULL) {
  70185. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL HCD\n");
  70186. + return -DWC_E_INVALID;
  70187. + }
  70188. + if (dwc_otg_urb == NULL) {
  70189. + DWC_ERROR("**** DWC OTG HCD URB Dequeue has NULL URB\n");
  70190. + return -DWC_E_INVALID;
  70191. + }
  70192. + if (dwc_otg_urb->qtd == NULL) {
  70193. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with NULL QTD\n");
  70194. + return -DWC_E_INVALID;
  70195. + }
  70196. + urb_qtd = dwc_otg_urb->qtd;
  70197. + BUG_ON(!urb_qtd);
  70198. + if (urb_qtd->qh == NULL) {
  70199. + DWC_ERROR("**** DWC OTG HCD URB Dequeue with QTD with NULL Q handler\n");
  70200. + return -DWC_E_INVALID;
  70201. + }
  70202. +#else
  70203. + urb_qtd = dwc_otg_urb->qtd;
  70204. + BUG_ON(!urb_qtd);
  70205. +#endif
  70206. + qh = urb_qtd->qh;
  70207. + BUG_ON(!qh);
  70208. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  70209. + if (urb_qtd->in_process) {
  70210. + dump_channel_info(hcd, qh);
  70211. + }
  70212. + }
  70213. +#ifdef DEBUG /* integrity checks (Broadcom) */
  70214. + if (hcd->core_if == NULL) {
  70215. + DWC_ERROR("**** DWC OTG HCD URB Dequeue HCD has NULL core_if\n");
  70216. + return -DWC_E_INVALID;
  70217. + }
  70218. +#endif
  70219. + if (urb_qtd->in_process && qh->channel) {
  70220. + /* The QTD is in process (it has been assigned to a channel). */
  70221. + if (hcd->flags.b.port_connect_status) {
  70222. + int n = qh->channel->hc_num;
  70223. + /*
  70224. + * If still connected (i.e. in host mode), halt the
  70225. + * channel so it can be used for other transfers. If
  70226. + * no longer connected, the host registers can't be
  70227. + * written to halt the channel since the core is in
  70228. + * device mode.
  70229. + */
  70230. + /* In FIQ FSM mode, we need to shut down carefully.
  70231. + * The FIQ may attempt to restart a disabled channel */
  70232. + if (fiq_fsm_enable && (hcd->fiq_state->channel[n].fsm != FIQ_PASSTHROUGH)) {
  70233. + qh->channel->halt_status = DWC_OTG_HC_XFER_URB_DEQUEUE;
  70234. + qh->channel->halt_pending = 1;
  70235. + hcd->fiq_state->channel[n].fsm = FIQ_DEQUEUE_ISSUED;
  70236. + } else {
  70237. + dwc_otg_hc_halt(hcd->core_if, qh->channel,
  70238. + DWC_OTG_HC_XFER_URB_DEQUEUE);
  70239. + }
  70240. + }
  70241. + }
  70242. +
  70243. + /*
  70244. + * Free the QTD and clean up the associated QH. Leave the QH in the
  70245. + * schedule if it has any remaining QTDs.
  70246. + */
  70247. +
  70248. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue - "
  70249. + "delete %sQueue handler\n",
  70250. + hcd->core_if->dma_desc_enable?"DMA ":"");
  70251. + if (!hcd->core_if->dma_desc_enable) {
  70252. + uint8_t b = urb_qtd->in_process;
  70253. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  70254. + if (b) {
  70255. + dwc_otg_hcd_qh_deactivate(hcd, qh, 0);
  70256. + qh->channel = NULL;
  70257. + } else if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  70258. + dwc_otg_hcd_qh_remove(hcd, qh);
  70259. + }
  70260. + } else {
  70261. + dwc_otg_hcd_qtd_remove_and_free(hcd, urb_qtd, qh);
  70262. + }
  70263. + return 0;
  70264. +}
  70265. +
  70266. +int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  70267. + int retry)
  70268. +{
  70269. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70270. + int retval = 0;
  70271. + dwc_irqflags_t flags;
  70272. +
  70273. + if (retry < 0) {
  70274. + retval = -DWC_E_INVALID;
  70275. + goto done;
  70276. + }
  70277. +
  70278. + if (!qh) {
  70279. + retval = -DWC_E_INVALID;
  70280. + goto done;
  70281. + }
  70282. +
  70283. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70284. +
  70285. + while (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list) && retry) {
  70286. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70287. + retry--;
  70288. + dwc_msleep(5);
  70289. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70290. + }
  70291. +
  70292. + dwc_otg_hcd_qh_remove(hcd, qh);
  70293. +
  70294. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70295. + /*
  70296. + * Split dwc_otg_hcd_qh_remove_and_free() into qh_remove
  70297. + * and qh_free to prevent stack dump on DWC_DMA_FREE() with
  70298. + * irq_disabled (spinlock_irqsave) in dwc_otg_hcd_desc_list_free()
  70299. + * and dwc_otg_hcd_frame_list_alloc().
  70300. + */
  70301. + dwc_otg_hcd_qh_free(hcd, qh);
  70302. +
  70303. +done:
  70304. + return retval;
  70305. +}
  70306. +
  70307. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  70308. +int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle)
  70309. +{
  70310. + int retval = 0;
  70311. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  70312. + if (!qh)
  70313. + return -DWC_E_INVALID;
  70314. +
  70315. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  70316. + return retval;
  70317. +}
  70318. +#endif
  70319. +
  70320. +/**
  70321. + * HCD Callback structure for handling mode switching.
  70322. + */
  70323. +static dwc_otg_cil_callbacks_t hcd_cil_callbacks = {
  70324. + .start = dwc_otg_hcd_start_cb,
  70325. + .stop = dwc_otg_hcd_stop_cb,
  70326. + .disconnect = dwc_otg_hcd_disconnect_cb,
  70327. + .session_start = dwc_otg_hcd_session_start_cb,
  70328. + .resume_wakeup = dwc_otg_hcd_rem_wakeup_cb,
  70329. +#ifdef CONFIG_USB_DWC_OTG_LPM
  70330. + .sleep = dwc_otg_hcd_sleep_cb,
  70331. +#endif
  70332. + .p = 0,
  70333. +};
  70334. +
  70335. +/**
  70336. + * Reset tasklet function
  70337. + */
  70338. +static void reset_tasklet_func(void *data)
  70339. +{
  70340. + dwc_otg_hcd_t *dwc_otg_hcd = (dwc_otg_hcd_t *) data;
  70341. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  70342. + hprt0_data_t hprt0;
  70343. +
  70344. + DWC_DEBUGPL(DBG_HCDV, "USB RESET tasklet called\n");
  70345. +
  70346. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  70347. + hprt0.b.prtrst = 1;
  70348. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70349. + dwc_mdelay(60);
  70350. +
  70351. + hprt0.b.prtrst = 0;
  70352. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  70353. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  70354. +}
  70355. +
  70356. +static void completion_tasklet_func(void *ptr)
  70357. +{
  70358. + dwc_otg_hcd_t *hcd = (dwc_otg_hcd_t *) ptr;
  70359. + struct urb *urb;
  70360. + urb_tq_entry_t *item;
  70361. + dwc_irqflags_t flags;
  70362. +
  70363. + /* This could just be spin_lock_irq */
  70364. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70365. + while (!DWC_TAILQ_EMPTY(&hcd->completed_urb_list)) {
  70366. + item = DWC_TAILQ_FIRST(&hcd->completed_urb_list);
  70367. + urb = item->urb;
  70368. + DWC_TAILQ_REMOVE(&hcd->completed_urb_list, item,
  70369. + urb_tq_entries);
  70370. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70371. + DWC_FREE(item);
  70372. +
  70373. + usb_hcd_giveback_urb(hcd->priv, urb, urb->status);
  70374. +
  70375. +
  70376. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70377. + }
  70378. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70379. + return;
  70380. +}
  70381. +
  70382. +static void qh_list_free(dwc_otg_hcd_t * hcd, dwc_list_link_t * qh_list)
  70383. +{
  70384. + dwc_list_link_t *item;
  70385. + dwc_otg_qh_t *qh;
  70386. + dwc_irqflags_t flags;
  70387. +
  70388. + if (!qh_list->next) {
  70389. + /* The list hasn't been initialized yet. */
  70390. + return;
  70391. + }
  70392. + /*
  70393. + * Hold spinlock here. Not needed in that case if bellow
  70394. + * function is being called from ISR
  70395. + */
  70396. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  70397. + /* Ensure there are no QTDs or URBs left. */
  70398. + kill_urbs_in_qh_list(hcd, qh_list);
  70399. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  70400. +
  70401. + DWC_LIST_FOREACH(item, qh_list) {
  70402. + qh = DWC_LIST_ENTRY(item, dwc_otg_qh_t, qh_list_entry);
  70403. + dwc_otg_hcd_qh_remove_and_free(hcd, qh);
  70404. + }
  70405. +}
  70406. +
  70407. +/**
  70408. + * Exit from Hibernation if Host did not detect SRP from connected SRP capable
  70409. + * Device during SRP time by host power up.
  70410. + */
  70411. +void dwc_otg_hcd_power_up(void *ptr)
  70412. +{
  70413. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  70414. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  70415. +
  70416. + DWC_PRINTF("%s called\n", __FUNCTION__);
  70417. +
  70418. + if (!core_if->hibernation_suspend) {
  70419. + DWC_PRINTF("Already exited from Hibernation\n");
  70420. + return;
  70421. + }
  70422. +
  70423. + /* Switch on the voltage to the core */
  70424. + gpwrdn.b.pwrdnswtch = 1;
  70425. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70426. + dwc_udelay(10);
  70427. +
  70428. + /* Reset the core */
  70429. + gpwrdn.d32 = 0;
  70430. + gpwrdn.b.pwrdnrstn = 1;
  70431. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70432. + dwc_udelay(10);
  70433. +
  70434. + /* Disable power clamps */
  70435. + gpwrdn.d32 = 0;
  70436. + gpwrdn.b.pwrdnclmp = 1;
  70437. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70438. +
  70439. + /* Remove reset the core signal */
  70440. + gpwrdn.d32 = 0;
  70441. + gpwrdn.b.pwrdnrstn = 1;
  70442. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0, gpwrdn.d32);
  70443. + dwc_udelay(10);
  70444. +
  70445. + /* Disable PMU interrupt */
  70446. + gpwrdn.d32 = 0;
  70447. + gpwrdn.b.pmuintsel = 1;
  70448. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70449. +
  70450. + core_if->hibernation_suspend = 0;
  70451. +
  70452. + /* Disable PMU */
  70453. + gpwrdn.d32 = 0;
  70454. + gpwrdn.b.pmuactv = 1;
  70455. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70456. + dwc_udelay(10);
  70457. +
  70458. + /* Enable VBUS */
  70459. + gpwrdn.d32 = 0;
  70460. + gpwrdn.b.dis_vbus = 1;
  70461. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, gpwrdn.d32, 0);
  70462. +
  70463. + core_if->op_state = A_HOST;
  70464. + dwc_otg_core_init(core_if);
  70465. + dwc_otg_enable_global_interrupts(core_if);
  70466. + cil_hcd_start(core_if);
  70467. +}
  70468. +
  70469. +void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num)
  70470. +{
  70471. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  70472. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  70473. + int i;
  70474. +
  70475. + st->fsm = FIQ_PASSTHROUGH;
  70476. + st->hcchar_copy.d32 = 0;
  70477. + st->hcsplt_copy.d32 = 0;
  70478. + st->hcint_copy.d32 = 0;
  70479. + st->hcintmsk_copy.d32 = 0;
  70480. + st->hctsiz_copy.d32 = 0;
  70481. + st->hcdma_copy.d32 = 0;
  70482. + st->nr_errors = 0;
  70483. + st->hub_addr = 0;
  70484. + st->port_addr = 0;
  70485. + st->expected_uframe = 0;
  70486. + st->nrpackets = 0;
  70487. + st->dma_info.index = 0;
  70488. + for (i = 0; i < 6; i++)
  70489. + st->dma_info.slot_len[i] = 255;
  70490. + st->hs_isoc_info.index = 0;
  70491. + st->hs_isoc_info.iso_desc = NULL;
  70492. + st->hs_isoc_info.nrframes = 0;
  70493. +
  70494. + DWC_MEMSET(&blob->channel[num].index[0], 0x6b, 1128);
  70495. +}
  70496. +
  70497. +/**
  70498. + * Frees secondary storage associated with the dwc_otg_hcd structure contained
  70499. + * in the struct usb_hcd field.
  70500. + */
  70501. +static void dwc_otg_hcd_free(dwc_otg_hcd_t * dwc_otg_hcd)
  70502. +{
  70503. + int i;
  70504. +
  70505. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD FREE\n");
  70506. +
  70507. + del_timers(dwc_otg_hcd);
  70508. +
  70509. + /* Free memory for QH/QTD lists */
  70510. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_inactive);
  70511. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->non_periodic_sched_active);
  70512. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_inactive);
  70513. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_ready);
  70514. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_assigned);
  70515. + qh_list_free(dwc_otg_hcd, &dwc_otg_hcd->periodic_sched_queued);
  70516. +
  70517. + /* Free memory for the host channels. */
  70518. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  70519. + dwc_hc_t *hc = dwc_otg_hcd->hc_ptr_array[i];
  70520. +
  70521. +#ifdef DEBUG
  70522. + if (dwc_otg_hcd->core_if->hc_xfer_timer[i]) {
  70523. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->hc_xfer_timer[i]);
  70524. + }
  70525. +#endif
  70526. + if (hc != NULL) {
  70527. + DWC_DEBUGPL(DBG_HCDV, "HCD Free channel #%i, hc=%p\n",
  70528. + i, hc);
  70529. + DWC_FREE(hc);
  70530. + }
  70531. + }
  70532. +
  70533. + if (dwc_otg_hcd->core_if->dma_enable) {
  70534. + if (dwc_otg_hcd->status_buf_dma) {
  70535. + DWC_DMA_FREE(DWC_OTG_HCD_STATUS_BUF_SIZE,
  70536. + dwc_otg_hcd->status_buf,
  70537. + dwc_otg_hcd->status_buf_dma);
  70538. + }
  70539. + } else if (dwc_otg_hcd->status_buf != NULL) {
  70540. + DWC_FREE(dwc_otg_hcd->status_buf);
  70541. + }
  70542. + DWC_SPINLOCK_FREE(dwc_otg_hcd->channel_lock);
  70543. + DWC_SPINLOCK_FREE(dwc_otg_hcd->lock);
  70544. + /* Set core_if's lock pointer to NULL */
  70545. + dwc_otg_hcd->core_if->lock = NULL;
  70546. +
  70547. + DWC_TIMER_FREE(dwc_otg_hcd->conn_timer);
  70548. + DWC_TASK_FREE(dwc_otg_hcd->reset_tasklet);
  70549. + DWC_TASK_FREE(dwc_otg_hcd->completion_tasklet);
  70550. + DWC_FREE(dwc_otg_hcd->fiq_state);
  70551. +
  70552. +#ifdef DWC_DEV_SRPCAP
  70553. + if (dwc_otg_hcd->core_if->power_down == 2 &&
  70554. + dwc_otg_hcd->core_if->pwron_timer) {
  70555. + DWC_TIMER_FREE(dwc_otg_hcd->core_if->pwron_timer);
  70556. + }
  70557. +#endif
  70558. + DWC_FREE(dwc_otg_hcd);
  70559. +}
  70560. +
  70561. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd);
  70562. +
  70563. +int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if)
  70564. +{
  70565. + int retval = 0;
  70566. + int num_channels;
  70567. + int i;
  70568. + dwc_hc_t *channel;
  70569. +
  70570. + hcd->lock = DWC_SPINLOCK_ALLOC();
  70571. + hcd->channel_lock = DWC_SPINLOCK_ALLOC();
  70572. + DWC_DEBUGPL(DBG_HCDV, "init of HCD %p given core_if %p\n",
  70573. + hcd, core_if);
  70574. + if (!hcd->lock) {
  70575. + DWC_ERROR("Could not allocate lock for pcd");
  70576. + DWC_FREE(hcd);
  70577. + retval = -DWC_E_NO_MEMORY;
  70578. + goto out;
  70579. + }
  70580. + hcd->core_if = core_if;
  70581. +
  70582. + /* Register the HCD CIL Callbacks */
  70583. + dwc_otg_cil_register_hcd_callbacks(hcd->core_if,
  70584. + &hcd_cil_callbacks, hcd);
  70585. +
  70586. + /* Initialize the non-periodic schedule. */
  70587. + DWC_LIST_INIT(&hcd->non_periodic_sched_inactive);
  70588. + DWC_LIST_INIT(&hcd->non_periodic_sched_active);
  70589. +
  70590. + /* Initialize the periodic schedule. */
  70591. + DWC_LIST_INIT(&hcd->periodic_sched_inactive);
  70592. + DWC_LIST_INIT(&hcd->periodic_sched_ready);
  70593. + DWC_LIST_INIT(&hcd->periodic_sched_assigned);
  70594. + DWC_LIST_INIT(&hcd->periodic_sched_queued);
  70595. + DWC_TAILQ_INIT(&hcd->completed_urb_list);
  70596. + /*
  70597. + * Create a host channel descriptor for each host channel implemented
  70598. + * in the controller. Initialize the channel descriptor array.
  70599. + */
  70600. + DWC_CIRCLEQ_INIT(&hcd->free_hc_list);
  70601. + num_channels = hcd->core_if->core_params->host_channels;
  70602. + DWC_MEMSET(hcd->hc_ptr_array, 0, sizeof(hcd->hc_ptr_array));
  70603. + for (i = 0; i < num_channels; i++) {
  70604. + channel = DWC_ALLOC(sizeof(dwc_hc_t));
  70605. + if (channel == NULL) {
  70606. + retval = -DWC_E_NO_MEMORY;
  70607. + DWC_ERROR("%s: host channel allocation failed\n",
  70608. + __func__);
  70609. + dwc_otg_hcd_free(hcd);
  70610. + goto out;
  70611. + }
  70612. + channel->hc_num = i;
  70613. + hcd->hc_ptr_array[i] = channel;
  70614. +#ifdef DEBUG
  70615. + hcd->core_if->hc_xfer_timer[i] =
  70616. + DWC_TIMER_ALLOC("hc timer", hc_xfer_timeout,
  70617. + &hcd->core_if->hc_xfer_info[i]);
  70618. +#endif
  70619. + DWC_DEBUGPL(DBG_HCDV, "HCD Added channel #%d, hc=%p\n", i,
  70620. + channel);
  70621. + }
  70622. +
  70623. + if (fiq_enable) {
  70624. + hcd->fiq_state = DWC_ALLOC(sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels));
  70625. + if (!hcd->fiq_state) {
  70626. + retval = -DWC_E_NO_MEMORY;
  70627. + DWC_ERROR("%s: cannot allocate fiq_state structure\n", __func__);
  70628. + dwc_otg_hcd_free(hcd);
  70629. + goto out;
  70630. + }
  70631. + DWC_MEMSET(hcd->fiq_state, 0, (sizeof(struct fiq_state) + (sizeof(struct fiq_channel_state) * num_channels)));
  70632. +
  70633. + for (i = 0; i < num_channels; i++) {
  70634. + hcd->fiq_state->channel[i].fsm = FIQ_PASSTHROUGH;
  70635. + }
  70636. + hcd->fiq_state->dummy_send = DWC_ALLOC_ATOMIC(16);
  70637. +
  70638. + hcd->fiq_stack = DWC_ALLOC(sizeof(struct fiq_stack));
  70639. + if (!hcd->fiq_stack) {
  70640. + retval = -DWC_E_NO_MEMORY;
  70641. + DWC_ERROR("%s: cannot allocate fiq_stack structure\n", __func__);
  70642. + dwc_otg_hcd_free(hcd);
  70643. + goto out;
  70644. + }
  70645. + hcd->fiq_stack->magic1 = 0xDEADBEEF;
  70646. + hcd->fiq_stack->magic2 = 0xD00DFEED;
  70647. + hcd->fiq_state->gintmsk_saved.d32 = ~0;
  70648. + hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  70649. +
  70650. + /* This bit is terrible and uses no API, but necessary. The FIQ has no concept of DMA pools
  70651. + * (and if it did, would be a lot slower). This allocates a chunk of memory (~9kiB for 8 host channels)
  70652. + * for use as transaction bounce buffers in a 2-D array. Our access into this chunk is done by some
  70653. + * moderately readable array casts.
  70654. + */
  70655. + hcd->fiq_dmab = DWC_DMA_ALLOC((sizeof(struct fiq_dma_channel) * num_channels), &hcd->fiq_state->dma_base);
  70656. + DWC_WARN("FIQ DMA bounce buffers: virt = 0x%08x dma = 0x%08x len=%d",
  70657. + (unsigned int)hcd->fiq_dmab, (unsigned int)hcd->fiq_state->dma_base,
  70658. + sizeof(struct fiq_dma_channel) * num_channels);
  70659. +
  70660. + DWC_MEMSET(hcd->fiq_dmab, 0x6b, 9024);
  70661. +
  70662. + /* pointer for debug in fiq_print */
  70663. + hcd->fiq_state->fiq_dmab = hcd->fiq_dmab;
  70664. + if (fiq_fsm_enable) {
  70665. + int i;
  70666. + for (i=0; i < hcd->core_if->core_params->host_channels; i++) {
  70667. + dwc_otg_cleanup_fiq_channel(hcd, i);
  70668. + }
  70669. + DWC_PRINTF("FIQ FSM acceleration enabled for :\n%s%s%s",
  70670. + (fiq_fsm_mask & 0x1) ? "Non-periodic Split Transactions\n" : "",
  70671. + (fiq_fsm_mask & 0x2) ? "Periodic Split Transactions\n" : "",
  70672. + (fiq_fsm_mask & 0x4) ? "High-Speed Isochronous Endpoints\n" : "");
  70673. + }
  70674. + }
  70675. +
  70676. + /* Initialize the Connection timeout timer. */
  70677. + hcd->conn_timer = DWC_TIMER_ALLOC("Connection timer",
  70678. + dwc_otg_hcd_connect_timeout, 0);
  70679. +
  70680. + printk(KERN_DEBUG "dwc_otg: Microframe scheduler %s\n", microframe_schedule ? "enabled":"disabled");
  70681. + if (microframe_schedule)
  70682. + init_hcd_usecs(hcd);
  70683. +
  70684. + /* Initialize reset tasklet. */
  70685. + hcd->reset_tasklet = DWC_TASK_ALLOC("reset_tasklet", reset_tasklet_func, hcd);
  70686. +
  70687. + hcd->completion_tasklet = DWC_TASK_ALLOC("completion_tasklet",
  70688. + completion_tasklet_func, hcd);
  70689. +#ifdef DWC_DEV_SRPCAP
  70690. + if (hcd->core_if->power_down == 2) {
  70691. + /* Initialize Power on timer for Host power up in case hibernation */
  70692. + hcd->core_if->pwron_timer = DWC_TIMER_ALLOC("PWRON TIMER",
  70693. + dwc_otg_hcd_power_up, core_if);
  70694. + }
  70695. +#endif
  70696. +
  70697. + /*
  70698. + * Allocate space for storing data on status transactions. Normally no
  70699. + * data is sent, but this space acts as a bit bucket. This must be
  70700. + * done after usb_add_hcd since that function allocates the DMA buffer
  70701. + * pool.
  70702. + */
  70703. + if (hcd->core_if->dma_enable) {
  70704. + hcd->status_buf =
  70705. + DWC_DMA_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE,
  70706. + &hcd->status_buf_dma);
  70707. + } else {
  70708. + hcd->status_buf = DWC_ALLOC(DWC_OTG_HCD_STATUS_BUF_SIZE);
  70709. + }
  70710. + if (!hcd->status_buf) {
  70711. + retval = -DWC_E_NO_MEMORY;
  70712. + DWC_ERROR("%s: status_buf allocation failed\n", __func__);
  70713. + dwc_otg_hcd_free(hcd);
  70714. + goto out;
  70715. + }
  70716. +
  70717. + hcd->otg_port = 1;
  70718. + hcd->frame_list = NULL;
  70719. + hcd->frame_list_dma = 0;
  70720. + hcd->periodic_qh_count = 0;
  70721. +
  70722. + DWC_MEMSET(hcd->hub_port, 0, sizeof(hcd->hub_port));
  70723. +#ifdef FIQ_DEBUG
  70724. + DWC_MEMSET(hcd->hub_port_alloc, -1, sizeof(hcd->hub_port_alloc));
  70725. +#endif
  70726. +
  70727. +out:
  70728. + return retval;
  70729. +}
  70730. +
  70731. +void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd)
  70732. +{
  70733. + /* Turn off all host-specific interrupts. */
  70734. + dwc_otg_disable_host_interrupts(hcd->core_if);
  70735. +
  70736. + dwc_otg_hcd_free(hcd);
  70737. +}
  70738. +
  70739. +/**
  70740. + * Initializes dynamic portions of the DWC_otg HCD state.
  70741. + */
  70742. +static void dwc_otg_hcd_reinit(dwc_otg_hcd_t * hcd)
  70743. +{
  70744. + int num_channels;
  70745. + int i;
  70746. + dwc_hc_t *channel;
  70747. + dwc_hc_t *channel_tmp;
  70748. +
  70749. + hcd->flags.d32 = 0;
  70750. +
  70751. + hcd->non_periodic_qh_ptr = &hcd->non_periodic_sched_active;
  70752. + if (!microframe_schedule) {
  70753. + hcd->non_periodic_channels = 0;
  70754. + hcd->periodic_channels = 0;
  70755. + } else {
  70756. + hcd->available_host_channels = hcd->core_if->core_params->host_channels;
  70757. + }
  70758. + /*
  70759. + * Put all channels in the free channel list and clean up channel
  70760. + * states.
  70761. + */
  70762. + DWC_CIRCLEQ_FOREACH_SAFE(channel, channel_tmp,
  70763. + &hcd->free_hc_list, hc_list_entry) {
  70764. + DWC_CIRCLEQ_REMOVE(&hcd->free_hc_list, channel, hc_list_entry);
  70765. + }
  70766. +
  70767. + num_channels = hcd->core_if->core_params->host_channels;
  70768. + for (i = 0; i < num_channels; i++) {
  70769. + channel = hcd->hc_ptr_array[i];
  70770. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, channel,
  70771. + hc_list_entry);
  70772. + dwc_otg_hc_cleanup(hcd->core_if, channel);
  70773. + }
  70774. +
  70775. + /* Initialize the DWC core for host mode operation. */
  70776. + dwc_otg_core_host_init(hcd->core_if);
  70777. +
  70778. + /* Set core_if's lock pointer to the hcd->lock */
  70779. + hcd->core_if->lock = hcd->lock;
  70780. +}
  70781. +
  70782. +/**
  70783. + * Assigns transactions from a QTD to a free host channel and initializes the
  70784. + * host channel to perform the transactions. The host channel is removed from
  70785. + * the free list.
  70786. + *
  70787. + * @param hcd The HCD state structure.
  70788. + * @param qh Transactions from the first QTD for this QH are selected and
  70789. + * assigned to a free host channel.
  70790. + */
  70791. +static void assign_and_init_hc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  70792. +{
  70793. + dwc_hc_t *hc;
  70794. + dwc_otg_qtd_t *qtd;
  70795. + dwc_otg_hcd_urb_t *urb;
  70796. + void* ptr = NULL;
  70797. +
  70798. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  70799. +
  70800. + urb = qtd->urb;
  70801. +
  70802. + DWC_DEBUGPL(DBG_HCDV, "%s(%p,%p) - urb %x, actual_length %d\n", __func__, hcd, qh, (unsigned int)urb, urb->actual_length);
  70803. +
  70804. + if (((urb->actual_length < 0) || (urb->actual_length > urb->length)) && !dwc_otg_hcd_is_pipe_in(&urb->pipe_info))
  70805. + urb->actual_length = urb->length;
  70806. +
  70807. +
  70808. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  70809. +
  70810. + /* Remove the host channel from the free list. */
  70811. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  70812. +
  70813. + qh->channel = hc;
  70814. +
  70815. + qtd->in_process = 1;
  70816. +
  70817. + /*
  70818. + * Use usb_pipedevice to determine device address. This address is
  70819. + * 0 before the SET_ADDRESS command and the correct address afterward.
  70820. + */
  70821. + hc->dev_addr = dwc_otg_hcd_get_dev_addr(&urb->pipe_info);
  70822. + hc->ep_num = dwc_otg_hcd_get_ep_num(&urb->pipe_info);
  70823. + hc->speed = qh->dev_speed;
  70824. + hc->max_packet = dwc_max_packet(qh->maxp);
  70825. +
  70826. + hc->xfer_started = 0;
  70827. + hc->halt_status = DWC_OTG_HC_XFER_NO_HALT_STATUS;
  70828. + hc->error_state = (qtd->error_count > 0);
  70829. + hc->halt_on_queue = 0;
  70830. + hc->halt_pending = 0;
  70831. + hc->requests = 0;
  70832. +
  70833. + /*
  70834. + * The following values may be modified in the transfer type section
  70835. + * below. The xfer_len value may be reduced when the transfer is
  70836. + * started to accommodate the max widths of the XferSize and PktCnt
  70837. + * fields in the HCTSIZn register.
  70838. + */
  70839. +
  70840. + hc->ep_is_in = (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) != 0);
  70841. + if (hc->ep_is_in) {
  70842. + hc->do_ping = 0;
  70843. + } else {
  70844. + hc->do_ping = qh->ping_state;
  70845. + }
  70846. +
  70847. + hc->data_pid_start = qh->data_toggle;
  70848. + hc->multi_count = 1;
  70849. +
  70850. + if (hcd->core_if->dma_enable) {
  70851. + hc->xfer_buff = (uint8_t *) urb->dma + urb->actual_length;
  70852. +
  70853. + /* For non-dword aligned case */
  70854. + if (((unsigned long)hc->xfer_buff & 0x3)
  70855. + && !hcd->core_if->dma_desc_enable) {
  70856. + ptr = (uint8_t *) urb->buf + urb->actual_length;
  70857. + }
  70858. + } else {
  70859. + hc->xfer_buff = (uint8_t *) urb->buf + urb->actual_length;
  70860. + }
  70861. + hc->xfer_len = urb->length - urb->actual_length;
  70862. + hc->xfer_count = 0;
  70863. +
  70864. + /*
  70865. + * Set the split attributes
  70866. + */
  70867. + hc->do_split = 0;
  70868. + if (qh->do_split) {
  70869. + uint32_t hub_addr, port_addr;
  70870. + hc->do_split = 1;
  70871. + hc->xact_pos = qtd->isoc_split_pos;
  70872. + /* We don't need to do complete splits anymore */
  70873. +// if(fiq_fsm_enable)
  70874. + if (0)
  70875. + hc->complete_split = qtd->complete_split = 0;
  70876. + else
  70877. + hc->complete_split = qtd->complete_split;
  70878. +
  70879. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &port_addr);
  70880. + hc->hub_addr = (uint8_t) hub_addr;
  70881. + hc->port_addr = (uint8_t) port_addr;
  70882. + }
  70883. +
  70884. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  70885. + case UE_CONTROL:
  70886. + hc->ep_type = DWC_OTG_EP_TYPE_CONTROL;
  70887. + switch (qtd->control_phase) {
  70888. + case DWC_OTG_CONTROL_SETUP:
  70889. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction\n");
  70890. + hc->do_ping = 0;
  70891. + hc->ep_is_in = 0;
  70892. + hc->data_pid_start = DWC_OTG_HC_PID_SETUP;
  70893. + if (hcd->core_if->dma_enable) {
  70894. + hc->xfer_buff = (uint8_t *) urb->setup_dma;
  70895. + } else {
  70896. + hc->xfer_buff = (uint8_t *) urb->setup_packet;
  70897. + }
  70898. + hc->xfer_len = 8;
  70899. + ptr = NULL;
  70900. + break;
  70901. + case DWC_OTG_CONTROL_DATA:
  70902. + DWC_DEBUGPL(DBG_HCDV, " Control data transaction\n");
  70903. + hc->data_pid_start = qtd->data_toggle;
  70904. + break;
  70905. + case DWC_OTG_CONTROL_STATUS:
  70906. + /*
  70907. + * Direction is opposite of data direction or IN if no
  70908. + * data.
  70909. + */
  70910. + DWC_DEBUGPL(DBG_HCDV, " Control status transaction\n");
  70911. + if (urb->length == 0) {
  70912. + hc->ep_is_in = 1;
  70913. + } else {
  70914. + hc->ep_is_in =
  70915. + dwc_otg_hcd_is_pipe_out(&urb->pipe_info);
  70916. + }
  70917. + if (hc->ep_is_in) {
  70918. + hc->do_ping = 0;
  70919. + }
  70920. +
  70921. + hc->data_pid_start = DWC_OTG_HC_PID_DATA1;
  70922. +
  70923. + hc->xfer_len = 0;
  70924. + if (hcd->core_if->dma_enable) {
  70925. + hc->xfer_buff = (uint8_t *) hcd->status_buf_dma;
  70926. + } else {
  70927. + hc->xfer_buff = (uint8_t *) hcd->status_buf;
  70928. + }
  70929. + ptr = NULL;
  70930. + break;
  70931. + }
  70932. + break;
  70933. + case UE_BULK:
  70934. + hc->ep_type = DWC_OTG_EP_TYPE_BULK;
  70935. + break;
  70936. + case UE_INTERRUPT:
  70937. + hc->ep_type = DWC_OTG_EP_TYPE_INTR;
  70938. + break;
  70939. + case UE_ISOCHRONOUS:
  70940. + {
  70941. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  70942. +
  70943. + hc->ep_type = DWC_OTG_EP_TYPE_ISOC;
  70944. +
  70945. + if (hcd->core_if->dma_desc_enable)
  70946. + break;
  70947. +
  70948. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  70949. +
  70950. + frame_desc->status = 0;
  70951. +
  70952. + if (hcd->core_if->dma_enable) {
  70953. + hc->xfer_buff = (uint8_t *) urb->dma;
  70954. + } else {
  70955. + hc->xfer_buff = (uint8_t *) urb->buf;
  70956. + }
  70957. + hc->xfer_buff +=
  70958. + frame_desc->offset + qtd->isoc_split_offset;
  70959. + hc->xfer_len =
  70960. + frame_desc->length - qtd->isoc_split_offset;
  70961. +
  70962. + /* For non-dword aligned buffers */
  70963. + if (((unsigned long)hc->xfer_buff & 0x3)
  70964. + && hcd->core_if->dma_enable) {
  70965. + ptr =
  70966. + (uint8_t *) urb->buf + frame_desc->offset +
  70967. + qtd->isoc_split_offset;
  70968. + } else
  70969. + ptr = NULL;
  70970. +
  70971. + if (hc->xact_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  70972. + if (hc->xfer_len <= 188) {
  70973. + hc->xact_pos = DWC_HCSPLIT_XACTPOS_ALL;
  70974. + } else {
  70975. + hc->xact_pos =
  70976. + DWC_HCSPLIT_XACTPOS_BEGIN;
  70977. + }
  70978. + }
  70979. + }
  70980. + break;
  70981. + }
  70982. + /* non DWORD-aligned buffer case */
  70983. + if (ptr) {
  70984. + uint32_t buf_size;
  70985. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  70986. + buf_size = hcd->core_if->core_params->max_transfer_size;
  70987. + } else {
  70988. + buf_size = 4096;
  70989. + }
  70990. + if (!qh->dw_align_buf) {
  70991. + qh->dw_align_buf = DWC_DMA_ALLOC_ATOMIC(buf_size,
  70992. + &qh->dw_align_buf_dma);
  70993. + if (!qh->dw_align_buf) {
  70994. + DWC_ERROR
  70995. + ("%s: Failed to allocate memory to handle "
  70996. + "non-dword aligned buffer case\n",
  70997. + __func__);
  70998. + return;
  70999. + }
  71000. + }
  71001. + if (!hc->ep_is_in) {
  71002. + dwc_memcpy(qh->dw_align_buf, ptr, hc->xfer_len);
  71003. + }
  71004. + hc->align_buff = qh->dw_align_buf_dma;
  71005. + } else {
  71006. + hc->align_buff = 0;
  71007. + }
  71008. +
  71009. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  71010. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  71011. + /*
  71012. + * This value may be modified when the transfer is started to
  71013. + * reflect the actual transfer length.
  71014. + */
  71015. + hc->multi_count = dwc_hb_mult(qh->maxp);
  71016. + }
  71017. +
  71018. + if (hcd->core_if->dma_desc_enable)
  71019. + hc->desc_list_addr = qh->desc_list_dma;
  71020. +
  71021. + dwc_otg_hc_init(hcd->core_if, hc);
  71022. + hc->qh = qh;
  71023. +}
  71024. +
  71025. +
  71026. +/**
  71027. + * fiq_fsm_transaction_suitable() - Test a QH for compatibility with the FIQ
  71028. + * @qh: pointer to the endpoint's queue head
  71029. + *
  71030. + * Transaction start/end control flow is grafted onto the existing dwc_otg
  71031. + * mechanisms, to avoid spaghettifying the functions more than they already are.
  71032. + * This function's eligibility check is altered by debug parameter.
  71033. + *
  71034. + * Returns: 0 for unsuitable, 1 implies the FIQ can be enabled for this transaction.
  71035. + */
  71036. +
  71037. +int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh)
  71038. +{
  71039. + if (qh->do_split) {
  71040. + switch (qh->ep_type) {
  71041. + case UE_CONTROL:
  71042. + case UE_BULK:
  71043. + if (fiq_fsm_mask & (1 << 0))
  71044. + return 1;
  71045. + break;
  71046. + case UE_INTERRUPT:
  71047. + case UE_ISOCHRONOUS:
  71048. + if (fiq_fsm_mask & (1 << 1))
  71049. + return 1;
  71050. + break;
  71051. + default:
  71052. + break;
  71053. + }
  71054. + } else if (qh->ep_type == UE_ISOCHRONOUS) {
  71055. + if (fiq_fsm_mask & (1 << 2)) {
  71056. + /* HS ISOCH support. We test for compatibility:
  71057. + * - DWORD aligned buffers
  71058. + * - Must be at least 2 transfers (otherwise pointless to use the FIQ)
  71059. + * If yes, then the fsm enqueue function will handle the state machine setup.
  71060. + */
  71061. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71062. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  71063. + struct dwc_otg_hcd_iso_packet_desc (*iso_descs)[0] = &urb->iso_descs;
  71064. + int nr_iso_frames = urb->packet_count;
  71065. + int i;
  71066. + uint32_t ptr;
  71067. +
  71068. + if (nr_iso_frames < 2)
  71069. + return 0;
  71070. + for (i = 0; i < nr_iso_frames; i++) {
  71071. + ptr = urb->dma + iso_descs[i]->offset;
  71072. + if (ptr & 0x3) {
  71073. + printk_ratelimited("%s: Non-Dword aligned isochronous frame offset."
  71074. + " Cannot queue FIQ-accelerated transfer to device %d endpoint %d\n",
  71075. + __FUNCTION__, qh->channel->dev_addr, qh->channel->ep_num);
  71076. + return 0;
  71077. + }
  71078. + }
  71079. + return 1;
  71080. + }
  71081. + }
  71082. + return 0;
  71083. +}
  71084. +
  71085. +/**
  71086. + * fiq_fsm_setup_periodic_dma() - Set up DMA bounce buffers
  71087. + * @hcd: Pointer to the dwc_otg_hcd struct
  71088. + * @qh: Pointer to the endpoint's queue head
  71089. + *
  71090. + * Periodic split transactions are transmitted modulo 188 bytes.
  71091. + * This necessitates slicing data up into buckets for isochronous out
  71092. + * and fixing up the DMA address for all IN transfers.
  71093. + *
  71094. + * Returns 1 if the DMA bounce buffers have been used, 0 if the default
  71095. + * HC buffer has been used.
  71096. + */
  71097. +int fiq_fsm_setup_periodic_dma(dwc_otg_hcd_t *hcd, struct fiq_channel_state *st, dwc_otg_qh_t *qh)
  71098. + {
  71099. + int frame_length, i = 0;
  71100. + uint8_t *ptr = NULL;
  71101. + dwc_hc_t *hc = qh->channel;
  71102. + struct fiq_dma_blob *blob;
  71103. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  71104. +
  71105. + for (i = 0; i < 6; i++) {
  71106. + st->dma_info.slot_len[i] = 255;
  71107. + }
  71108. + st->dma_info.index = 0;
  71109. + i = 0;
  71110. + if (hc->ep_is_in) {
  71111. + /*
  71112. + * Set dma_regs to bounce buffer. FIQ will update the
  71113. + * state depending on transaction progress.
  71114. + */
  71115. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  71116. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  71117. + /* Calculate the max number of CSPLITS such that the FIQ can time out
  71118. + * a transaction if it fails.
  71119. + */
  71120. + frame_length = st->hcchar_copy.b.mps;
  71121. + do {
  71122. + i++;
  71123. + frame_length -= 188;
  71124. + } while (frame_length >= 0);
  71125. + st->nrpackets = i;
  71126. + return 1;
  71127. + } else {
  71128. + if (qh->ep_type == UE_ISOCHRONOUS) {
  71129. +
  71130. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71131. +
  71132. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  71133. + frame_length = frame_desc->length;
  71134. +
  71135. + /* Virtual address for bounce buffers */
  71136. + blob = hcd->fiq_dmab;
  71137. +
  71138. + ptr = qtd->urb->buf + frame_desc->offset;
  71139. + if (frame_length == 0) {
  71140. + /*
  71141. + * for isochronous transactions, we must still transmit a packet
  71142. + * even if the length is zero.
  71143. + */
  71144. + st->dma_info.slot_len[0] = 0;
  71145. + st->nrpackets = 1;
  71146. + } else {
  71147. + do {
  71148. + if (frame_length <= 188) {
  71149. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, frame_length);
  71150. + st->dma_info.slot_len[i] = frame_length;
  71151. + ptr += frame_length;
  71152. + } else {
  71153. + dwc_memcpy(&blob->channel[hc->hc_num].index[i].buf[0], ptr, 188);
  71154. + st->dma_info.slot_len[i] = 188;
  71155. + ptr += 188;
  71156. + }
  71157. + i++;
  71158. + frame_length -= 188;
  71159. + } while (frame_length > 0);
  71160. + st->nrpackets = i;
  71161. + }
  71162. + ptr = qtd->urb->buf + frame_desc->offset;
  71163. + /* Point the HC at the DMA address of the bounce buffers */
  71164. + blob = (struct fiq_dma_blob *) hcd->fiq_state->dma_base;
  71165. + st->hcdma_copy.d32 = (uint32_t) &blob->channel[hc->hc_num].index[0].buf[0];
  71166. +
  71167. + /* fixup xfersize to the actual packet size */
  71168. + st->hctsiz_copy.b.pid = 0;
  71169. + st->hctsiz_copy.b.xfersize = st->dma_info.slot_len[0];
  71170. + return 1;
  71171. + } else {
  71172. + /* For interrupt, single OUT packet required, goes in the SSPLIT from hc_buff. */
  71173. + return 0;
  71174. + }
  71175. + }
  71176. +}
  71177. +
  71178. +/*
  71179. + * Pushing a periodic request into the queue near the EOF1 point
  71180. + * in a microframe causes erroneous behaviour (frmovrun) interrupt.
  71181. + * Usually, the request goes out on the bus causing a transfer but
  71182. + * the core does not transfer the data to memory.
  71183. + * This guard interval (in number of 60MHz clocks) is required which
  71184. + * must cater for CPU latency between reading the value and enabling
  71185. + * the channel.
  71186. + */
  71187. +#define PERIODIC_FRREM_BACKOFF 1000
  71188. +
  71189. +int fiq_fsm_queue_isoc_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  71190. +{
  71191. + dwc_hc_t *hc = qh->channel;
  71192. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  71193. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  71194. + int frame;
  71195. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  71196. + int xfer_len, nrpackets;
  71197. + hcdma_data_t hcdma;
  71198. + hfnum_data_t hfnum;
  71199. +
  71200. + if (st->fsm != FIQ_PASSTHROUGH)
  71201. + return 0;
  71202. +
  71203. + st->nr_errors = 0;
  71204. +
  71205. + st->hcchar_copy.d32 = 0;
  71206. + st->hcchar_copy.b.mps = hc->max_packet;
  71207. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  71208. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  71209. + st->hcchar_copy.b.epnum = hc->ep_num;
  71210. + st->hcchar_copy.b.eptype = hc->ep_type;
  71211. +
  71212. + st->hcintmsk_copy.b.chhltd = 1;
  71213. +
  71214. + frame = dwc_otg_hcd_get_frame_number(hcd);
  71215. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  71216. +
  71217. + st->hcchar_copy.b.lspddev = 0;
  71218. + /* Enable the channel later as a final register write. */
  71219. +
  71220. + st->hcsplt_copy.d32 = 0;
  71221. +
  71222. + st->hs_isoc_info.iso_desc = (struct dwc_otg_hcd_iso_packet_desc *) &qtd->urb->iso_descs;
  71223. + st->hs_isoc_info.nrframes = qtd->urb->packet_count;
  71224. + /* grab the next DMA address offset from the array */
  71225. + st->hcdma_copy.d32 = qtd->urb->dma;
  71226. + hcdma.d32 = st->hcdma_copy.d32 + st->hs_isoc_info.iso_desc[0].offset;
  71227. +
  71228. + /* We need to set multi_count. This is a bit tricky - has to be set per-transaction as
  71229. + * the core needs to be told to send the correct number. Caution: for IN transfers,
  71230. + * this is always set to the maximum size of the endpoint. */
  71231. + xfer_len = st->hs_isoc_info.iso_desc[0].length;
  71232. + nrpackets = (xfer_len + st->hcchar_copy.b.mps - 1) / st->hcchar_copy.b.mps;
  71233. + if (nrpackets == 0)
  71234. + nrpackets = 1;
  71235. + st->hcchar_copy.b.multicnt = nrpackets;
  71236. + st->hctsiz_copy.b.pktcnt = nrpackets;
  71237. +
  71238. + /* Initial PID also needs to be set */
  71239. + if (st->hcchar_copy.b.epdir == 0) {
  71240. + st->hctsiz_copy.b.xfersize = xfer_len;
  71241. + switch (st->hcchar_copy.b.multicnt) {
  71242. + case 1:
  71243. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  71244. + break;
  71245. + case 2:
  71246. + case 3:
  71247. + st->hctsiz_copy.b.pid = DWC_PID_MDATA;
  71248. + break;
  71249. + }
  71250. +
  71251. + } else {
  71252. + st->hctsiz_copy.b.xfersize = nrpackets * st->hcchar_copy.b.mps;
  71253. + switch (st->hcchar_copy.b.multicnt) {
  71254. + case 1:
  71255. + st->hctsiz_copy.b.pid = DWC_PID_DATA0;
  71256. + break;
  71257. + case 2:
  71258. + st->hctsiz_copy.b.pid = DWC_PID_DATA1;
  71259. + break;
  71260. + case 3:
  71261. + st->hctsiz_copy.b.pid = DWC_PID_DATA2;
  71262. + break;
  71263. + }
  71264. + }
  71265. +
  71266. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d ", hc->hc_num);
  71267. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcchar_copy.d32);
  71268. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  71269. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  71270. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  71271. + local_fiq_disable();
  71272. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  71273. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  71274. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  71275. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71276. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  71277. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  71278. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  71279. + * split transaction is queued very close to EOF.
  71280. + */
  71281. + st->fsm = FIQ_HS_ISOC_SLEEPING;
  71282. + } else {
  71283. + st->fsm = FIQ_HS_ISOC_TURBO;
  71284. + st->hcchar_copy.b.chen = 1;
  71285. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71286. + }
  71287. + mb();
  71288. + st->hcchar_copy.b.chen = 0;
  71289. + local_fiq_enable();
  71290. + return 0;
  71291. +}
  71292. +
  71293. +
  71294. +/**
  71295. + * fiq_fsm_queue_split_transaction() - Set up a host channel and FIQ state
  71296. + * @hcd: Pointer to the dwc_otg_hcd struct
  71297. + * @qh: Pointer to the endpoint's queue head
  71298. + *
  71299. + * This overrides the dwc_otg driver's normal method of queueing a transaction.
  71300. + * Called from dwc_otg_hcd_queue_transactions(), this performs specific setup
  71301. + * for the nominated host channel.
  71302. + *
  71303. + * For periodic transfers, it also peeks at the FIQ state to see if an immediate
  71304. + * start is possible. If not, then the FIQ is left to start the transfer.
  71305. + */
  71306. +int fiq_fsm_queue_split_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh)
  71307. +{
  71308. + int start_immediate = 1, i;
  71309. + hfnum_data_t hfnum;
  71310. + dwc_hc_t *hc = qh->channel;
  71311. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[hc->hc_num];
  71312. + /* Program HC registers, setup FIQ_state, examine FIQ if periodic, start transfer (not if uframe 5) */
  71313. + int hub_addr, port_addr, frame, uframe;
  71314. + struct fiq_channel_state *st = &hcd->fiq_state->channel[hc->hc_num];
  71315. +
  71316. + if (st->fsm != FIQ_PASSTHROUGH)
  71317. + return 0;
  71318. + st->nr_errors = 0;
  71319. +
  71320. + st->hcchar_copy.d32 = 0;
  71321. + st->hcchar_copy.b.mps = hc->max_packet;
  71322. + st->hcchar_copy.b.epdir = hc->ep_is_in;
  71323. + st->hcchar_copy.b.devaddr = hc->dev_addr;
  71324. + st->hcchar_copy.b.epnum = hc->ep_num;
  71325. + st->hcchar_copy.b.eptype = hc->ep_type;
  71326. + if (hc->ep_type & 0x1) {
  71327. + if (hc->ep_is_in)
  71328. + st->hcchar_copy.b.multicnt = 3;
  71329. + else
  71330. + /* Docs say set this to 1, but driver sets to 0! */
  71331. + st->hcchar_copy.b.multicnt = 0;
  71332. + } else {
  71333. + st->hcchar_copy.b.multicnt = 1;
  71334. + st->hcchar_copy.b.oddfrm = 0;
  71335. + }
  71336. + st->hcchar_copy.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW) ? 1 : 0;
  71337. + /* Enable the channel later as a final register write. */
  71338. +
  71339. + st->hcsplt_copy.d32 = 0;
  71340. + if(qh->do_split) {
  71341. + hcd->fops->hub_info(hcd, DWC_CIRCLEQ_FIRST(&qh->qtd_list)->urb->priv, &hub_addr, &port_addr);
  71342. + st->hcsplt_copy.b.compsplt = 0;
  71343. + st->hcsplt_copy.b.spltena = 1;
  71344. + // XACTPOS is for isoc-out only but needs initialising anyway.
  71345. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_ALL;
  71346. + if((qh->ep_type == DWC_OTG_EP_TYPE_ISOC) && (!qh->ep_is_in)) {
  71347. + /* For packetsize 0 < L < 188, ISOC_XACTPOS_ALL.
  71348. + * for longer than this, ISOC_XACTPOS_BEGIN and the FIQ
  71349. + * will update as necessary.
  71350. + */
  71351. + if (hc->xfer_len > 188) {
  71352. + st->hcsplt_copy.b.xactpos = ISOC_XACTPOS_BEGIN;
  71353. + }
  71354. + }
  71355. + st->hcsplt_copy.b.hubaddr = (uint8_t) hub_addr;
  71356. + st->hcsplt_copy.b.prtaddr = (uint8_t) port_addr;
  71357. + st->hub_addr = hub_addr;
  71358. + st->port_addr = port_addr;
  71359. + }
  71360. +
  71361. + st->hctsiz_copy.d32 = 0;
  71362. + st->hctsiz_copy.b.dopng = 0;
  71363. + st->hctsiz_copy.b.pid = hc->data_pid_start;
  71364. +
  71365. + if (hc->ep_is_in || (hc->xfer_len > hc->max_packet)) {
  71366. + hc->xfer_len = hc->max_packet;
  71367. + } else if (!hc->ep_is_in && (hc->xfer_len > 188)) {
  71368. + hc->xfer_len = 188;
  71369. + }
  71370. + st->hctsiz_copy.b.xfersize = hc->xfer_len;
  71371. +
  71372. + st->hctsiz_copy.b.pktcnt = 1;
  71373. +
  71374. + if (hc->ep_type & 0x1) {
  71375. + /*
  71376. + * For potentially multi-packet transfers, must use the DMA bounce buffers. For IN transfers,
  71377. + * the DMA address is the address of the first 188byte slot buffer in the bounce buffer array.
  71378. + * For multi-packet OUT transfers, we need to copy the data into the bounce buffer array so the FIQ can punt
  71379. + * the right address out as necessary. hc->xfer_buff and hc->xfer_len have already been set
  71380. + * in assign_and_init_hc(), but this is for the eventual transaction completion only. The FIQ
  71381. + * must not touch internal driver state.
  71382. + */
  71383. + if(!fiq_fsm_setup_periodic_dma(hcd, st, qh)) {
  71384. + if (hc->align_buff) {
  71385. + st->hcdma_copy.d32 = hc->align_buff;
  71386. + } else {
  71387. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  71388. + }
  71389. + }
  71390. + } else {
  71391. + if (hc->align_buff) {
  71392. + st->hcdma_copy.d32 = hc->align_buff;
  71393. + } else {
  71394. + st->hcdma_copy.d32 = ((unsigned long) hc->xfer_buff & 0xFFFFFFFF);
  71395. + }
  71396. + }
  71397. + /* The FIQ depends upon no other interrupts being enabled except channel halt.
  71398. + * Fixup channel interrupt mask. */
  71399. + st->hcintmsk_copy.d32 = 0;
  71400. + st->hcintmsk_copy.b.chhltd = 1;
  71401. + st->hcintmsk_copy.b.ahberr = 1;
  71402. +
  71403. + DWC_WRITE_REG32(&hc_regs->hcdma, st->hcdma_copy.d32);
  71404. + DWC_WRITE_REG32(&hc_regs->hctsiz, st->hctsiz_copy.d32);
  71405. + DWC_WRITE_REG32(&hc_regs->hcsplt, st->hcsplt_copy.d32);
  71406. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71407. + DWC_WRITE_REG32(&hc_regs->hcintmsk, st->hcintmsk_copy.d32);
  71408. +
  71409. + local_fiq_disable();
  71410. + mb();
  71411. +
  71412. + if (hc->ep_type & 0x1) {
  71413. + hfnum.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  71414. + frame = (hfnum.b.frnum & ~0x7) >> 3;
  71415. + uframe = hfnum.b.frnum & 0x7;
  71416. + if (hfnum.b.frrem < PERIODIC_FRREM_BACKOFF) {
  71417. + /* Prevent queueing near EOF1. Bad things happen if a periodic
  71418. + * split transaction is queued very close to EOF.
  71419. + */
  71420. + start_immediate = 0;
  71421. + } else if (uframe == 5) {
  71422. + start_immediate = 0;
  71423. + } else if (hc->ep_type == UE_ISOCHRONOUS && !hc->ep_is_in) {
  71424. + start_immediate = 0;
  71425. + } else if (hc->ep_is_in && fiq_fsm_too_late(hcd->fiq_state, hc->hc_num)) {
  71426. + start_immediate = 0;
  71427. + } else {
  71428. + /* Search through all host channels to determine if a transaction
  71429. + * is currently in progress */
  71430. + for (i = 0; i < hcd->core_if->core_params->host_channels; i++) {
  71431. + if (i == hc->hc_num || hcd->fiq_state->channel[i].fsm == FIQ_PASSTHROUGH)
  71432. + continue;
  71433. + switch (hcd->fiq_state->channel[i].fsm) {
  71434. + /* TT is reserved for channels that are in the middle of a periodic
  71435. + * split transaction.
  71436. + */
  71437. + case FIQ_PER_SSPLIT_STARTED:
  71438. + case FIQ_PER_CSPLIT_WAIT:
  71439. + case FIQ_PER_CSPLIT_NYET1:
  71440. + case FIQ_PER_CSPLIT_POLL:
  71441. + case FIQ_PER_ISO_OUT_ACTIVE:
  71442. + case FIQ_PER_ISO_OUT_LAST:
  71443. + if (hcd->fiq_state->channel[i].hub_addr == hub_addr &&
  71444. + hcd->fiq_state->channel[i].port_addr == port_addr) {
  71445. + start_immediate = 0;
  71446. + }
  71447. + break;
  71448. + default:
  71449. + break;
  71450. + }
  71451. + if (!start_immediate)
  71452. + break;
  71453. + }
  71454. + }
  71455. + }
  71456. + fiq_print(FIQDBG_INT, hcd->fiq_state, "FSMQ %01d %01d", hc->hc_num, start_immediate);
  71457. + fiq_print(FIQDBG_INT, hcd->fiq_state, "%08d", hfnum.b.frrem);
  71458. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "H:%02dP:%02d", hub_addr, port_addr);
  71459. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hctsiz_copy.d32);
  71460. + //fiq_print(FIQDBG_INT, hcd->fiq_state, "%08x", st->hcdma_copy.d32);
  71461. + switch (hc->ep_type) {
  71462. + case UE_CONTROL:
  71463. + case UE_BULK:
  71464. + st->fsm = FIQ_NP_SSPLIT_STARTED;
  71465. + break;
  71466. + case UE_ISOCHRONOUS:
  71467. + if (hc->ep_is_in) {
  71468. + if (start_immediate) {
  71469. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  71470. + } else {
  71471. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  71472. + }
  71473. + } else {
  71474. + if (start_immediate) {
  71475. + /* Single-isoc OUT packets don't require FIQ involvement */
  71476. + if (st->nrpackets == 1) {
  71477. + st->fsm = FIQ_PER_ISO_OUT_LAST;
  71478. + } else {
  71479. + st->fsm = FIQ_PER_ISO_OUT_ACTIVE;
  71480. + }
  71481. + } else {
  71482. + st->fsm = FIQ_PER_ISO_OUT_PENDING;
  71483. + }
  71484. + }
  71485. + break;
  71486. + case UE_INTERRUPT:
  71487. + if (start_immediate) {
  71488. + st->fsm = FIQ_PER_SSPLIT_STARTED;
  71489. + } else {
  71490. + st->fsm = FIQ_PER_SSPLIT_QUEUED;
  71491. + }
  71492. + default:
  71493. + break;
  71494. + }
  71495. + if (start_immediate) {
  71496. + /* Set the oddfrm bit as close as possible to actual queueing */
  71497. + frame = dwc_otg_hcd_get_frame_number(hcd);
  71498. + st->expected_uframe = (frame + 1) & 0x3FFF;
  71499. + st->hcchar_copy.b.oddfrm = (frame & 0x1) ? 0 : 1;
  71500. + st->hcchar_copy.b.chen = 1;
  71501. + DWC_WRITE_REG32(&hc_regs->hcchar, st->hcchar_copy.d32);
  71502. + }
  71503. + mb();
  71504. + local_fiq_enable();
  71505. + return 0;
  71506. +}
  71507. +
  71508. +
  71509. +/**
  71510. + * This function selects transactions from the HCD transfer schedule and
  71511. + * assigns them to available host channels. It is called from HCD interrupt
  71512. + * handler functions.
  71513. + *
  71514. + * @param hcd The HCD state structure.
  71515. + *
  71516. + * @return The types of new transactions that were assigned to host channels.
  71517. + */
  71518. +dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t * hcd)
  71519. +{
  71520. + dwc_list_link_t *qh_ptr;
  71521. + dwc_otg_qh_t *qh;
  71522. + int num_channels;
  71523. + dwc_irqflags_t flags;
  71524. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  71525. + dwc_otg_transaction_type_e ret_val = DWC_OTG_TRANSACTION_NONE;
  71526. +
  71527. +#ifdef DEBUG_HOST_CHANNELS
  71528. + last_sel_trans_num_per_scheduled = 0;
  71529. + last_sel_trans_num_nonper_scheduled = 0;
  71530. + last_sel_trans_num_avail_hc_at_start = hcd->available_host_channels;
  71531. +#endif /* DEBUG_HOST_CHANNELS */
  71532. +
  71533. + /* Process entries in the periodic ready list. */
  71534. + qh_ptr = DWC_LIST_FIRST(&hcd->periodic_sched_ready);
  71535. +
  71536. + while (qh_ptr != &hcd->periodic_sched_ready &&
  71537. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71538. +
  71539. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71540. +
  71541. + if (microframe_schedule) {
  71542. + // Make sure we leave one channel for non periodic transactions.
  71543. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71544. + if (hcd->available_host_channels <= 1) {
  71545. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71546. + break;
  71547. + }
  71548. + hcd->available_host_channels--;
  71549. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71550. +#ifdef DEBUG_HOST_CHANNELS
  71551. + last_sel_trans_num_per_scheduled++;
  71552. +#endif /* DEBUG_HOST_CHANNELS */
  71553. + }
  71554. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71555. + assign_and_init_hc(hcd, qh);
  71556. +
  71557. + /*
  71558. + * Move the QH from the periodic ready schedule to the
  71559. + * periodic assigned schedule.
  71560. + */
  71561. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71562. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71563. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  71564. + &qh->qh_list_entry);
  71565. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71566. + }
  71567. +
  71568. + /*
  71569. + * Process entries in the inactive portion of the non-periodic
  71570. + * schedule. Some free host channels may not be used if they are
  71571. + * reserved for periodic transfers.
  71572. + */
  71573. + qh_ptr = hcd->non_periodic_sched_inactive.next;
  71574. + num_channels = hcd->core_if->core_params->host_channels;
  71575. + while (qh_ptr != &hcd->non_periodic_sched_inactive &&
  71576. + (microframe_schedule || hcd->non_periodic_channels <
  71577. + num_channels - hcd->periodic_channels) &&
  71578. + !DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  71579. +
  71580. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71581. + /*
  71582. + * Check to see if this is a NAK'd retransmit, in which case ignore for retransmission
  71583. + * we hold off on bulk retransmissions to reduce NAK interrupt overhead for full-speed
  71584. + * cheeky devices that just hold off using NAKs
  71585. + */
  71586. + if (nak_holdoff && qh->do_split) {
  71587. + if (qh->nak_frame != 0xffff) {
  71588. + uint16_t next_frame = dwc_frame_num_inc(qh->nak_frame, (qh->ep_type == UE_BULK) ? nak_holdoff : 8);
  71589. + uint16_t frame = dwc_otg_hcd_get_frame_number(hcd);
  71590. + if (dwc_frame_num_le(frame, next_frame)) {
  71591. + if(dwc_frame_num_le(next_frame, hcd->fiq_state->next_sched_frame)) {
  71592. + hcd->fiq_state->next_sched_frame = next_frame;
  71593. + }
  71594. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71595. + continue;
  71596. + } else {
  71597. + qh->nak_frame = 0xFFFF;
  71598. + }
  71599. + }
  71600. + }
  71601. +
  71602. + if (microframe_schedule) {
  71603. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71604. + if (hcd->available_host_channels < 1) {
  71605. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71606. + break;
  71607. + }
  71608. + hcd->available_host_channels--;
  71609. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71610. +#ifdef DEBUG_HOST_CHANNELS
  71611. + last_sel_trans_num_nonper_scheduled++;
  71612. +#endif /* DEBUG_HOST_CHANNELS */
  71613. + }
  71614. +
  71615. + assign_and_init_hc(hcd, qh);
  71616. +
  71617. + /*
  71618. + * Move the QH from the non-periodic inactive schedule to the
  71619. + * non-periodic active schedule.
  71620. + */
  71621. + qh_ptr = DWC_LIST_NEXT(qh_ptr);
  71622. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  71623. + DWC_LIST_MOVE_HEAD(&hcd->non_periodic_sched_active,
  71624. + &qh->qh_list_entry);
  71625. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  71626. +
  71627. +
  71628. + if (!microframe_schedule)
  71629. + hcd->non_periodic_channels++;
  71630. + }
  71631. + /* we moved a non-periodic QH to the active schedule. If the inactive queue is empty,
  71632. + * stop the FIQ from kicking us. We could potentially still have elements here if we
  71633. + * ran out of host channels.
  71634. + */
  71635. + if (fiq_enable) {
  71636. + if (DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive)) {
  71637. + hcd->fiq_state->kick_np_queues = 0;
  71638. + } else {
  71639. + /* For each entry remaining in the NP inactive queue,
  71640. + * if this a NAK'd retransmit then don't set the kick flag.
  71641. + */
  71642. + if(nak_holdoff) {
  71643. + DWC_LIST_FOREACH(qh_ptr, &hcd->non_periodic_sched_inactive) {
  71644. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71645. + if (qh->nak_frame == 0xFFFF) {
  71646. + hcd->fiq_state->kick_np_queues = 1;
  71647. + }
  71648. + }
  71649. + }
  71650. + }
  71651. + }
  71652. + if(!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned))
  71653. + ret_val |= DWC_OTG_TRANSACTION_PERIODIC;
  71654. +
  71655. + if(!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active))
  71656. + ret_val |= DWC_OTG_TRANSACTION_NON_PERIODIC;
  71657. +
  71658. +
  71659. +#ifdef DEBUG_HOST_CHANNELS
  71660. + last_sel_trans_num_avail_hc_at_end = hcd->available_host_channels;
  71661. +#endif /* DEBUG_HOST_CHANNELS */
  71662. + return ret_val;
  71663. +}
  71664. +
  71665. +/**
  71666. + * Attempts to queue a single transaction request for a host channel
  71667. + * associated with either a periodic or non-periodic transfer. This function
  71668. + * assumes that there is space available in the appropriate request queue. For
  71669. + * an OUT transfer or SETUP transaction in Slave mode, it checks whether space
  71670. + * is available in the appropriate Tx FIFO.
  71671. + *
  71672. + * @param hcd The HCD state structure.
  71673. + * @param hc Host channel descriptor associated with either a periodic or
  71674. + * non-periodic transfer.
  71675. + * @param fifo_dwords_avail Number of DWORDs available in the periodic Tx
  71676. + * FIFO for periodic transfers or the non-periodic Tx FIFO for non-periodic
  71677. + * transfers.
  71678. + *
  71679. + * @return 1 if a request is queued and more requests may be needed to
  71680. + * complete the transfer, 0 if no more requests are required for this
  71681. + * transfer, -1 if there is insufficient space in the Tx FIFO.
  71682. + */
  71683. +static int queue_transaction(dwc_otg_hcd_t * hcd,
  71684. + dwc_hc_t * hc, uint16_t fifo_dwords_avail)
  71685. +{
  71686. + int retval;
  71687. +
  71688. + if (hcd->core_if->dma_enable) {
  71689. + if (hcd->core_if->dma_desc_enable) {
  71690. + if (!hc->xfer_started
  71691. + || (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)) {
  71692. + dwc_otg_hcd_start_xfer_ddma(hcd, hc->qh);
  71693. + hc->qh->ping_state = 0;
  71694. + }
  71695. + } else if (!hc->xfer_started) {
  71696. + if (fiq_fsm_enable && hc->error_state) {
  71697. + hcd->fiq_state->channel[hc->hc_num].nr_errors =
  71698. + DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list)->error_count;
  71699. + hcd->fiq_state->channel[hc->hc_num].fsm =
  71700. + FIQ_PASSTHROUGH_ERRORSTATE;
  71701. + }
  71702. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71703. + hc->qh->ping_state = 0;
  71704. + }
  71705. + retval = 0;
  71706. + } else if (hc->halt_pending) {
  71707. + /* Don't queue a request if the channel has been halted. */
  71708. + retval = 0;
  71709. + } else if (hc->halt_on_queue) {
  71710. + dwc_otg_hc_halt(hcd->core_if, hc, hc->halt_status);
  71711. + retval = 0;
  71712. + } else if (hc->do_ping) {
  71713. + if (!hc->xfer_started) {
  71714. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71715. + }
  71716. + retval = 0;
  71717. + } else if (!hc->ep_is_in || hc->data_pid_start == DWC_OTG_HC_PID_SETUP) {
  71718. + if ((fifo_dwords_avail * 4) >= hc->max_packet) {
  71719. + if (!hc->xfer_started) {
  71720. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71721. + retval = 1;
  71722. + } else {
  71723. + retval =
  71724. + dwc_otg_hc_continue_transfer(hcd->core_if,
  71725. + hc);
  71726. + }
  71727. + } else {
  71728. + retval = -1;
  71729. + }
  71730. + } else {
  71731. + if (!hc->xfer_started) {
  71732. + dwc_otg_hc_start_transfer(hcd->core_if, hc);
  71733. + retval = 1;
  71734. + } else {
  71735. + retval = dwc_otg_hc_continue_transfer(hcd->core_if, hc);
  71736. + }
  71737. + }
  71738. +
  71739. + return retval;
  71740. +}
  71741. +
  71742. +/**
  71743. + * Processes periodic channels for the next frame and queues transactions for
  71744. + * these channels to the DWC_otg controller. After queueing transactions, the
  71745. + * Periodic Tx FIFO Empty interrupt is enabled if there are more transactions
  71746. + * to queue as Periodic Tx FIFO or request queue space becomes available.
  71747. + * Otherwise, the Periodic Tx FIFO Empty interrupt is disabled.
  71748. + */
  71749. +static void process_periodic_channels(dwc_otg_hcd_t * hcd)
  71750. +{
  71751. + hptxsts_data_t tx_status;
  71752. + dwc_list_link_t *qh_ptr;
  71753. + dwc_otg_qh_t *qh;
  71754. + int status = 0;
  71755. + int no_queue_space = 0;
  71756. + int no_fifo_space = 0;
  71757. +
  71758. + dwc_otg_host_global_regs_t *host_regs;
  71759. + host_regs = hcd->core_if->host_if->host_global_regs;
  71760. +
  71761. + DWC_DEBUGPL(DBG_HCDV, "Queue periodic transactions\n");
  71762. +#ifdef DEBUG
  71763. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71764. + DWC_DEBUGPL(DBG_HCDV,
  71765. + " P Tx Req Queue Space Avail (before queue): %d\n",
  71766. + tx_status.b.ptxqspcavail);
  71767. + DWC_DEBUGPL(DBG_HCDV, " P Tx FIFO Space Avail (before queue): %d\n",
  71768. + tx_status.b.ptxfspcavail);
  71769. +#endif
  71770. +
  71771. + qh_ptr = hcd->periodic_sched_assigned.next;
  71772. + while (qh_ptr != &hcd->periodic_sched_assigned) {
  71773. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71774. + if (tx_status.b.ptxqspcavail == 0) {
  71775. + no_queue_space = 1;
  71776. + break;
  71777. + }
  71778. +
  71779. + qh = DWC_LIST_ENTRY(qh_ptr, dwc_otg_qh_t, qh_list_entry);
  71780. +
  71781. + // Do not send a split start transaction any later than frame .6
  71782. + // Note, we have to schedule a periodic in .5 to make it go in .6
  71783. + if(fiq_fsm_enable && qh->do_split && ((dwc_otg_hcd_get_frame_number(hcd) + 1) & 7) > 6)
  71784. + {
  71785. + qh_ptr = qh_ptr->next;
  71786. + hcd->fiq_state->next_sched_frame = dwc_otg_hcd_get_frame_number(hcd) | 7;
  71787. + continue;
  71788. + }
  71789. +
  71790. + if (fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  71791. + if (qh->do_split)
  71792. + fiq_fsm_queue_split_transaction(hcd, qh);
  71793. + else
  71794. + fiq_fsm_queue_isoc_transaction(hcd, qh);
  71795. + } else {
  71796. +
  71797. + /*
  71798. + * Set a flag if we're queueing high-bandwidth in slave mode.
  71799. + * The flag prevents any halts to get into the request queue in
  71800. + * the middle of multiple high-bandwidth packets getting queued.
  71801. + */
  71802. + if (!hcd->core_if->dma_enable && qh->channel->multi_count > 1) {
  71803. + hcd->core_if->queuing_high_bandwidth = 1;
  71804. + }
  71805. + status = queue_transaction(hcd, qh->channel,
  71806. + tx_status.b.ptxfspcavail);
  71807. + if (status < 0) {
  71808. + no_fifo_space = 1;
  71809. + break;
  71810. + }
  71811. + }
  71812. +
  71813. + /*
  71814. + * In Slave mode, stay on the current transfer until there is
  71815. + * nothing more to do or the high-bandwidth request count is
  71816. + * reached. In DMA mode, only need to queue one request. The
  71817. + * controller automatically handles multiple packets for
  71818. + * high-bandwidth transfers.
  71819. + */
  71820. + if (hcd->core_if->dma_enable || status == 0 ||
  71821. + qh->channel->requests == qh->channel->multi_count) {
  71822. + qh_ptr = qh_ptr->next;
  71823. + /*
  71824. + * Move the QH from the periodic assigned schedule to
  71825. + * the periodic queued schedule.
  71826. + */
  71827. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_queued,
  71828. + &qh->qh_list_entry);
  71829. +
  71830. + /* done queuing high bandwidth */
  71831. + hcd->core_if->queuing_high_bandwidth = 0;
  71832. + }
  71833. + }
  71834. +
  71835. + if (!hcd->core_if->dma_enable) {
  71836. + dwc_otg_core_global_regs_t *global_regs;
  71837. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71838. +
  71839. + global_regs = hcd->core_if->core_global_regs;
  71840. + intr_mask.b.ptxfempty = 1;
  71841. +#ifdef DEBUG
  71842. + tx_status.d32 = DWC_READ_REG32(&host_regs->hptxsts);
  71843. + DWC_DEBUGPL(DBG_HCDV,
  71844. + " P Tx Req Queue Space Avail (after queue): %d\n",
  71845. + tx_status.b.ptxqspcavail);
  71846. + DWC_DEBUGPL(DBG_HCDV,
  71847. + " P Tx FIFO Space Avail (after queue): %d\n",
  71848. + tx_status.b.ptxfspcavail);
  71849. +#endif
  71850. + if (!DWC_LIST_EMPTY(&hcd->periodic_sched_assigned) ||
  71851. + no_queue_space || no_fifo_space) {
  71852. + /*
  71853. + * May need to queue more transactions as the request
  71854. + * queue or Tx FIFO empties. Enable the periodic Tx
  71855. + * FIFO empty interrupt. (Always use the half-empty
  71856. + * level to ensure that new requests are loaded as
  71857. + * soon as possible.)
  71858. + */
  71859. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  71860. + intr_mask.d32);
  71861. + } else {
  71862. + /*
  71863. + * Disable the Tx FIFO empty interrupt since there are
  71864. + * no more transactions that need to be queued right
  71865. + * now. This function is called from interrupt
  71866. + * handlers to queue more transactions as transfer
  71867. + * states change.
  71868. + */
  71869. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  71870. + 0);
  71871. + }
  71872. + }
  71873. +}
  71874. +
  71875. +/**
  71876. + * Processes active non-periodic channels and queues transactions for these
  71877. + * channels to the DWC_otg controller. After queueing transactions, the NP Tx
  71878. + * FIFO Empty interrupt is enabled if there are more transactions to queue as
  71879. + * NP Tx FIFO or request queue space becomes available. Otherwise, the NP Tx
  71880. + * FIFO Empty interrupt is disabled.
  71881. + */
  71882. +static void process_non_periodic_channels(dwc_otg_hcd_t * hcd)
  71883. +{
  71884. + gnptxsts_data_t tx_status;
  71885. + dwc_list_link_t *orig_qh_ptr;
  71886. + dwc_otg_qh_t *qh;
  71887. + int status;
  71888. + int no_queue_space = 0;
  71889. + int no_fifo_space = 0;
  71890. + int more_to_do = 0;
  71891. +
  71892. + dwc_otg_core_global_regs_t *global_regs =
  71893. + hcd->core_if->core_global_regs;
  71894. +
  71895. + DWC_DEBUGPL(DBG_HCDV, "Queue non-periodic transactions\n");
  71896. +#ifdef DEBUG
  71897. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71898. + DWC_DEBUGPL(DBG_HCDV,
  71899. + " NP Tx Req Queue Space Avail (before queue): %d\n",
  71900. + tx_status.b.nptxqspcavail);
  71901. + DWC_DEBUGPL(DBG_HCDV, " NP Tx FIFO Space Avail (before queue): %d\n",
  71902. + tx_status.b.nptxfspcavail);
  71903. +#endif
  71904. + /*
  71905. + * Keep track of the starting point. Skip over the start-of-list
  71906. + * entry.
  71907. + */
  71908. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  71909. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  71910. + }
  71911. + orig_qh_ptr = hcd->non_periodic_qh_ptr;
  71912. +
  71913. + /*
  71914. + * Process once through the active list or until no more space is
  71915. + * available in the request queue or the Tx FIFO.
  71916. + */
  71917. + do {
  71918. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71919. + if (!hcd->core_if->dma_enable && tx_status.b.nptxqspcavail == 0) {
  71920. + no_queue_space = 1;
  71921. + break;
  71922. + }
  71923. +
  71924. + qh = DWC_LIST_ENTRY(hcd->non_periodic_qh_ptr, dwc_otg_qh_t,
  71925. + qh_list_entry);
  71926. +
  71927. + if(fiq_fsm_enable && fiq_fsm_transaction_suitable(qh)) {
  71928. + fiq_fsm_queue_split_transaction(hcd, qh);
  71929. + } else {
  71930. + status = queue_transaction(hcd, qh->channel,
  71931. + tx_status.b.nptxfspcavail);
  71932. +
  71933. + if (status > 0) {
  71934. + more_to_do = 1;
  71935. + } else if (status < 0) {
  71936. + no_fifo_space = 1;
  71937. + break;
  71938. + }
  71939. + }
  71940. + /* Advance to next QH, skipping start-of-list entry. */
  71941. + hcd->non_periodic_qh_ptr = hcd->non_periodic_qh_ptr->next;
  71942. + if (hcd->non_periodic_qh_ptr == &hcd->non_periodic_sched_active) {
  71943. + hcd->non_periodic_qh_ptr =
  71944. + hcd->non_periodic_qh_ptr->next;
  71945. + }
  71946. +
  71947. + } while (hcd->non_periodic_qh_ptr != orig_qh_ptr);
  71948. +
  71949. + if (!hcd->core_if->dma_enable) {
  71950. + gintmsk_data_t intr_mask = {.d32 = 0 };
  71951. + intr_mask.b.nptxfempty = 1;
  71952. +
  71953. +#ifdef DEBUG
  71954. + tx_status.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  71955. + DWC_DEBUGPL(DBG_HCDV,
  71956. + " NP Tx Req Queue Space Avail (after queue): %d\n",
  71957. + tx_status.b.nptxqspcavail);
  71958. + DWC_DEBUGPL(DBG_HCDV,
  71959. + " NP Tx FIFO Space Avail (after queue): %d\n",
  71960. + tx_status.b.nptxfspcavail);
  71961. +#endif
  71962. + if (more_to_do || no_queue_space || no_fifo_space) {
  71963. + /*
  71964. + * May need to queue more transactions as the request
  71965. + * queue or Tx FIFO empties. Enable the non-periodic
  71966. + * Tx FIFO empty interrupt. (Always use the half-empty
  71967. + * level to ensure that new requests are loaded as
  71968. + * soon as possible.)
  71969. + */
  71970. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0,
  71971. + intr_mask.d32);
  71972. + } else {
  71973. + /*
  71974. + * Disable the Tx FIFO empty interrupt since there are
  71975. + * no more transactions that need to be queued right
  71976. + * now. This function is called from interrupt
  71977. + * handlers to queue more transactions as transfer
  71978. + * states change.
  71979. + */
  71980. + DWC_MODIFY_REG32(&global_regs->gintmsk, intr_mask.d32,
  71981. + 0);
  71982. + }
  71983. + }
  71984. +}
  71985. +
  71986. +/**
  71987. + * This function processes the currently active host channels and queues
  71988. + * transactions for these channels to the DWC_otg controller. It is called
  71989. + * from HCD interrupt handler functions.
  71990. + *
  71991. + * @param hcd The HCD state structure.
  71992. + * @param tr_type The type(s) of transactions to queue (non-periodic,
  71993. + * periodic, or both).
  71994. + */
  71995. +void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  71996. + dwc_otg_transaction_type_e tr_type)
  71997. +{
  71998. +#ifdef DEBUG_SOF
  71999. + DWC_DEBUGPL(DBG_HCD, "Queue Transactions\n");
  72000. +#endif
  72001. + /* Process host channels associated with periodic transfers. */
  72002. + if ((tr_type == DWC_OTG_TRANSACTION_PERIODIC ||
  72003. + tr_type == DWC_OTG_TRANSACTION_ALL) &&
  72004. + !DWC_LIST_EMPTY(&hcd->periodic_sched_assigned)) {
  72005. +
  72006. + process_periodic_channels(hcd);
  72007. + }
  72008. +
  72009. + /* Process host channels associated with non-periodic transfers. */
  72010. + if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC ||
  72011. + tr_type == DWC_OTG_TRANSACTION_ALL) {
  72012. + if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_active)) {
  72013. + process_non_periodic_channels(hcd);
  72014. + } else {
  72015. + /*
  72016. + * Ensure NP Tx FIFO empty interrupt is disabled when
  72017. + * there are no non-periodic transfers to process.
  72018. + */
  72019. + gintmsk_data_t gintmsk = {.d32 = 0 };
  72020. + gintmsk.b.nptxfempty = 1;
  72021. + DWC_MODIFY_REG32(&hcd->core_if->
  72022. + core_global_regs->gintmsk, gintmsk.d32,
  72023. + 0);
  72024. + }
  72025. + }
  72026. +}
  72027. +
  72028. +#ifdef DWC_HS_ELECT_TST
  72029. +/*
  72030. + * Quick and dirty hack to implement the HS Electrical Test
  72031. + * SINGLE_STEP_GET_DEVICE_DESCRIPTOR feature.
  72032. + *
  72033. + * This code was copied from our userspace app "hset". It sends a
  72034. + * Get Device Descriptor control sequence in two parts, first the
  72035. + * Setup packet by itself, followed some time later by the In and
  72036. + * Ack packets. Rather than trying to figure out how to add this
  72037. + * functionality to the normal driver code, we just hijack the
  72038. + * hardware, using these two function to drive the hardware
  72039. + * directly.
  72040. + */
  72041. +
  72042. +static dwc_otg_core_global_regs_t *global_regs;
  72043. +static dwc_otg_host_global_regs_t *hc_global_regs;
  72044. +static dwc_otg_hc_regs_t *hc_regs;
  72045. +static uint32_t *data_fifo;
  72046. +
  72047. +static void do_setup(void)
  72048. +{
  72049. + gintsts_data_t gintsts;
  72050. + hctsiz_data_t hctsiz;
  72051. + hcchar_data_t hcchar;
  72052. + haint_data_t haint;
  72053. + hcint_data_t hcint;
  72054. +
  72055. + /* Enable HAINTs */
  72056. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  72057. +
  72058. + /* Enable HCINTs */
  72059. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  72060. +
  72061. + /* Read GINTSTS */
  72062. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72063. +
  72064. + /* Read HAINT */
  72065. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72066. +
  72067. + /* Read HCINT */
  72068. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72069. +
  72070. + /* Read HCCHAR */
  72071. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72072. +
  72073. + /* Clear HCINT */
  72074. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72075. +
  72076. + /* Clear HAINT */
  72077. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72078. +
  72079. + /* Clear GINTSTS */
  72080. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72081. +
  72082. + /* Read GINTSTS */
  72083. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72084. +
  72085. + /*
  72086. + * Send Setup packet (Get Device Descriptor)
  72087. + */
  72088. +
  72089. + /* Make sure channel is disabled */
  72090. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72091. + if (hcchar.b.chen) {
  72092. + hcchar.b.chdis = 1;
  72093. +// hcchar.b.chen = 1;
  72094. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72095. + //sleep(1);
  72096. + dwc_mdelay(1000);
  72097. +
  72098. + /* Read GINTSTS */
  72099. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72100. +
  72101. + /* Read HAINT */
  72102. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72103. +
  72104. + /* Read HCINT */
  72105. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72106. +
  72107. + /* Read HCCHAR */
  72108. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72109. +
  72110. + /* Clear HCINT */
  72111. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72112. +
  72113. + /* Clear HAINT */
  72114. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72115. +
  72116. + /* Clear GINTSTS */
  72117. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72118. +
  72119. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72120. + }
  72121. +
  72122. + /* Set HCTSIZ */
  72123. + hctsiz.d32 = 0;
  72124. + hctsiz.b.xfersize = 8;
  72125. + hctsiz.b.pktcnt = 1;
  72126. + hctsiz.b.pid = DWC_OTG_HC_PID_SETUP;
  72127. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72128. +
  72129. + /* Set HCCHAR */
  72130. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72131. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72132. + hcchar.b.epdir = 0;
  72133. + hcchar.b.epnum = 0;
  72134. + hcchar.b.mps = 8;
  72135. + hcchar.b.chen = 1;
  72136. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72137. +
  72138. + /* Fill FIFO with Setup data for Get Device Descriptor */
  72139. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  72140. + DWC_WRITE_REG32(data_fifo++, 0x01000680);
  72141. + DWC_WRITE_REG32(data_fifo++, 0x00080000);
  72142. +
  72143. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72144. +
  72145. + /* Wait for host channel interrupt */
  72146. + do {
  72147. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72148. + } while (gintsts.b.hcintr == 0);
  72149. +
  72150. + /* Disable HCINTs */
  72151. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  72152. +
  72153. + /* Disable HAINTs */
  72154. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  72155. +
  72156. + /* Read HAINT */
  72157. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72158. +
  72159. + /* Read HCINT */
  72160. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72161. +
  72162. + /* Read HCCHAR */
  72163. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72164. +
  72165. + /* Clear HCINT */
  72166. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72167. +
  72168. + /* Clear HAINT */
  72169. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72170. +
  72171. + /* Clear GINTSTS */
  72172. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72173. +
  72174. + /* Read GINTSTS */
  72175. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72176. +}
  72177. +
  72178. +static void do_in_ack(void)
  72179. +{
  72180. + gintsts_data_t gintsts;
  72181. + hctsiz_data_t hctsiz;
  72182. + hcchar_data_t hcchar;
  72183. + haint_data_t haint;
  72184. + hcint_data_t hcint;
  72185. + host_grxsts_data_t grxsts;
  72186. +
  72187. + /* Enable HAINTs */
  72188. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0001);
  72189. +
  72190. + /* Enable HCINTs */
  72191. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x04a3);
  72192. +
  72193. + /* Read GINTSTS */
  72194. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72195. +
  72196. + /* Read HAINT */
  72197. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72198. +
  72199. + /* Read HCINT */
  72200. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72201. +
  72202. + /* Read HCCHAR */
  72203. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72204. +
  72205. + /* Clear HCINT */
  72206. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72207. +
  72208. + /* Clear HAINT */
  72209. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72210. +
  72211. + /* Clear GINTSTS */
  72212. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72213. +
  72214. + /* Read GINTSTS */
  72215. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72216. +
  72217. + /*
  72218. + * Receive Control In packet
  72219. + */
  72220. +
  72221. + /* Make sure channel is disabled */
  72222. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72223. + if (hcchar.b.chen) {
  72224. + hcchar.b.chdis = 1;
  72225. + hcchar.b.chen = 1;
  72226. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72227. + //sleep(1);
  72228. + dwc_mdelay(1000);
  72229. +
  72230. + /* Read GINTSTS */
  72231. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72232. +
  72233. + /* Read HAINT */
  72234. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72235. +
  72236. + /* Read HCINT */
  72237. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72238. +
  72239. + /* Read HCCHAR */
  72240. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72241. +
  72242. + /* Clear HCINT */
  72243. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72244. +
  72245. + /* Clear HAINT */
  72246. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72247. +
  72248. + /* Clear GINTSTS */
  72249. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72250. +
  72251. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72252. + }
  72253. +
  72254. + /* Set HCTSIZ */
  72255. + hctsiz.d32 = 0;
  72256. + hctsiz.b.xfersize = 8;
  72257. + hctsiz.b.pktcnt = 1;
  72258. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  72259. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72260. +
  72261. + /* Set HCCHAR */
  72262. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72263. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72264. + hcchar.b.epdir = 1;
  72265. + hcchar.b.epnum = 0;
  72266. + hcchar.b.mps = 8;
  72267. + hcchar.b.chen = 1;
  72268. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72269. +
  72270. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72271. +
  72272. + /* Wait for receive status queue interrupt */
  72273. + do {
  72274. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72275. + } while (gintsts.b.rxstsqlvl == 0);
  72276. +
  72277. + /* Read RXSTS */
  72278. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  72279. +
  72280. + /* Clear RXSTSQLVL in GINTSTS */
  72281. + gintsts.d32 = 0;
  72282. + gintsts.b.rxstsqlvl = 1;
  72283. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72284. +
  72285. + switch (grxsts.b.pktsts) {
  72286. + case DWC_GRXSTS_PKTSTS_IN:
  72287. + /* Read the data into the host buffer */
  72288. + if (grxsts.b.bcnt > 0) {
  72289. + int i;
  72290. + int word_count = (grxsts.b.bcnt + 3) / 4;
  72291. +
  72292. + data_fifo = (uint32_t *) ((char *)global_regs + 0x1000);
  72293. +
  72294. + for (i = 0; i < word_count; i++) {
  72295. + (void)DWC_READ_REG32(data_fifo++);
  72296. + }
  72297. + }
  72298. + break;
  72299. +
  72300. + default:
  72301. + break;
  72302. + }
  72303. +
  72304. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72305. +
  72306. + /* Wait for receive status queue interrupt */
  72307. + do {
  72308. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72309. + } while (gintsts.b.rxstsqlvl == 0);
  72310. +
  72311. + /* Read RXSTS */
  72312. + grxsts.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  72313. +
  72314. + /* Clear RXSTSQLVL in GINTSTS */
  72315. + gintsts.d32 = 0;
  72316. + gintsts.b.rxstsqlvl = 1;
  72317. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72318. +
  72319. + switch (grxsts.b.pktsts) {
  72320. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  72321. + break;
  72322. +
  72323. + default:
  72324. + break;
  72325. + }
  72326. +
  72327. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72328. +
  72329. + /* Wait for host channel interrupt */
  72330. + do {
  72331. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72332. + } while (gintsts.b.hcintr == 0);
  72333. +
  72334. + /* Read HAINT */
  72335. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72336. +
  72337. + /* Read HCINT */
  72338. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72339. +
  72340. + /* Read HCCHAR */
  72341. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72342. +
  72343. + /* Clear HCINT */
  72344. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72345. +
  72346. + /* Clear HAINT */
  72347. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72348. +
  72349. + /* Clear GINTSTS */
  72350. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72351. +
  72352. + /* Read GINTSTS */
  72353. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72354. +
  72355. +// usleep(100000);
  72356. +// mdelay(100);
  72357. + dwc_mdelay(1);
  72358. +
  72359. + /*
  72360. + * Send handshake packet
  72361. + */
  72362. +
  72363. + /* Read HAINT */
  72364. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72365. +
  72366. + /* Read HCINT */
  72367. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72368. +
  72369. + /* Read HCCHAR */
  72370. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72371. +
  72372. + /* Clear HCINT */
  72373. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72374. +
  72375. + /* Clear HAINT */
  72376. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72377. +
  72378. + /* Clear GINTSTS */
  72379. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72380. +
  72381. + /* Read GINTSTS */
  72382. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72383. +
  72384. + /* Make sure channel is disabled */
  72385. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72386. + if (hcchar.b.chen) {
  72387. + hcchar.b.chdis = 1;
  72388. + hcchar.b.chen = 1;
  72389. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72390. + //sleep(1);
  72391. + dwc_mdelay(1000);
  72392. +
  72393. + /* Read GINTSTS */
  72394. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72395. +
  72396. + /* Read HAINT */
  72397. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72398. +
  72399. + /* Read HCINT */
  72400. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72401. +
  72402. + /* Read HCCHAR */
  72403. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72404. +
  72405. + /* Clear HCINT */
  72406. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72407. +
  72408. + /* Clear HAINT */
  72409. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72410. +
  72411. + /* Clear GINTSTS */
  72412. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72413. +
  72414. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72415. + }
  72416. +
  72417. + /* Set HCTSIZ */
  72418. + hctsiz.d32 = 0;
  72419. + hctsiz.b.xfersize = 0;
  72420. + hctsiz.b.pktcnt = 1;
  72421. + hctsiz.b.pid = DWC_OTG_HC_PID_DATA1;
  72422. + DWC_WRITE_REG32(&hc_regs->hctsiz, hctsiz.d32);
  72423. +
  72424. + /* Set HCCHAR */
  72425. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72426. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  72427. + hcchar.b.epdir = 0;
  72428. + hcchar.b.epnum = 0;
  72429. + hcchar.b.mps = 8;
  72430. + hcchar.b.chen = 1;
  72431. + DWC_WRITE_REG32(&hc_regs->hcchar, hcchar.d32);
  72432. +
  72433. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72434. +
  72435. + /* Wait for host channel interrupt */
  72436. + do {
  72437. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72438. + } while (gintsts.b.hcintr == 0);
  72439. +
  72440. + /* Disable HCINTs */
  72441. + DWC_WRITE_REG32(&hc_regs->hcintmsk, 0x0000);
  72442. +
  72443. + /* Disable HAINTs */
  72444. + DWC_WRITE_REG32(&hc_global_regs->haintmsk, 0x0000);
  72445. +
  72446. + /* Read HAINT */
  72447. + haint.d32 = DWC_READ_REG32(&hc_global_regs->haint);
  72448. +
  72449. + /* Read HCINT */
  72450. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  72451. +
  72452. + /* Read HCCHAR */
  72453. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  72454. +
  72455. + /* Clear HCINT */
  72456. + DWC_WRITE_REG32(&hc_regs->hcint, hcint.d32);
  72457. +
  72458. + /* Clear HAINT */
  72459. + DWC_WRITE_REG32(&hc_global_regs->haint, haint.d32);
  72460. +
  72461. + /* Clear GINTSTS */
  72462. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  72463. +
  72464. + /* Read GINTSTS */
  72465. + gintsts.d32 = DWC_READ_REG32(&global_regs->gintsts);
  72466. +}
  72467. +#endif
  72468. +
  72469. +/** Handles hub class-specific requests. */
  72470. +int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  72471. + uint16_t typeReq,
  72472. + uint16_t wValue,
  72473. + uint16_t wIndex, uint8_t * buf, uint16_t wLength)
  72474. +{
  72475. + int retval = 0;
  72476. +
  72477. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  72478. + usb_hub_descriptor_t *hub_desc;
  72479. + hprt0_data_t hprt0 = {.d32 = 0 };
  72480. +
  72481. + uint32_t port_status;
  72482. +
  72483. + switch (typeReq) {
  72484. + case UCR_CLEAR_HUB_FEATURE:
  72485. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72486. + "ClearHubFeature 0x%x\n", wValue);
  72487. + switch (wValue) {
  72488. + case UHF_C_HUB_LOCAL_POWER:
  72489. + case UHF_C_HUB_OVER_CURRENT:
  72490. + /* Nothing required here */
  72491. + break;
  72492. + default:
  72493. + retval = -DWC_E_INVALID;
  72494. + DWC_ERROR("DWC OTG HCD - "
  72495. + "ClearHubFeature request %xh unknown\n",
  72496. + wValue);
  72497. + }
  72498. + break;
  72499. + case UCR_CLEAR_PORT_FEATURE:
  72500. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72501. + if (wValue != UHF_PORT_L1)
  72502. +#endif
  72503. + if (!wIndex || wIndex > 1)
  72504. + goto error;
  72505. +
  72506. + switch (wValue) {
  72507. + case UHF_PORT_ENABLE:
  72508. + DWC_DEBUGPL(DBG_ANY, "DWC OTG HCD HUB CONTROL - "
  72509. + "ClearPortFeature USB_PORT_FEAT_ENABLE\n");
  72510. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72511. + hprt0.b.prtena = 1;
  72512. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72513. + break;
  72514. + case UHF_PORT_SUSPEND:
  72515. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72516. + "ClearPortFeature USB_PORT_FEAT_SUSPEND\n");
  72517. +
  72518. + if (core_if->power_down == 2) {
  72519. + dwc_otg_host_hibernation_restore(core_if, 0, 0);
  72520. + } else {
  72521. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72522. + dwc_mdelay(5);
  72523. +
  72524. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72525. + hprt0.b.prtres = 1;
  72526. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72527. + hprt0.b.prtsusp = 0;
  72528. + /* Clear Resume bit */
  72529. + dwc_mdelay(100);
  72530. + hprt0.b.prtres = 0;
  72531. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72532. + }
  72533. + break;
  72534. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72535. + case UHF_PORT_L1:
  72536. + {
  72537. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72538. + glpmcfg_data_t lpmcfg = {.d32 = 0 };
  72539. +
  72540. + lpmcfg.d32 =
  72541. + DWC_READ_REG32(&core_if->
  72542. + core_global_regs->glpmcfg);
  72543. + lpmcfg.b.en_utmi_sleep = 0;
  72544. + lpmcfg.b.hird_thres &= (~(1 << 4));
  72545. + lpmcfg.b.prt_sleep_sts = 1;
  72546. + DWC_WRITE_REG32(&core_if->
  72547. + core_global_regs->glpmcfg,
  72548. + lpmcfg.d32);
  72549. +
  72550. + /* Clear Enbl_L1Gating bit. */
  72551. + pcgcctl.b.enbl_sleep_gating = 1;
  72552. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32,
  72553. + 0);
  72554. +
  72555. + dwc_mdelay(5);
  72556. +
  72557. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72558. + hprt0.b.prtres = 1;
  72559. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  72560. + hprt0.d32);
  72561. + /* This bit will be cleared in wakeup interrupt handle */
  72562. + break;
  72563. + }
  72564. +#endif
  72565. + case UHF_PORT_POWER:
  72566. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72567. + "ClearPortFeature USB_PORT_FEAT_POWER\n");
  72568. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72569. + hprt0.b.prtpwr = 0;
  72570. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72571. + break;
  72572. + case UHF_PORT_INDICATOR:
  72573. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72574. + "ClearPortFeature USB_PORT_FEAT_INDICATOR\n");
  72575. + /* Port inidicator not supported */
  72576. + break;
  72577. + case UHF_C_PORT_CONNECTION:
  72578. + /* Clears drivers internal connect status change
  72579. + * flag */
  72580. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72581. + "ClearPortFeature USB_PORT_FEAT_C_CONNECTION\n");
  72582. + dwc_otg_hcd->flags.b.port_connect_status_change = 0;
  72583. + break;
  72584. + case UHF_C_PORT_RESET:
  72585. + /* Clears the driver's internal Port Reset Change
  72586. + * flag */
  72587. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72588. + "ClearPortFeature USB_PORT_FEAT_C_RESET\n");
  72589. + dwc_otg_hcd->flags.b.port_reset_change = 0;
  72590. + break;
  72591. + case UHF_C_PORT_ENABLE:
  72592. + /* Clears the driver's internal Port
  72593. + * Enable/Disable Change flag */
  72594. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72595. + "ClearPortFeature USB_PORT_FEAT_C_ENABLE\n");
  72596. + dwc_otg_hcd->flags.b.port_enable_change = 0;
  72597. + break;
  72598. + case UHF_C_PORT_SUSPEND:
  72599. + /* Clears the driver's internal Port Suspend
  72600. + * Change flag, which is set when resume signaling on
  72601. + * the host port is complete */
  72602. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72603. + "ClearPortFeature USB_PORT_FEAT_C_SUSPEND\n");
  72604. + dwc_otg_hcd->flags.b.port_suspend_change = 0;
  72605. + break;
  72606. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72607. + case UHF_C_PORT_L1:
  72608. + dwc_otg_hcd->flags.b.port_l1_change = 0;
  72609. + break;
  72610. +#endif
  72611. + case UHF_C_PORT_OVER_CURRENT:
  72612. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72613. + "ClearPortFeature USB_PORT_FEAT_C_OVER_CURRENT\n");
  72614. + dwc_otg_hcd->flags.b.port_over_current_change = 0;
  72615. + break;
  72616. + default:
  72617. + retval = -DWC_E_INVALID;
  72618. + DWC_ERROR("DWC OTG HCD - "
  72619. + "ClearPortFeature request %xh "
  72620. + "unknown or unsupported\n", wValue);
  72621. + }
  72622. + break;
  72623. + case UCR_GET_HUB_DESCRIPTOR:
  72624. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72625. + "GetHubDescriptor\n");
  72626. + hub_desc = (usb_hub_descriptor_t *) buf;
  72627. + hub_desc->bDescLength = 9;
  72628. + hub_desc->bDescriptorType = 0x29;
  72629. + hub_desc->bNbrPorts = 1;
  72630. + USETW(hub_desc->wHubCharacteristics, 0x08);
  72631. + hub_desc->bPwrOn2PwrGood = 1;
  72632. + hub_desc->bHubContrCurrent = 0;
  72633. + hub_desc->DeviceRemovable[0] = 0;
  72634. + hub_desc->DeviceRemovable[1] = 0xff;
  72635. + break;
  72636. + case UCR_GET_HUB_STATUS:
  72637. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72638. + "GetHubStatus\n");
  72639. + DWC_MEMSET(buf, 0, 4);
  72640. + break;
  72641. + case UCR_GET_PORT_STATUS:
  72642. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72643. + "GetPortStatus wIndex = 0x%04x FLAGS=0x%08x\n",
  72644. + wIndex, dwc_otg_hcd->flags.d32);
  72645. + if (!wIndex || wIndex > 1)
  72646. + goto error;
  72647. +
  72648. + port_status = 0;
  72649. +
  72650. + if (dwc_otg_hcd->flags.b.port_connect_status_change)
  72651. + port_status |= (1 << UHF_C_PORT_CONNECTION);
  72652. +
  72653. + if (dwc_otg_hcd->flags.b.port_enable_change)
  72654. + port_status |= (1 << UHF_C_PORT_ENABLE);
  72655. +
  72656. + if (dwc_otg_hcd->flags.b.port_suspend_change)
  72657. + port_status |= (1 << UHF_C_PORT_SUSPEND);
  72658. +
  72659. + if (dwc_otg_hcd->flags.b.port_l1_change)
  72660. + port_status |= (1 << UHF_C_PORT_L1);
  72661. +
  72662. + if (dwc_otg_hcd->flags.b.port_reset_change) {
  72663. + port_status |= (1 << UHF_C_PORT_RESET);
  72664. + }
  72665. +
  72666. + if (dwc_otg_hcd->flags.b.port_over_current_change) {
  72667. + DWC_WARN("Overcurrent change detected\n");
  72668. + port_status |= (1 << UHF_C_PORT_OVER_CURRENT);
  72669. + }
  72670. +
  72671. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  72672. + /*
  72673. + * The port is disconnected, which means the core is
  72674. + * either in device mode or it soon will be. Just
  72675. + * return 0's for the remainder of the port status
  72676. + * since the port register can't be read if the core
  72677. + * is in device mode.
  72678. + */
  72679. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  72680. + break;
  72681. + }
  72682. +
  72683. + hprt0.d32 = DWC_READ_REG32(core_if->host_if->hprt0);
  72684. + DWC_DEBUGPL(DBG_HCDV, " HPRT0: 0x%08x\n", hprt0.d32);
  72685. +
  72686. + if (hprt0.b.prtconnsts)
  72687. + port_status |= (1 << UHF_PORT_CONNECTION);
  72688. +
  72689. + if (hprt0.b.prtena)
  72690. + port_status |= (1 << UHF_PORT_ENABLE);
  72691. +
  72692. + if (hprt0.b.prtsusp)
  72693. + port_status |= (1 << UHF_PORT_SUSPEND);
  72694. +
  72695. + if (hprt0.b.prtovrcurract)
  72696. + port_status |= (1 << UHF_PORT_OVER_CURRENT);
  72697. +
  72698. + if (hprt0.b.prtrst)
  72699. + port_status |= (1 << UHF_PORT_RESET);
  72700. +
  72701. + if (hprt0.b.prtpwr)
  72702. + port_status |= (1 << UHF_PORT_POWER);
  72703. +
  72704. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  72705. + port_status |= (1 << UHF_PORT_HIGH_SPEED);
  72706. + else if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED)
  72707. + port_status |= (1 << UHF_PORT_LOW_SPEED);
  72708. +
  72709. + if (hprt0.b.prttstctl)
  72710. + port_status |= (1 << UHF_PORT_TEST);
  72711. + if (dwc_otg_get_lpm_portsleepstatus(dwc_otg_hcd->core_if)) {
  72712. + port_status |= (1 << UHF_PORT_L1);
  72713. + }
  72714. + /*
  72715. + For Synopsys HW emulation of Power down wkup_control asserts the
  72716. + hreset_n and prst_n on suspned. This causes the HPRT0 to be zero.
  72717. + We intentionally tell the software that port is in L2Suspend state.
  72718. + Only for STE.
  72719. + */
  72720. + if ((core_if->power_down == 2)
  72721. + && (core_if->hibernation_suspend == 1)) {
  72722. + port_status |= (1 << UHF_PORT_SUSPEND);
  72723. + }
  72724. + /* USB_PORT_FEAT_INDICATOR unsupported always 0 */
  72725. +
  72726. + *((__le32 *) buf) = dwc_cpu_to_le32(&port_status);
  72727. +
  72728. + break;
  72729. + case UCR_SET_HUB_FEATURE:
  72730. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72731. + "SetHubFeature\n");
  72732. + /* No HUB features supported */
  72733. + break;
  72734. + case UCR_SET_PORT_FEATURE:
  72735. + if (wValue != UHF_PORT_TEST && (!wIndex || wIndex > 1))
  72736. + goto error;
  72737. +
  72738. + if (!dwc_otg_hcd->flags.b.port_connect_status) {
  72739. + /*
  72740. + * The port is disconnected, which means the core is
  72741. + * either in device mode or it soon will be. Just
  72742. + * return without doing anything since the port
  72743. + * register can't be written if the core is in device
  72744. + * mode.
  72745. + */
  72746. + break;
  72747. + }
  72748. +
  72749. + switch (wValue) {
  72750. + case UHF_PORT_SUSPEND:
  72751. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72752. + "SetPortFeature - USB_PORT_FEAT_SUSPEND\n");
  72753. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) != wIndex) {
  72754. + goto error;
  72755. + }
  72756. + if (core_if->power_down == 2) {
  72757. + int timeout = 300;
  72758. + dwc_irqflags_t flags;
  72759. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72760. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  72761. + gusbcfg_data_t gusbcfg = {.d32 = 0 };
  72762. +#ifdef DWC_DEV_SRPCAP
  72763. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  72764. +#endif
  72765. + DWC_PRINTF("Preparing for complete power-off\n");
  72766. +
  72767. + /* Save registers before hibernation */
  72768. + dwc_otg_save_global_regs(core_if);
  72769. + dwc_otg_save_host_regs(core_if);
  72770. +
  72771. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72772. + hprt0.b.prtsusp = 1;
  72773. + hprt0.b.prtena = 0;
  72774. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72775. + /* Spin hprt0.b.prtsusp to became 1 */
  72776. + do {
  72777. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72778. + if (hprt0.b.prtsusp) {
  72779. + break;
  72780. + }
  72781. + dwc_mdelay(1);
  72782. + } while (--timeout);
  72783. + if (!timeout) {
  72784. + DWC_WARN("Suspend wasn't genereted\n");
  72785. + }
  72786. + dwc_udelay(10);
  72787. +
  72788. + /*
  72789. + * We need to disable interrupts to prevent servicing of any IRQ
  72790. + * during going to hibernation
  72791. + */
  72792. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  72793. + core_if->lx_state = DWC_OTG_L2;
  72794. +#ifdef DWC_DEV_SRPCAP
  72795. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72796. + hprt0.b.prtpwr = 0;
  72797. + hprt0.b.prtena = 0;
  72798. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  72799. + hprt0.d32);
  72800. +#endif
  72801. + gusbcfg.d32 =
  72802. + DWC_READ_REG32(&core_if->core_global_regs->
  72803. + gusbcfg);
  72804. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  72805. + /* ULPI interface */
  72806. + /* Suspend the Phy Clock */
  72807. + pcgcctl.d32 = 0;
  72808. + pcgcctl.b.stoppclk = 1;
  72809. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  72810. + pcgcctl.d32);
  72811. + dwc_udelay(10);
  72812. + gpwrdn.b.pmuactv = 1;
  72813. + DWC_MODIFY_REG32(&core_if->
  72814. + core_global_regs->
  72815. + gpwrdn, 0, gpwrdn.d32);
  72816. + } else {
  72817. + /* UTMI+ Interface */
  72818. + gpwrdn.b.pmuactv = 1;
  72819. + DWC_MODIFY_REG32(&core_if->
  72820. + core_global_regs->
  72821. + gpwrdn, 0, gpwrdn.d32);
  72822. + dwc_udelay(10);
  72823. + pcgcctl.b.stoppclk = 1;
  72824. + DWC_MODIFY_REG32(core_if->pcgcctl, 0, pcgcctl.d32);
  72825. + dwc_udelay(10);
  72826. + }
  72827. +#ifdef DWC_DEV_SRPCAP
  72828. + gpwrdn.d32 = 0;
  72829. + gpwrdn.b.dis_vbus = 1;
  72830. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72831. + gpwrdn, 0, gpwrdn.d32);
  72832. +#endif
  72833. + gpwrdn.d32 = 0;
  72834. + gpwrdn.b.pmuintsel = 1;
  72835. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72836. + gpwrdn, 0, gpwrdn.d32);
  72837. + dwc_udelay(10);
  72838. +
  72839. + gpwrdn.d32 = 0;
  72840. +#ifdef DWC_DEV_SRPCAP
  72841. + gpwrdn.b.srp_det_msk = 1;
  72842. +#endif
  72843. + gpwrdn.b.disconn_det_msk = 1;
  72844. + gpwrdn.b.lnstchng_msk = 1;
  72845. + gpwrdn.b.sts_chngint_msk = 1;
  72846. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72847. + gpwrdn, 0, gpwrdn.d32);
  72848. + dwc_udelay(10);
  72849. +
  72850. + /* Enable Power Down Clamp and all interrupts in GPWRDN */
  72851. + gpwrdn.d32 = 0;
  72852. + gpwrdn.b.pwrdnclmp = 1;
  72853. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72854. + gpwrdn, 0, gpwrdn.d32);
  72855. + dwc_udelay(10);
  72856. +
  72857. + /* Switch off VDD */
  72858. + gpwrdn.d32 = 0;
  72859. + gpwrdn.b.pwrdnswtch = 1;
  72860. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72861. + gpwrdn, 0, gpwrdn.d32);
  72862. +
  72863. +#ifdef DWC_DEV_SRPCAP
  72864. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE)
  72865. + {
  72866. + core_if->pwron_timer_started = 1;
  72867. + DWC_TIMER_SCHEDULE(core_if->pwron_timer, 6000 /* 6 secs */ );
  72868. + }
  72869. +#endif
  72870. + /* Save gpwrdn register for further usage if stschng interrupt */
  72871. + core_if->gr_backup->gpwrdn_local =
  72872. + DWC_READ_REG32(&core_if->core_global_regs->gpwrdn);
  72873. +
  72874. + /* Set flag to indicate that we are in hibernation */
  72875. + core_if->hibernation_suspend = 1;
  72876. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock,flags);
  72877. +
  72878. + DWC_PRINTF("Host hibernation completed\n");
  72879. + // Exit from case statement
  72880. + break;
  72881. +
  72882. + }
  72883. + if (dwc_otg_hcd_otg_port(dwc_otg_hcd) == wIndex &&
  72884. + dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  72885. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72886. + gotgctl.b.hstsethnpen = 1;
  72887. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72888. + gotgctl, 0, gotgctl.d32);
  72889. + core_if->op_state = A_SUSPEND;
  72890. + }
  72891. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72892. + hprt0.b.prtsusp = 1;
  72893. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72894. + {
  72895. + dwc_irqflags_t flags;
  72896. + /* Update lx_state */
  72897. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  72898. + core_if->lx_state = DWC_OTG_L2;
  72899. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  72900. + }
  72901. + /* Suspend the Phy Clock */
  72902. + {
  72903. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72904. + pcgcctl.b.stoppclk = 1;
  72905. + DWC_MODIFY_REG32(core_if->pcgcctl, 0,
  72906. + pcgcctl.d32);
  72907. + dwc_udelay(10);
  72908. + }
  72909. +
  72910. + /* For HNP the bus must be suspended for at least 200ms. */
  72911. + if (dwc_otg_hcd->fops->get_b_hnp_enable(dwc_otg_hcd)) {
  72912. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72913. + pcgcctl.b.stoppclk = 1;
  72914. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  72915. + dwc_mdelay(200);
  72916. + }
  72917. +
  72918. + /** @todo - check how sw can wait for 1 sec to check asesvld??? */
  72919. +#if 0 //vahrama !!!!!!!!!!!!!!!!!!
  72920. + if (core_if->adp_enable) {
  72921. + gotgctl_data_t gotgctl = {.d32 = 0 };
  72922. + gpwrdn_data_t gpwrdn;
  72923. +
  72924. + while (gotgctl.b.asesvld == 1) {
  72925. + gotgctl.d32 =
  72926. + DWC_READ_REG32(&core_if->
  72927. + core_global_regs->
  72928. + gotgctl);
  72929. + dwc_mdelay(100);
  72930. + }
  72931. +
  72932. + /* Enable Power Down Logic */
  72933. + gpwrdn.d32 = 0;
  72934. + gpwrdn.b.pmuactv = 1;
  72935. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72936. + gpwrdn, 0, gpwrdn.d32);
  72937. +
  72938. + /* Unmask SRP detected interrupt from Power Down Logic */
  72939. + gpwrdn.d32 = 0;
  72940. + gpwrdn.b.srp_det_msk = 1;
  72941. + DWC_MODIFY_REG32(&core_if->core_global_regs->
  72942. + gpwrdn, 0, gpwrdn.d32);
  72943. +
  72944. + dwc_otg_adp_probe_start(core_if);
  72945. + }
  72946. +#endif
  72947. + break;
  72948. + case UHF_PORT_POWER:
  72949. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  72950. + "SetPortFeature - USB_PORT_FEAT_POWER\n");
  72951. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72952. + hprt0.b.prtpwr = 1;
  72953. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  72954. + break;
  72955. + case UHF_PORT_RESET:
  72956. + if ((core_if->power_down == 2)
  72957. + && (core_if->hibernation_suspend == 1)) {
  72958. + /* If we are going to exit from Hibernated
  72959. + * state via USB RESET.
  72960. + */
  72961. + dwc_otg_host_hibernation_restore(core_if, 0, 1);
  72962. + } else {
  72963. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72964. +
  72965. + DWC_DEBUGPL(DBG_HCD,
  72966. + "DWC OTG HCD HUB CONTROL - "
  72967. + "SetPortFeature - USB_PORT_FEAT_RESET\n");
  72968. + {
  72969. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  72970. + pcgcctl.b.enbl_sleep_gating = 1;
  72971. + pcgcctl.b.stoppclk = 1;
  72972. + DWC_MODIFY_REG32(core_if->pcgcctl, pcgcctl.d32, 0);
  72973. + DWC_WRITE_REG32(core_if->pcgcctl, 0);
  72974. + }
  72975. +#ifdef CONFIG_USB_DWC_OTG_LPM
  72976. + {
  72977. + glpmcfg_data_t lpmcfg;
  72978. + lpmcfg.d32 =
  72979. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  72980. + if (lpmcfg.b.prt_sleep_sts) {
  72981. + lpmcfg.b.en_utmi_sleep = 0;
  72982. + lpmcfg.b.hird_thres &= (~(1 << 4));
  72983. + DWC_WRITE_REG32
  72984. + (&core_if->core_global_regs->glpmcfg,
  72985. + lpmcfg.d32);
  72986. + dwc_mdelay(1);
  72987. + }
  72988. + }
  72989. +#endif
  72990. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  72991. + /* Clear suspend bit if resetting from suspended state. */
  72992. + hprt0.b.prtsusp = 0;
  72993. + /* When B-Host the Port reset bit is set in
  72994. + * the Start HCD Callback function, so that
  72995. + * the reset is started within 1ms of the HNP
  72996. + * success interrupt. */
  72997. + if (!dwc_otg_hcd_is_b_host(dwc_otg_hcd)) {
  72998. + hprt0.b.prtpwr = 1;
  72999. + hprt0.b.prtrst = 1;
  73000. + DWC_PRINTF("Indeed it is in host mode hprt0 = %08x\n",hprt0.d32);
  73001. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73002. + hprt0.d32);
  73003. + }
  73004. + /* Clear reset bit in 10ms (FS/LS) or 50ms (HS) */
  73005. + dwc_mdelay(60);
  73006. + hprt0.b.prtrst = 0;
  73007. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73008. + core_if->lx_state = DWC_OTG_L0; /* Now back to the on state */
  73009. + }
  73010. + break;
  73011. +#ifdef DWC_HS_ELECT_TST
  73012. + case UHF_PORT_TEST:
  73013. + {
  73014. + uint32_t t;
  73015. + gintmsk_data_t gintmsk;
  73016. +
  73017. + t = (wIndex >> 8); /* MSB wIndex USB */
  73018. + DWC_DEBUGPL(DBG_HCD,
  73019. + "DWC OTG HCD HUB CONTROL - "
  73020. + "SetPortFeature - USB_PORT_FEAT_TEST %d\n",
  73021. + t);
  73022. + DWC_WARN("USB_PORT_FEAT_TEST %d\n", t);
  73023. + if (t < 6) {
  73024. + hprt0.d32 = dwc_otg_read_hprt0(core_if);
  73025. + hprt0.b.prttstctl = t;
  73026. + DWC_WRITE_REG32(core_if->host_if->hprt0,
  73027. + hprt0.d32);
  73028. + } else {
  73029. + /* Setup global vars with reg addresses (quick and
  73030. + * dirty hack, should be cleaned up)
  73031. + */
  73032. + global_regs = core_if->core_global_regs;
  73033. + hc_global_regs =
  73034. + core_if->host_if->host_global_regs;
  73035. + hc_regs =
  73036. + (dwc_otg_hc_regs_t *) ((char *)
  73037. + global_regs +
  73038. + 0x500);
  73039. + data_fifo =
  73040. + (uint32_t *) ((char *)global_regs +
  73041. + 0x1000);
  73042. +
  73043. + if (t == 6) { /* HS_HOST_PORT_SUSPEND_RESUME */
  73044. + /* Save current interrupt mask */
  73045. + gintmsk.d32 =
  73046. + DWC_READ_REG32
  73047. + (&global_regs->gintmsk);
  73048. +
  73049. + /* Disable all interrupts while we muck with
  73050. + * the hardware directly
  73051. + */
  73052. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73053. +
  73054. + /* 15 second delay per the test spec */
  73055. + dwc_mdelay(15000);
  73056. +
  73057. + /* Drive suspend on the root port */
  73058. + hprt0.d32 =
  73059. + dwc_otg_read_hprt0(core_if);
  73060. + hprt0.b.prtsusp = 1;
  73061. + hprt0.b.prtres = 0;
  73062. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73063. +
  73064. + /* 15 second delay per the test spec */
  73065. + dwc_mdelay(15000);
  73066. +
  73067. + /* Drive resume on the root port */
  73068. + hprt0.d32 =
  73069. + dwc_otg_read_hprt0(core_if);
  73070. + hprt0.b.prtsusp = 0;
  73071. + hprt0.b.prtres = 1;
  73072. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73073. + dwc_mdelay(100);
  73074. +
  73075. + /* Clear the resume bit */
  73076. + hprt0.b.prtres = 0;
  73077. + DWC_WRITE_REG32(core_if->host_if->hprt0, hprt0.d32);
  73078. +
  73079. + /* Restore interrupts */
  73080. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73081. + } else if (t == 7) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR setup */
  73082. + /* Save current interrupt mask */
  73083. + gintmsk.d32 =
  73084. + DWC_READ_REG32
  73085. + (&global_regs->gintmsk);
  73086. +
  73087. + /* Disable all interrupts while we muck with
  73088. + * the hardware directly
  73089. + */
  73090. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73091. +
  73092. + /* 15 second delay per the test spec */
  73093. + dwc_mdelay(15000);
  73094. +
  73095. + /* Send the Setup packet */
  73096. + do_setup();
  73097. +
  73098. + /* 15 second delay so nothing else happens for awhile */
  73099. + dwc_mdelay(15000);
  73100. +
  73101. + /* Restore interrupts */
  73102. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73103. + } else if (t == 8) { /* SINGLE_STEP_GET_DEVICE_DESCRIPTOR execute */
  73104. + /* Save current interrupt mask */
  73105. + gintmsk.d32 =
  73106. + DWC_READ_REG32
  73107. + (&global_regs->gintmsk);
  73108. +
  73109. + /* Disable all interrupts while we muck with
  73110. + * the hardware directly
  73111. + */
  73112. + DWC_WRITE_REG32(&global_regs->gintmsk, 0);
  73113. +
  73114. + /* Send the Setup packet */
  73115. + do_setup();
  73116. +
  73117. + /* 15 second delay so nothing else happens for awhile */
  73118. + dwc_mdelay(15000);
  73119. +
  73120. + /* Send the In and Ack packets */
  73121. + do_in_ack();
  73122. +
  73123. + /* 15 second delay so nothing else happens for awhile */
  73124. + dwc_mdelay(15000);
  73125. +
  73126. + /* Restore interrupts */
  73127. + DWC_WRITE_REG32(&global_regs->gintmsk, gintmsk.d32);
  73128. + }
  73129. + }
  73130. + break;
  73131. + }
  73132. +#endif /* DWC_HS_ELECT_TST */
  73133. +
  73134. + case UHF_PORT_INDICATOR:
  73135. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB CONTROL - "
  73136. + "SetPortFeature - USB_PORT_FEAT_INDICATOR\n");
  73137. + /* Not supported */
  73138. + break;
  73139. + default:
  73140. + retval = -DWC_E_INVALID;
  73141. + DWC_ERROR("DWC OTG HCD - "
  73142. + "SetPortFeature request %xh "
  73143. + "unknown or unsupported\n", wValue);
  73144. + break;
  73145. + }
  73146. + break;
  73147. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73148. + case UCR_SET_AND_TEST_PORT_FEATURE:
  73149. + if (wValue != UHF_PORT_L1) {
  73150. + goto error;
  73151. + }
  73152. + {
  73153. + int portnum, hird, devaddr, remwake;
  73154. + glpmcfg_data_t lpmcfg;
  73155. + uint32_t time_usecs;
  73156. + gintsts_data_t gintsts;
  73157. + gintmsk_data_t gintmsk;
  73158. +
  73159. + if (!dwc_otg_get_param_lpm_enable(core_if)) {
  73160. + goto error;
  73161. + }
  73162. + if (wValue != UHF_PORT_L1 || wLength != 1) {
  73163. + goto error;
  73164. + }
  73165. + /* Check if the port currently is in SLEEP state */
  73166. + lpmcfg.d32 =
  73167. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  73168. + if (lpmcfg.b.prt_sleep_sts) {
  73169. + DWC_INFO("Port is already in sleep mode\n");
  73170. + buf[0] = 0; /* Return success */
  73171. + break;
  73172. + }
  73173. +
  73174. + portnum = wIndex & 0xf;
  73175. + hird = (wIndex >> 4) & 0xf;
  73176. + devaddr = (wIndex >> 8) & 0x7f;
  73177. + remwake = (wIndex >> 15);
  73178. +
  73179. + if (portnum != 1) {
  73180. + retval = -DWC_E_INVALID;
  73181. + DWC_WARN
  73182. + ("Wrong port number(%d) in SetandTestPortFeature request\n",
  73183. + portnum);
  73184. + break;
  73185. + }
  73186. +
  73187. + DWC_PRINTF
  73188. + ("SetandTestPortFeature request: portnum = %d, hird = %d, devaddr = %d, rewake = %d\n",
  73189. + portnum, hird, devaddr, remwake);
  73190. + /* Disable LPM interrupt */
  73191. + gintmsk.d32 = 0;
  73192. + gintmsk.b.lpmtranrcvd = 1;
  73193. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  73194. + gintmsk.d32, 0);
  73195. +
  73196. + if (dwc_otg_hcd_send_lpm
  73197. + (dwc_otg_hcd, devaddr, hird, remwake)) {
  73198. + retval = -DWC_E_INVALID;
  73199. + break;
  73200. + }
  73201. +
  73202. + time_usecs = 10 * (lpmcfg.b.retry_count + 1);
  73203. + /* We will consider timeout if time_usecs microseconds pass,
  73204. + * and we don't receive LPM transaction status.
  73205. + * After receiving non-error responce(ACK/NYET/STALL) from device,
  73206. + * core will set lpmtranrcvd bit.
  73207. + */
  73208. + do {
  73209. + gintsts.d32 =
  73210. + DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  73211. + if (gintsts.b.lpmtranrcvd) {
  73212. + break;
  73213. + }
  73214. + dwc_udelay(1);
  73215. + } while (--time_usecs);
  73216. + /* lpm_int bit will be cleared in LPM interrupt handler */
  73217. +
  73218. + /* Now fill status
  73219. + * 0x00 - Success
  73220. + * 0x10 - NYET
  73221. + * 0x11 - Timeout
  73222. + */
  73223. + if (!gintsts.b.lpmtranrcvd) {
  73224. + buf[0] = 0x3; /* Completion code is Timeout */
  73225. + dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd);
  73226. + } else {
  73227. + lpmcfg.d32 =
  73228. + DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  73229. + if (lpmcfg.b.lpm_resp == 0x3) {
  73230. + /* ACK responce from the device */
  73231. + buf[0] = 0x00; /* Success */
  73232. + } else if (lpmcfg.b.lpm_resp == 0x2) {
  73233. + /* NYET responce from the device */
  73234. + buf[0] = 0x2;
  73235. + } else {
  73236. + /* Otherwise responce with Timeout */
  73237. + buf[0] = 0x3;
  73238. + }
  73239. + }
  73240. + DWC_PRINTF("Device responce to LPM trans is %x\n",
  73241. + lpmcfg.b.lpm_resp);
  73242. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0,
  73243. + gintmsk.d32);
  73244. +
  73245. + break;
  73246. + }
  73247. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  73248. + default:
  73249. +error:
  73250. + retval = -DWC_E_INVALID;
  73251. + DWC_WARN("DWC OTG HCD - "
  73252. + "Unknown hub control request type or invalid typeReq: %xh wIndex: %xh wValue: %xh\n",
  73253. + typeReq, wIndex, wValue);
  73254. + break;
  73255. + }
  73256. +
  73257. + return retval;
  73258. +}
  73259. +
  73260. +#ifdef CONFIG_USB_DWC_OTG_LPM
  73261. +/** Returns index of host channel to perform LPM transaction. */
  73262. +int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd, uint8_t devaddr)
  73263. +{
  73264. + dwc_otg_core_if_t *core_if = hcd->core_if;
  73265. + dwc_hc_t *hc;
  73266. + hcchar_data_t hcchar;
  73267. + gintmsk_data_t gintmsk = {.d32 = 0 };
  73268. +
  73269. + if (DWC_CIRCLEQ_EMPTY(&hcd->free_hc_list)) {
  73270. + DWC_PRINTF("No free channel to select for LPM transaction\n");
  73271. + return -1;
  73272. + }
  73273. +
  73274. + hc = DWC_CIRCLEQ_FIRST(&hcd->free_hc_list);
  73275. +
  73276. + /* Mask host channel interrupts. */
  73277. + gintmsk.b.hcintr = 1;
  73278. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, gintmsk.d32, 0);
  73279. +
  73280. + /* Fill fields that core needs for LPM transaction */
  73281. + hcchar.b.devaddr = devaddr;
  73282. + hcchar.b.epnum = 0;
  73283. + hcchar.b.eptype = DWC_OTG_EP_TYPE_CONTROL;
  73284. + hcchar.b.mps = 64;
  73285. + hcchar.b.lspddev = (hc->speed == DWC_OTG_EP_SPEED_LOW);
  73286. + hcchar.b.epdir = 0; /* OUT */
  73287. + DWC_WRITE_REG32(&core_if->host_if->hc_regs[hc->hc_num]->hcchar,
  73288. + hcchar.d32);
  73289. +
  73290. + /* Remove the host channel from the free list. */
  73291. + DWC_CIRCLEQ_REMOVE_INIT(&hcd->free_hc_list, hc, hc_list_entry);
  73292. +
  73293. + DWC_PRINTF("hcnum = %d devaddr = %d\n", hc->hc_num, devaddr);
  73294. +
  73295. + return hc->hc_num;
  73296. +}
  73297. +
  73298. +/** Release hc after performing LPM transaction */
  73299. +void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd)
  73300. +{
  73301. + dwc_hc_t *hc;
  73302. + glpmcfg_data_t lpmcfg;
  73303. + uint8_t hc_num;
  73304. +
  73305. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  73306. + hc_num = lpmcfg.b.lpm_chan_index;
  73307. +
  73308. + hc = hcd->hc_ptr_array[hc_num];
  73309. +
  73310. + DWC_PRINTF("Freeing channel %d after LPM\n", hc_num);
  73311. + /* Return host channel to free list */
  73312. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  73313. +}
  73314. +
  73315. +int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr, uint8_t hird,
  73316. + uint8_t bRemoteWake)
  73317. +{
  73318. + glpmcfg_data_t lpmcfg;
  73319. + pcgcctl_data_t pcgcctl = {.d32 = 0 };
  73320. + int channel;
  73321. +
  73322. + channel = dwc_otg_hcd_get_hc_for_lpm_tran(hcd, devaddr);
  73323. + if (channel < 0) {
  73324. + return channel;
  73325. + }
  73326. +
  73327. + pcgcctl.b.enbl_sleep_gating = 1;
  73328. + DWC_MODIFY_REG32(hcd->core_if->pcgcctl, 0, pcgcctl.d32);
  73329. +
  73330. + /* Read LPM config register */
  73331. + lpmcfg.d32 = DWC_READ_REG32(&hcd->core_if->core_global_regs->glpmcfg);
  73332. +
  73333. + /* Program LPM transaction fields */
  73334. + lpmcfg.b.rem_wkup_en = bRemoteWake;
  73335. + lpmcfg.b.hird = hird;
  73336. + lpmcfg.b.hird_thres = 0x1c;
  73337. + lpmcfg.b.lpm_chan_index = channel;
  73338. + lpmcfg.b.en_utmi_sleep = 1;
  73339. + /* Program LPM config register */
  73340. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  73341. +
  73342. + /* Send LPM transaction */
  73343. + lpmcfg.b.send_lpm = 1;
  73344. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  73345. +
  73346. + return 0;
  73347. +}
  73348. +
  73349. +#endif /* CONFIG_USB_DWC_OTG_LPM */
  73350. +
  73351. +int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port)
  73352. +{
  73353. + int retval;
  73354. +
  73355. + if (port != 1) {
  73356. + return -DWC_E_INVALID;
  73357. + }
  73358. +
  73359. + retval = (hcd->flags.b.port_connect_status_change ||
  73360. + hcd->flags.b.port_reset_change ||
  73361. + hcd->flags.b.port_enable_change ||
  73362. + hcd->flags.b.port_suspend_change ||
  73363. + hcd->flags.b.port_over_current_change);
  73364. +#ifdef DEBUG
  73365. + if (retval) {
  73366. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD HUB STATUS DATA:"
  73367. + " Root port status changed\n");
  73368. + DWC_DEBUGPL(DBG_HCDV, " port_connect_status_change: %d\n",
  73369. + hcd->flags.b.port_connect_status_change);
  73370. + DWC_DEBUGPL(DBG_HCDV, " port_reset_change: %d\n",
  73371. + hcd->flags.b.port_reset_change);
  73372. + DWC_DEBUGPL(DBG_HCDV, " port_enable_change: %d\n",
  73373. + hcd->flags.b.port_enable_change);
  73374. + DWC_DEBUGPL(DBG_HCDV, " port_suspend_change: %d\n",
  73375. + hcd->flags.b.port_suspend_change);
  73376. + DWC_DEBUGPL(DBG_HCDV, " port_over_current_change: %d\n",
  73377. + hcd->flags.b.port_over_current_change);
  73378. + }
  73379. +#endif
  73380. + return retval;
  73381. +}
  73382. +
  73383. +int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * dwc_otg_hcd)
  73384. +{
  73385. + hfnum_data_t hfnum;
  73386. + hfnum.d32 =
  73387. + DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->
  73388. + hfnum);
  73389. +
  73390. +#ifdef DEBUG_SOF
  73391. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD GET FRAME NUMBER %d\n",
  73392. + hfnum.b.frnum);
  73393. +#endif
  73394. + return hfnum.b.frnum;
  73395. +}
  73396. +
  73397. +int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  73398. + struct dwc_otg_hcd_function_ops *fops)
  73399. +{
  73400. + int retval = 0;
  73401. +
  73402. + hcd->fops = fops;
  73403. + if (!dwc_otg_is_device_mode(hcd->core_if) &&
  73404. + (!hcd->core_if->adp_enable || hcd->core_if->adp.adp_started)) {
  73405. + dwc_otg_hcd_reinit(hcd);
  73406. + } else {
  73407. + retval = -DWC_E_NO_DEVICE;
  73408. + }
  73409. +
  73410. + return retval;
  73411. +}
  73412. +
  73413. +void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd)
  73414. +{
  73415. + return hcd->priv;
  73416. +}
  73417. +
  73418. +void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data)
  73419. +{
  73420. + hcd->priv = priv_data;
  73421. +}
  73422. +
  73423. +uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd)
  73424. +{
  73425. + return hcd->otg_port;
  73426. +}
  73427. +
  73428. +uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd)
  73429. +{
  73430. + uint32_t is_b_host;
  73431. + if (hcd->core_if->op_state == B_HOST) {
  73432. + is_b_host = 1;
  73433. + } else {
  73434. + is_b_host = 0;
  73435. + }
  73436. +
  73437. + return is_b_host;
  73438. +}
  73439. +
  73440. +dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  73441. + int iso_desc_count, int atomic_alloc)
  73442. +{
  73443. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  73444. + uint32_t size;
  73445. +
  73446. + size =
  73447. + sizeof(*dwc_otg_urb) +
  73448. + iso_desc_count * sizeof(struct dwc_otg_hcd_iso_packet_desc);
  73449. + if (atomic_alloc)
  73450. + dwc_otg_urb = DWC_ALLOC_ATOMIC(size);
  73451. + else
  73452. + dwc_otg_urb = DWC_ALLOC(size);
  73453. +
  73454. + if (dwc_otg_urb)
  73455. + dwc_otg_urb->packet_count = iso_desc_count;
  73456. + else {
  73457. + DWC_ERROR("**** DWC OTG HCD URB alloc - "
  73458. + "%salloc of %db failed\n",
  73459. + atomic_alloc?"atomic ":"", size);
  73460. + }
  73461. + return dwc_otg_urb;
  73462. +}
  73463. +
  73464. +void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73465. + uint8_t dev_addr, uint8_t ep_num,
  73466. + uint8_t ep_type, uint8_t ep_dir, uint16_t mps)
  73467. +{
  73468. + dwc_otg_hcd_fill_pipe(&dwc_otg_urb->pipe_info, dev_addr, ep_num,
  73469. + ep_type, ep_dir, mps);
  73470. +#if 0
  73471. + DWC_PRINTF
  73472. + ("addr = %d, ep_num = %d, ep_dir = 0x%x, ep_type = 0x%x, mps = %d\n",
  73473. + dev_addr, ep_num, ep_dir, ep_type, mps);
  73474. +#endif
  73475. +}
  73476. +
  73477. +void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73478. + void *urb_handle, void *buf, dwc_dma_t dma,
  73479. + uint32_t buflen, void *setup_packet,
  73480. + dwc_dma_t setup_dma, uint32_t flags,
  73481. + uint16_t interval)
  73482. +{
  73483. + dwc_otg_urb->priv = urb_handle;
  73484. + dwc_otg_urb->buf = buf;
  73485. + dwc_otg_urb->dma = dma;
  73486. + dwc_otg_urb->length = buflen;
  73487. + dwc_otg_urb->setup_packet = setup_packet;
  73488. + dwc_otg_urb->setup_dma = setup_dma;
  73489. + dwc_otg_urb->flags = flags;
  73490. + dwc_otg_urb->interval = interval;
  73491. + dwc_otg_urb->status = -DWC_E_IN_PROGRESS;
  73492. +}
  73493. +
  73494. +uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73495. +{
  73496. + return dwc_otg_urb->status;
  73497. +}
  73498. +
  73499. +uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73500. +{
  73501. + return dwc_otg_urb->actual_length;
  73502. +}
  73503. +
  73504. +uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t * dwc_otg_urb)
  73505. +{
  73506. + return dwc_otg_urb->error_count;
  73507. +}
  73508. +
  73509. +void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73510. + int desc_num, uint32_t offset,
  73511. + uint32_t length)
  73512. +{
  73513. + dwc_otg_urb->iso_descs[desc_num].offset = offset;
  73514. + dwc_otg_urb->iso_descs[desc_num].length = length;
  73515. +}
  73516. +
  73517. +uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t * dwc_otg_urb,
  73518. + int desc_num)
  73519. +{
  73520. + return dwc_otg_urb->iso_descs[desc_num].status;
  73521. +}
  73522. +
  73523. +uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  73524. + dwc_otg_urb, int desc_num)
  73525. +{
  73526. + return dwc_otg_urb->iso_descs[desc_num].actual_length;
  73527. +}
  73528. +
  73529. +int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd, void *ep_handle)
  73530. +{
  73531. + int allocated = 0;
  73532. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73533. +
  73534. + if (qh) {
  73535. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  73536. + allocated = 1;
  73537. + }
  73538. + }
  73539. + return allocated;
  73540. +}
  73541. +
  73542. +int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle)
  73543. +{
  73544. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73545. + int freed = 0;
  73546. + DWC_ASSERT(qh, "qh is not allocated\n");
  73547. +
  73548. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  73549. + freed = 1;
  73550. + }
  73551. +
  73552. + return freed;
  73553. +}
  73554. +
  73555. +uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd, void *ep_handle)
  73556. +{
  73557. + dwc_otg_qh_t *qh = (dwc_otg_qh_t *) ep_handle;
  73558. + DWC_ASSERT(qh, "qh is not allocated\n");
  73559. + return qh->usecs;
  73560. +}
  73561. +
  73562. +void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd)
  73563. +{
  73564. +#ifdef DEBUG
  73565. + int num_channels;
  73566. + int i;
  73567. + gnptxsts_data_t np_tx_status;
  73568. + hptxsts_data_t p_tx_status;
  73569. +
  73570. + num_channels = hcd->core_if->core_params->host_channels;
  73571. + DWC_PRINTF("\n");
  73572. + DWC_PRINTF
  73573. + ("************************************************************\n");
  73574. + DWC_PRINTF("HCD State:\n");
  73575. + DWC_PRINTF(" Num channels: %d\n", num_channels);
  73576. + for (i = 0; i < num_channels; i++) {
  73577. + dwc_hc_t *hc = hcd->hc_ptr_array[i];
  73578. + DWC_PRINTF(" Channel %d:\n", i);
  73579. + DWC_PRINTF(" dev_addr: %d, ep_num: %d, ep_is_in: %d\n",
  73580. + hc->dev_addr, hc->ep_num, hc->ep_is_in);
  73581. + DWC_PRINTF(" speed: %d\n", hc->speed);
  73582. + DWC_PRINTF(" ep_type: %d\n", hc->ep_type);
  73583. + DWC_PRINTF(" max_packet: %d\n", hc->max_packet);
  73584. + DWC_PRINTF(" data_pid_start: %d\n", hc->data_pid_start);
  73585. + DWC_PRINTF(" multi_count: %d\n", hc->multi_count);
  73586. + DWC_PRINTF(" xfer_started: %d\n", hc->xfer_started);
  73587. + DWC_PRINTF(" xfer_buff: %p\n", hc->xfer_buff);
  73588. + DWC_PRINTF(" xfer_len: %d\n", hc->xfer_len);
  73589. + DWC_PRINTF(" xfer_count: %d\n", hc->xfer_count);
  73590. + DWC_PRINTF(" halt_on_queue: %d\n", hc->halt_on_queue);
  73591. + DWC_PRINTF(" halt_pending: %d\n", hc->halt_pending);
  73592. + DWC_PRINTF(" halt_status: %d\n", hc->halt_status);
  73593. + DWC_PRINTF(" do_split: %d\n", hc->do_split);
  73594. + DWC_PRINTF(" complete_split: %d\n", hc->complete_split);
  73595. + DWC_PRINTF(" hub_addr: %d\n", hc->hub_addr);
  73596. + DWC_PRINTF(" port_addr: %d\n", hc->port_addr);
  73597. + DWC_PRINTF(" xact_pos: %d\n", hc->xact_pos);
  73598. + DWC_PRINTF(" requests: %d\n", hc->requests);
  73599. + DWC_PRINTF(" qh: %p\n", hc->qh);
  73600. + if (hc->xfer_started) {
  73601. + hfnum_data_t hfnum;
  73602. + hcchar_data_t hcchar;
  73603. + hctsiz_data_t hctsiz;
  73604. + hcint_data_t hcint;
  73605. + hcintmsk_data_t hcintmsk;
  73606. + hfnum.d32 =
  73607. + DWC_READ_REG32(&hcd->core_if->
  73608. + host_if->host_global_regs->hfnum);
  73609. + hcchar.d32 =
  73610. + DWC_READ_REG32(&hcd->core_if->host_if->
  73611. + hc_regs[i]->hcchar);
  73612. + hctsiz.d32 =
  73613. + DWC_READ_REG32(&hcd->core_if->host_if->
  73614. + hc_regs[i]->hctsiz);
  73615. + hcint.d32 =
  73616. + DWC_READ_REG32(&hcd->core_if->host_if->
  73617. + hc_regs[i]->hcint);
  73618. + hcintmsk.d32 =
  73619. + DWC_READ_REG32(&hcd->core_if->host_if->
  73620. + hc_regs[i]->hcintmsk);
  73621. + DWC_PRINTF(" hfnum: 0x%08x\n", hfnum.d32);
  73622. + DWC_PRINTF(" hcchar: 0x%08x\n", hcchar.d32);
  73623. + DWC_PRINTF(" hctsiz: 0x%08x\n", hctsiz.d32);
  73624. + DWC_PRINTF(" hcint: 0x%08x\n", hcint.d32);
  73625. + DWC_PRINTF(" hcintmsk: 0x%08x\n", hcintmsk.d32);
  73626. + }
  73627. + if (hc->xfer_started && hc->qh) {
  73628. + dwc_otg_qtd_t *qtd;
  73629. + dwc_otg_hcd_urb_t *urb;
  73630. +
  73631. + DWC_CIRCLEQ_FOREACH(qtd, &hc->qh->qtd_list, qtd_list_entry) {
  73632. + if (!qtd->in_process)
  73633. + break;
  73634. +
  73635. + urb = qtd->urb;
  73636. + DWC_PRINTF(" URB Info:\n");
  73637. + DWC_PRINTF(" qtd: %p, urb: %p\n", qtd, urb);
  73638. + if (urb) {
  73639. + DWC_PRINTF(" Dev: %d, EP: %d %s\n",
  73640. + dwc_otg_hcd_get_dev_addr(&urb->
  73641. + pipe_info),
  73642. + dwc_otg_hcd_get_ep_num(&urb->
  73643. + pipe_info),
  73644. + dwc_otg_hcd_is_pipe_in(&urb->
  73645. + pipe_info) ?
  73646. + "IN" : "OUT");
  73647. + DWC_PRINTF(" Max packet size: %d\n",
  73648. + dwc_otg_hcd_get_mps(&urb->
  73649. + pipe_info));
  73650. + DWC_PRINTF(" transfer_buffer: %p\n",
  73651. + urb->buf);
  73652. + DWC_PRINTF(" transfer_dma: %p\n",
  73653. + (void *)urb->dma);
  73654. + DWC_PRINTF(" transfer_buffer_length: %d\n",
  73655. + urb->length);
  73656. + DWC_PRINTF(" actual_length: %d\n",
  73657. + urb->actual_length);
  73658. + }
  73659. + }
  73660. + }
  73661. + }
  73662. + DWC_PRINTF(" non_periodic_channels: %d\n", hcd->non_periodic_channels);
  73663. + DWC_PRINTF(" periodic_channels: %d\n", hcd->periodic_channels);
  73664. + DWC_PRINTF(" periodic_usecs: %d\n", hcd->periodic_usecs);
  73665. + np_tx_status.d32 =
  73666. + DWC_READ_REG32(&hcd->core_if->core_global_regs->gnptxsts);
  73667. + DWC_PRINTF(" NP Tx Req Queue Space Avail: %d\n",
  73668. + np_tx_status.b.nptxqspcavail);
  73669. + DWC_PRINTF(" NP Tx FIFO Space Avail: %d\n",
  73670. + np_tx_status.b.nptxfspcavail);
  73671. + p_tx_status.d32 =
  73672. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hptxsts);
  73673. + DWC_PRINTF(" P Tx Req Queue Space Avail: %d\n",
  73674. + p_tx_status.b.ptxqspcavail);
  73675. + DWC_PRINTF(" P Tx FIFO Space Avail: %d\n", p_tx_status.b.ptxfspcavail);
  73676. + dwc_otg_hcd_dump_frrem(hcd);
  73677. + dwc_otg_dump_global_registers(hcd->core_if);
  73678. + dwc_otg_dump_host_registers(hcd->core_if);
  73679. + DWC_PRINTF
  73680. + ("************************************************************\n");
  73681. + DWC_PRINTF("\n");
  73682. +#endif
  73683. +}
  73684. +
  73685. +#ifdef DEBUG
  73686. +void dwc_print_setup_data(uint8_t * setup)
  73687. +{
  73688. + int i;
  73689. + if (CHK_DEBUG_LEVEL(DBG_HCD)) {
  73690. + DWC_PRINTF("Setup Data = MSB ");
  73691. + for (i = 7; i >= 0; i--)
  73692. + DWC_PRINTF("%02x ", setup[i]);
  73693. + DWC_PRINTF("\n");
  73694. + DWC_PRINTF(" bmRequestType Tranfer = %s\n",
  73695. + (setup[0] & 0x80) ? "Device-to-Host" :
  73696. + "Host-to-Device");
  73697. + DWC_PRINTF(" bmRequestType Type = ");
  73698. + switch ((setup[0] & 0x60) >> 5) {
  73699. + case 0:
  73700. + DWC_PRINTF("Standard\n");
  73701. + break;
  73702. + case 1:
  73703. + DWC_PRINTF("Class\n");
  73704. + break;
  73705. + case 2:
  73706. + DWC_PRINTF("Vendor\n");
  73707. + break;
  73708. + case 3:
  73709. + DWC_PRINTF("Reserved\n");
  73710. + break;
  73711. + }
  73712. + DWC_PRINTF(" bmRequestType Recipient = ");
  73713. + switch (setup[0] & 0x1f) {
  73714. + case 0:
  73715. + DWC_PRINTF("Device\n");
  73716. + break;
  73717. + case 1:
  73718. + DWC_PRINTF("Interface\n");
  73719. + break;
  73720. + case 2:
  73721. + DWC_PRINTF("Endpoint\n");
  73722. + break;
  73723. + case 3:
  73724. + DWC_PRINTF("Other\n");
  73725. + break;
  73726. + default:
  73727. + DWC_PRINTF("Reserved\n");
  73728. + break;
  73729. + }
  73730. + DWC_PRINTF(" bRequest = 0x%0x\n", setup[1]);
  73731. + DWC_PRINTF(" wValue = 0x%0x\n", *((uint16_t *) & setup[2]));
  73732. + DWC_PRINTF(" wIndex = 0x%0x\n", *((uint16_t *) & setup[4]));
  73733. + DWC_PRINTF(" wLength = 0x%0x\n\n", *((uint16_t *) & setup[6]));
  73734. + }
  73735. +}
  73736. +#endif
  73737. +
  73738. +void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd)
  73739. +{
  73740. +#if 0
  73741. + DWC_PRINTF("Frame remaining at SOF:\n");
  73742. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73743. + hcd->frrem_samples, hcd->frrem_accum,
  73744. + (hcd->frrem_samples > 0) ?
  73745. + hcd->frrem_accum / hcd->frrem_samples : 0);
  73746. +
  73747. + DWC_PRINTF("\n");
  73748. + DWC_PRINTF("Frame remaining at start_transfer (uframe 7):\n");
  73749. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73750. + hcd->core_if->hfnum_7_samples,
  73751. + hcd->core_if->hfnum_7_frrem_accum,
  73752. + (hcd->core_if->hfnum_7_samples >
  73753. + 0) ? hcd->core_if->hfnum_7_frrem_accum /
  73754. + hcd->core_if->hfnum_7_samples : 0);
  73755. + DWC_PRINTF("Frame remaining at start_transfer (uframe 0):\n");
  73756. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73757. + hcd->core_if->hfnum_0_samples,
  73758. + hcd->core_if->hfnum_0_frrem_accum,
  73759. + (hcd->core_if->hfnum_0_samples >
  73760. + 0) ? hcd->core_if->hfnum_0_frrem_accum /
  73761. + hcd->core_if->hfnum_0_samples : 0);
  73762. + DWC_PRINTF("Frame remaining at start_transfer (uframe 1-6):\n");
  73763. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73764. + hcd->core_if->hfnum_other_samples,
  73765. + hcd->core_if->hfnum_other_frrem_accum,
  73766. + (hcd->core_if->hfnum_other_samples >
  73767. + 0) ? hcd->core_if->hfnum_other_frrem_accum /
  73768. + hcd->core_if->hfnum_other_samples : 0);
  73769. +
  73770. + DWC_PRINTF("\n");
  73771. + DWC_PRINTF("Frame remaining at sample point A (uframe 7):\n");
  73772. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73773. + hcd->hfnum_7_samples_a, hcd->hfnum_7_frrem_accum_a,
  73774. + (hcd->hfnum_7_samples_a > 0) ?
  73775. + hcd->hfnum_7_frrem_accum_a / hcd->hfnum_7_samples_a : 0);
  73776. + DWC_PRINTF("Frame remaining at sample point A (uframe 0):\n");
  73777. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73778. + hcd->hfnum_0_samples_a, hcd->hfnum_0_frrem_accum_a,
  73779. + (hcd->hfnum_0_samples_a > 0) ?
  73780. + hcd->hfnum_0_frrem_accum_a / hcd->hfnum_0_samples_a : 0);
  73781. + DWC_PRINTF("Frame remaining at sample point A (uframe 1-6):\n");
  73782. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73783. + hcd->hfnum_other_samples_a, hcd->hfnum_other_frrem_accum_a,
  73784. + (hcd->hfnum_other_samples_a > 0) ?
  73785. + hcd->hfnum_other_frrem_accum_a /
  73786. + hcd->hfnum_other_samples_a : 0);
  73787. +
  73788. + DWC_PRINTF("\n");
  73789. + DWC_PRINTF("Frame remaining at sample point B (uframe 7):\n");
  73790. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73791. + hcd->hfnum_7_samples_b, hcd->hfnum_7_frrem_accum_b,
  73792. + (hcd->hfnum_7_samples_b > 0) ?
  73793. + hcd->hfnum_7_frrem_accum_b / hcd->hfnum_7_samples_b : 0);
  73794. + DWC_PRINTF("Frame remaining at sample point B (uframe 0):\n");
  73795. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73796. + hcd->hfnum_0_samples_b, hcd->hfnum_0_frrem_accum_b,
  73797. + (hcd->hfnum_0_samples_b > 0) ?
  73798. + hcd->hfnum_0_frrem_accum_b / hcd->hfnum_0_samples_b : 0);
  73799. + DWC_PRINTF("Frame remaining at sample point B (uframe 1-6):\n");
  73800. + DWC_PRINTF(" samples %u, accum %llu, avg %llu\n",
  73801. + hcd->hfnum_other_samples_b, hcd->hfnum_other_frrem_accum_b,
  73802. + (hcd->hfnum_other_samples_b > 0) ?
  73803. + hcd->hfnum_other_frrem_accum_b /
  73804. + hcd->hfnum_other_samples_b : 0);
  73805. +#endif
  73806. +}
  73807. +
  73808. +#endif /* DWC_DEVICE_ONLY */
  73809. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c
  73810. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 1970-01-01 01:00:00.000000000 +0100
  73811. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_ddma.c 2014-06-11 21:03:43.000000000 +0200
  73812. @@ -0,0 +1,1132 @@
  73813. +/*==========================================================================
  73814. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_ddma.c $
  73815. + * $Revision: #10 $
  73816. + * $Date: 2011/10/20 $
  73817. + * $Change: 1869464 $
  73818. + *
  73819. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  73820. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  73821. + * otherwise expressly agreed to in writing between Synopsys and you.
  73822. + *
  73823. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  73824. + * any End User Software License Agreement or Agreement for Licensed Product
  73825. + * with Synopsys or any supplement thereto. You are permitted to use and
  73826. + * redistribute this Software in source and binary forms, with or without
  73827. + * modification, provided that redistributions of source code must retain this
  73828. + * notice. You may not view, use, disclose, copy or distribute this file or
  73829. + * any information contained herein except pursuant to this license grant from
  73830. + * Synopsys. If you do not agree with this notice, including the disclaimer
  73831. + * below, then you are not authorized to use the Software.
  73832. + *
  73833. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  73834. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  73835. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  73836. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  73837. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  73838. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  73839. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  73840. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73841. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73842. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  73843. + * DAMAGE.
  73844. + * ========================================================================== */
  73845. +#ifndef DWC_DEVICE_ONLY
  73846. +
  73847. +/** @file
  73848. + * This file contains Descriptor DMA support implementation for host mode.
  73849. + */
  73850. +
  73851. +#include "dwc_otg_hcd.h"
  73852. +#include "dwc_otg_regs.h"
  73853. +
  73854. +extern bool microframe_schedule;
  73855. +
  73856. +static inline uint8_t frame_list_idx(uint16_t frame)
  73857. +{
  73858. + return (frame & (MAX_FRLIST_EN_NUM - 1));
  73859. +}
  73860. +
  73861. +static inline uint16_t desclist_idx_inc(uint16_t idx, uint16_t inc, uint8_t speed)
  73862. +{
  73863. + return (idx + inc) &
  73864. + (((speed ==
  73865. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  73866. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  73867. +}
  73868. +
  73869. +static inline uint16_t desclist_idx_dec(uint16_t idx, uint16_t inc, uint8_t speed)
  73870. +{
  73871. + return (idx - inc) &
  73872. + (((speed ==
  73873. + DWC_OTG_EP_SPEED_HIGH) ? MAX_DMA_DESC_NUM_HS_ISOC :
  73874. + MAX_DMA_DESC_NUM_GENERIC) - 1);
  73875. +}
  73876. +
  73877. +static inline uint16_t max_desc_num(dwc_otg_qh_t * qh)
  73878. +{
  73879. + return (((qh->ep_type == UE_ISOCHRONOUS)
  73880. + && (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH))
  73881. + ? MAX_DMA_DESC_NUM_HS_ISOC : MAX_DMA_DESC_NUM_GENERIC);
  73882. +}
  73883. +static inline uint16_t frame_incr_val(dwc_otg_qh_t * qh)
  73884. +{
  73885. + return ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH)
  73886. + ? ((qh->interval + 8 - 1) / 8)
  73887. + : qh->interval);
  73888. +}
  73889. +
  73890. +static int desc_list_alloc(dwc_otg_qh_t * qh)
  73891. +{
  73892. + int retval = 0;
  73893. +
  73894. + qh->desc_list = (dwc_otg_host_dma_desc_t *)
  73895. + DWC_DMA_ALLOC(sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh),
  73896. + &qh->desc_list_dma);
  73897. +
  73898. + if (!qh->desc_list) {
  73899. + retval = -DWC_E_NO_MEMORY;
  73900. + DWC_ERROR("%s: DMA descriptor list allocation failed\n", __func__);
  73901. +
  73902. + }
  73903. +
  73904. + dwc_memset(qh->desc_list, 0x00,
  73905. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  73906. +
  73907. + qh->n_bytes =
  73908. + (uint32_t *) DWC_ALLOC(sizeof(uint32_t) * max_desc_num(qh));
  73909. +
  73910. + if (!qh->n_bytes) {
  73911. + retval = -DWC_E_NO_MEMORY;
  73912. + DWC_ERROR
  73913. + ("%s: Failed to allocate array for descriptors' size actual values\n",
  73914. + __func__);
  73915. +
  73916. + }
  73917. + return retval;
  73918. +
  73919. +}
  73920. +
  73921. +static void desc_list_free(dwc_otg_qh_t * qh)
  73922. +{
  73923. + if (qh->desc_list) {
  73924. + DWC_DMA_FREE(max_desc_num(qh), qh->desc_list,
  73925. + qh->desc_list_dma);
  73926. + qh->desc_list = NULL;
  73927. + }
  73928. +
  73929. + if (qh->n_bytes) {
  73930. + DWC_FREE(qh->n_bytes);
  73931. + qh->n_bytes = NULL;
  73932. + }
  73933. +}
  73934. +
  73935. +static int frame_list_alloc(dwc_otg_hcd_t * hcd)
  73936. +{
  73937. + int retval = 0;
  73938. + if (hcd->frame_list)
  73939. + return 0;
  73940. +
  73941. + hcd->frame_list = DWC_DMA_ALLOC(4 * MAX_FRLIST_EN_NUM,
  73942. + &hcd->frame_list_dma);
  73943. + if (!hcd->frame_list) {
  73944. + retval = -DWC_E_NO_MEMORY;
  73945. + DWC_ERROR("%s: Frame List allocation failed\n", __func__);
  73946. + }
  73947. +
  73948. + dwc_memset(hcd->frame_list, 0x00, 4 * MAX_FRLIST_EN_NUM);
  73949. +
  73950. + return retval;
  73951. +}
  73952. +
  73953. +static void frame_list_free(dwc_otg_hcd_t * hcd)
  73954. +{
  73955. + if (!hcd->frame_list)
  73956. + return;
  73957. +
  73958. + DWC_DMA_FREE(4 * MAX_FRLIST_EN_NUM, hcd->frame_list, hcd->frame_list_dma);
  73959. + hcd->frame_list = NULL;
  73960. +}
  73961. +
  73962. +static void per_sched_enable(dwc_otg_hcd_t * hcd, uint16_t fr_list_en)
  73963. +{
  73964. +
  73965. + hcfg_data_t hcfg;
  73966. +
  73967. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  73968. +
  73969. + if (hcfg.b.perschedena) {
  73970. + /* already enabled */
  73971. + return;
  73972. + }
  73973. +
  73974. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hflbaddr,
  73975. + hcd->frame_list_dma);
  73976. +
  73977. + switch (fr_list_en) {
  73978. + case 64:
  73979. + hcfg.b.frlisten = 3;
  73980. + break;
  73981. + case 32:
  73982. + hcfg.b.frlisten = 2;
  73983. + break;
  73984. + case 16:
  73985. + hcfg.b.frlisten = 1;
  73986. + break;
  73987. + case 8:
  73988. + hcfg.b.frlisten = 0;
  73989. + break;
  73990. + default:
  73991. + break;
  73992. + }
  73993. +
  73994. + hcfg.b.perschedena = 1;
  73995. +
  73996. + DWC_DEBUGPL(DBG_HCD, "Enabling Periodic schedule\n");
  73997. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  73998. +
  73999. +}
  74000. +
  74001. +static void per_sched_disable(dwc_otg_hcd_t * hcd)
  74002. +{
  74003. + hcfg_data_t hcfg;
  74004. +
  74005. + hcfg.d32 = DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hcfg);
  74006. +
  74007. + if (!hcfg.b.perschedena) {
  74008. + /* already disabled */
  74009. + return;
  74010. + }
  74011. + hcfg.b.perschedena = 0;
  74012. +
  74013. + DWC_DEBUGPL(DBG_HCD, "Disabling Periodic schedule\n");
  74014. + DWC_WRITE_REG32(&hcd->core_if->host_if->host_global_regs->hcfg, hcfg.d32);
  74015. +}
  74016. +
  74017. +/*
  74018. + * Activates/Deactivates FrameList entries for the channel
  74019. + * based on endpoint servicing period.
  74020. + */
  74021. +void update_frame_list(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, uint8_t enable)
  74022. +{
  74023. + uint16_t i, j, inc;
  74024. + dwc_hc_t *hc = NULL;
  74025. +
  74026. + if (!qh->channel) {
  74027. + DWC_ERROR("qh->channel = %p", qh->channel);
  74028. + return;
  74029. + }
  74030. +
  74031. + if (!hcd) {
  74032. + DWC_ERROR("------hcd = %p", hcd);
  74033. + return;
  74034. + }
  74035. +
  74036. + if (!hcd->frame_list) {
  74037. + DWC_ERROR("-------hcd->frame_list = %p", hcd->frame_list);
  74038. + return;
  74039. + }
  74040. +
  74041. + hc = qh->channel;
  74042. + inc = frame_incr_val(qh);
  74043. + if (qh->ep_type == UE_ISOCHRONOUS)
  74044. + i = frame_list_idx(qh->sched_frame);
  74045. + else
  74046. + i = 0;
  74047. +
  74048. + j = i;
  74049. + do {
  74050. + if (enable)
  74051. + hcd->frame_list[j] |= (1 << hc->hc_num);
  74052. + else
  74053. + hcd->frame_list[j] &= ~(1 << hc->hc_num);
  74054. + j = (j + inc) & (MAX_FRLIST_EN_NUM - 1);
  74055. + }
  74056. + while (j != i);
  74057. + if (!enable)
  74058. + return;
  74059. + hc->schinfo = 0;
  74060. + if (qh->channel->speed == DWC_OTG_EP_SPEED_HIGH) {
  74061. + j = 1;
  74062. + /* TODO - check this */
  74063. + inc = (8 + qh->interval - 1) / qh->interval;
  74064. + for (i = 0; i < inc; i++) {
  74065. + hc->schinfo |= j;
  74066. + j = j << qh->interval;
  74067. + }
  74068. + } else {
  74069. + hc->schinfo = 0xff;
  74070. + }
  74071. +}
  74072. +
  74073. +#if 1
  74074. +void dump_frame_list(dwc_otg_hcd_t * hcd)
  74075. +{
  74076. + int i = 0;
  74077. + DWC_PRINTF("--FRAME LIST (hex) --\n");
  74078. + for (i = 0; i < MAX_FRLIST_EN_NUM; i++) {
  74079. + DWC_PRINTF("%x\t", hcd->frame_list[i]);
  74080. + if (!(i % 8) && i)
  74081. + DWC_PRINTF("\n");
  74082. + }
  74083. + DWC_PRINTF("\n----\n");
  74084. +
  74085. +}
  74086. +#endif
  74087. +
  74088. +static void release_channel_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74089. +{
  74090. + dwc_irqflags_t flags;
  74091. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  74092. +
  74093. + dwc_hc_t *hc = qh->channel;
  74094. + if (dwc_qh_is_non_per(qh)) {
  74095. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  74096. + if (!microframe_schedule)
  74097. + hcd->non_periodic_channels--;
  74098. + else
  74099. + hcd->available_host_channels++;
  74100. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  74101. + } else
  74102. + update_frame_list(hcd, qh, 0);
  74103. +
  74104. + /*
  74105. + * The condition is added to prevent double cleanup try in case of device
  74106. + * disconnect. See channel cleanup in dwc_otg_hcd_disconnect_cb().
  74107. + */
  74108. + if (hc->qh) {
  74109. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  74110. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  74111. + hc->qh = NULL;
  74112. + }
  74113. +
  74114. + qh->channel = NULL;
  74115. + qh->ntd = 0;
  74116. +
  74117. + if (qh->desc_list) {
  74118. + dwc_memset(qh->desc_list, 0x00,
  74119. + sizeof(dwc_otg_host_dma_desc_t) * max_desc_num(qh));
  74120. + }
  74121. +}
  74122. +
  74123. +/**
  74124. + * Initializes a QH structure's Descriptor DMA related members.
  74125. + * Allocates memory for descriptor list.
  74126. + * On first periodic QH, allocates memory for FrameList
  74127. + * and enables periodic scheduling.
  74128. + *
  74129. + * @param hcd The HCD state structure for the DWC OTG controller.
  74130. + * @param qh The QH to init.
  74131. + *
  74132. + * @return 0 if successful, negative error code otherwise.
  74133. + */
  74134. +int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74135. +{
  74136. + int retval = 0;
  74137. +
  74138. + if (qh->do_split) {
  74139. + DWC_ERROR("SPLIT Transfers are not supported in Descriptor DMA.\n");
  74140. + return -1;
  74141. + }
  74142. +
  74143. + retval = desc_list_alloc(qh);
  74144. +
  74145. + if ((retval == 0)
  74146. + && (qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)) {
  74147. + if (!hcd->frame_list) {
  74148. + retval = frame_list_alloc(hcd);
  74149. + /* Enable periodic schedule on first periodic QH */
  74150. + if (retval == 0)
  74151. + per_sched_enable(hcd, MAX_FRLIST_EN_NUM);
  74152. + }
  74153. + }
  74154. +
  74155. + qh->ntd = 0;
  74156. +
  74157. + return retval;
  74158. +}
  74159. +
  74160. +/**
  74161. + * Frees descriptor list memory associated with the QH.
  74162. + * If QH is periodic and the last, frees FrameList memory
  74163. + * and disables periodic scheduling.
  74164. + *
  74165. + * @param hcd The HCD state structure for the DWC OTG controller.
  74166. + * @param qh The QH to init.
  74167. + */
  74168. +void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74169. +{
  74170. + desc_list_free(qh);
  74171. +
  74172. + /*
  74173. + * Channel still assigned due to some reasons.
  74174. + * Seen on Isoc URB dequeue. Channel halted but no subsequent
  74175. + * ChHalted interrupt to release the channel. Afterwards
  74176. + * when it comes here from endpoint disable routine
  74177. + * channel remains assigned.
  74178. + */
  74179. + if (qh->channel)
  74180. + release_channel_ddma(hcd, qh);
  74181. +
  74182. + if ((qh->ep_type == UE_ISOCHRONOUS || qh->ep_type == UE_INTERRUPT)
  74183. + && (microframe_schedule || !hcd->periodic_channels) && hcd->frame_list) {
  74184. +
  74185. + per_sched_disable(hcd);
  74186. + frame_list_free(hcd);
  74187. + }
  74188. +}
  74189. +
  74190. +static uint8_t frame_to_desc_idx(dwc_otg_qh_t * qh, uint16_t frame_idx)
  74191. +{
  74192. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  74193. + /*
  74194. + * Descriptor set(8 descriptors) index
  74195. + * which is 8-aligned.
  74196. + */
  74197. + return (frame_idx & ((MAX_DMA_DESC_NUM_HS_ISOC / 8) - 1)) * 8;
  74198. + } else {
  74199. + return (frame_idx & (MAX_DMA_DESC_NUM_GENERIC - 1));
  74200. + }
  74201. +}
  74202. +
  74203. +/*
  74204. + * Determine starting frame for Isochronous transfer.
  74205. + * Few frames skipped to prevent race condition with HC.
  74206. + */
  74207. +static uint8_t calc_starting_frame(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  74208. + uint8_t * skip_frames)
  74209. +{
  74210. + uint16_t frame = 0;
  74211. + hcd->frame_number = dwc_otg_hcd_get_frame_number(hcd);
  74212. +
  74213. + /* sched_frame is always frame number(not uFrame) both in FS and HS !! */
  74214. +
  74215. + /*
  74216. + * skip_frames is used to limit activated descriptors number
  74217. + * to avoid the situation when HC services the last activated
  74218. + * descriptor firstly.
  74219. + * Example for FS:
  74220. + * Current frame is 1, scheduled frame is 3. Since HC always fetches the descriptor
  74221. + * corresponding to curr_frame+1, the descriptor corresponding to frame 2
  74222. + * will be fetched. If the number of descriptors is max=64 (or greather) the
  74223. + * list will be fully programmed with Active descriptors and it is possible
  74224. + * case(rare) that the latest descriptor(considering rollback) corresponding
  74225. + * to frame 2 will be serviced first. HS case is more probable because, in fact,
  74226. + * up to 11 uframes(16 in the code) may be skipped.
  74227. + */
  74228. + if (qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) {
  74229. + /*
  74230. + * Consider uframe counter also, to start xfer asap.
  74231. + * If half of the frame elapsed skip 2 frames otherwise
  74232. + * just 1 frame.
  74233. + * Starting descriptor index must be 8-aligned, so
  74234. + * if the current frame is near to complete the next one
  74235. + * is skipped as well.
  74236. + */
  74237. +
  74238. + if (dwc_micro_frame_num(hcd->frame_number) >= 5) {
  74239. + *skip_frames = 2 * 8;
  74240. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  74241. + } else {
  74242. + *skip_frames = 1 * 8;
  74243. + frame = dwc_frame_num_inc(hcd->frame_number, *skip_frames);
  74244. + }
  74245. +
  74246. + frame = dwc_full_frame_num(frame);
  74247. + } else {
  74248. + /*
  74249. + * Two frames are skipped for FS - the current and the next.
  74250. + * But for descriptor programming, 1 frame(descriptor) is enough,
  74251. + * see example above.
  74252. + */
  74253. + *skip_frames = 1;
  74254. + frame = dwc_frame_num_inc(hcd->frame_number, 2);
  74255. + }
  74256. +
  74257. + return frame;
  74258. +}
  74259. +
  74260. +/*
  74261. + * Calculate initial descriptor index for isochronous transfer
  74262. + * based on scheduled frame.
  74263. + */
  74264. +static uint8_t recalc_initial_desc_idx(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74265. +{
  74266. + uint16_t frame = 0, fr_idx, fr_idx_tmp;
  74267. + uint8_t skip_frames = 0;
  74268. + /*
  74269. + * With current ISOC processing algorithm the channel is being
  74270. + * released when no more QTDs in the list(qh->ntd == 0).
  74271. + * Thus this function is called only when qh->ntd == 0 and qh->channel == 0.
  74272. + *
  74273. + * So qh->channel != NULL branch is not used and just not removed from the
  74274. + * source file. It is required for another possible approach which is,
  74275. + * do not disable and release the channel when ISOC session completed,
  74276. + * just move QH to inactive schedule until new QTD arrives.
  74277. + * On new QTD, the QH moved back to 'ready' schedule,
  74278. + * starting frame and therefore starting desc_index are recalculated.
  74279. + * In this case channel is released only on ep_disable.
  74280. + */
  74281. +
  74282. + /* Calculate starting descriptor index. For INTERRUPT endpoint it is always 0. */
  74283. + if (qh->channel) {
  74284. + frame = calc_starting_frame(hcd, qh, &skip_frames);
  74285. + /*
  74286. + * Calculate initial descriptor index based on FrameList current bitmap
  74287. + * and servicing period.
  74288. + */
  74289. + fr_idx_tmp = frame_list_idx(frame);
  74290. + fr_idx =
  74291. + (MAX_FRLIST_EN_NUM + frame_list_idx(qh->sched_frame) -
  74292. + fr_idx_tmp)
  74293. + % frame_incr_val(qh);
  74294. + fr_idx = (fr_idx + fr_idx_tmp) % MAX_FRLIST_EN_NUM;
  74295. + } else {
  74296. + qh->sched_frame = calc_starting_frame(hcd, qh, &skip_frames);
  74297. + fr_idx = frame_list_idx(qh->sched_frame);
  74298. + }
  74299. +
  74300. + qh->td_first = qh->td_last = frame_to_desc_idx(qh, fr_idx);
  74301. +
  74302. + return skip_frames;
  74303. +}
  74304. +
  74305. +#define ISOC_URB_GIVEBACK_ASAP
  74306. +
  74307. +#define MAX_ISOC_XFER_SIZE_FS 1023
  74308. +#define MAX_ISOC_XFER_SIZE_HS 3072
  74309. +#define DESCNUM_THRESHOLD 4
  74310. +
  74311. +static void init_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  74312. + uint8_t skip_frames)
  74313. +{
  74314. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74315. + dwc_otg_qtd_t *qtd;
  74316. + dwc_otg_host_dma_desc_t *dma_desc;
  74317. + uint16_t idx, inc, n_desc, ntd_max, max_xfer_size;
  74318. +
  74319. + idx = qh->td_last;
  74320. + inc = qh->interval;
  74321. + n_desc = 0;
  74322. +
  74323. + ntd_max = (max_desc_num(qh) + qh->interval - 1) / qh->interval;
  74324. + if (skip_frames && !qh->channel)
  74325. + ntd_max = ntd_max - skip_frames / qh->interval;
  74326. +
  74327. + max_xfer_size =
  74328. + (qh->dev_speed ==
  74329. + DWC_OTG_EP_SPEED_HIGH) ? MAX_ISOC_XFER_SIZE_HS :
  74330. + MAX_ISOC_XFER_SIZE_FS;
  74331. +
  74332. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  74333. + while ((qh->ntd < ntd_max)
  74334. + && (qtd->isoc_frame_index_last <
  74335. + qtd->urb->packet_count)) {
  74336. +
  74337. + dma_desc = &qh->desc_list[idx];
  74338. + dwc_memset(dma_desc, 0x00, sizeof(dwc_otg_host_dma_desc_t));
  74339. +
  74340. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index_last];
  74341. +
  74342. + if (frame_desc->length > max_xfer_size)
  74343. + qh->n_bytes[idx] = max_xfer_size;
  74344. + else
  74345. + qh->n_bytes[idx] = frame_desc->length;
  74346. + dma_desc->status.b_isoc.n_bytes = qh->n_bytes[idx];
  74347. + dma_desc->status.b_isoc.a = 1;
  74348. + dma_desc->status.b_isoc.sts = 0;
  74349. +
  74350. + dma_desc->buf = qtd->urb->dma + frame_desc->offset;
  74351. +
  74352. + qh->ntd++;
  74353. +
  74354. + qtd->isoc_frame_index_last++;
  74355. +
  74356. +#ifdef ISOC_URB_GIVEBACK_ASAP
  74357. + /*
  74358. + * Set IOC for each descriptor corresponding to the
  74359. + * last frame of the URB.
  74360. + */
  74361. + if (qtd->isoc_frame_index_last ==
  74362. + qtd->urb->packet_count)
  74363. + dma_desc->status.b_isoc.ioc = 1;
  74364. +
  74365. +#endif
  74366. + idx = desclist_idx_inc(idx, inc, qh->dev_speed);
  74367. + n_desc++;
  74368. +
  74369. + }
  74370. + qtd->in_process = 1;
  74371. + }
  74372. +
  74373. + qh->td_last = idx;
  74374. +
  74375. +#ifdef ISOC_URB_GIVEBACK_ASAP
  74376. + /* Set IOC for the last descriptor if descriptor list is full */
  74377. + if (qh->ntd == ntd_max) {
  74378. + idx = desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  74379. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  74380. + }
  74381. +#else
  74382. + /*
  74383. + * Set IOC bit only for one descriptor.
  74384. + * Always try to be ahead of HW processing,
  74385. + * i.e. on IOC generation driver activates next descriptors but
  74386. + * core continues to process descriptors followed the one with IOC set.
  74387. + */
  74388. +
  74389. + if (n_desc > DESCNUM_THRESHOLD) {
  74390. + /*
  74391. + * Move IOC "up". Required even if there is only one QTD
  74392. + * in the list, cause QTDs migth continue to be queued,
  74393. + * but during the activation it was only one queued.
  74394. + * Actually more than one QTD might be in the list if this function called
  74395. + * from XferCompletion - QTDs was queued during HW processing of the previous
  74396. + * descriptor chunk.
  74397. + */
  74398. + idx = dwc_desclist_idx_dec(idx, inc * ((qh->ntd + 1) / 2), qh->dev_speed);
  74399. + } else {
  74400. + /*
  74401. + * Set the IOC for the latest descriptor
  74402. + * if either number of descriptor is not greather than threshold
  74403. + * or no more new descriptors activated.
  74404. + */
  74405. + idx = dwc_desclist_idx_dec(qh->td_last, inc, qh->dev_speed);
  74406. + }
  74407. +
  74408. + qh->desc_list[idx].status.b_isoc.ioc = 1;
  74409. +#endif
  74410. +}
  74411. +
  74412. +static void init_non_isoc_dma_desc(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74413. +{
  74414. +
  74415. + dwc_hc_t *hc;
  74416. + dwc_otg_host_dma_desc_t *dma_desc;
  74417. + dwc_otg_qtd_t *qtd;
  74418. + int num_packets, len, n_desc = 0;
  74419. +
  74420. + hc = qh->channel;
  74421. +
  74422. + /*
  74423. + * Start with hc->xfer_buff initialized in
  74424. + * assign_and_init_hc(), then if SG transfer consists of multiple URBs,
  74425. + * this pointer re-assigned to the buffer of the currently processed QTD.
  74426. + * For non-SG request there is always one QTD active.
  74427. + */
  74428. +
  74429. + DWC_CIRCLEQ_FOREACH(qtd, &qh->qtd_list, qtd_list_entry) {
  74430. +
  74431. + if (n_desc) {
  74432. + /* SG request - more than 1 QTDs */
  74433. + hc->xfer_buff = (uint8_t *)qtd->urb->dma + qtd->urb->actual_length;
  74434. + hc->xfer_len = qtd->urb->length - qtd->urb->actual_length;
  74435. + }
  74436. +
  74437. + qtd->n_desc = 0;
  74438. +
  74439. + do {
  74440. + dma_desc = &qh->desc_list[n_desc];
  74441. + len = hc->xfer_len;
  74442. +
  74443. + if (len > MAX_DMA_DESC_SIZE)
  74444. + len = MAX_DMA_DESC_SIZE - hc->max_packet + 1;
  74445. +
  74446. + if (hc->ep_is_in) {
  74447. + if (len > 0) {
  74448. + num_packets = (len + hc->max_packet - 1) / hc->max_packet;
  74449. + } else {
  74450. + /* Need 1 packet for transfer length of 0. */
  74451. + num_packets = 1;
  74452. + }
  74453. + /* Always program an integral # of max packets for IN transfers. */
  74454. + len = num_packets * hc->max_packet;
  74455. + }
  74456. +
  74457. + dma_desc->status.b.n_bytes = len;
  74458. +
  74459. + qh->n_bytes[n_desc] = len;
  74460. +
  74461. + if ((qh->ep_type == UE_CONTROL)
  74462. + && (qtd->control_phase == DWC_OTG_CONTROL_SETUP))
  74463. + dma_desc->status.b.sup = 1; /* Setup Packet */
  74464. +
  74465. + dma_desc->status.b.a = 1; /* Active descriptor */
  74466. + dma_desc->status.b.sts = 0;
  74467. +
  74468. + dma_desc->buf =
  74469. + ((unsigned long)hc->xfer_buff & 0xffffffff);
  74470. +
  74471. + /*
  74472. + * Last descriptor(or single) of IN transfer
  74473. + * with actual size less than MaxPacket.
  74474. + */
  74475. + if (len > hc->xfer_len) {
  74476. + hc->xfer_len = 0;
  74477. + } else {
  74478. + hc->xfer_buff += len;
  74479. + hc->xfer_len -= len;
  74480. + }
  74481. +
  74482. + qtd->n_desc++;
  74483. + n_desc++;
  74484. + }
  74485. + while ((hc->xfer_len > 0) && (n_desc != MAX_DMA_DESC_NUM_GENERIC));
  74486. +
  74487. +
  74488. + qtd->in_process = 1;
  74489. +
  74490. + if (qh->ep_type == UE_CONTROL)
  74491. + break;
  74492. +
  74493. + if (n_desc == MAX_DMA_DESC_NUM_GENERIC)
  74494. + break;
  74495. + }
  74496. +
  74497. + if (n_desc) {
  74498. + /* Request Transfer Complete interrupt for the last descriptor */
  74499. + qh->desc_list[n_desc - 1].status.b.ioc = 1;
  74500. + /* End of List indicator */
  74501. + qh->desc_list[n_desc - 1].status.b.eol = 1;
  74502. +
  74503. + hc->ntd = n_desc;
  74504. + }
  74505. +}
  74506. +
  74507. +/**
  74508. + * For Control and Bulk endpoints initializes descriptor list
  74509. + * and starts the transfer.
  74510. + *
  74511. + * For Interrupt and Isochronous endpoints initializes descriptor list
  74512. + * then updates FrameList, marking appropriate entries as active.
  74513. + * In case of Isochronous, the starting descriptor index is calculated based
  74514. + * on the scheduled frame, but only on the first transfer descriptor within a session.
  74515. + * Then starts the transfer via enabling the channel.
  74516. + * For Isochronous endpoint the channel is not halted on XferComplete
  74517. + * interrupt so remains assigned to the endpoint(QH) until session is done.
  74518. + *
  74519. + * @param hcd The HCD state structure for the DWC OTG controller.
  74520. + * @param qh The QH to init.
  74521. + *
  74522. + * @return 0 if successful, negative error code otherwise.
  74523. + */
  74524. +void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  74525. +{
  74526. + /* Channel is already assigned */
  74527. + dwc_hc_t *hc = qh->channel;
  74528. + uint8_t skip_frames = 0;
  74529. +
  74530. + switch (hc->ep_type) {
  74531. + case DWC_OTG_EP_TYPE_CONTROL:
  74532. + case DWC_OTG_EP_TYPE_BULK:
  74533. + init_non_isoc_dma_desc(hcd, qh);
  74534. +
  74535. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74536. + break;
  74537. + case DWC_OTG_EP_TYPE_INTR:
  74538. + init_non_isoc_dma_desc(hcd, qh);
  74539. +
  74540. + update_frame_list(hcd, qh, 1);
  74541. +
  74542. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74543. + break;
  74544. + case DWC_OTG_EP_TYPE_ISOC:
  74545. +
  74546. + if (!qh->ntd)
  74547. + skip_frames = recalc_initial_desc_idx(hcd, qh);
  74548. +
  74549. + init_isoc_dma_desc(hcd, qh, skip_frames);
  74550. +
  74551. + if (!hc->xfer_started) {
  74552. +
  74553. + update_frame_list(hcd, qh, 1);
  74554. +
  74555. + /*
  74556. + * Always set to max, instead of actual size.
  74557. + * Otherwise ntd will be changed with
  74558. + * channel being enabled. Not recommended.
  74559. + *
  74560. + */
  74561. + hc->ntd = max_desc_num(qh);
  74562. + /* Enable channel only once for ISOC */
  74563. + dwc_otg_hc_start_transfer_ddma(hcd->core_if, hc);
  74564. + }
  74565. +
  74566. + break;
  74567. + default:
  74568. +
  74569. + break;
  74570. + }
  74571. +}
  74572. +
  74573. +static void complete_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  74574. + dwc_hc_t * hc,
  74575. + dwc_otg_hc_regs_t * hc_regs,
  74576. + dwc_otg_halt_status_e halt_status)
  74577. +{
  74578. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  74579. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  74580. + dwc_otg_qh_t *qh;
  74581. + dwc_otg_host_dma_desc_t *dma_desc;
  74582. + uint16_t idx, remain;
  74583. + uint8_t urb_compl;
  74584. +
  74585. + qh = hc->qh;
  74586. + idx = qh->td_first;
  74587. +
  74588. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74589. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry)
  74590. + qtd->in_process = 0;
  74591. + return;
  74592. + } else if ((halt_status == DWC_OTG_HC_XFER_AHB_ERR) ||
  74593. + (halt_status == DWC_OTG_HC_XFER_BABBLE_ERR)) {
  74594. + /*
  74595. + * Channel is halted in these error cases.
  74596. + * Considered as serious issues.
  74597. + * Complete all URBs marking all frames as failed,
  74598. + * irrespective whether some of the descriptors(frames) succeeded or no.
  74599. + * Pass error code to completion routine as well, to
  74600. + * update urb->status, some of class drivers might use it to stop
  74601. + * queing transfer requests.
  74602. + */
  74603. + int err = (halt_status == DWC_OTG_HC_XFER_AHB_ERR)
  74604. + ? (-DWC_E_IO)
  74605. + : (-DWC_E_OVERFLOW);
  74606. +
  74607. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74608. + for (idx = 0; idx < qtd->urb->packet_count; idx++) {
  74609. + frame_desc = &qtd->urb->iso_descs[idx];
  74610. + frame_desc->status = err;
  74611. + }
  74612. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, err);
  74613. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74614. + }
  74615. + return;
  74616. + }
  74617. +
  74618. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74619. +
  74620. + if (!qtd->in_process)
  74621. + break;
  74622. +
  74623. + urb_compl = 0;
  74624. +
  74625. + do {
  74626. +
  74627. + dma_desc = &qh->desc_list[idx];
  74628. +
  74629. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  74630. + remain = hc->ep_is_in ? dma_desc->status.b_isoc.n_bytes : 0;
  74631. +
  74632. + if (dma_desc->status.b_isoc.sts == DMA_DESC_STS_PKTERR) {
  74633. + /*
  74634. + * XactError or, unable to complete all the transactions
  74635. + * in the scheduled micro-frame/frame,
  74636. + * both indicated by DMA_DESC_STS_PKTERR.
  74637. + */
  74638. + qtd->urb->error_count++;
  74639. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  74640. + frame_desc->status = -DWC_E_PROTOCOL;
  74641. + } else {
  74642. + /* Success */
  74643. +
  74644. + frame_desc->actual_length = qh->n_bytes[idx] - remain;
  74645. + frame_desc->status = 0;
  74646. + }
  74647. +
  74648. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  74649. + /*
  74650. + * urb->status is not used for isoc transfers here.
  74651. + * The individual frame_desc status are used instead.
  74652. + */
  74653. +
  74654. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  74655. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74656. +
  74657. + /*
  74658. + * This check is necessary because urb_dequeue can be called
  74659. + * from urb complete callback(sound driver example).
  74660. + * All pending URBs are dequeued there, so no need for
  74661. + * further processing.
  74662. + */
  74663. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74664. + return;
  74665. + }
  74666. +
  74667. + urb_compl = 1;
  74668. +
  74669. + }
  74670. +
  74671. + qh->ntd--;
  74672. +
  74673. + /* Stop if IOC requested descriptor reached */
  74674. + if (dma_desc->status.b_isoc.ioc) {
  74675. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  74676. + goto stop_scan;
  74677. + }
  74678. +
  74679. + idx = desclist_idx_inc(idx, qh->interval, hc->speed);
  74680. +
  74681. + if (urb_compl)
  74682. + break;
  74683. + }
  74684. + while (idx != qh->td_first);
  74685. + }
  74686. +stop_scan:
  74687. + qh->td_first = idx;
  74688. +}
  74689. +
  74690. +uint8_t update_non_isoc_urb_state_ddma(dwc_otg_hcd_t * hcd,
  74691. + dwc_hc_t * hc,
  74692. + dwc_otg_qtd_t * qtd,
  74693. + dwc_otg_host_dma_desc_t * dma_desc,
  74694. + dwc_otg_halt_status_e halt_status,
  74695. + uint32_t n_bytes, uint8_t * xfer_done)
  74696. +{
  74697. +
  74698. + uint16_t remain = hc->ep_is_in ? dma_desc->status.b.n_bytes : 0;
  74699. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  74700. +
  74701. + if (halt_status == DWC_OTG_HC_XFER_AHB_ERR) {
  74702. + urb->status = -DWC_E_IO;
  74703. + return 1;
  74704. + }
  74705. + if (dma_desc->status.b.sts == DMA_DESC_STS_PKTERR) {
  74706. + switch (halt_status) {
  74707. + case DWC_OTG_HC_XFER_STALL:
  74708. + urb->status = -DWC_E_PIPE;
  74709. + break;
  74710. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  74711. + urb->status = -DWC_E_OVERFLOW;
  74712. + break;
  74713. + case DWC_OTG_HC_XFER_XACT_ERR:
  74714. + urb->status = -DWC_E_PROTOCOL;
  74715. + break;
  74716. + default:
  74717. + DWC_ERROR("%s: Unhandled descriptor error status (%d)\n", __func__,
  74718. + halt_status);
  74719. + break;
  74720. + }
  74721. + return 1;
  74722. + }
  74723. +
  74724. + if (dma_desc->status.b.a == 1) {
  74725. + DWC_DEBUGPL(DBG_HCDV,
  74726. + "Active descriptor encountered on channel %d\n",
  74727. + hc->hc_num);
  74728. + return 0;
  74729. + }
  74730. +
  74731. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL) {
  74732. + if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  74733. + urb->actual_length += n_bytes - remain;
  74734. + if (remain || urb->actual_length == urb->length) {
  74735. + /*
  74736. + * For Control Data stage do not set urb->status=0 to prevent
  74737. + * URB callback. Set it when Status phase done. See below.
  74738. + */
  74739. + *xfer_done = 1;
  74740. + }
  74741. +
  74742. + } else if (qtd->control_phase == DWC_OTG_CONTROL_STATUS) {
  74743. + urb->status = 0;
  74744. + *xfer_done = 1;
  74745. + }
  74746. + /* No handling for SETUP stage */
  74747. + } else {
  74748. + /* BULK and INTR */
  74749. + urb->actual_length += n_bytes - remain;
  74750. + if (remain || urb->actual_length == urb->length) {
  74751. + urb->status = 0;
  74752. + *xfer_done = 1;
  74753. + }
  74754. + }
  74755. +
  74756. + return 0;
  74757. +}
  74758. +
  74759. +static void complete_non_isoc_xfer_ddma(dwc_otg_hcd_t * hcd,
  74760. + dwc_hc_t * hc,
  74761. + dwc_otg_hc_regs_t * hc_regs,
  74762. + dwc_otg_halt_status_e halt_status)
  74763. +{
  74764. + dwc_otg_hcd_urb_t *urb = NULL;
  74765. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  74766. + dwc_otg_qh_t *qh;
  74767. + dwc_otg_host_dma_desc_t *dma_desc;
  74768. + uint32_t n_bytes, n_desc, i;
  74769. + uint8_t failed = 0, xfer_done;
  74770. +
  74771. + n_desc = 0;
  74772. +
  74773. + qh = hc->qh;
  74774. +
  74775. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  74776. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &hc->qh->qtd_list, qtd_list_entry) {
  74777. + qtd->in_process = 0;
  74778. + }
  74779. + return;
  74780. + }
  74781. +
  74782. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  74783. +
  74784. + urb = qtd->urb;
  74785. +
  74786. + n_bytes = 0;
  74787. + xfer_done = 0;
  74788. +
  74789. + for (i = 0; i < qtd->n_desc; i++) {
  74790. + dma_desc = &qh->desc_list[n_desc];
  74791. +
  74792. + n_bytes = qh->n_bytes[n_desc];
  74793. +
  74794. + failed =
  74795. + update_non_isoc_urb_state_ddma(hcd, hc, qtd,
  74796. + dma_desc,
  74797. + halt_status, n_bytes,
  74798. + &xfer_done);
  74799. +
  74800. + if (failed
  74801. + || (xfer_done
  74802. + && (urb->status != -DWC_E_IN_PROGRESS))) {
  74803. +
  74804. + hcd->fops->complete(hcd, urb->priv, urb,
  74805. + urb->status);
  74806. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  74807. +
  74808. + if (failed)
  74809. + goto stop_scan;
  74810. + } else if (qh->ep_type == UE_CONTROL) {
  74811. + if (qtd->control_phase == DWC_OTG_CONTROL_SETUP) {
  74812. + if (urb->length > 0) {
  74813. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  74814. + } else {
  74815. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  74816. + }
  74817. + DWC_DEBUGPL(DBG_HCDV, " Control setup transaction done\n");
  74818. + } else if (qtd->control_phase == DWC_OTG_CONTROL_DATA) {
  74819. + if (xfer_done) {
  74820. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  74821. + DWC_DEBUGPL(DBG_HCDV, " Control data transfer done\n");
  74822. + } else if (i + 1 == qtd->n_desc) {
  74823. + /*
  74824. + * Last descriptor for Control data stage which is
  74825. + * not completed yet.
  74826. + */
  74827. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74828. + }
  74829. + }
  74830. + }
  74831. +
  74832. + n_desc++;
  74833. + }
  74834. +
  74835. + }
  74836. +
  74837. +stop_scan:
  74838. +
  74839. + if (qh->ep_type != UE_CONTROL) {
  74840. + /*
  74841. + * Resetting the data toggle for bulk
  74842. + * and interrupt endpoints in case of stall. See handle_hc_stall_intr()
  74843. + */
  74844. + if (halt_status == DWC_OTG_HC_XFER_STALL)
  74845. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  74846. + else
  74847. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  74848. + }
  74849. +
  74850. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  74851. + hcint_data_t hcint;
  74852. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  74853. + if (hcint.b.nyet) {
  74854. + /*
  74855. + * Got a NYET on the last transaction of the transfer. It
  74856. + * means that the endpoint should be in the PING state at the
  74857. + * beginning of the next transfer.
  74858. + */
  74859. + qh->ping_state = 1;
  74860. + clear_hc_int(hc_regs, nyet);
  74861. + }
  74862. +
  74863. + }
  74864. +
  74865. +}
  74866. +
  74867. +/**
  74868. + * This function is called from interrupt handlers.
  74869. + * Scans the descriptor list, updates URB's status and
  74870. + * calls completion routine for the URB if it's done.
  74871. + * Releases the channel to be used by other transfers.
  74872. + * In case of Isochronous endpoint the channel is not halted until
  74873. + * the end of the session, i.e. QTD list is empty.
  74874. + * If periodic channel released the FrameList is updated accordingly.
  74875. + *
  74876. + * Calls transaction selection routines to activate pending transfers.
  74877. + *
  74878. + * @param hcd The HCD state structure for the DWC OTG controller.
  74879. + * @param hc Host channel, the transfer is completed on.
  74880. + * @param hc_regs Host channel registers.
  74881. + * @param halt_status Reason the channel is being halted,
  74882. + * or just XferComplete for isochronous transfer
  74883. + */
  74884. +void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  74885. + dwc_hc_t * hc,
  74886. + dwc_otg_hc_regs_t * hc_regs,
  74887. + dwc_otg_halt_status_e halt_status)
  74888. +{
  74889. + uint8_t continue_isoc_xfer = 0;
  74890. + dwc_otg_transaction_type_e tr_type;
  74891. + dwc_otg_qh_t *qh = hc->qh;
  74892. +
  74893. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  74894. +
  74895. + complete_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  74896. +
  74897. + /* Release the channel if halted or session completed */
  74898. + if (halt_status != DWC_OTG_HC_XFER_COMPLETE ||
  74899. + DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  74900. +
  74901. + /* Halt the channel if session completed */
  74902. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  74903. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  74904. + }
  74905. +
  74906. + release_channel_ddma(hcd, qh);
  74907. + dwc_otg_hcd_qh_remove(hcd, qh);
  74908. + } else {
  74909. + /* Keep in assigned schedule to continue transfer */
  74910. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  74911. + &qh->qh_list_entry);
  74912. + continue_isoc_xfer = 1;
  74913. +
  74914. + }
  74915. + /** @todo Consider the case when period exceeds FrameList size.
  74916. + * Frame Rollover interrupt should be used.
  74917. + */
  74918. + } else {
  74919. + /* Scan descriptor list to complete the URB(s), then release the channel */
  74920. + complete_non_isoc_xfer_ddma(hcd, hc, hc_regs, halt_status);
  74921. +
  74922. + release_channel_ddma(hcd, qh);
  74923. + dwc_otg_hcd_qh_remove(hcd, qh);
  74924. +
  74925. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  74926. + /* Add back to inactive non-periodic schedule on normal completion */
  74927. + dwc_otg_hcd_qh_add(hcd, qh);
  74928. + }
  74929. +
  74930. + }
  74931. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  74932. + if (tr_type != DWC_OTG_TRANSACTION_NONE || continue_isoc_xfer) {
  74933. + if (continue_isoc_xfer) {
  74934. + if (tr_type == DWC_OTG_TRANSACTION_NONE) {
  74935. + tr_type = DWC_OTG_TRANSACTION_PERIODIC;
  74936. + } else if (tr_type == DWC_OTG_TRANSACTION_NON_PERIODIC) {
  74937. + tr_type = DWC_OTG_TRANSACTION_ALL;
  74938. + }
  74939. + }
  74940. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  74941. + }
  74942. +}
  74943. +
  74944. +#endif /* DWC_DEVICE_ONLY */
  74945. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h
  74946. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 1970-01-01 01:00:00.000000000 +0100
  74947. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd.h 2014-06-11 21:03:43.000000000 +0200
  74948. @@ -0,0 +1,862 @@
  74949. +/* ==========================================================================
  74950. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd.h $
  74951. + * $Revision: #58 $
  74952. + * $Date: 2011/09/15 $
  74953. + * $Change: 1846647 $
  74954. + *
  74955. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  74956. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  74957. + * otherwise expressly agreed to in writing between Synopsys and you.
  74958. + *
  74959. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  74960. + * any End User Software License Agreement or Agreement for Licensed Product
  74961. + * with Synopsys or any supplement thereto. You are permitted to use and
  74962. + * redistribute this Software in source and binary forms, with or without
  74963. + * modification, provided that redistributions of source code must retain this
  74964. + * notice. You may not view, use, disclose, copy or distribute this file or
  74965. + * any information contained herein except pursuant to this license grant from
  74966. + * Synopsys. If you do not agree with this notice, including the disclaimer
  74967. + * below, then you are not authorized to use the Software.
  74968. + *
  74969. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  74970. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  74971. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  74972. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  74973. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  74974. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  74975. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  74976. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  74977. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74978. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  74979. + * DAMAGE.
  74980. + * ========================================================================== */
  74981. +#ifndef DWC_DEVICE_ONLY
  74982. +#ifndef __DWC_HCD_H__
  74983. +#define __DWC_HCD_H__
  74984. +
  74985. +#include "dwc_otg_os_dep.h"
  74986. +#include "usb.h"
  74987. +#include "dwc_otg_hcd_if.h"
  74988. +#include "dwc_otg_core_if.h"
  74989. +#include "dwc_list.h"
  74990. +#include "dwc_otg_cil.h"
  74991. +#include "dwc_otg_fiq_fsm.h"
  74992. +
  74993. +
  74994. +/**
  74995. + * @file
  74996. + *
  74997. + * This file contains the structures, constants, and interfaces for
  74998. + * the Host Contoller Driver (HCD).
  74999. + *
  75000. + * The Host Controller Driver (HCD) is responsible for translating requests
  75001. + * from the USB Driver into the appropriate actions on the DWC_otg controller.
  75002. + * It isolates the USBD from the specifics of the controller by providing an
  75003. + * API to the USBD.
  75004. + */
  75005. +
  75006. +struct dwc_otg_hcd_pipe_info {
  75007. + uint8_t dev_addr;
  75008. + uint8_t ep_num;
  75009. + uint8_t pipe_type;
  75010. + uint8_t pipe_dir;
  75011. + uint16_t mps;
  75012. +};
  75013. +
  75014. +struct dwc_otg_hcd_iso_packet_desc {
  75015. + uint32_t offset;
  75016. + uint32_t length;
  75017. + uint32_t actual_length;
  75018. + uint32_t status;
  75019. +};
  75020. +
  75021. +struct dwc_otg_qtd;
  75022. +
  75023. +struct dwc_otg_hcd_urb {
  75024. + void *priv;
  75025. + struct dwc_otg_qtd *qtd;
  75026. + void *buf;
  75027. + dwc_dma_t dma;
  75028. + void *setup_packet;
  75029. + dwc_dma_t setup_dma;
  75030. + uint32_t length;
  75031. + uint32_t actual_length;
  75032. + uint32_t status;
  75033. + uint32_t error_count;
  75034. + uint32_t packet_count;
  75035. + uint32_t flags;
  75036. + uint16_t interval;
  75037. + struct dwc_otg_hcd_pipe_info pipe_info;
  75038. + struct dwc_otg_hcd_iso_packet_desc iso_descs[0];
  75039. +};
  75040. +
  75041. +static inline uint8_t dwc_otg_hcd_get_ep_num(struct dwc_otg_hcd_pipe_info *pipe)
  75042. +{
  75043. + return pipe->ep_num;
  75044. +}
  75045. +
  75046. +static inline uint8_t dwc_otg_hcd_get_pipe_type(struct dwc_otg_hcd_pipe_info
  75047. + *pipe)
  75048. +{
  75049. + return pipe->pipe_type;
  75050. +}
  75051. +
  75052. +static inline uint16_t dwc_otg_hcd_get_mps(struct dwc_otg_hcd_pipe_info *pipe)
  75053. +{
  75054. + return pipe->mps;
  75055. +}
  75056. +
  75057. +static inline uint8_t dwc_otg_hcd_get_dev_addr(struct dwc_otg_hcd_pipe_info
  75058. + *pipe)
  75059. +{
  75060. + return pipe->dev_addr;
  75061. +}
  75062. +
  75063. +static inline uint8_t dwc_otg_hcd_is_pipe_isoc(struct dwc_otg_hcd_pipe_info
  75064. + *pipe)
  75065. +{
  75066. + return (pipe->pipe_type == UE_ISOCHRONOUS);
  75067. +}
  75068. +
  75069. +static inline uint8_t dwc_otg_hcd_is_pipe_int(struct dwc_otg_hcd_pipe_info
  75070. + *pipe)
  75071. +{
  75072. + return (pipe->pipe_type == UE_INTERRUPT);
  75073. +}
  75074. +
  75075. +static inline uint8_t dwc_otg_hcd_is_pipe_bulk(struct dwc_otg_hcd_pipe_info
  75076. + *pipe)
  75077. +{
  75078. + return (pipe->pipe_type == UE_BULK);
  75079. +}
  75080. +
  75081. +static inline uint8_t dwc_otg_hcd_is_pipe_control(struct dwc_otg_hcd_pipe_info
  75082. + *pipe)
  75083. +{
  75084. + return (pipe->pipe_type == UE_CONTROL);
  75085. +}
  75086. +
  75087. +static inline uint8_t dwc_otg_hcd_is_pipe_in(struct dwc_otg_hcd_pipe_info *pipe)
  75088. +{
  75089. + return (pipe->pipe_dir == UE_DIR_IN);
  75090. +}
  75091. +
  75092. +static inline uint8_t dwc_otg_hcd_is_pipe_out(struct dwc_otg_hcd_pipe_info
  75093. + *pipe)
  75094. +{
  75095. + return (!dwc_otg_hcd_is_pipe_in(pipe));
  75096. +}
  75097. +
  75098. +static inline void dwc_otg_hcd_fill_pipe(struct dwc_otg_hcd_pipe_info *pipe,
  75099. + uint8_t devaddr, uint8_t ep_num,
  75100. + uint8_t pipe_type, uint8_t pipe_dir,
  75101. + uint16_t mps)
  75102. +{
  75103. + pipe->dev_addr = devaddr;
  75104. + pipe->ep_num = ep_num;
  75105. + pipe->pipe_type = pipe_type;
  75106. + pipe->pipe_dir = pipe_dir;
  75107. + pipe->mps = mps;
  75108. +}
  75109. +
  75110. +/**
  75111. + * Phases for control transfers.
  75112. + */
  75113. +typedef enum dwc_otg_control_phase {
  75114. + DWC_OTG_CONTROL_SETUP,
  75115. + DWC_OTG_CONTROL_DATA,
  75116. + DWC_OTG_CONTROL_STATUS
  75117. +} dwc_otg_control_phase_e;
  75118. +
  75119. +/** Transaction types. */
  75120. +typedef enum dwc_otg_transaction_type {
  75121. + DWC_OTG_TRANSACTION_NONE = 0,
  75122. + DWC_OTG_TRANSACTION_PERIODIC = 1,
  75123. + DWC_OTG_TRANSACTION_NON_PERIODIC = 2,
  75124. + DWC_OTG_TRANSACTION_ALL = DWC_OTG_TRANSACTION_PERIODIC + DWC_OTG_TRANSACTION_NON_PERIODIC
  75125. +} dwc_otg_transaction_type_e;
  75126. +
  75127. +struct dwc_otg_qh;
  75128. +
  75129. +/**
  75130. + * A Queue Transfer Descriptor (QTD) holds the state of a bulk, control,
  75131. + * interrupt, or isochronous transfer. A single QTD is created for each URB
  75132. + * (of one of these types) submitted to the HCD. The transfer associated with
  75133. + * a QTD may require one or multiple transactions.
  75134. + *
  75135. + * A QTD is linked to a Queue Head, which is entered in either the
  75136. + * non-periodic or periodic schedule for execution. When a QTD is chosen for
  75137. + * execution, some or all of its transactions may be executed. After
  75138. + * execution, the state of the QTD is updated. The QTD may be retired if all
  75139. + * its transactions are complete or if an error occurred. Otherwise, it
  75140. + * remains in the schedule so more transactions can be executed later.
  75141. + */
  75142. +typedef struct dwc_otg_qtd {
  75143. + /**
  75144. + * Determines the PID of the next data packet for the data phase of
  75145. + * control transfers. Ignored for other transfer types.<br>
  75146. + * One of the following values:
  75147. + * - DWC_OTG_HC_PID_DATA0
  75148. + * - DWC_OTG_HC_PID_DATA1
  75149. + */
  75150. + uint8_t data_toggle;
  75151. +
  75152. + /** Current phase for control transfers (Setup, Data, or Status). */
  75153. + dwc_otg_control_phase_e control_phase;
  75154. +
  75155. + /** Keep track of the current split type
  75156. + * for FS/LS endpoints on a HS Hub */
  75157. + uint8_t complete_split;
  75158. +
  75159. + /** How many bytes transferred during SSPLIT OUT */
  75160. + uint32_t ssplit_out_xfer_count;
  75161. +
  75162. + /**
  75163. + * Holds the number of bus errors that have occurred for a transaction
  75164. + * within this transfer.
  75165. + */
  75166. + uint8_t error_count;
  75167. +
  75168. + /**
  75169. + * Index of the next frame descriptor for an isochronous transfer. A
  75170. + * frame descriptor describes the buffer position and length of the
  75171. + * data to be transferred in the next scheduled (micro)frame of an
  75172. + * isochronous transfer. It also holds status for that transaction.
  75173. + * The frame index starts at 0.
  75174. + */
  75175. + uint16_t isoc_frame_index;
  75176. +
  75177. + /** Position of the ISOC split on full/low speed */
  75178. + uint8_t isoc_split_pos;
  75179. +
  75180. + /** Position of the ISOC split in the buffer for the current frame */
  75181. + uint16_t isoc_split_offset;
  75182. +
  75183. + /** URB for this transfer */
  75184. + struct dwc_otg_hcd_urb *urb;
  75185. +
  75186. + struct dwc_otg_qh *qh;
  75187. +
  75188. + /** This list of QTDs */
  75189. + DWC_CIRCLEQ_ENTRY(dwc_otg_qtd) qtd_list_entry;
  75190. +
  75191. + /** Indicates if this QTD is currently processed by HW. */
  75192. + uint8_t in_process;
  75193. +
  75194. + /** Number of DMA descriptors for this QTD */
  75195. + uint8_t n_desc;
  75196. +
  75197. + /**
  75198. + * Last activated frame(packet) index.
  75199. + * Used in Descriptor DMA mode only.
  75200. + */
  75201. + uint16_t isoc_frame_index_last;
  75202. +
  75203. +} dwc_otg_qtd_t;
  75204. +
  75205. +DWC_CIRCLEQ_HEAD(dwc_otg_qtd_list, dwc_otg_qtd);
  75206. +
  75207. +/**
  75208. + * A Queue Head (QH) holds the static characteristics of an endpoint and
  75209. + * maintains a list of transfers (QTDs) for that endpoint. A QH structure may
  75210. + * be entered in either the non-periodic or periodic schedule.
  75211. + */
  75212. +typedef struct dwc_otg_qh {
  75213. + /**
  75214. + * Endpoint type.
  75215. + * One of the following values:
  75216. + * - UE_CONTROL
  75217. + * - UE_BULK
  75218. + * - UE_INTERRUPT
  75219. + * - UE_ISOCHRONOUS
  75220. + */
  75221. + uint8_t ep_type;
  75222. + uint8_t ep_is_in;
  75223. +
  75224. + /** wMaxPacketSize Field of Endpoint Descriptor. */
  75225. + uint16_t maxp;
  75226. +
  75227. + /**
  75228. + * Device speed.
  75229. + * One of the following values:
  75230. + * - DWC_OTG_EP_SPEED_LOW
  75231. + * - DWC_OTG_EP_SPEED_FULL
  75232. + * - DWC_OTG_EP_SPEED_HIGH
  75233. + */
  75234. + uint8_t dev_speed;
  75235. +
  75236. + /**
  75237. + * Determines the PID of the next data packet for non-control
  75238. + * transfers. Ignored for control transfers.<br>
  75239. + * One of the following values:
  75240. + * - DWC_OTG_HC_PID_DATA0
  75241. + * - DWC_OTG_HC_PID_DATA1
  75242. + */
  75243. + uint8_t data_toggle;
  75244. +
  75245. + /** Ping state if 1. */
  75246. + uint8_t ping_state;
  75247. +
  75248. + /**
  75249. + * List of QTDs for this QH.
  75250. + */
  75251. + struct dwc_otg_qtd_list qtd_list;
  75252. +
  75253. + /** Host channel currently processing transfers for this QH. */
  75254. + struct dwc_hc *channel;
  75255. +
  75256. + /** Full/low speed endpoint on high-speed hub requires split. */
  75257. + uint8_t do_split;
  75258. +
  75259. + /** @name Periodic schedule information */
  75260. + /** @{ */
  75261. +
  75262. + /** Bandwidth in microseconds per (micro)frame. */
  75263. + uint16_t usecs;
  75264. +
  75265. + /** Interval between transfers in (micro)frames. */
  75266. + uint16_t interval;
  75267. +
  75268. + /**
  75269. + * (micro)frame to initialize a periodic transfer. The transfer
  75270. + * executes in the following (micro)frame.
  75271. + */
  75272. + uint16_t sched_frame;
  75273. +
  75274. + /*
  75275. + ** Frame a NAK was received on this queue head, used to minimise NAK retransmission
  75276. + */
  75277. + uint16_t nak_frame;
  75278. +
  75279. + /** (micro)frame at which last start split was initialized. */
  75280. + uint16_t start_split_frame;
  75281. +
  75282. + /** @} */
  75283. +
  75284. + /**
  75285. + * Used instead of original buffer if
  75286. + * it(physical address) is not dword-aligned.
  75287. + */
  75288. + uint8_t *dw_align_buf;
  75289. + dwc_dma_t dw_align_buf_dma;
  75290. +
  75291. + /** Entry for QH in either the periodic or non-periodic schedule. */
  75292. + dwc_list_link_t qh_list_entry;
  75293. +
  75294. + /** @name Descriptor DMA support */
  75295. + /** @{ */
  75296. +
  75297. + /** Descriptor List. */
  75298. + dwc_otg_host_dma_desc_t *desc_list;
  75299. +
  75300. + /** Descriptor List physical address. */
  75301. + dwc_dma_t desc_list_dma;
  75302. +
  75303. + /**
  75304. + * Xfer Bytes array.
  75305. + * Each element corresponds to a descriptor and indicates
  75306. + * original XferSize size value for the descriptor.
  75307. + */
  75308. + uint32_t *n_bytes;
  75309. +
  75310. + /** Actual number of transfer descriptors in a list. */
  75311. + uint16_t ntd;
  75312. +
  75313. + /** First activated isochronous transfer descriptor index. */
  75314. + uint8_t td_first;
  75315. + /** Last activated isochronous transfer descriptor index. */
  75316. + uint8_t td_last;
  75317. +
  75318. + /** @} */
  75319. +
  75320. +
  75321. + uint16_t speed;
  75322. + uint16_t frame_usecs[8];
  75323. +
  75324. + uint32_t skip_count;
  75325. +} dwc_otg_qh_t;
  75326. +
  75327. +DWC_CIRCLEQ_HEAD(hc_list, dwc_hc);
  75328. +
  75329. +typedef struct urb_tq_entry {
  75330. + struct urb *urb;
  75331. + DWC_TAILQ_ENTRY(urb_tq_entry) urb_tq_entries;
  75332. +} urb_tq_entry_t;
  75333. +
  75334. +DWC_TAILQ_HEAD(urb_list, urb_tq_entry);
  75335. +
  75336. +/**
  75337. + * This structure holds the state of the HCD, including the non-periodic and
  75338. + * periodic schedules.
  75339. + */
  75340. +struct dwc_otg_hcd {
  75341. + /** The DWC otg device pointer */
  75342. + struct dwc_otg_device *otg_dev;
  75343. + /** DWC OTG Core Interface Layer */
  75344. + dwc_otg_core_if_t *core_if;
  75345. +
  75346. + /** Function HCD driver callbacks */
  75347. + struct dwc_otg_hcd_function_ops *fops;
  75348. +
  75349. + /** Internal DWC HCD Flags */
  75350. + volatile union dwc_otg_hcd_internal_flags {
  75351. + uint32_t d32;
  75352. + struct {
  75353. + unsigned port_connect_status_change:1;
  75354. + unsigned port_connect_status:1;
  75355. + unsigned port_reset_change:1;
  75356. + unsigned port_enable_change:1;
  75357. + unsigned port_suspend_change:1;
  75358. + unsigned port_over_current_change:1;
  75359. + unsigned port_l1_change:1;
  75360. + unsigned reserved:26;
  75361. + } b;
  75362. + } flags;
  75363. +
  75364. + /**
  75365. + * Inactive items in the non-periodic schedule. This is a list of
  75366. + * Queue Heads. Transfers associated with these Queue Heads are not
  75367. + * currently assigned to a host channel.
  75368. + */
  75369. + dwc_list_link_t non_periodic_sched_inactive;
  75370. +
  75371. + /**
  75372. + * Active items in the non-periodic schedule. This is a list of
  75373. + * Queue Heads. Transfers associated with these Queue Heads are
  75374. + * currently assigned to a host channel.
  75375. + */
  75376. + dwc_list_link_t non_periodic_sched_active;
  75377. +
  75378. + /**
  75379. + * Pointer to the next Queue Head to process in the active
  75380. + * non-periodic schedule.
  75381. + */
  75382. + dwc_list_link_t *non_periodic_qh_ptr;
  75383. +
  75384. + /**
  75385. + * Inactive items in the periodic schedule. This is a list of QHs for
  75386. + * periodic transfers that are _not_ scheduled for the next frame.
  75387. + * Each QH in the list has an interval counter that determines when it
  75388. + * needs to be scheduled for execution. This scheduling mechanism
  75389. + * allows only a simple calculation for periodic bandwidth used (i.e.
  75390. + * must assume that all periodic transfers may need to execute in the
  75391. + * same frame). However, it greatly simplifies scheduling and should
  75392. + * be sufficient for the vast majority of OTG hosts, which need to
  75393. + * connect to a small number of peripherals at one time.
  75394. + *
  75395. + * Items move from this list to periodic_sched_ready when the QH
  75396. + * interval counter is 0 at SOF.
  75397. + */
  75398. + dwc_list_link_t periodic_sched_inactive;
  75399. +
  75400. + /**
  75401. + * List of periodic QHs that are ready for execution in the next
  75402. + * frame, but have not yet been assigned to host channels.
  75403. + *
  75404. + * Items move from this list to periodic_sched_assigned as host
  75405. + * channels become available during the current frame.
  75406. + */
  75407. + dwc_list_link_t periodic_sched_ready;
  75408. +
  75409. + /**
  75410. + * List of periodic QHs to be executed in the next frame that are
  75411. + * assigned to host channels.
  75412. + *
  75413. + * Items move from this list to periodic_sched_queued as the
  75414. + * transactions for the QH are queued to the DWC_otg controller.
  75415. + */
  75416. + dwc_list_link_t periodic_sched_assigned;
  75417. +
  75418. + /**
  75419. + * List of periodic QHs that have been queued for execution.
  75420. + *
  75421. + * Items move from this list to either periodic_sched_inactive or
  75422. + * periodic_sched_ready when the channel associated with the transfer
  75423. + * is released. If the interval for the QH is 1, the item moves to
  75424. + * periodic_sched_ready because it must be rescheduled for the next
  75425. + * frame. Otherwise, the item moves to periodic_sched_inactive.
  75426. + */
  75427. + dwc_list_link_t periodic_sched_queued;
  75428. +
  75429. + /**
  75430. + * Total bandwidth claimed so far for periodic transfers. This value
  75431. + * is in microseconds per (micro)frame. The assumption is that all
  75432. + * periodic transfers may occur in the same (micro)frame.
  75433. + */
  75434. + uint16_t periodic_usecs;
  75435. +
  75436. + /**
  75437. + * Total bandwidth claimed so far for all periodic transfers
  75438. + * in a frame.
  75439. + * This will include a mixture of HS and FS transfers.
  75440. + * Units are microseconds per (micro)frame.
  75441. + * We have a budget per frame and have to schedule
  75442. + * transactions accordingly.
  75443. + * Watch out for the fact that things are actually scheduled for the
  75444. + * "next frame".
  75445. + */
  75446. + uint16_t frame_usecs[8];
  75447. +
  75448. +
  75449. + /**
  75450. + * Frame number read from the core at SOF. The value ranges from 0 to
  75451. + * DWC_HFNUM_MAX_FRNUM.
  75452. + */
  75453. + uint16_t frame_number;
  75454. +
  75455. + /**
  75456. + * Count of periodic QHs, if using several eps. For SOF enable/disable.
  75457. + */
  75458. + uint16_t periodic_qh_count;
  75459. +
  75460. + /**
  75461. + * Free host channels in the controller. This is a list of
  75462. + * dwc_hc_t items.
  75463. + */
  75464. + struct hc_list free_hc_list;
  75465. + /**
  75466. + * Number of host channels assigned to periodic transfers. Currently
  75467. + * assuming that there is a dedicated host channel for each periodic
  75468. + * transaction and at least one host channel available for
  75469. + * non-periodic transactions.
  75470. + */
  75471. + int periodic_channels; /* microframe_schedule==0 */
  75472. +
  75473. + /**
  75474. + * Number of host channels assigned to non-periodic transfers.
  75475. + */
  75476. + int non_periodic_channels; /* microframe_schedule==0 */
  75477. +
  75478. + /**
  75479. + * Number of host channels assigned to non-periodic transfers.
  75480. + */
  75481. + int available_host_channels;
  75482. +
  75483. + /**
  75484. + * Array of pointers to the host channel descriptors. Allows accessing
  75485. + * a host channel descriptor given the host channel number. This is
  75486. + * useful in interrupt handlers.
  75487. + */
  75488. + struct dwc_hc *hc_ptr_array[MAX_EPS_CHANNELS];
  75489. +
  75490. + /**
  75491. + * Buffer to use for any data received during the status phase of a
  75492. + * control transfer. Normally no data is transferred during the status
  75493. + * phase. This buffer is used as a bit bucket.
  75494. + */
  75495. + uint8_t *status_buf;
  75496. +
  75497. + /**
  75498. + * DMA address for status_buf.
  75499. + */
  75500. + dma_addr_t status_buf_dma;
  75501. +#define DWC_OTG_HCD_STATUS_BUF_SIZE 64
  75502. +
  75503. + /**
  75504. + * Connection timer. An OTG host must display a message if the device
  75505. + * does not connect. Started when the VBus power is turned on via
  75506. + * sysfs attribute "buspower".
  75507. + */
  75508. + dwc_timer_t *conn_timer;
  75509. +
  75510. + /* Tasket to do a reset */
  75511. + dwc_tasklet_t *reset_tasklet;
  75512. +
  75513. + dwc_tasklet_t *completion_tasklet;
  75514. + struct urb_list completed_urb_list;
  75515. +
  75516. + /* */
  75517. + dwc_spinlock_t *lock;
  75518. + dwc_spinlock_t *channel_lock;
  75519. + /**
  75520. + * Private data that could be used by OS wrapper.
  75521. + */
  75522. + void *priv;
  75523. +
  75524. + uint8_t otg_port;
  75525. +
  75526. + /** Frame List */
  75527. + uint32_t *frame_list;
  75528. +
  75529. + /** Hub - Port assignment */
  75530. + int hub_port[128];
  75531. +#ifdef FIQ_DEBUG
  75532. + int hub_port_alloc[2048];
  75533. +#endif
  75534. +
  75535. + /** Frame List DMA address */
  75536. + dma_addr_t frame_list_dma;
  75537. +
  75538. + struct fiq_stack *fiq_stack;
  75539. + struct fiq_state *fiq_state;
  75540. +
  75541. + /** Virtual address for split transaction DMA bounce buffers */
  75542. + struct fiq_dma_blob *fiq_dmab;
  75543. +
  75544. +#ifdef DEBUG
  75545. + uint32_t frrem_samples;
  75546. + uint64_t frrem_accum;
  75547. +
  75548. + uint32_t hfnum_7_samples_a;
  75549. + uint64_t hfnum_7_frrem_accum_a;
  75550. + uint32_t hfnum_0_samples_a;
  75551. + uint64_t hfnum_0_frrem_accum_a;
  75552. + uint32_t hfnum_other_samples_a;
  75553. + uint64_t hfnum_other_frrem_accum_a;
  75554. +
  75555. + uint32_t hfnum_7_samples_b;
  75556. + uint64_t hfnum_7_frrem_accum_b;
  75557. + uint32_t hfnum_0_samples_b;
  75558. + uint64_t hfnum_0_frrem_accum_b;
  75559. + uint32_t hfnum_other_samples_b;
  75560. + uint64_t hfnum_other_frrem_accum_b;
  75561. +#endif
  75562. +};
  75563. +
  75564. +/** @name Transaction Execution Functions */
  75565. +/** @{ */
  75566. +extern dwc_otg_transaction_type_e dwc_otg_hcd_select_transactions(dwc_otg_hcd_t
  75567. + * hcd);
  75568. +extern void dwc_otg_hcd_queue_transactions(dwc_otg_hcd_t * hcd,
  75569. + dwc_otg_transaction_type_e tr_type);
  75570. +
  75571. +int dwc_otg_hcd_allocate_port(dwc_otg_hcd_t * hcd, dwc_otg_qh_t *qh);
  75572. +void dwc_otg_hcd_release_port(dwc_otg_hcd_t * dwc_otg_hcd, dwc_otg_qh_t *qh);
  75573. +
  75574. +extern int fiq_fsm_queue_transaction(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh);
  75575. +extern int fiq_fsm_transaction_suitable(dwc_otg_qh_t *qh);
  75576. +extern void dwc_otg_cleanup_fiq_channel(dwc_otg_hcd_t *hcd, uint32_t num);
  75577. +
  75578. +/** @} */
  75579. +
  75580. +/** @name Interrupt Handler Functions */
  75581. +/** @{ */
  75582. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75583. +extern int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75584. +extern int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t *
  75585. + dwc_otg_hcd);
  75586. +extern int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t *
  75587. + dwc_otg_hcd);
  75588. +extern int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t *
  75589. + dwc_otg_hcd);
  75590. +extern int32_t dwc_otg_hcd_handle_incomplete_periodic_intr(dwc_otg_hcd_t *
  75591. + dwc_otg_hcd);
  75592. +extern int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75593. +extern int32_t dwc_otg_hcd_handle_conn_id_status_change_intr(dwc_otg_hcd_t *
  75594. + dwc_otg_hcd);
  75595. +extern int32_t dwc_otg_hcd_handle_disconnect_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75596. +extern int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75597. +extern int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd,
  75598. + uint32_t num);
  75599. +extern int32_t dwc_otg_hcd_handle_session_req_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75600. +extern int32_t dwc_otg_hcd_handle_wakeup_detected_intr(dwc_otg_hcd_t *
  75601. + dwc_otg_hcd);
  75602. +/** @} */
  75603. +
  75604. +/** @name Schedule Queue Functions */
  75605. +/** @{ */
  75606. +
  75607. +/* Implemented in dwc_otg_hcd_queue.c */
  75608. +extern dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  75609. + dwc_otg_hcd_urb_t * urb, int atomic_alloc);
  75610. +extern void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75611. +extern int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75612. +extern void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75613. +extern void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  75614. + int sched_csplit);
  75615. +
  75616. +/** Remove and free a QH */
  75617. +static inline void dwc_otg_hcd_qh_remove_and_free(dwc_otg_hcd_t * hcd,
  75618. + dwc_otg_qh_t * qh)
  75619. +{
  75620. + dwc_irqflags_t flags;
  75621. + DWC_SPINLOCK_IRQSAVE(hcd->lock, &flags);
  75622. + dwc_otg_hcd_qh_remove(hcd, qh);
  75623. + DWC_SPINUNLOCK_IRQRESTORE(hcd->lock, flags);
  75624. + dwc_otg_hcd_qh_free(hcd, qh);
  75625. +}
  75626. +
  75627. +/** Allocates memory for a QH structure.
  75628. + * @return Returns the memory allocate or NULL on error. */
  75629. +static inline dwc_otg_qh_t *dwc_otg_hcd_qh_alloc(int atomic_alloc)
  75630. +{
  75631. + if (atomic_alloc)
  75632. + return (dwc_otg_qh_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qh_t));
  75633. + else
  75634. + return (dwc_otg_qh_t *) DWC_ALLOC(sizeof(dwc_otg_qh_t));
  75635. +}
  75636. +
  75637. +extern dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb,
  75638. + int atomic_alloc);
  75639. +extern void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb);
  75640. +extern int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd, dwc_otg_hcd_t * dwc_otg_hcd,
  75641. + dwc_otg_qh_t ** qh, int atomic_alloc);
  75642. +
  75643. +/** Allocates memory for a QTD structure.
  75644. + * @return Returns the memory allocate or NULL on error. */
  75645. +static inline dwc_otg_qtd_t *dwc_otg_hcd_qtd_alloc(int atomic_alloc)
  75646. +{
  75647. + if (atomic_alloc)
  75648. + return (dwc_otg_qtd_t *) DWC_ALLOC_ATOMIC(sizeof(dwc_otg_qtd_t));
  75649. + else
  75650. + return (dwc_otg_qtd_t *) DWC_ALLOC(sizeof(dwc_otg_qtd_t));
  75651. +}
  75652. +
  75653. +/** Frees the memory for a QTD structure. QTD should already be removed from
  75654. + * list.
  75655. + * @param qtd QTD to free.*/
  75656. +static inline void dwc_otg_hcd_qtd_free(dwc_otg_qtd_t * qtd)
  75657. +{
  75658. + DWC_FREE(qtd);
  75659. +}
  75660. +
  75661. +/** Removes a QTD from list.
  75662. + * @param hcd HCD instance.
  75663. + * @param qtd QTD to remove from list.
  75664. + * @param qh QTD belongs to.
  75665. + */
  75666. +static inline void dwc_otg_hcd_qtd_remove(dwc_otg_hcd_t * hcd,
  75667. + dwc_otg_qtd_t * qtd,
  75668. + dwc_otg_qh_t * qh)
  75669. +{
  75670. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  75671. +}
  75672. +
  75673. +/** Remove and free a QTD
  75674. + * Need to disable IRQ and hold hcd lock while calling this function out of
  75675. + * interrupt servicing chain */
  75676. +static inline void dwc_otg_hcd_qtd_remove_and_free(dwc_otg_hcd_t * hcd,
  75677. + dwc_otg_qtd_t * qtd,
  75678. + dwc_otg_qh_t * qh)
  75679. +{
  75680. + dwc_otg_hcd_qtd_remove(hcd, qtd, qh);
  75681. + dwc_otg_hcd_qtd_free(qtd);
  75682. +}
  75683. +
  75684. +/** @} */
  75685. +
  75686. +/** @name Descriptor DMA Supporting Functions */
  75687. +/** @{ */
  75688. +
  75689. +extern void dwc_otg_hcd_start_xfer_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75690. +extern void dwc_otg_hcd_complete_xfer_ddma(dwc_otg_hcd_t * hcd,
  75691. + dwc_hc_t * hc,
  75692. + dwc_otg_hc_regs_t * hc_regs,
  75693. + dwc_otg_halt_status_e halt_status);
  75694. +
  75695. +extern int dwc_otg_hcd_qh_init_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75696. +extern void dwc_otg_hcd_qh_free_ddma(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh);
  75697. +
  75698. +/** @} */
  75699. +
  75700. +/** @name Internal Functions */
  75701. +/** @{ */
  75702. +dwc_otg_qh_t *dwc_urb_to_qh(dwc_otg_hcd_urb_t * urb);
  75703. +/** @} */
  75704. +
  75705. +#ifdef CONFIG_USB_DWC_OTG_LPM
  75706. +extern int dwc_otg_hcd_get_hc_for_lpm_tran(dwc_otg_hcd_t * hcd,
  75707. + uint8_t devaddr);
  75708. +extern void dwc_otg_hcd_free_hc_from_lpm(dwc_otg_hcd_t * hcd);
  75709. +#endif
  75710. +
  75711. +/** Gets the QH that contains the list_head */
  75712. +#define dwc_list_to_qh(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qh_t, qh_list_entry)
  75713. +
  75714. +/** Gets the QTD that contains the list_head */
  75715. +#define dwc_list_to_qtd(_list_head_ptr_) container_of(_list_head_ptr_, dwc_otg_qtd_t, qtd_list_entry)
  75716. +
  75717. +/** Check if QH is non-periodic */
  75718. +#define dwc_qh_is_non_per(_qh_ptr_) ((_qh_ptr_->ep_type == UE_BULK) || \
  75719. + (_qh_ptr_->ep_type == UE_CONTROL))
  75720. +
  75721. +/** High bandwidth multiplier as encoded in highspeed endpoint descriptors */
  75722. +#define dwc_hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
  75723. +
  75724. +/** Packet size for any kind of endpoint descriptor */
  75725. +#define dwc_max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
  75726. +
  75727. +/**
  75728. + * Returns true if _frame1 is less than or equal to _frame2. The comparison is
  75729. + * done modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the
  75730. + * frame number when the max frame number is reached.
  75731. + */
  75732. +static inline int dwc_frame_num_le(uint16_t frame1, uint16_t frame2)
  75733. +{
  75734. + return ((frame2 - frame1) & DWC_HFNUM_MAX_FRNUM) <=
  75735. + (DWC_HFNUM_MAX_FRNUM >> 1);
  75736. +}
  75737. +
  75738. +/**
  75739. + * Returns true if _frame1 is greater than _frame2. The comparison is done
  75740. + * modulo DWC_HFNUM_MAX_FRNUM. This accounts for the rollover of the frame
  75741. + * number when the max frame number is reached.
  75742. + */
  75743. +static inline int dwc_frame_num_gt(uint16_t frame1, uint16_t frame2)
  75744. +{
  75745. + return (frame1 != frame2) &&
  75746. + (((frame1 - frame2) & DWC_HFNUM_MAX_FRNUM) <
  75747. + (DWC_HFNUM_MAX_FRNUM >> 1));
  75748. +}
  75749. +
  75750. +/**
  75751. + * Increments _frame by the amount specified by _inc. The addition is done
  75752. + * modulo DWC_HFNUM_MAX_FRNUM. Returns the incremented value.
  75753. + */
  75754. +static inline uint16_t dwc_frame_num_inc(uint16_t frame, uint16_t inc)
  75755. +{
  75756. + return (frame + inc) & DWC_HFNUM_MAX_FRNUM;
  75757. +}
  75758. +
  75759. +static inline uint16_t dwc_full_frame_num(uint16_t frame)
  75760. +{
  75761. + return (frame & DWC_HFNUM_MAX_FRNUM) >> 3;
  75762. +}
  75763. +
  75764. +static inline uint16_t dwc_micro_frame_num(uint16_t frame)
  75765. +{
  75766. + return frame & 0x7;
  75767. +}
  75768. +
  75769. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  75770. + dwc_otg_hc_regs_t * hc_regs,
  75771. + dwc_otg_qtd_t * qtd);
  75772. +
  75773. +#ifdef DEBUG
  75774. +/**
  75775. + * Macro to sample the remaining PHY clocks left in the current frame. This
  75776. + * may be used during debugging to determine the average time it takes to
  75777. + * execute sections of code. There are two possible sample points, "a" and
  75778. + * "b", so the _letter argument must be one of these values.
  75779. + *
  75780. + * To dump the average sample times, read the "hcd_frrem" sysfs attribute. For
  75781. + * example, "cat /sys/devices/lm0/hcd_frrem".
  75782. + */
  75783. +#define dwc_sample_frrem(_hcd, _qh, _letter) \
  75784. +{ \
  75785. + hfnum_data_t hfnum; \
  75786. + dwc_otg_qtd_t *qtd; \
  75787. + qtd = list_entry(_qh->qtd_list.next, dwc_otg_qtd_t, qtd_list_entry); \
  75788. + if (usb_pipeint(qtd->urb->pipe) && _qh->start_split_frame != 0 && !qtd->complete_split) { \
  75789. + hfnum.d32 = DWC_READ_REG32(&_hcd->core_if->host_if->host_global_regs->hfnum); \
  75790. + switch (hfnum.b.frnum & 0x7) { \
  75791. + case 7: \
  75792. + _hcd->hfnum_7_samples_##_letter++; \
  75793. + _hcd->hfnum_7_frrem_accum_##_letter += hfnum.b.frrem; \
  75794. + break; \
  75795. + case 0: \
  75796. + _hcd->hfnum_0_samples_##_letter++; \
  75797. + _hcd->hfnum_0_frrem_accum_##_letter += hfnum.b.frrem; \
  75798. + break; \
  75799. + default: \
  75800. + _hcd->hfnum_other_samples_##_letter++; \
  75801. + _hcd->hfnum_other_frrem_accum_##_letter += hfnum.b.frrem; \
  75802. + break; \
  75803. + } \
  75804. + } \
  75805. +}
  75806. +#else
  75807. +#define dwc_sample_frrem(_hcd, _qh, _letter)
  75808. +#endif
  75809. +#endif
  75810. +#endif /* DWC_DEVICE_ONLY */
  75811. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h
  75812. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 1970-01-01 01:00:00.000000000 +0100
  75813. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_if.h 2014-06-11 21:03:43.000000000 +0200
  75814. @@ -0,0 +1,417 @@
  75815. +/* ==========================================================================
  75816. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_if.h $
  75817. + * $Revision: #12 $
  75818. + * $Date: 2011/10/26 $
  75819. + * $Change: 1873028 $
  75820. + *
  75821. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  75822. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  75823. + * otherwise expressly agreed to in writing between Synopsys and you.
  75824. + *
  75825. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  75826. + * any End User Software License Agreement or Agreement for Licensed Product
  75827. + * with Synopsys or any supplement thereto. You are permitted to use and
  75828. + * redistribute this Software in source and binary forms, with or without
  75829. + * modification, provided that redistributions of source code must retain this
  75830. + * notice. You may not view, use, disclose, copy or distribute this file or
  75831. + * any information contained herein except pursuant to this license grant from
  75832. + * Synopsys. If you do not agree with this notice, including the disclaimer
  75833. + * below, then you are not authorized to use the Software.
  75834. + *
  75835. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  75836. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  75837. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  75838. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  75839. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  75840. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  75841. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  75842. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  75843. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  75844. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  75845. + * DAMAGE.
  75846. + * ========================================================================== */
  75847. +#ifndef DWC_DEVICE_ONLY
  75848. +#ifndef __DWC_HCD_IF_H__
  75849. +#define __DWC_HCD_IF_H__
  75850. +
  75851. +#include "dwc_otg_core_if.h"
  75852. +
  75853. +/** @file
  75854. + * This file defines DWC_OTG HCD Core API.
  75855. + */
  75856. +
  75857. +struct dwc_otg_hcd;
  75858. +typedef struct dwc_otg_hcd dwc_otg_hcd_t;
  75859. +
  75860. +struct dwc_otg_hcd_urb;
  75861. +typedef struct dwc_otg_hcd_urb dwc_otg_hcd_urb_t;
  75862. +
  75863. +/** @name HCD Function Driver Callbacks */
  75864. +/** @{ */
  75865. +
  75866. +/** This function is called whenever core switches to host mode. */
  75867. +typedef int (*dwc_otg_hcd_start_cb_t) (dwc_otg_hcd_t * hcd);
  75868. +
  75869. +/** This function is called when device has been disconnected */
  75870. +typedef int (*dwc_otg_hcd_disconnect_cb_t) (dwc_otg_hcd_t * hcd);
  75871. +
  75872. +/** Wrapper provides this function to HCD to core, so it can get hub information to which device is connected */
  75873. +typedef int (*dwc_otg_hcd_hub_info_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75874. + void *urb_handle,
  75875. + uint32_t * hub_addr,
  75876. + uint32_t * port_addr);
  75877. +/** Via this function HCD core gets device speed */
  75878. +typedef int (*dwc_otg_hcd_speed_from_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75879. + void *urb_handle);
  75880. +
  75881. +/** This function is called when urb is completed */
  75882. +typedef int (*dwc_otg_hcd_complete_urb_cb_t) (dwc_otg_hcd_t * hcd,
  75883. + void *urb_handle,
  75884. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  75885. + int32_t status);
  75886. +
  75887. +/** Via this function HCD core gets b_hnp_enable parameter */
  75888. +typedef int (*dwc_otg_hcd_get_b_hnp_enable) (dwc_otg_hcd_t * hcd);
  75889. +
  75890. +struct dwc_otg_hcd_function_ops {
  75891. + dwc_otg_hcd_start_cb_t start;
  75892. + dwc_otg_hcd_disconnect_cb_t disconnect;
  75893. + dwc_otg_hcd_hub_info_from_urb_cb_t hub_info;
  75894. + dwc_otg_hcd_speed_from_urb_cb_t speed;
  75895. + dwc_otg_hcd_complete_urb_cb_t complete;
  75896. + dwc_otg_hcd_get_b_hnp_enable get_b_hnp_enable;
  75897. +};
  75898. +/** @} */
  75899. +
  75900. +/** @name HCD Core API */
  75901. +/** @{ */
  75902. +/** This function allocates dwc_otg_hcd structure and returns pointer on it. */
  75903. +extern dwc_otg_hcd_t *dwc_otg_hcd_alloc_hcd(void);
  75904. +
  75905. +/** This function should be called to initiate HCD Core.
  75906. + *
  75907. + * @param hcd The HCD
  75908. + * @param core_if The DWC_OTG Core
  75909. + *
  75910. + * Returns -DWC_E_NO_MEMORY if no enough memory.
  75911. + * Returns 0 on success
  75912. + */
  75913. +extern int dwc_otg_hcd_init(dwc_otg_hcd_t * hcd, dwc_otg_core_if_t * core_if);
  75914. +
  75915. +/** Frees HCD
  75916. + *
  75917. + * @param hcd The HCD
  75918. + */
  75919. +extern void dwc_otg_hcd_remove(dwc_otg_hcd_t * hcd);
  75920. +
  75921. +/** This function should be called on every hardware interrupt.
  75922. + *
  75923. + * @param dwc_otg_hcd The HCD
  75924. + *
  75925. + * Returns non zero if interrupt is handled
  75926. + * Return 0 if interrupt is not handled
  75927. + */
  75928. +extern int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd);
  75929. +
  75930. +/** This function is used to handle the fast interrupt
  75931. + *
  75932. + */
  75933. +extern void __attribute__ ((naked)) dwc_otg_hcd_handle_fiq(void);
  75934. +
  75935. +/**
  75936. + * Returns private data set by
  75937. + * dwc_otg_hcd_set_priv_data function.
  75938. + *
  75939. + * @param hcd The HCD
  75940. + */
  75941. +extern void *dwc_otg_hcd_get_priv_data(dwc_otg_hcd_t * hcd);
  75942. +
  75943. +/**
  75944. + * Set private data.
  75945. + *
  75946. + * @param hcd The HCD
  75947. + * @param priv_data pointer to be stored in private data
  75948. + */
  75949. +extern void dwc_otg_hcd_set_priv_data(dwc_otg_hcd_t * hcd, void *priv_data);
  75950. +
  75951. +/**
  75952. + * This function initializes the HCD Core.
  75953. + *
  75954. + * @param hcd The HCD
  75955. + * @param fops The Function Driver Operations data structure containing pointers to all callbacks.
  75956. + *
  75957. + * Returns -DWC_E_NO_DEVICE if Core is currently is in device mode.
  75958. + * Returns 0 on success
  75959. + */
  75960. +extern int dwc_otg_hcd_start(dwc_otg_hcd_t * hcd,
  75961. + struct dwc_otg_hcd_function_ops *fops);
  75962. +
  75963. +/**
  75964. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  75965. + * stopped.
  75966. + *
  75967. + * @param hcd The HCD
  75968. + */
  75969. +extern void dwc_otg_hcd_stop(dwc_otg_hcd_t * hcd);
  75970. +
  75971. +/**
  75972. + * Handles hub class-specific requests.
  75973. + *
  75974. + * @param dwc_otg_hcd The HCD
  75975. + * @param typeReq Request Type
  75976. + * @param wValue wValue from control request
  75977. + * @param wIndex wIndex from control request
  75978. + * @param buf data buffer
  75979. + * @param wLength data buffer length
  75980. + *
  75981. + * Returns -DWC_E_INVALID if invalid argument is passed
  75982. + * Returns 0 on success
  75983. + */
  75984. +extern int dwc_otg_hcd_hub_control(dwc_otg_hcd_t * dwc_otg_hcd,
  75985. + uint16_t typeReq, uint16_t wValue,
  75986. + uint16_t wIndex, uint8_t * buf,
  75987. + uint16_t wLength);
  75988. +
  75989. +/**
  75990. + * Returns otg port number.
  75991. + *
  75992. + * @param hcd The HCD
  75993. + */
  75994. +extern uint32_t dwc_otg_hcd_otg_port(dwc_otg_hcd_t * hcd);
  75995. +
  75996. +/**
  75997. + * Returns OTG version - either 1.3 or 2.0.
  75998. + *
  75999. + * @param core_if The core_if structure pointer
  76000. + */
  76001. +extern uint16_t dwc_otg_get_otg_version(dwc_otg_core_if_t * core_if);
  76002. +
  76003. +/**
  76004. + * Returns 1 if currently core is acting as B host, and 0 otherwise.
  76005. + *
  76006. + * @param hcd The HCD
  76007. + */
  76008. +extern uint32_t dwc_otg_hcd_is_b_host(dwc_otg_hcd_t * hcd);
  76009. +
  76010. +/**
  76011. + * Returns current frame number.
  76012. + *
  76013. + * @param hcd The HCD
  76014. + */
  76015. +extern int dwc_otg_hcd_get_frame_number(dwc_otg_hcd_t * hcd);
  76016. +
  76017. +/**
  76018. + * Dumps hcd state.
  76019. + *
  76020. + * @param hcd The HCD
  76021. + */
  76022. +extern void dwc_otg_hcd_dump_state(dwc_otg_hcd_t * hcd);
  76023. +
  76024. +/**
  76025. + * Dump the average frame remaining at SOF. This can be used to
  76026. + * determine average interrupt latency. Frame remaining is also shown for
  76027. + * start transfer and two additional sample points.
  76028. + * Currently this function is not implemented.
  76029. + *
  76030. + * @param hcd The HCD
  76031. + */
  76032. +extern void dwc_otg_hcd_dump_frrem(dwc_otg_hcd_t * hcd);
  76033. +
  76034. +/**
  76035. + * Sends LPM transaction to the local device.
  76036. + *
  76037. + * @param hcd The HCD
  76038. + * @param devaddr Device Address
  76039. + * @param hird Host initiated resume duration
  76040. + * @param bRemoteWake Value of bRemoteWake field in LPM transaction
  76041. + *
  76042. + * Returns negative value if sending LPM transaction was not succeeded.
  76043. + * Returns 0 on success.
  76044. + */
  76045. +extern int dwc_otg_hcd_send_lpm(dwc_otg_hcd_t * hcd, uint8_t devaddr,
  76046. + uint8_t hird, uint8_t bRemoteWake);
  76047. +
  76048. +/* URB interface */
  76049. +
  76050. +/**
  76051. + * Allocates memory for dwc_otg_hcd_urb structure.
  76052. + * Allocated memory should be freed by call of DWC_FREE.
  76053. + *
  76054. + * @param hcd The HCD
  76055. + * @param iso_desc_count Count of ISOC descriptors
  76056. + * @param atomic_alloc Specefies whether to perform atomic allocation.
  76057. + */
  76058. +extern dwc_otg_hcd_urb_t *dwc_otg_hcd_urb_alloc(dwc_otg_hcd_t * hcd,
  76059. + int iso_desc_count,
  76060. + int atomic_alloc);
  76061. +
  76062. +/**
  76063. + * Set pipe information in URB.
  76064. + *
  76065. + * @param hcd_urb DWC_OTG URB
  76066. + * @param devaddr Device Address
  76067. + * @param ep_num Endpoint Number
  76068. + * @param ep_type Endpoint Type
  76069. + * @param ep_dir Endpoint Direction
  76070. + * @param mps Max Packet Size
  76071. + */
  76072. +extern void dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_hcd_urb_t * hcd_urb,
  76073. + uint8_t devaddr, uint8_t ep_num,
  76074. + uint8_t ep_type, uint8_t ep_dir,
  76075. + uint16_t mps);
  76076. +
  76077. +/* Transfer flags */
  76078. +#define URB_GIVEBACK_ASAP 0x1
  76079. +#define URB_SEND_ZERO_PACKET 0x2
  76080. +
  76081. +/**
  76082. + * Sets dwc_otg_hcd_urb parameters.
  76083. + *
  76084. + * @param urb DWC_OTG URB allocated by dwc_otg_hcd_urb_alloc function.
  76085. + * @param urb_handle Unique handle for request, this will be passed back
  76086. + * to function driver in completion callback.
  76087. + * @param buf The buffer for the data
  76088. + * @param dma The DMA buffer for the data
  76089. + * @param buflen Transfer length
  76090. + * @param sp Buffer for setup data
  76091. + * @param sp_dma DMA address of setup data buffer
  76092. + * @param flags Transfer flags
  76093. + * @param interval Polling interval for interrupt or isochronous transfers.
  76094. + */
  76095. +extern void dwc_otg_hcd_urb_set_params(dwc_otg_hcd_urb_t * urb,
  76096. + void *urb_handle, void *buf,
  76097. + dwc_dma_t dma, uint32_t buflen, void *sp,
  76098. + dwc_dma_t sp_dma, uint32_t flags,
  76099. + uint16_t interval);
  76100. +
  76101. +/** Gets status from dwc_otg_hcd_urb
  76102. + *
  76103. + * @param dwc_otg_urb DWC_OTG URB
  76104. + */
  76105. +extern uint32_t dwc_otg_hcd_urb_get_status(dwc_otg_hcd_urb_t * dwc_otg_urb);
  76106. +
  76107. +/** Gets actual length from dwc_otg_hcd_urb
  76108. + *
  76109. + * @param dwc_otg_urb DWC_OTG URB
  76110. + */
  76111. +extern uint32_t dwc_otg_hcd_urb_get_actual_length(dwc_otg_hcd_urb_t *
  76112. + dwc_otg_urb);
  76113. +
  76114. +/** Gets error count from dwc_otg_hcd_urb. Only for ISOC URBs
  76115. + *
  76116. + * @param dwc_otg_urb DWC_OTG URB
  76117. + */
  76118. +extern uint32_t dwc_otg_hcd_urb_get_error_count(dwc_otg_hcd_urb_t *
  76119. + dwc_otg_urb);
  76120. +
  76121. +/** Set ISOC descriptor offset and length
  76122. + *
  76123. + * @param dwc_otg_urb DWC_OTG URB
  76124. + * @param desc_num ISOC descriptor number
  76125. + * @param offset Offset from beginig of buffer.
  76126. + * @param length Transaction length
  76127. + */
  76128. +extern void dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_hcd_urb_t * dwc_otg_urb,
  76129. + int desc_num, uint32_t offset,
  76130. + uint32_t length);
  76131. +
  76132. +/** Get status of ISOC descriptor, specified by desc_num
  76133. + *
  76134. + * @param dwc_otg_urb DWC_OTG URB
  76135. + * @param desc_num ISOC descriptor number
  76136. + */
  76137. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_hcd_urb_t *
  76138. + dwc_otg_urb, int desc_num);
  76139. +
  76140. +/** Get actual length of ISOC descriptor, specified by desc_num
  76141. + *
  76142. + * @param dwc_otg_urb DWC_OTG URB
  76143. + * @param desc_num ISOC descriptor number
  76144. + */
  76145. +extern uint32_t dwc_otg_hcd_urb_get_iso_desc_actual_length(dwc_otg_hcd_urb_t *
  76146. + dwc_otg_urb,
  76147. + int desc_num);
  76148. +
  76149. +/** Queue URB. After transfer is completes, the complete callback will be called with the URB status
  76150. + *
  76151. + * @param dwc_otg_hcd The HCD
  76152. + * @param dwc_otg_urb DWC_OTG URB
  76153. + * @param ep_handle Out parameter for returning endpoint handle
  76154. + * @param atomic_alloc Flag to do atomic allocation if needed
  76155. + *
  76156. + * Returns -DWC_E_NO_DEVICE if no device is connected.
  76157. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  76158. + * Returns 0 on success.
  76159. + */
  76160. +extern int dwc_otg_hcd_urb_enqueue(dwc_otg_hcd_t * dwc_otg_hcd,
  76161. + dwc_otg_hcd_urb_t * dwc_otg_urb,
  76162. + void **ep_handle, int atomic_alloc);
  76163. +
  76164. +/** De-queue the specified URB
  76165. + *
  76166. + * @param dwc_otg_hcd The HCD
  76167. + * @param dwc_otg_urb DWC_OTG URB
  76168. + */
  76169. +extern int dwc_otg_hcd_urb_dequeue(dwc_otg_hcd_t * dwc_otg_hcd,
  76170. + dwc_otg_hcd_urb_t * dwc_otg_urb);
  76171. +
  76172. +/** Frees resources in the DWC_otg controller related to a given endpoint.
  76173. + * Any URBs for the endpoint must already be dequeued.
  76174. + *
  76175. + * @param hcd The HCD
  76176. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  76177. + * @param retry Number of retries if there are queued transfers.
  76178. + *
  76179. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  76180. + * Returns 0 on success
  76181. + */
  76182. +extern int dwc_otg_hcd_endpoint_disable(dwc_otg_hcd_t * hcd, void *ep_handle,
  76183. + int retry);
  76184. +
  76185. +/* Resets the data toggle in qh structure. This function can be called from
  76186. + * usb_clear_halt routine.
  76187. + *
  76188. + * @param hcd The HCD
  76189. + * @param ep_handle Endpoint handle, returned by dwc_otg_hcd_urb_enqueue function
  76190. + *
  76191. + * Returns -DWC_E_INVALID if invalid arguments are passed.
  76192. + * Returns 0 on success
  76193. + */
  76194. +extern int dwc_otg_hcd_endpoint_reset(dwc_otg_hcd_t * hcd, void *ep_handle);
  76195. +
  76196. +/** Returns 1 if status of specified port is changed and 0 otherwise.
  76197. + *
  76198. + * @param hcd The HCD
  76199. + * @param port Port number
  76200. + */
  76201. +extern int dwc_otg_hcd_is_status_changed(dwc_otg_hcd_t * hcd, int port);
  76202. +
  76203. +/** Call this function to check if bandwidth was allocated for specified endpoint.
  76204. + * Only for ISOC and INTERRUPT endpoints.
  76205. + *
  76206. + * @param hcd The HCD
  76207. + * @param ep_handle Endpoint handle
  76208. + */
  76209. +extern int dwc_otg_hcd_is_bandwidth_allocated(dwc_otg_hcd_t * hcd,
  76210. + void *ep_handle);
  76211. +
  76212. +/** Call this function to check if bandwidth was freed for specified endpoint.
  76213. + *
  76214. + * @param hcd The HCD
  76215. + * @param ep_handle Endpoint handle
  76216. + */
  76217. +extern int dwc_otg_hcd_is_bandwidth_freed(dwc_otg_hcd_t * hcd, void *ep_handle);
  76218. +
  76219. +/** Returns bandwidth allocated for specified endpoint in microseconds.
  76220. + * Only for ISOC and INTERRUPT endpoints.
  76221. + *
  76222. + * @param hcd The HCD
  76223. + * @param ep_handle Endpoint handle
  76224. + */
  76225. +extern uint8_t dwc_otg_hcd_get_ep_bandwidth(dwc_otg_hcd_t * hcd,
  76226. + void *ep_handle);
  76227. +
  76228. +/** @} */
  76229. +
  76230. +#endif /* __DWC_HCD_IF_H__ */
  76231. +#endif /* DWC_DEVICE_ONLY */
  76232. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c
  76233. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  76234. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_intr.c 2014-06-11 21:05:32.000000000 +0200
  76235. @@ -0,0 +1,2688 @@
  76236. +/* ==========================================================================
  76237. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_intr.c $
  76238. + * $Revision: #89 $
  76239. + * $Date: 2011/10/20 $
  76240. + * $Change: 1869487 $
  76241. + *
  76242. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  76243. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  76244. + * otherwise expressly agreed to in writing between Synopsys and you.
  76245. + *
  76246. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  76247. + * any End User Software License Agreement or Agreement for Licensed Product
  76248. + * with Synopsys or any supplement thereto. You are permitted to use and
  76249. + * redistribute this Software in source and binary forms, with or without
  76250. + * modification, provided that redistributions of source code must retain this
  76251. + * notice. You may not view, use, disclose, copy or distribute this file or
  76252. + * any information contained herein except pursuant to this license grant from
  76253. + * Synopsys. If you do not agree with this notice, including the disclaimer
  76254. + * below, then you are not authorized to use the Software.
  76255. + *
  76256. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  76257. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76258. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  76259. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  76260. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76261. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  76262. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  76263. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  76264. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  76265. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  76266. + * DAMAGE.
  76267. + * ========================================================================== */
  76268. +#ifndef DWC_DEVICE_ONLY
  76269. +
  76270. +#include "dwc_otg_hcd.h"
  76271. +#include "dwc_otg_regs.h"
  76272. +
  76273. +#include <linux/jiffies.h>
  76274. +#include <mach/hardware.h>
  76275. +#include <asm/fiq.h>
  76276. +
  76277. +
  76278. +extern bool microframe_schedule;
  76279. +
  76280. +/** @file
  76281. + * This file contains the implementation of the HCD Interrupt handlers.
  76282. + */
  76283. +
  76284. +int fiq_done, int_done;
  76285. +
  76286. +#ifdef FIQ_DEBUG
  76287. +char buffer[1000*16];
  76288. +int wptr;
  76289. +void notrace _fiq_print(FIQDBG_T dbg_lvl, char *fmt, ...)
  76290. +{
  76291. + FIQDBG_T dbg_lvl_req = FIQDBG_PORTHUB;
  76292. + va_list args;
  76293. + char text[17];
  76294. + hfnum_data_t hfnum = { .d32 = FIQ_READ(dwc_regs_base + 0x408) };
  76295. +
  76296. + if(dbg_lvl & dbg_lvl_req || dbg_lvl == FIQDBG_ERR)
  76297. + {
  76298. + local_fiq_disable();
  76299. + snprintf(text, 9, "%4d%d:%d ", hfnum.b.frnum/8, hfnum.b.frnum%8, 8 - hfnum.b.frrem/937);
  76300. + va_start(args, fmt);
  76301. + vsnprintf(text+8, 9, fmt, args);
  76302. + va_end(args);
  76303. +
  76304. + memcpy(buffer + wptr, text, 16);
  76305. + wptr = (wptr + 16) % sizeof(buffer);
  76306. + local_fiq_enable();
  76307. + }
  76308. +}
  76309. +#endif
  76310. +
  76311. +/** This function handles interrupts for the HCD. */
  76312. +int32_t dwc_otg_hcd_handle_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76313. +{
  76314. + int retval = 0;
  76315. + static int last_time;
  76316. + dwc_otg_core_if_t *core_if = dwc_otg_hcd->core_if;
  76317. + gintsts_data_t gintsts;
  76318. + gintmsk_data_t gintmsk;
  76319. + hfnum_data_t hfnum;
  76320. + haintmsk_data_t haintmsk;
  76321. +
  76322. +#ifdef DEBUG
  76323. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  76324. +
  76325. +#endif
  76326. +
  76327. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  76328. + gintmsk.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  76329. +
  76330. + /* Exit from ISR if core is hibernated */
  76331. + if (core_if->hibernation_suspend == 1) {
  76332. + goto exit_handler_routine;
  76333. + }
  76334. + DWC_SPINLOCK(dwc_otg_hcd->lock);
  76335. + /* Check if HOST Mode */
  76336. + if (dwc_otg_is_host_mode(core_if)) {
  76337. + if (fiq_enable) {
  76338. + local_fiq_disable();
  76339. + /* Pull in from the FIQ's disabled mask */
  76340. + gintmsk.d32 = gintmsk.d32 | ~(dwc_otg_hcd->fiq_state->gintmsk_saved.d32);
  76341. + dwc_otg_hcd->fiq_state->gintmsk_saved.d32 = ~0;
  76342. + }
  76343. +
  76344. + if (fiq_fsm_enable && ( 0x0000FFFF & ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint))) {
  76345. + gintsts.b.hcintr = 1;
  76346. + }
  76347. +
  76348. + /* Danger will robinson: fake a SOF if necessary */
  76349. + if (fiq_fsm_enable && (dwc_otg_hcd->fiq_state->gintmsk_saved.b.sofintr == 1)) {
  76350. + gintsts.b.sofintr = 1;
  76351. + }
  76352. + gintsts.d32 &= gintmsk.d32;
  76353. +
  76354. + if (fiq_enable)
  76355. + local_fiq_enable();
  76356. +
  76357. + if (!gintsts.d32) {
  76358. + goto exit_handler_routine;
  76359. + }
  76360. +
  76361. +#ifdef DEBUG
  76362. + // We should be OK doing this because the common interrupts should already have been serviced
  76363. + /* Don't print debug message in the interrupt handler on SOF */
  76364. +#ifndef DEBUG_SOF
  76365. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76366. +#endif
  76367. + DWC_DEBUGPL(DBG_HCDI, "\n");
  76368. +#endif
  76369. +
  76370. +#ifdef DEBUG
  76371. +#ifndef DEBUG_SOF
  76372. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76373. +#endif
  76374. + DWC_DEBUGPL(DBG_HCDI,
  76375. + "DWC OTG HCD Interrupt Detected gintsts&gintmsk=0x%08x core_if=%p\n",
  76376. + gintsts.d32, core_if);
  76377. +#endif
  76378. + hfnum.d32 = DWC_READ_REG32(&dwc_otg_hcd->core_if->host_if->host_global_regs->hfnum);
  76379. + if (gintsts.b.sofintr) {
  76380. + retval |= dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd);
  76381. + }
  76382. +
  76383. + if (gintsts.b.rxstsqlvl) {
  76384. + retval |=
  76385. + dwc_otg_hcd_handle_rx_status_q_level_intr
  76386. + (dwc_otg_hcd);
  76387. + }
  76388. + if (gintsts.b.nptxfempty) {
  76389. + retval |=
  76390. + dwc_otg_hcd_handle_np_tx_fifo_empty_intr
  76391. + (dwc_otg_hcd);
  76392. + }
  76393. + if (gintsts.b.i2cintr) {
  76394. + /** @todo Implement i2cintr handler. */
  76395. + }
  76396. + if (gintsts.b.portintr) {
  76397. +
  76398. + gintmsk_data_t gintmsk = { .b.portintr = 1};
  76399. + retval |= dwc_otg_hcd_handle_port_intr(dwc_otg_hcd);
  76400. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk.d32);
  76401. + }
  76402. + if (gintsts.b.hcintr) {
  76403. + retval |= dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd);
  76404. + }
  76405. + if (gintsts.b.ptxfempty) {
  76406. + retval |=
  76407. + dwc_otg_hcd_handle_perio_tx_fifo_empty_intr
  76408. + (dwc_otg_hcd);
  76409. + }
  76410. +#ifdef DEBUG
  76411. +#ifndef DEBUG_SOF
  76412. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76413. +#endif
  76414. + {
  76415. + DWC_DEBUGPL(DBG_HCDI,
  76416. + "DWC OTG HCD Finished Servicing Interrupts\n");
  76417. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintsts=0x%08x\n",
  76418. + DWC_READ_REG32(&global_regs->gintsts));
  76419. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD gintmsk=0x%08x\n",
  76420. + DWC_READ_REG32(&global_regs->gintmsk));
  76421. + }
  76422. +#endif
  76423. +
  76424. +#ifdef DEBUG
  76425. +#ifndef DEBUG_SOF
  76426. + if (gintsts.d32 != DWC_SOF_INTR_MASK)
  76427. +#endif
  76428. + DWC_DEBUGPL(DBG_HCDI, "\n");
  76429. +#endif
  76430. +
  76431. + }
  76432. +
  76433. +exit_handler_routine:
  76434. + if (fiq_enable) {
  76435. + gintmsk_data_t gintmsk_new;
  76436. + haintmsk_data_t haintmsk_new;
  76437. + local_fiq_disable();
  76438. + gintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->gintmsk_saved.d32;
  76439. + if(fiq_fsm_enable)
  76440. + haintmsk_new.d32 = *(volatile uint32_t *)&dwc_otg_hcd->fiq_state->haintmsk_saved.d32;
  76441. + else
  76442. + haintmsk_new.d32 = 0x0000FFFF;
  76443. +
  76444. + /* The FIQ could have sneaked another interrupt in. If so, don't clear MPHI */
  76445. + if ((gintmsk_new.d32 == ~0) && (haintmsk_new.d32 == 0x0000FFFF)) {
  76446. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.intstat, (1<<16));
  76447. + if (dwc_otg_hcd->fiq_state->mphi_int_count >= 50) {
  76448. + fiq_print(FIQDBG_INT, dwc_otg_hcd->fiq_state, "MPHI CLR");
  76449. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, ((1<<31) + (1<<16)));
  76450. + while (!(DWC_READ_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & (1 << 17)))
  76451. + ;
  76452. + DWC_WRITE_REG32(dwc_otg_hcd->fiq_state->mphi_regs.ctrl, (1<<31));
  76453. + dwc_otg_hcd->fiq_state->mphi_int_count = 0;
  76454. + }
  76455. + int_done++;
  76456. + }
  76457. + haintmsk.d32 = DWC_READ_REG32(&core_if->host_if->host_global_regs->haintmsk);
  76458. + /* Re-enable interrupts that the FIQ masked (first time round) */
  76459. + FIQ_WRITE(dwc_otg_hcd->fiq_state->dwc_regs_base + GINTMSK, gintmsk.d32);
  76460. + local_fiq_enable();
  76461. +
  76462. + if ((jiffies / HZ) > last_time) {
  76463. + //dwc_otg_qh_t *qh;
  76464. + //dwc_list_link_t *cur;
  76465. + /* Once a second output the fiq and irq numbers, useful for debug */
  76466. + last_time = jiffies / HZ;
  76467. + // DWC_WARN("np_kick=%d AHC=%d sched_frame=%d cur_frame=%d int_done=%d fiq_done=%d",
  76468. + // dwc_otg_hcd->fiq_state->kick_np_queues, dwc_otg_hcd->available_host_channels,
  76469. + // dwc_otg_hcd->fiq_state->next_sched_frame, hfnum.b.frnum, int_done, dwc_otg_hcd->fiq_state->fiq_done);
  76470. + //printk(KERN_WARNING "Periodic queues:\n");
  76471. + }
  76472. + }
  76473. +
  76474. + DWC_SPINUNLOCK(dwc_otg_hcd->lock);
  76475. + return retval;
  76476. +}
  76477. +
  76478. +#ifdef DWC_TRACK_MISSED_SOFS
  76479. +
  76480. +#warning Compiling code to track missed SOFs
  76481. +#define FRAME_NUM_ARRAY_SIZE 1000
  76482. +/**
  76483. + * This function is for debug only.
  76484. + */
  76485. +static inline void track_missed_sofs(uint16_t curr_frame_number)
  76486. +{
  76487. + static uint16_t frame_num_array[FRAME_NUM_ARRAY_SIZE];
  76488. + static uint16_t last_frame_num_array[FRAME_NUM_ARRAY_SIZE];
  76489. + static int frame_num_idx = 0;
  76490. + static uint16_t last_frame_num = DWC_HFNUM_MAX_FRNUM;
  76491. + static int dumped_frame_num_array = 0;
  76492. +
  76493. + if (frame_num_idx < FRAME_NUM_ARRAY_SIZE) {
  76494. + if (((last_frame_num + 1) & DWC_HFNUM_MAX_FRNUM) !=
  76495. + curr_frame_number) {
  76496. + frame_num_array[frame_num_idx] = curr_frame_number;
  76497. + last_frame_num_array[frame_num_idx++] = last_frame_num;
  76498. + }
  76499. + } else if (!dumped_frame_num_array) {
  76500. + int i;
  76501. + DWC_PRINTF("Frame Last Frame\n");
  76502. + DWC_PRINTF("----- ----------\n");
  76503. + for (i = 0; i < FRAME_NUM_ARRAY_SIZE; i++) {
  76504. + DWC_PRINTF("0x%04x 0x%04x\n",
  76505. + frame_num_array[i], last_frame_num_array[i]);
  76506. + }
  76507. + dumped_frame_num_array = 1;
  76508. + }
  76509. + last_frame_num = curr_frame_number;
  76510. +}
  76511. +#endif
  76512. +
  76513. +/**
  76514. + * Handles the start-of-frame interrupt in host mode. Non-periodic
  76515. + * transactions may be queued to the DWC_otg controller for the current
  76516. + * (micro)frame. Periodic transactions may be queued to the controller for the
  76517. + * next (micro)frame.
  76518. + */
  76519. +int32_t dwc_otg_hcd_handle_sof_intr(dwc_otg_hcd_t * hcd)
  76520. +{
  76521. + hfnum_data_t hfnum;
  76522. + gintsts_data_t gintsts = { .d32 = 0 };
  76523. + dwc_list_link_t *qh_entry;
  76524. + dwc_otg_qh_t *qh;
  76525. + dwc_otg_transaction_type_e tr_type;
  76526. + int did_something = 0;
  76527. + int32_t next_sched_frame = -1;
  76528. +
  76529. + hfnum.d32 =
  76530. + DWC_READ_REG32(&hcd->core_if->host_if->host_global_regs->hfnum);
  76531. +
  76532. +#ifdef DEBUG_SOF
  76533. + DWC_DEBUGPL(DBG_HCD, "--Start of Frame Interrupt--\n");
  76534. +#endif
  76535. + hcd->frame_number = hfnum.b.frnum;
  76536. +
  76537. +#ifdef DEBUG
  76538. + hcd->frrem_accum += hfnum.b.frrem;
  76539. + hcd->frrem_samples++;
  76540. +#endif
  76541. +
  76542. +#ifdef DWC_TRACK_MISSED_SOFS
  76543. + track_missed_sofs(hcd->frame_number);
  76544. +#endif
  76545. + /* Determine whether any periodic QHs should be executed. */
  76546. + qh_entry = DWC_LIST_FIRST(&hcd->periodic_sched_inactive);
  76547. + while (qh_entry != &hcd->periodic_sched_inactive) {
  76548. + qh = DWC_LIST_ENTRY(qh_entry, dwc_otg_qh_t, qh_list_entry);
  76549. + qh_entry = qh_entry->next;
  76550. + if (dwc_frame_num_le(qh->sched_frame, hcd->frame_number)) {
  76551. +
  76552. + /*
  76553. + * Move QH to the ready list to be executed next
  76554. + * (micro)frame.
  76555. + */
  76556. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  76557. + &qh->qh_list_entry);
  76558. +
  76559. + did_something = 1;
  76560. + }
  76561. + else
  76562. + {
  76563. + if(next_sched_frame < 0 || dwc_frame_num_le(qh->sched_frame, next_sched_frame))
  76564. + {
  76565. + next_sched_frame = qh->sched_frame;
  76566. + }
  76567. + }
  76568. + }
  76569. + if (fiq_enable)
  76570. + hcd->fiq_state->next_sched_frame = next_sched_frame;
  76571. +
  76572. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  76573. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  76574. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  76575. + did_something = 1;
  76576. + }
  76577. +
  76578. + /* Clear interrupt - but do not trample on the FIQ sof */
  76579. + if (!fiq_fsm_enable) {
  76580. + gintsts.b.sofintr = 1;
  76581. + DWC_WRITE_REG32(&hcd->core_if->core_global_regs->gintsts, gintsts.d32);
  76582. + }
  76583. + return 1;
  76584. +}
  76585. +
  76586. +/** Handles the Rx Status Queue Level Interrupt, which indicates that there is at
  76587. + * least one packet in the Rx FIFO. The packets are moved from the FIFO to
  76588. + * memory if the DWC_otg controller is operating in Slave mode. */
  76589. +int32_t dwc_otg_hcd_handle_rx_status_q_level_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76590. +{
  76591. + host_grxsts_data_t grxsts;
  76592. + dwc_hc_t *hc = NULL;
  76593. +
  76594. + DWC_DEBUGPL(DBG_HCD, "--RxStsQ Level Interrupt--\n");
  76595. +
  76596. + grxsts.d32 =
  76597. + DWC_READ_REG32(&dwc_otg_hcd->core_if->core_global_regs->grxstsp);
  76598. +
  76599. + hc = dwc_otg_hcd->hc_ptr_array[grxsts.b.chnum];
  76600. + if (!hc) {
  76601. + DWC_ERROR("Unable to get corresponding channel\n");
  76602. + return 0;
  76603. + }
  76604. +
  76605. + /* Packet Status */
  76606. + DWC_DEBUGPL(DBG_HCDV, " Ch num = %d\n", grxsts.b.chnum);
  76607. + DWC_DEBUGPL(DBG_HCDV, " Count = %d\n", grxsts.b.bcnt);
  76608. + DWC_DEBUGPL(DBG_HCDV, " DPID = %d, hc.dpid = %d\n", grxsts.b.dpid,
  76609. + hc->data_pid_start);
  76610. + DWC_DEBUGPL(DBG_HCDV, " PStatus = %d\n", grxsts.b.pktsts);
  76611. +
  76612. + switch (grxsts.b.pktsts) {
  76613. + case DWC_GRXSTS_PKTSTS_IN:
  76614. + /* Read the data into the host buffer. */
  76615. + if (grxsts.b.bcnt > 0) {
  76616. + dwc_otg_read_packet(dwc_otg_hcd->core_if,
  76617. + hc->xfer_buff, grxsts.b.bcnt);
  76618. +
  76619. + /* Update the HC fields for the next packet received. */
  76620. + hc->xfer_count += grxsts.b.bcnt;
  76621. + hc->xfer_buff += grxsts.b.bcnt;
  76622. + }
  76623. +
  76624. + case DWC_GRXSTS_PKTSTS_IN_XFER_COMP:
  76625. + case DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR:
  76626. + case DWC_GRXSTS_PKTSTS_CH_HALTED:
  76627. + /* Handled in interrupt, just ignore data */
  76628. + break;
  76629. + default:
  76630. + DWC_ERROR("RX_STS_Q Interrupt: Unknown status %d\n",
  76631. + grxsts.b.pktsts);
  76632. + break;
  76633. + }
  76634. +
  76635. + return 1;
  76636. +}
  76637. +
  76638. +/** This interrupt occurs when the non-periodic Tx FIFO is half-empty. More
  76639. + * data packets may be written to the FIFO for OUT transfers. More requests
  76640. + * may be written to the non-periodic request queue for IN transfers. This
  76641. + * interrupt is enabled only in Slave mode. */
  76642. +int32_t dwc_otg_hcd_handle_np_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76643. +{
  76644. + DWC_DEBUGPL(DBG_HCD, "--Non-Periodic TxFIFO Empty Interrupt--\n");
  76645. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  76646. + DWC_OTG_TRANSACTION_NON_PERIODIC);
  76647. + return 1;
  76648. +}
  76649. +
  76650. +/** This interrupt occurs when the periodic Tx FIFO is half-empty. More data
  76651. + * packets may be written to the FIFO for OUT transfers. More requests may be
  76652. + * written to the periodic request queue for IN transfers. This interrupt is
  76653. + * enabled only in Slave mode. */
  76654. +int32_t dwc_otg_hcd_handle_perio_tx_fifo_empty_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76655. +{
  76656. + DWC_DEBUGPL(DBG_HCD, "--Periodic TxFIFO Empty Interrupt--\n");
  76657. + dwc_otg_hcd_queue_transactions(dwc_otg_hcd,
  76658. + DWC_OTG_TRANSACTION_PERIODIC);
  76659. + return 1;
  76660. +}
  76661. +
  76662. +/** There are multiple conditions that can cause a port interrupt. This function
  76663. + * determines which interrupt conditions have occurred and handles them
  76664. + * appropriately. */
  76665. +int32_t dwc_otg_hcd_handle_port_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76666. +{
  76667. + int retval = 0;
  76668. + hprt0_data_t hprt0;
  76669. + hprt0_data_t hprt0_modify;
  76670. +
  76671. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76672. + hprt0_modify.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76673. +
  76674. + /* Clear appropriate bits in HPRT0 to clear the interrupt bit in
  76675. + * GINTSTS */
  76676. +
  76677. + hprt0_modify.b.prtena = 0;
  76678. + hprt0_modify.b.prtconndet = 0;
  76679. + hprt0_modify.b.prtenchng = 0;
  76680. + hprt0_modify.b.prtovrcurrchng = 0;
  76681. +
  76682. + /* Port Connect Detected
  76683. + * Set flag and clear if detected */
  76684. + if (dwc_otg_hcd->core_if->hibernation_suspend == 1) {
  76685. + // Dont modify port status if we are in hibernation state
  76686. + hprt0_modify.b.prtconndet = 1;
  76687. + hprt0_modify.b.prtenchng = 1;
  76688. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  76689. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  76690. + return retval;
  76691. + }
  76692. +
  76693. + if (hprt0.b.prtconndet) {
  76694. + /** @todo - check if steps performed in 'else' block should be perfromed regardles adp */
  76695. + if (dwc_otg_hcd->core_if->adp_enable &&
  76696. + dwc_otg_hcd->core_if->adp.vbuson_timer_started == 1) {
  76697. + DWC_PRINTF("PORT CONNECT DETECTED ----------------\n");
  76698. + DWC_TIMER_CANCEL(dwc_otg_hcd->core_if->adp.vbuson_timer);
  76699. + dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  76700. + /* TODO - check if this is required, as
  76701. + * host initialization was already performed
  76702. + * after initial ADP probing
  76703. + */
  76704. + /*dwc_otg_hcd->core_if->adp.vbuson_timer_started = 0;
  76705. + dwc_otg_core_init(dwc_otg_hcd->core_if);
  76706. + dwc_otg_enable_global_interrupts(dwc_otg_hcd->core_if);
  76707. + cil_hcd_start(dwc_otg_hcd->core_if);*/
  76708. + } else {
  76709. +
  76710. + DWC_DEBUGPL(DBG_HCD, "--Port Interrupt HPRT0=0x%08x "
  76711. + "Port Connect Detected--\n", hprt0.d32);
  76712. + dwc_otg_hcd->flags.b.port_connect_status_change = 1;
  76713. + dwc_otg_hcd->flags.b.port_connect_status = 1;
  76714. + hprt0_modify.b.prtconndet = 1;
  76715. +
  76716. + /* B-Device has connected, Delete the connection timer. */
  76717. + DWC_TIMER_CANCEL(dwc_otg_hcd->conn_timer);
  76718. + }
  76719. + /* The Hub driver asserts a reset when it sees port connect
  76720. + * status change flag */
  76721. + retval |= 1;
  76722. + }
  76723. +
  76724. + /* Port Enable Changed
  76725. + * Clear if detected - Set internal flag if disabled */
  76726. + if (hprt0.b.prtenchng) {
  76727. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  76728. + "Port Enable Changed--\n", hprt0.d32);
  76729. + hprt0_modify.b.prtenchng = 1;
  76730. + if (hprt0.b.prtena == 1) {
  76731. + hfir_data_t hfir;
  76732. + int do_reset = 0;
  76733. + dwc_otg_core_params_t *params =
  76734. + dwc_otg_hcd->core_if->core_params;
  76735. + dwc_otg_core_global_regs_t *global_regs =
  76736. + dwc_otg_hcd->core_if->core_global_regs;
  76737. + dwc_otg_host_if_t *host_if =
  76738. + dwc_otg_hcd->core_if->host_if;
  76739. +
  76740. + /* Every time when port enables calculate
  76741. + * HFIR.FrInterval
  76742. + */
  76743. + hfir.d32 = DWC_READ_REG32(&host_if->host_global_regs->hfir);
  76744. + hfir.b.frint = calc_frame_interval(dwc_otg_hcd->core_if);
  76745. + DWC_WRITE_REG32(&host_if->host_global_regs->hfir, hfir.d32);
  76746. +
  76747. + /* Check if we need to adjust the PHY clock speed for
  76748. + * low power and adjust it */
  76749. + if (params->host_support_fs_ls_low_power) {
  76750. + gusbcfg_data_t usbcfg;
  76751. +
  76752. + usbcfg.d32 =
  76753. + DWC_READ_REG32(&global_regs->gusbcfg);
  76754. +
  76755. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_LOW_SPEED
  76756. + || hprt0.b.prtspd ==
  76757. + DWC_HPRT0_PRTSPD_FULL_SPEED) {
  76758. + /*
  76759. + * Low power
  76760. + */
  76761. + hcfg_data_t hcfg;
  76762. + if (usbcfg.b.phylpwrclksel == 0) {
  76763. + /* Set PHY low power clock select for FS/LS devices */
  76764. + usbcfg.b.phylpwrclksel = 1;
  76765. + DWC_WRITE_REG32
  76766. + (&global_regs->gusbcfg,
  76767. + usbcfg.d32);
  76768. + do_reset = 1;
  76769. + }
  76770. +
  76771. + hcfg.d32 =
  76772. + DWC_READ_REG32
  76773. + (&host_if->host_global_regs->hcfg);
  76774. +
  76775. + if (hprt0.b.prtspd ==
  76776. + DWC_HPRT0_PRTSPD_LOW_SPEED
  76777. + && params->host_ls_low_power_phy_clk
  76778. + ==
  76779. + DWC_HOST_LS_LOW_POWER_PHY_CLK_PARAM_6MHZ)
  76780. + {
  76781. + /* 6 MHZ */
  76782. + DWC_DEBUGPL(DBG_CIL,
  76783. + "FS_PHY programming HCFG to 6 MHz (Low Power)\n");
  76784. + if (hcfg.b.fslspclksel !=
  76785. + DWC_HCFG_6_MHZ) {
  76786. + hcfg.b.fslspclksel =
  76787. + DWC_HCFG_6_MHZ;
  76788. + DWC_WRITE_REG32
  76789. + (&host_if->host_global_regs->hcfg,
  76790. + hcfg.d32);
  76791. + do_reset = 1;
  76792. + }
  76793. + } else {
  76794. + /* 48 MHZ */
  76795. + DWC_DEBUGPL(DBG_CIL,
  76796. + "FS_PHY programming HCFG to 48 MHz ()\n");
  76797. + if (hcfg.b.fslspclksel !=
  76798. + DWC_HCFG_48_MHZ) {
  76799. + hcfg.b.fslspclksel =
  76800. + DWC_HCFG_48_MHZ;
  76801. + DWC_WRITE_REG32
  76802. + (&host_if->host_global_regs->hcfg,
  76803. + hcfg.d32);
  76804. + do_reset = 1;
  76805. + }
  76806. + }
  76807. + } else {
  76808. + /*
  76809. + * Not low power
  76810. + */
  76811. + if (usbcfg.b.phylpwrclksel == 1) {
  76812. + usbcfg.b.phylpwrclksel = 0;
  76813. + DWC_WRITE_REG32
  76814. + (&global_regs->gusbcfg,
  76815. + usbcfg.d32);
  76816. + do_reset = 1;
  76817. + }
  76818. + }
  76819. +
  76820. + if (do_reset) {
  76821. + DWC_TASK_SCHEDULE(dwc_otg_hcd->reset_tasklet);
  76822. + }
  76823. + }
  76824. +
  76825. + if (!do_reset) {
  76826. + /* Port has been enabled set the reset change flag */
  76827. + dwc_otg_hcd->flags.b.port_reset_change = 1;
  76828. + }
  76829. + } else {
  76830. + dwc_otg_hcd->flags.b.port_enable_change = 1;
  76831. + }
  76832. + retval |= 1;
  76833. + }
  76834. +
  76835. + /** Overcurrent Change Interrupt */
  76836. + if (hprt0.b.prtovrcurrchng) {
  76837. + DWC_DEBUGPL(DBG_HCD, " --Port Interrupt HPRT0=0x%08x "
  76838. + "Port Overcurrent Changed--\n", hprt0.d32);
  76839. + dwc_otg_hcd->flags.b.port_over_current_change = 1;
  76840. + hprt0_modify.b.prtovrcurrchng = 1;
  76841. + retval |= 1;
  76842. + }
  76843. +
  76844. + /* Clear Port Interrupts */
  76845. + DWC_WRITE_REG32(dwc_otg_hcd->core_if->host_if->hprt0, hprt0_modify.d32);
  76846. +
  76847. + return retval;
  76848. +}
  76849. +
  76850. +/** This interrupt indicates that one or more host channels has a pending
  76851. + * interrupt. There are multiple conditions that can cause each host channel
  76852. + * interrupt. This function determines which conditions have occurred for each
  76853. + * host channel interrupt and handles them appropriately. */
  76854. +int32_t dwc_otg_hcd_handle_hc_intr(dwc_otg_hcd_t * dwc_otg_hcd)
  76855. +{
  76856. + int i;
  76857. + int retval = 0;
  76858. + haint_data_t haint = { .d32 = 0 } ;
  76859. +
  76860. + /* Clear appropriate bits in HCINTn to clear the interrupt bit in
  76861. + * GINTSTS */
  76862. +
  76863. + if (!fiq_fsm_enable)
  76864. + haint.d32 = dwc_otg_read_host_all_channels_intr(dwc_otg_hcd->core_if);
  76865. +
  76866. + // Overwrite with saved interrupts from fiq handler
  76867. + if(fiq_fsm_enable)
  76868. + {
  76869. + /* check the mask? */
  76870. + local_fiq_disable();
  76871. + haint.b2.chint |= ~(dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint);
  76872. + dwc_otg_hcd->fiq_state->haintmsk_saved.b2.chint = ~0;
  76873. + local_fiq_enable();
  76874. + }
  76875. +
  76876. + for (i = 0; i < dwc_otg_hcd->core_if->core_params->host_channels; i++) {
  76877. + if (haint.b2.chint & (1 << i)) {
  76878. + retval |= dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd, i);
  76879. + }
  76880. + }
  76881. +
  76882. + return retval;
  76883. +}
  76884. +
  76885. +/**
  76886. + * Gets the actual length of a transfer after the transfer halts. _halt_status
  76887. + * holds the reason for the halt.
  76888. + *
  76889. + * For IN transfers where halt_status is DWC_OTG_HC_XFER_COMPLETE,
  76890. + * *short_read is set to 1 upon return if less than the requested
  76891. + * number of bytes were transferred. Otherwise, *short_read is set to 0 upon
  76892. + * return. short_read may also be NULL on entry, in which case it remains
  76893. + * unchanged.
  76894. + */
  76895. +static uint32_t get_actual_xfer_length(dwc_hc_t * hc,
  76896. + dwc_otg_hc_regs_t * hc_regs,
  76897. + dwc_otg_qtd_t * qtd,
  76898. + dwc_otg_halt_status_e halt_status,
  76899. + int *short_read)
  76900. +{
  76901. + hctsiz_data_t hctsiz;
  76902. + uint32_t length;
  76903. +
  76904. + if (short_read != NULL) {
  76905. + *short_read = 0;
  76906. + }
  76907. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76908. +
  76909. + if (halt_status == DWC_OTG_HC_XFER_COMPLETE) {
  76910. + if (hc->ep_is_in) {
  76911. + length = hc->xfer_len - hctsiz.b.xfersize;
  76912. + if (short_read != NULL) {
  76913. + *short_read = (hctsiz.b.xfersize != 0);
  76914. + }
  76915. + } else if (hc->qh->do_split) {
  76916. + //length = split_out_xfersize[hc->hc_num];
  76917. + length = qtd->ssplit_out_xfer_count;
  76918. + } else {
  76919. + length = hc->xfer_len;
  76920. + }
  76921. + } else {
  76922. + /*
  76923. + * Must use the hctsiz.pktcnt field to determine how much data
  76924. + * has been transferred. This field reflects the number of
  76925. + * packets that have been transferred via the USB. This is
  76926. + * always an integral number of packets if the transfer was
  76927. + * halted before its normal completion. (Can't use the
  76928. + * hctsiz.xfersize field because that reflects the number of
  76929. + * bytes transferred via the AHB, not the USB).
  76930. + */
  76931. + length =
  76932. + (hc->start_pkt_count - hctsiz.b.pktcnt) * hc->max_packet;
  76933. + }
  76934. +
  76935. + return length;
  76936. +}
  76937. +
  76938. +/**
  76939. + * Updates the state of the URB after a Transfer Complete interrupt on the
  76940. + * host channel. Updates the actual_length field of the URB based on the
  76941. + * number of bytes transferred via the host channel. Sets the URB status
  76942. + * if the data transfer is finished.
  76943. + *
  76944. + * @return 1 if the data transfer specified by the URB is completely finished,
  76945. + * 0 otherwise.
  76946. + */
  76947. +static int update_urb_state_xfer_comp(dwc_hc_t * hc,
  76948. + dwc_otg_hc_regs_t * hc_regs,
  76949. + dwc_otg_hcd_urb_t * urb,
  76950. + dwc_otg_qtd_t * qtd)
  76951. +{
  76952. + int xfer_done = 0;
  76953. + int short_read = 0;
  76954. +
  76955. + int xfer_length;
  76956. +
  76957. + xfer_length = get_actual_xfer_length(hc, hc_regs, qtd,
  76958. + DWC_OTG_HC_XFER_COMPLETE,
  76959. + &short_read);
  76960. +
  76961. + /* non DWORD-aligned buffer case handling. */
  76962. + if (hc->align_buff && xfer_length && hc->ep_is_in) {
  76963. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  76964. + xfer_length);
  76965. + }
  76966. +
  76967. + urb->actual_length += xfer_length;
  76968. +
  76969. + if (xfer_length && (hc->ep_type == DWC_OTG_EP_TYPE_BULK) &&
  76970. + (urb->flags & URB_SEND_ZERO_PACKET)
  76971. + && (urb->actual_length == urb->length)
  76972. + && !(urb->length % hc->max_packet)) {
  76973. + xfer_done = 0;
  76974. + } else if (short_read || urb->actual_length >= urb->length) {
  76975. + xfer_done = 1;
  76976. + urb->status = 0;
  76977. + }
  76978. +
  76979. +#ifdef DEBUG
  76980. + {
  76981. + hctsiz_data_t hctsiz;
  76982. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  76983. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  76984. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  76985. + hc->hc_num);
  76986. + DWC_DEBUGPL(DBG_HCDV, " hc->xfer_len %d\n", hc->xfer_len);
  76987. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.xfersize %d\n",
  76988. + hctsiz.b.xfersize);
  76989. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  76990. + urb->length);
  76991. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  76992. + urb->actual_length);
  76993. + DWC_DEBUGPL(DBG_HCDV, " short_read %d, xfer_done %d\n",
  76994. + short_read, xfer_done);
  76995. + }
  76996. +#endif
  76997. +
  76998. + return xfer_done;
  76999. +}
  77000. +
  77001. +/*
  77002. + * Save the starting data toggle for the next transfer. The data toggle is
  77003. + * saved in the QH for non-control transfers and it's saved in the QTD for
  77004. + * control transfers.
  77005. + */
  77006. +void dwc_otg_hcd_save_data_toggle(dwc_hc_t * hc,
  77007. + dwc_otg_hc_regs_t * hc_regs, dwc_otg_qtd_t * qtd)
  77008. +{
  77009. + hctsiz_data_t hctsiz;
  77010. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77011. +
  77012. + if (hc->ep_type != DWC_OTG_EP_TYPE_CONTROL) {
  77013. + dwc_otg_qh_t *qh = hc->qh;
  77014. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  77015. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  77016. + } else {
  77017. + qh->data_toggle = DWC_OTG_HC_PID_DATA1;
  77018. + }
  77019. + } else {
  77020. + if (hctsiz.b.pid == DWC_HCTSIZ_DATA0) {
  77021. + qtd->data_toggle = DWC_OTG_HC_PID_DATA0;
  77022. + } else {
  77023. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  77024. + }
  77025. + }
  77026. +}
  77027. +
  77028. +/**
  77029. + * Updates the state of an Isochronous URB when the transfer is stopped for
  77030. + * any reason. The fields of the current entry in the frame descriptor array
  77031. + * are set based on the transfer state and the input _halt_status. Completes
  77032. + * the Isochronous URB if all the URB frames have been completed.
  77033. + *
  77034. + * @return DWC_OTG_HC_XFER_COMPLETE if there are more frames remaining to be
  77035. + * transferred in the URB. Otherwise return DWC_OTG_HC_XFER_URB_COMPLETE.
  77036. + */
  77037. +static dwc_otg_halt_status_e
  77038. +update_isoc_urb_state(dwc_otg_hcd_t * hcd,
  77039. + dwc_hc_t * hc,
  77040. + dwc_otg_hc_regs_t * hc_regs,
  77041. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  77042. +{
  77043. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77044. + dwc_otg_halt_status_e ret_val = halt_status;
  77045. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  77046. +
  77047. + frame_desc = &urb->iso_descs[qtd->isoc_frame_index];
  77048. + switch (halt_status) {
  77049. + case DWC_OTG_HC_XFER_COMPLETE:
  77050. + frame_desc->status = 0;
  77051. + frame_desc->actual_length =
  77052. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  77053. +
  77054. + /* non DWORD-aligned buffer case handling. */
  77055. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  77056. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  77057. + hc->qh->dw_align_buf, frame_desc->actual_length);
  77058. + }
  77059. +
  77060. + break;
  77061. + case DWC_OTG_HC_XFER_FRAME_OVERRUN:
  77062. + urb->error_count++;
  77063. + if (hc->ep_is_in) {
  77064. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  77065. + } else {
  77066. + frame_desc->status = -DWC_E_COMMUNICATION;
  77067. + }
  77068. + frame_desc->actual_length = 0;
  77069. + break;
  77070. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  77071. + urb->error_count++;
  77072. + frame_desc->status = -DWC_E_OVERFLOW;
  77073. + /* Don't need to update actual_length in this case. */
  77074. + break;
  77075. + case DWC_OTG_HC_XFER_XACT_ERR:
  77076. + urb->error_count++;
  77077. + frame_desc->status = -DWC_E_PROTOCOL;
  77078. + frame_desc->actual_length =
  77079. + get_actual_xfer_length(hc, hc_regs, qtd, halt_status, NULL);
  77080. +
  77081. + /* non DWORD-aligned buffer case handling. */
  77082. + if (hc->align_buff && frame_desc->actual_length && hc->ep_is_in) {
  77083. + dwc_memcpy(urb->buf + frame_desc->offset + qtd->isoc_split_offset,
  77084. + hc->qh->dw_align_buf, frame_desc->actual_length);
  77085. + }
  77086. + /* Skip whole frame */
  77087. + if (hc->qh->do_split && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC) &&
  77088. + hc->ep_is_in && hcd->core_if->dma_enable) {
  77089. + qtd->complete_split = 0;
  77090. + qtd->isoc_split_offset = 0;
  77091. + }
  77092. +
  77093. + break;
  77094. + default:
  77095. + DWC_ASSERT(1, "Unhandled _halt_status (%d)\n", halt_status);
  77096. + break;
  77097. + }
  77098. + if (++qtd->isoc_frame_index == urb->packet_count) {
  77099. + /*
  77100. + * urb->status is not used for isoc transfers.
  77101. + * The individual frame_desc statuses are used instead.
  77102. + */
  77103. + hcd->fops->complete(hcd, urb->priv, urb, 0);
  77104. + ret_val = DWC_OTG_HC_XFER_URB_COMPLETE;
  77105. + } else {
  77106. + ret_val = DWC_OTG_HC_XFER_COMPLETE;
  77107. + }
  77108. + return ret_val;
  77109. +}
  77110. +
  77111. +/**
  77112. + * Frees the first QTD in the QH's list if free_qtd is 1. For non-periodic
  77113. + * QHs, removes the QH from the active non-periodic schedule. If any QTDs are
  77114. + * still linked to the QH, the QH is added to the end of the inactive
  77115. + * non-periodic schedule. For periodic QHs, removes the QH from the periodic
  77116. + * schedule if no more QTDs are linked to the QH.
  77117. + */
  77118. +static void deactivate_qh(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, int free_qtd)
  77119. +{
  77120. + int continue_split = 0;
  77121. + dwc_otg_qtd_t *qtd;
  77122. +
  77123. + DWC_DEBUGPL(DBG_HCDV, " %s(%p,%p,%d)\n", __func__, hcd, qh, free_qtd);
  77124. +
  77125. + qtd = DWC_CIRCLEQ_FIRST(&qh->qtd_list);
  77126. +
  77127. + if (qtd->complete_split) {
  77128. + continue_split = 1;
  77129. + } else if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_MID ||
  77130. + qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_END) {
  77131. + continue_split = 1;
  77132. + }
  77133. +
  77134. + if (free_qtd) {
  77135. + dwc_otg_hcd_qtd_remove_and_free(hcd, qtd, qh);
  77136. + continue_split = 0;
  77137. + }
  77138. +
  77139. + qh->channel = NULL;
  77140. + dwc_otg_hcd_qh_deactivate(hcd, qh, continue_split);
  77141. +}
  77142. +
  77143. +/**
  77144. + * Releases a host channel for use by other transfers. Attempts to select and
  77145. + * queue more transactions since at least one host channel is available.
  77146. + *
  77147. + * @param hcd The HCD state structure.
  77148. + * @param hc The host channel to release.
  77149. + * @param qtd The QTD associated with the host channel. This QTD may be freed
  77150. + * if the transfer is complete or an error has occurred.
  77151. + * @param halt_status Reason the channel is being released. This status
  77152. + * determines the actions taken by this function.
  77153. + */
  77154. +static void release_channel(dwc_otg_hcd_t * hcd,
  77155. + dwc_hc_t * hc,
  77156. + dwc_otg_qtd_t * qtd,
  77157. + dwc_otg_halt_status_e halt_status)
  77158. +{
  77159. + dwc_otg_transaction_type_e tr_type;
  77160. + int free_qtd;
  77161. + dwc_irqflags_t flags;
  77162. + dwc_spinlock_t *channel_lock = hcd->channel_lock;
  77163. +
  77164. + int hog_port = 0;
  77165. +
  77166. + DWC_DEBUGPL(DBG_HCDV, " %s: channel %d, halt_status %d, xfer_len %d\n",
  77167. + __func__, hc->hc_num, halt_status, hc->xfer_len);
  77168. +
  77169. + if(fiq_fsm_enable && hc->do_split) {
  77170. + if(!hc->ep_is_in && hc->ep_type == UE_ISOCHRONOUS) {
  77171. + if(hc->xact_pos == DWC_HCSPLIT_XACTPOS_MID ||
  77172. + hc->xact_pos == DWC_HCSPLIT_XACTPOS_BEGIN) {
  77173. + hog_port = 0;
  77174. + }
  77175. + }
  77176. + }
  77177. +
  77178. + switch (halt_status) {
  77179. + case DWC_OTG_HC_XFER_URB_COMPLETE:
  77180. + free_qtd = 1;
  77181. + break;
  77182. + case DWC_OTG_HC_XFER_AHB_ERR:
  77183. + case DWC_OTG_HC_XFER_STALL:
  77184. + case DWC_OTG_HC_XFER_BABBLE_ERR:
  77185. + free_qtd = 1;
  77186. + break;
  77187. + case DWC_OTG_HC_XFER_XACT_ERR:
  77188. + if (qtd->error_count >= 3) {
  77189. + DWC_DEBUGPL(DBG_HCDV,
  77190. + " Complete URB with transaction error\n");
  77191. + free_qtd = 1;
  77192. + qtd->urb->status = -DWC_E_PROTOCOL;
  77193. + hcd->fops->complete(hcd, qtd->urb->priv,
  77194. + qtd->urb, -DWC_E_PROTOCOL);
  77195. + } else {
  77196. + free_qtd = 0;
  77197. + }
  77198. + break;
  77199. + case DWC_OTG_HC_XFER_URB_DEQUEUE:
  77200. + /*
  77201. + * The QTD has already been removed and the QH has been
  77202. + * deactivated. Don't want to do anything except release the
  77203. + * host channel and try to queue more transfers.
  77204. + */
  77205. + goto cleanup;
  77206. + case DWC_OTG_HC_XFER_NO_HALT_STATUS:
  77207. + free_qtd = 0;
  77208. + break;
  77209. + case DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE:
  77210. + DWC_DEBUGPL(DBG_HCDV,
  77211. + " Complete URB with I/O error\n");
  77212. + free_qtd = 1;
  77213. + qtd->urb->status = -DWC_E_IO;
  77214. + hcd->fops->complete(hcd, qtd->urb->priv,
  77215. + qtd->urb, -DWC_E_IO);
  77216. + break;
  77217. + default:
  77218. + free_qtd = 0;
  77219. + break;
  77220. + }
  77221. +
  77222. + deactivate_qh(hcd, hc->qh, free_qtd);
  77223. +
  77224. +cleanup:
  77225. + /*
  77226. + * Release the host channel for use by other transfers. The cleanup
  77227. + * function clears the channel interrupt enables and conditions, so
  77228. + * there's no need to clear the Channel Halted interrupt separately.
  77229. + */
  77230. + if (fiq_fsm_enable && hcd->fiq_state->channel[hc->hc_num].fsm != FIQ_PASSTHROUGH)
  77231. + dwc_otg_cleanup_fiq_channel(hcd, hc->hc_num);
  77232. + dwc_otg_hc_cleanup(hcd->core_if, hc);
  77233. + DWC_CIRCLEQ_INSERT_TAIL(&hcd->free_hc_list, hc, hc_list_entry);
  77234. +
  77235. + if (!microframe_schedule) {
  77236. + switch (hc->ep_type) {
  77237. + case DWC_OTG_EP_TYPE_CONTROL:
  77238. + case DWC_OTG_EP_TYPE_BULK:
  77239. + hcd->non_periodic_channels--;
  77240. + break;
  77241. +
  77242. + default:
  77243. + /*
  77244. + * Don't release reservations for periodic channels here.
  77245. + * That's done when a periodic transfer is descheduled (i.e.
  77246. + * when the QH is removed from the periodic schedule).
  77247. + */
  77248. + break;
  77249. + }
  77250. + } else {
  77251. +
  77252. + DWC_SPINLOCK_IRQSAVE(channel_lock, &flags);
  77253. + hcd->available_host_channels++;
  77254. + fiq_print(FIQDBG_INT, hcd->fiq_state, "AHC = %d ", hcd->available_host_channels);
  77255. + DWC_SPINUNLOCK_IRQRESTORE(channel_lock, flags);
  77256. + }
  77257. +
  77258. + /* Try to queue more transfers now that there's a free channel. */
  77259. + tr_type = dwc_otg_hcd_select_transactions(hcd);
  77260. + if (tr_type != DWC_OTG_TRANSACTION_NONE) {
  77261. + dwc_otg_hcd_queue_transactions(hcd, tr_type);
  77262. + }
  77263. +}
  77264. +
  77265. +/**
  77266. + * Halts a host channel. If the channel cannot be halted immediately because
  77267. + * the request queue is full, this function ensures that the FIFO empty
  77268. + * interrupt for the appropriate queue is enabled so that the halt request can
  77269. + * be queued when there is space in the request queue.
  77270. + *
  77271. + * This function may also be called in DMA mode. In that case, the channel is
  77272. + * simply released since the core always halts the channel automatically in
  77273. + * DMA mode.
  77274. + */
  77275. +static void halt_channel(dwc_otg_hcd_t * hcd,
  77276. + dwc_hc_t * hc,
  77277. + dwc_otg_qtd_t * qtd, dwc_otg_halt_status_e halt_status)
  77278. +{
  77279. + if (hcd->core_if->dma_enable) {
  77280. + release_channel(hcd, hc, qtd, halt_status);
  77281. + return;
  77282. + }
  77283. +
  77284. + /* Slave mode processing... */
  77285. + dwc_otg_hc_halt(hcd->core_if, hc, halt_status);
  77286. +
  77287. + if (hc->halt_on_queue) {
  77288. + gintmsk_data_t gintmsk = {.d32 = 0 };
  77289. + dwc_otg_core_global_regs_t *global_regs;
  77290. + global_regs = hcd->core_if->core_global_regs;
  77291. +
  77292. + if (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  77293. + hc->ep_type == DWC_OTG_EP_TYPE_BULK) {
  77294. + /*
  77295. + * Make sure the Non-periodic Tx FIFO empty interrupt
  77296. + * is enabled so that the non-periodic schedule will
  77297. + * be processed.
  77298. + */
  77299. + gintmsk.b.nptxfempty = 1;
  77300. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  77301. + } else {
  77302. + /*
  77303. + * Move the QH from the periodic queued schedule to
  77304. + * the periodic assigned schedule. This allows the
  77305. + * halt to be queued when the periodic schedule is
  77306. + * processed.
  77307. + */
  77308. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_assigned,
  77309. + &hc->qh->qh_list_entry);
  77310. +
  77311. + /*
  77312. + * Make sure the Periodic Tx FIFO Empty interrupt is
  77313. + * enabled so that the periodic schedule will be
  77314. + * processed.
  77315. + */
  77316. + gintmsk.b.ptxfempty = 1;
  77317. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmsk.d32);
  77318. + }
  77319. + }
  77320. +}
  77321. +
  77322. +/**
  77323. + * Performs common cleanup for non-periodic transfers after a Transfer
  77324. + * Complete interrupt. This function should be called after any endpoint type
  77325. + * specific handling is finished to release the host channel.
  77326. + */
  77327. +static void complete_non_periodic_xfer(dwc_otg_hcd_t * hcd,
  77328. + dwc_hc_t * hc,
  77329. + dwc_otg_hc_regs_t * hc_regs,
  77330. + dwc_otg_qtd_t * qtd,
  77331. + dwc_otg_halt_status_e halt_status)
  77332. +{
  77333. + hcint_data_t hcint;
  77334. +
  77335. + qtd->error_count = 0;
  77336. +
  77337. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  77338. + if (hcint.b.nyet) {
  77339. + /*
  77340. + * Got a NYET on the last transaction of the transfer. This
  77341. + * means that the endpoint should be in the PING state at the
  77342. + * beginning of the next transfer.
  77343. + */
  77344. + hc->qh->ping_state = 1;
  77345. + clear_hc_int(hc_regs, nyet);
  77346. + }
  77347. +
  77348. + /*
  77349. + * Always halt and release the host channel to make it available for
  77350. + * more transfers. There may still be more phases for a control
  77351. + * transfer or more data packets for a bulk transfer at this point,
  77352. + * but the host channel is still halted. A channel will be reassigned
  77353. + * to the transfer when the non-periodic schedule is processed after
  77354. + * the channel is released. This allows transactions to be queued
  77355. + * properly via dwc_otg_hcd_queue_transactions, which also enables the
  77356. + * Tx FIFO Empty interrupt if necessary.
  77357. + */
  77358. + if (hc->ep_is_in) {
  77359. + /*
  77360. + * IN transfers in Slave mode require an explicit disable to
  77361. + * halt the channel. (In DMA mode, this call simply releases
  77362. + * the channel.)
  77363. + */
  77364. + halt_channel(hcd, hc, qtd, halt_status);
  77365. + } else {
  77366. + /*
  77367. + * The channel is automatically disabled by the core for OUT
  77368. + * transfers in Slave mode.
  77369. + */
  77370. + release_channel(hcd, hc, qtd, halt_status);
  77371. + }
  77372. +}
  77373. +
  77374. +/**
  77375. + * Performs common cleanup for periodic transfers after a Transfer Complete
  77376. + * interrupt. This function should be called after any endpoint type specific
  77377. + * handling is finished to release the host channel.
  77378. + */
  77379. +static void complete_periodic_xfer(dwc_otg_hcd_t * hcd,
  77380. + dwc_hc_t * hc,
  77381. + dwc_otg_hc_regs_t * hc_regs,
  77382. + dwc_otg_qtd_t * qtd,
  77383. + dwc_otg_halt_status_e halt_status)
  77384. +{
  77385. + hctsiz_data_t hctsiz;
  77386. + qtd->error_count = 0;
  77387. +
  77388. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77389. + if (!hc->ep_is_in || hctsiz.b.pktcnt == 0) {
  77390. + /* Core halts channel in these cases. */
  77391. + release_channel(hcd, hc, qtd, halt_status);
  77392. + } else {
  77393. + /* Flush any outstanding requests from the Tx queue. */
  77394. + halt_channel(hcd, hc, qtd, halt_status);
  77395. + }
  77396. +}
  77397. +
  77398. +static int32_t handle_xfercomp_isoc_split_in(dwc_otg_hcd_t * hcd,
  77399. + dwc_hc_t * hc,
  77400. + dwc_otg_hc_regs_t * hc_regs,
  77401. + dwc_otg_qtd_t * qtd)
  77402. +{
  77403. + uint32_t len;
  77404. + struct dwc_otg_hcd_iso_packet_desc *frame_desc;
  77405. + frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  77406. +
  77407. + len = get_actual_xfer_length(hc, hc_regs, qtd,
  77408. + DWC_OTG_HC_XFER_COMPLETE, NULL);
  77409. +
  77410. + if (!len) {
  77411. + qtd->complete_split = 0;
  77412. + qtd->isoc_split_offset = 0;
  77413. + return 0;
  77414. + }
  77415. + frame_desc->actual_length += len;
  77416. +
  77417. + if (hc->align_buff && len)
  77418. + dwc_memcpy(qtd->urb->buf + frame_desc->offset +
  77419. + qtd->isoc_split_offset, hc->qh->dw_align_buf, len);
  77420. + qtd->isoc_split_offset += len;
  77421. +
  77422. + if (frame_desc->length == frame_desc->actual_length) {
  77423. + frame_desc->status = 0;
  77424. + qtd->isoc_frame_index++;
  77425. + qtd->complete_split = 0;
  77426. + qtd->isoc_split_offset = 0;
  77427. + }
  77428. +
  77429. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  77430. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  77431. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  77432. + } else {
  77433. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  77434. + }
  77435. +
  77436. + return 1; /* Indicates that channel released */
  77437. +}
  77438. +
  77439. +/**
  77440. + * Handles a host channel Transfer Complete interrupt. This handler may be
  77441. + * called in either DMA mode or Slave mode.
  77442. + */
  77443. +static int32_t handle_hc_xfercomp_intr(dwc_otg_hcd_t * hcd,
  77444. + dwc_hc_t * hc,
  77445. + dwc_otg_hc_regs_t * hc_regs,
  77446. + dwc_otg_qtd_t * qtd)
  77447. +{
  77448. + int urb_xfer_done;
  77449. + dwc_otg_halt_status_e halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77450. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77451. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77452. +
  77453. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77454. + "Transfer Complete--\n", hc->hc_num);
  77455. +
  77456. + if (hcd->core_if->dma_desc_enable) {
  77457. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, halt_status);
  77458. + if (pipe_type == UE_ISOCHRONOUS) {
  77459. + /* Do not disable the interrupt, just clear it */
  77460. + clear_hc_int(hc_regs, xfercomp);
  77461. + return 1;
  77462. + }
  77463. + goto handle_xfercomp_done;
  77464. + }
  77465. +
  77466. + /*
  77467. + * Handle xfer complete on CSPLIT.
  77468. + */
  77469. +
  77470. + if (hc->qh->do_split) {
  77471. + if ((hc->ep_type == DWC_OTG_EP_TYPE_ISOC) && hc->ep_is_in
  77472. + && hcd->core_if->dma_enable) {
  77473. + if (qtd->complete_split
  77474. + && handle_xfercomp_isoc_split_in(hcd, hc, hc_regs,
  77475. + qtd))
  77476. + goto handle_xfercomp_done;
  77477. + } else {
  77478. + qtd->complete_split = 0;
  77479. + }
  77480. + }
  77481. +
  77482. + /* Update the QTD and URB states. */
  77483. + switch (pipe_type) {
  77484. + case UE_CONTROL:
  77485. + switch (qtd->control_phase) {
  77486. + case DWC_OTG_CONTROL_SETUP:
  77487. + if (urb->length > 0) {
  77488. + qtd->control_phase = DWC_OTG_CONTROL_DATA;
  77489. + } else {
  77490. + qtd->control_phase = DWC_OTG_CONTROL_STATUS;
  77491. + }
  77492. + DWC_DEBUGPL(DBG_HCDV,
  77493. + " Control setup transaction done\n");
  77494. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77495. + break;
  77496. + case DWC_OTG_CONTROL_DATA:{
  77497. + urb_xfer_done =
  77498. + update_urb_state_xfer_comp(hc, hc_regs, urb,
  77499. + qtd);
  77500. + if (urb_xfer_done) {
  77501. + qtd->control_phase =
  77502. + DWC_OTG_CONTROL_STATUS;
  77503. + DWC_DEBUGPL(DBG_HCDV,
  77504. + " Control data transfer done\n");
  77505. + } else {
  77506. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77507. + }
  77508. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77509. + break;
  77510. + }
  77511. + case DWC_OTG_CONTROL_STATUS:
  77512. + DWC_DEBUGPL(DBG_HCDV, " Control transfer complete\n");
  77513. + if (urb->status == -DWC_E_IN_PROGRESS) {
  77514. + urb->status = 0;
  77515. + }
  77516. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77517. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77518. + break;
  77519. + }
  77520. +
  77521. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77522. + break;
  77523. + case UE_BULK:
  77524. + DWC_DEBUGPL(DBG_HCDV, " Bulk transfer complete\n");
  77525. + urb_xfer_done =
  77526. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  77527. + if (urb_xfer_done) {
  77528. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77529. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77530. + } else {
  77531. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77532. + }
  77533. +
  77534. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77535. + complete_non_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77536. + break;
  77537. + case UE_INTERRUPT:
  77538. + DWC_DEBUGPL(DBG_HCDV, " Interrupt transfer complete\n");
  77539. + urb_xfer_done =
  77540. + update_urb_state_xfer_comp(hc, hc_regs, urb, qtd);
  77541. +
  77542. + /*
  77543. + * Interrupt URB is done on the first transfer complete
  77544. + * interrupt.
  77545. + */
  77546. + if (urb_xfer_done) {
  77547. + hcd->fops->complete(hcd, urb->priv, urb, urb->status);
  77548. + halt_status = DWC_OTG_HC_XFER_URB_COMPLETE;
  77549. + } else {
  77550. + halt_status = DWC_OTG_HC_XFER_COMPLETE;
  77551. + }
  77552. +
  77553. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77554. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77555. + break;
  77556. + case UE_ISOCHRONOUS:
  77557. + DWC_DEBUGPL(DBG_HCDV, " Isochronous transfer complete\n");
  77558. + if (qtd->isoc_split_pos == DWC_HCSPLIT_XACTPOS_ALL) {
  77559. + halt_status =
  77560. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77561. + DWC_OTG_HC_XFER_COMPLETE);
  77562. + }
  77563. + complete_periodic_xfer(hcd, hc, hc_regs, qtd, halt_status);
  77564. + break;
  77565. + }
  77566. +
  77567. +handle_xfercomp_done:
  77568. + disable_hc_int(hc_regs, xfercompl);
  77569. +
  77570. + return 1;
  77571. +}
  77572. +
  77573. +/**
  77574. + * Handles a host channel STALL interrupt. This handler may be called in
  77575. + * either DMA mode or Slave mode.
  77576. + */
  77577. +static int32_t handle_hc_stall_intr(dwc_otg_hcd_t * hcd,
  77578. + dwc_hc_t * hc,
  77579. + dwc_otg_hc_regs_t * hc_regs,
  77580. + dwc_otg_qtd_t * qtd)
  77581. +{
  77582. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77583. + int pipe_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  77584. +
  77585. + DWC_DEBUGPL(DBG_HCD, "--Host Channel %d Interrupt: "
  77586. + "STALL Received--\n", hc->hc_num);
  77587. +
  77588. + if (hcd->core_if->dma_desc_enable) {
  77589. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs, DWC_OTG_HC_XFER_STALL);
  77590. + goto handle_stall_done;
  77591. + }
  77592. +
  77593. + if (pipe_type == UE_CONTROL) {
  77594. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  77595. + }
  77596. +
  77597. + if (pipe_type == UE_BULK || pipe_type == UE_INTERRUPT) {
  77598. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_PIPE);
  77599. + /*
  77600. + * USB protocol requires resetting the data toggle for bulk
  77601. + * and interrupt endpoints when a CLEAR_FEATURE(ENDPOINT_HALT)
  77602. + * setup command is issued to the endpoint. Anticipate the
  77603. + * CLEAR_FEATURE command since a STALL has occurred and reset
  77604. + * the data toggle now.
  77605. + */
  77606. + hc->qh->data_toggle = 0;
  77607. + }
  77608. +
  77609. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_STALL);
  77610. +
  77611. +handle_stall_done:
  77612. + disable_hc_int(hc_regs, stall);
  77613. +
  77614. + return 1;
  77615. +}
  77616. +
  77617. +/*
  77618. + * Updates the state of the URB when a transfer has been stopped due to an
  77619. + * abnormal condition before the transfer completes. Modifies the
  77620. + * actual_length field of the URB to reflect the number of bytes that have
  77621. + * actually been transferred via the host channel.
  77622. + */
  77623. +static void update_urb_state_xfer_intr(dwc_hc_t * hc,
  77624. + dwc_otg_hc_regs_t * hc_regs,
  77625. + dwc_otg_hcd_urb_t * urb,
  77626. + dwc_otg_qtd_t * qtd,
  77627. + dwc_otg_halt_status_e halt_status)
  77628. +{
  77629. + uint32_t bytes_transferred = get_actual_xfer_length(hc, hc_regs, qtd,
  77630. + halt_status, NULL);
  77631. + /* non DWORD-aligned buffer case handling. */
  77632. + if (hc->align_buff && bytes_transferred && hc->ep_is_in) {
  77633. + dwc_memcpy(urb->buf + urb->actual_length, hc->qh->dw_align_buf,
  77634. + bytes_transferred);
  77635. + }
  77636. +
  77637. + urb->actual_length += bytes_transferred;
  77638. +
  77639. +#ifdef DEBUG
  77640. + {
  77641. + hctsiz_data_t hctsiz;
  77642. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77643. + DWC_DEBUGPL(DBG_HCDV, "DWC_otg: %s: %s, channel %d\n",
  77644. + __func__, (hc->ep_is_in ? "IN" : "OUT"),
  77645. + hc->hc_num);
  77646. + DWC_DEBUGPL(DBG_HCDV, " hc->start_pkt_count %d\n",
  77647. + hc->start_pkt_count);
  77648. + DWC_DEBUGPL(DBG_HCDV, " hctsiz.pktcnt %d\n", hctsiz.b.pktcnt);
  77649. + DWC_DEBUGPL(DBG_HCDV, " hc->max_packet %d\n", hc->max_packet);
  77650. + DWC_DEBUGPL(DBG_HCDV, " bytes_transferred %d\n",
  77651. + bytes_transferred);
  77652. + DWC_DEBUGPL(DBG_HCDV, " urb->actual_length %d\n",
  77653. + urb->actual_length);
  77654. + DWC_DEBUGPL(DBG_HCDV, " urb->transfer_buffer_length %d\n",
  77655. + urb->length);
  77656. + }
  77657. +#endif
  77658. +}
  77659. +
  77660. +/**
  77661. + * Handles a host channel NAK interrupt. This handler may be called in either
  77662. + * DMA mode or Slave mode.
  77663. + */
  77664. +static int32_t handle_hc_nak_intr(dwc_otg_hcd_t * hcd,
  77665. + dwc_hc_t * hc,
  77666. + dwc_otg_hc_regs_t * hc_regs,
  77667. + dwc_otg_qtd_t * qtd)
  77668. +{
  77669. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77670. + "NAK Received--\n", hc->hc_num);
  77671. +
  77672. + /*
  77673. + * When we get bulk NAKs then remember this so we holdoff on this qh until
  77674. + * the beginning of the next frame
  77675. + */
  77676. + switch(dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77677. + case UE_BULK:
  77678. + case UE_CONTROL:
  77679. + if (nak_holdoff && qtd->qh->do_split)
  77680. + hc->qh->nak_frame = dwc_otg_hcd_get_frame_number(hcd);
  77681. + }
  77682. +
  77683. + /*
  77684. + * Handle NAK for IN/OUT SSPLIT/CSPLIT transfers, bulk, control, and
  77685. + * interrupt. Re-start the SSPLIT transfer.
  77686. + */
  77687. + if (hc->do_split) {
  77688. + if (hc->complete_split) {
  77689. + qtd->error_count = 0;
  77690. + }
  77691. + qtd->complete_split = 0;
  77692. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77693. + goto handle_nak_done;
  77694. + }
  77695. +
  77696. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  77697. + case UE_CONTROL:
  77698. + case UE_BULK:
  77699. + if (hcd->core_if->dma_enable && hc->ep_is_in) {
  77700. + /*
  77701. + * NAK interrupts are enabled on bulk/control IN
  77702. + * transfers in DMA mode for the sole purpose of
  77703. + * resetting the error count after a transaction error
  77704. + * occurs. The core will continue transferring data.
  77705. + * Disable other interrupts unmasked for the same
  77706. + * reason.
  77707. + */
  77708. + disable_hc_int(hc_regs, datatglerr);
  77709. + disable_hc_int(hc_regs, ack);
  77710. + qtd->error_count = 0;
  77711. + goto handle_nak_done;
  77712. + }
  77713. +
  77714. + /*
  77715. + * NAK interrupts normally occur during OUT transfers in DMA
  77716. + * or Slave mode. For IN transfers, more requests will be
  77717. + * queued as request queue space is available.
  77718. + */
  77719. + qtd->error_count = 0;
  77720. +
  77721. + if (!hc->qh->ping_state) {
  77722. + update_urb_state_xfer_intr(hc, hc_regs,
  77723. + qtd->urb, qtd,
  77724. + DWC_OTG_HC_XFER_NAK);
  77725. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77726. +
  77727. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH)
  77728. + hc->qh->ping_state = 1;
  77729. + }
  77730. +
  77731. + /*
  77732. + * Halt the channel so the transfer can be re-started from
  77733. + * the appropriate point or the PING protocol will
  77734. + * start/continue.
  77735. + */
  77736. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77737. + break;
  77738. + case UE_INTERRUPT:
  77739. + qtd->error_count = 0;
  77740. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NAK);
  77741. + break;
  77742. + case UE_ISOCHRONOUS:
  77743. + /* Should never get called for isochronous transfers. */
  77744. + DWC_ASSERT(1, "NACK interrupt for ISOC transfer\n");
  77745. + break;
  77746. + }
  77747. +
  77748. +handle_nak_done:
  77749. + disable_hc_int(hc_regs, nak);
  77750. +
  77751. + return 1;
  77752. +}
  77753. +
  77754. +/**
  77755. + * Handles a host channel ACK interrupt. This interrupt is enabled when
  77756. + * performing the PING protocol in Slave mode, when errors occur during
  77757. + * either Slave mode or DMA mode, and during Start Split transactions.
  77758. + */
  77759. +static int32_t handle_hc_ack_intr(dwc_otg_hcd_t * hcd,
  77760. + dwc_hc_t * hc,
  77761. + dwc_otg_hc_regs_t * hc_regs,
  77762. + dwc_otg_qtd_t * qtd)
  77763. +{
  77764. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77765. + "ACK Received--\n", hc->hc_num);
  77766. +
  77767. + if (hc->do_split) {
  77768. + /*
  77769. + * Handle ACK on SSPLIT.
  77770. + * ACK should not occur in CSPLIT.
  77771. + */
  77772. + if (!hc->ep_is_in && hc->data_pid_start != DWC_OTG_HC_PID_SETUP) {
  77773. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  77774. + }
  77775. + if (!(hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in)) {
  77776. + /* Don't need complete for isochronous out transfers. */
  77777. + qtd->complete_split = 1;
  77778. + }
  77779. +
  77780. + /* ISOC OUT */
  77781. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  77782. + switch (hc->xact_pos) {
  77783. + case DWC_HCSPLIT_XACTPOS_ALL:
  77784. + break;
  77785. + case DWC_HCSPLIT_XACTPOS_END:
  77786. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  77787. + qtd->isoc_split_offset = 0;
  77788. + break;
  77789. + case DWC_HCSPLIT_XACTPOS_BEGIN:
  77790. + case DWC_HCSPLIT_XACTPOS_MID:
  77791. + /*
  77792. + * For BEGIN or MID, calculate the length for
  77793. + * the next microframe to determine the correct
  77794. + * SSPLIT token, either MID or END.
  77795. + */
  77796. + {
  77797. + struct dwc_otg_hcd_iso_packet_desc
  77798. + *frame_desc;
  77799. +
  77800. + frame_desc =
  77801. + &qtd->urb->
  77802. + iso_descs[qtd->isoc_frame_index];
  77803. + qtd->isoc_split_offset += 188;
  77804. +
  77805. + if ((frame_desc->length -
  77806. + qtd->isoc_split_offset) <= 188) {
  77807. + qtd->isoc_split_pos =
  77808. + DWC_HCSPLIT_XACTPOS_END;
  77809. + } else {
  77810. + qtd->isoc_split_pos =
  77811. + DWC_HCSPLIT_XACTPOS_MID;
  77812. + }
  77813. +
  77814. + }
  77815. + break;
  77816. + }
  77817. + } else {
  77818. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  77819. + }
  77820. + } else {
  77821. + /*
  77822. + * An unmasked ACK on a non-split DMA transaction is
  77823. + * for the sole purpose of resetting error counts. Disable other
  77824. + * interrupts unmasked for the same reason.
  77825. + */
  77826. + if(hcd->core_if->dma_enable) {
  77827. + disable_hc_int(hc_regs, datatglerr);
  77828. + disable_hc_int(hc_regs, nak);
  77829. + }
  77830. + qtd->error_count = 0;
  77831. +
  77832. + if (hc->qh->ping_state) {
  77833. + hc->qh->ping_state = 0;
  77834. + /*
  77835. + * Halt the channel so the transfer can be re-started
  77836. + * from the appropriate point. This only happens in
  77837. + * Slave mode. In DMA mode, the ping_state is cleared
  77838. + * when the transfer is started because the core
  77839. + * automatically executes the PING, then the transfer.
  77840. + */
  77841. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_ACK);
  77842. + }
  77843. + }
  77844. +
  77845. + /*
  77846. + * If the ACK occurred when _not_ in the PING state, let the channel
  77847. + * continue transferring data after clearing the error count.
  77848. + */
  77849. +
  77850. + disable_hc_int(hc_regs, ack);
  77851. +
  77852. + return 1;
  77853. +}
  77854. +
  77855. +/**
  77856. + * Handles a host channel NYET interrupt. This interrupt should only occur on
  77857. + * Bulk and Control OUT endpoints and for complete split transactions. If a
  77858. + * NYET occurs at the same time as a Transfer Complete interrupt, it is
  77859. + * handled in the xfercomp interrupt handler, not here. This handler may be
  77860. + * called in either DMA mode or Slave mode.
  77861. + */
  77862. +static int32_t handle_hc_nyet_intr(dwc_otg_hcd_t * hcd,
  77863. + dwc_hc_t * hc,
  77864. + dwc_otg_hc_regs_t * hc_regs,
  77865. + dwc_otg_qtd_t * qtd)
  77866. +{
  77867. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77868. + "NYET Received--\n", hc->hc_num);
  77869. +
  77870. + /*
  77871. + * NYET on CSPLIT
  77872. + * re-do the CSPLIT immediately on non-periodic
  77873. + */
  77874. + if (hc->do_split && hc->complete_split) {
  77875. + if (hc->ep_is_in && (hc->ep_type == DWC_OTG_EP_TYPE_ISOC)
  77876. + && hcd->core_if->dma_enable) {
  77877. + qtd->complete_split = 0;
  77878. + qtd->isoc_split_offset = 0;
  77879. + if (++qtd->isoc_frame_index == qtd->urb->packet_count) {
  77880. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  77881. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  77882. + }
  77883. + else
  77884. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  77885. + goto handle_nyet_done;
  77886. + }
  77887. +
  77888. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  77889. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  77890. + int frnum = dwc_otg_hcd_get_frame_number(hcd);
  77891. +
  77892. + // With the FIQ running we only ever see the failed NYET
  77893. + if (dwc_full_frame_num(frnum) !=
  77894. + dwc_full_frame_num(hc->qh->sched_frame) ||
  77895. + fiq_fsm_enable) {
  77896. + /*
  77897. + * No longer in the same full speed frame.
  77898. + * Treat this as a transaction error.
  77899. + */
  77900. +#if 0
  77901. + /** @todo Fix system performance so this can
  77902. + * be treated as an error. Right now complete
  77903. + * splits cannot be scheduled precisely enough
  77904. + * due to other system activity, so this error
  77905. + * occurs regularly in Slave mode.
  77906. + */
  77907. + qtd->error_count++;
  77908. +#endif
  77909. + qtd->complete_split = 0;
  77910. + halt_channel(hcd, hc, qtd,
  77911. + DWC_OTG_HC_XFER_XACT_ERR);
  77912. + /** @todo add support for isoc release */
  77913. + goto handle_nyet_done;
  77914. + }
  77915. + }
  77916. +
  77917. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77918. + goto handle_nyet_done;
  77919. + }
  77920. +
  77921. + hc->qh->ping_state = 1;
  77922. + qtd->error_count = 0;
  77923. +
  77924. + update_urb_state_xfer_intr(hc, hc_regs, qtd->urb, qtd,
  77925. + DWC_OTG_HC_XFER_NYET);
  77926. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  77927. +
  77928. + /*
  77929. + * Halt the channel and re-start the transfer so the PING
  77930. + * protocol will start.
  77931. + */
  77932. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NYET);
  77933. +
  77934. +handle_nyet_done:
  77935. + disable_hc_int(hc_regs, nyet);
  77936. + return 1;
  77937. +}
  77938. +
  77939. +/**
  77940. + * Handles a host channel babble interrupt. This handler may be called in
  77941. + * either DMA mode or Slave mode.
  77942. + */
  77943. +static int32_t handle_hc_babble_intr(dwc_otg_hcd_t * hcd,
  77944. + dwc_hc_t * hc,
  77945. + dwc_otg_hc_regs_t * hc_regs,
  77946. + dwc_otg_qtd_t * qtd)
  77947. +{
  77948. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77949. + "Babble Error--\n", hc->hc_num);
  77950. +
  77951. + if (hcd->core_if->dma_desc_enable) {
  77952. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  77953. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77954. + goto handle_babble_done;
  77955. + }
  77956. +
  77957. + if (hc->ep_type != DWC_OTG_EP_TYPE_ISOC) {
  77958. + hcd->fops->complete(hcd, qtd->urb->priv,
  77959. + qtd->urb, -DWC_E_OVERFLOW);
  77960. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_BABBLE_ERR);
  77961. + } else {
  77962. + dwc_otg_halt_status_e halt_status;
  77963. + halt_status = update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  77964. + DWC_OTG_HC_XFER_BABBLE_ERR);
  77965. + halt_channel(hcd, hc, qtd, halt_status);
  77966. + }
  77967. +
  77968. +handle_babble_done:
  77969. + disable_hc_int(hc_regs, bblerr);
  77970. + return 1;
  77971. +}
  77972. +
  77973. +/**
  77974. + * Handles a host channel AHB error interrupt. This handler is only called in
  77975. + * DMA mode.
  77976. + */
  77977. +static int32_t handle_hc_ahberr_intr(dwc_otg_hcd_t * hcd,
  77978. + dwc_hc_t * hc,
  77979. + dwc_otg_hc_regs_t * hc_regs,
  77980. + dwc_otg_qtd_t * qtd)
  77981. +{
  77982. + hcchar_data_t hcchar;
  77983. + hcsplt_data_t hcsplt;
  77984. + hctsiz_data_t hctsiz;
  77985. + uint32_t hcdma;
  77986. + char *pipetype, *speed;
  77987. +
  77988. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  77989. +
  77990. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  77991. + "AHB Error--\n", hc->hc_num);
  77992. +
  77993. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  77994. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  77995. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  77996. + hcdma = DWC_READ_REG32(&hc_regs->hcdma);
  77997. +
  77998. + DWC_ERROR("AHB ERROR, Channel %d\n", hc->hc_num);
  77999. + DWC_ERROR(" hcchar 0x%08x, hcsplt 0x%08x\n", hcchar.d32, hcsplt.d32);
  78000. + DWC_ERROR(" hctsiz 0x%08x, hcdma 0x%08x\n", hctsiz.d32, hcdma);
  78001. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Enqueue\n");
  78002. + DWC_ERROR(" Device address: %d\n",
  78003. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  78004. + DWC_ERROR(" Endpoint: %d, %s\n",
  78005. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  78006. + (dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT"));
  78007. +
  78008. + switch (dwc_otg_hcd_get_pipe_type(&urb->pipe_info)) {
  78009. + case UE_CONTROL:
  78010. + pipetype = "CONTROL";
  78011. + break;
  78012. + case UE_BULK:
  78013. + pipetype = "BULK";
  78014. + break;
  78015. + case UE_INTERRUPT:
  78016. + pipetype = "INTERRUPT";
  78017. + break;
  78018. + case UE_ISOCHRONOUS:
  78019. + pipetype = "ISOCHRONOUS";
  78020. + break;
  78021. + default:
  78022. + pipetype = "UNKNOWN";
  78023. + break;
  78024. + }
  78025. +
  78026. + DWC_ERROR(" Endpoint type: %s\n", pipetype);
  78027. +
  78028. + switch (hc->speed) {
  78029. + case DWC_OTG_EP_SPEED_HIGH:
  78030. + speed = "HIGH";
  78031. + break;
  78032. + case DWC_OTG_EP_SPEED_FULL:
  78033. + speed = "FULL";
  78034. + break;
  78035. + case DWC_OTG_EP_SPEED_LOW:
  78036. + speed = "LOW";
  78037. + break;
  78038. + default:
  78039. + speed = "UNKNOWN";
  78040. + break;
  78041. + };
  78042. +
  78043. + DWC_ERROR(" Speed: %s\n", speed);
  78044. +
  78045. + DWC_ERROR(" Max packet size: %d\n",
  78046. + dwc_otg_hcd_get_mps(&urb->pipe_info));
  78047. + DWC_ERROR(" Data buffer length: %d\n", urb->length);
  78048. + DWC_ERROR(" Transfer buffer: %p, Transfer DMA: %p\n",
  78049. + urb->buf, (void *)urb->dma);
  78050. + DWC_ERROR(" Setup buffer: %p, Setup DMA: %p\n",
  78051. + urb->setup_packet, (void *)urb->setup_dma);
  78052. + DWC_ERROR(" Interval: %d\n", urb->interval);
  78053. +
  78054. + /* Core haltes the channel for Descriptor DMA mode */
  78055. + if (hcd->core_if->dma_desc_enable) {
  78056. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78057. + DWC_OTG_HC_XFER_AHB_ERR);
  78058. + goto handle_ahberr_done;
  78059. + }
  78060. +
  78061. + hcd->fops->complete(hcd, urb->priv, urb, -DWC_E_IO);
  78062. +
  78063. + /*
  78064. + * Force a channel halt. Don't call halt_channel because that won't
  78065. + * write to the HCCHARn register in DMA mode to force the halt.
  78066. + */
  78067. + dwc_otg_hc_halt(hcd->core_if, hc, DWC_OTG_HC_XFER_AHB_ERR);
  78068. +handle_ahberr_done:
  78069. + disable_hc_int(hc_regs, ahberr);
  78070. + return 1;
  78071. +}
  78072. +
  78073. +/**
  78074. + * Handles a host channel transaction error interrupt. This handler may be
  78075. + * called in either DMA mode or Slave mode.
  78076. + */
  78077. +static int32_t handle_hc_xacterr_intr(dwc_otg_hcd_t * hcd,
  78078. + dwc_hc_t * hc,
  78079. + dwc_otg_hc_regs_t * hc_regs,
  78080. + dwc_otg_qtd_t * qtd)
  78081. +{
  78082. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78083. + "Transaction Error--\n", hc->hc_num);
  78084. +
  78085. + if (hcd->core_if->dma_desc_enable) {
  78086. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78087. + DWC_OTG_HC_XFER_XACT_ERR);
  78088. + goto handle_xacterr_done;
  78089. + }
  78090. +
  78091. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78092. + case UE_CONTROL:
  78093. + case UE_BULK:
  78094. + qtd->error_count++;
  78095. + if (!hc->qh->ping_state) {
  78096. +
  78097. + update_urb_state_xfer_intr(hc, hc_regs,
  78098. + qtd->urb, qtd,
  78099. + DWC_OTG_HC_XFER_XACT_ERR);
  78100. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78101. + if (!hc->ep_is_in && hc->speed == DWC_OTG_EP_SPEED_HIGH) {
  78102. + hc->qh->ping_state = 1;
  78103. + }
  78104. + }
  78105. +
  78106. + /*
  78107. + * Halt the channel so the transfer can be re-started from
  78108. + * the appropriate point or the PING protocol will start.
  78109. + */
  78110. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78111. + break;
  78112. + case UE_INTERRUPT:
  78113. + qtd->error_count++;
  78114. + if (hc->do_split && hc->complete_split) {
  78115. + qtd->complete_split = 0;
  78116. + }
  78117. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78118. + break;
  78119. + case UE_ISOCHRONOUS:
  78120. + {
  78121. + dwc_otg_halt_status_e halt_status;
  78122. + halt_status =
  78123. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78124. + DWC_OTG_HC_XFER_XACT_ERR);
  78125. +
  78126. + halt_channel(hcd, hc, qtd, halt_status);
  78127. + }
  78128. + break;
  78129. + }
  78130. +handle_xacterr_done:
  78131. + disable_hc_int(hc_regs, xacterr);
  78132. +
  78133. + return 1;
  78134. +}
  78135. +
  78136. +/**
  78137. + * Handles a host channel frame overrun interrupt. This handler may be called
  78138. + * in either DMA mode or Slave mode.
  78139. + */
  78140. +static int32_t handle_hc_frmovrun_intr(dwc_otg_hcd_t * hcd,
  78141. + dwc_hc_t * hc,
  78142. + dwc_otg_hc_regs_t * hc_regs,
  78143. + dwc_otg_qtd_t * qtd)
  78144. +{
  78145. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78146. + "Frame Overrun--\n", hc->hc_num);
  78147. +
  78148. + switch (dwc_otg_hcd_get_pipe_type(&qtd->urb->pipe_info)) {
  78149. + case UE_CONTROL:
  78150. + case UE_BULK:
  78151. + break;
  78152. + case UE_INTERRUPT:
  78153. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_FRAME_OVERRUN);
  78154. + break;
  78155. + case UE_ISOCHRONOUS:
  78156. + {
  78157. + dwc_otg_halt_status_e halt_status;
  78158. + halt_status =
  78159. + update_isoc_urb_state(hcd, hc, hc_regs, qtd,
  78160. + DWC_OTG_HC_XFER_FRAME_OVERRUN);
  78161. +
  78162. + halt_channel(hcd, hc, qtd, halt_status);
  78163. + }
  78164. + break;
  78165. + }
  78166. +
  78167. + disable_hc_int(hc_regs, frmovrun);
  78168. +
  78169. + return 1;
  78170. +}
  78171. +
  78172. +/**
  78173. + * Handles a host channel data toggle error interrupt. This handler may be
  78174. + * called in either DMA mode or Slave mode.
  78175. + */
  78176. +static int32_t handle_hc_datatglerr_intr(dwc_otg_hcd_t * hcd,
  78177. + dwc_hc_t * hc,
  78178. + dwc_otg_hc_regs_t * hc_regs,
  78179. + dwc_otg_qtd_t * qtd)
  78180. +{
  78181. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78182. + "Data Toggle Error on %s transfer--\n",
  78183. + hc->hc_num, (hc->ep_is_in ? "IN" : "OUT"));
  78184. +
  78185. + /* Data toggles on split transactions cause the hc to halt.
  78186. + * restart transfer */
  78187. + if(hc->qh->do_split)
  78188. + {
  78189. + qtd->error_count++;
  78190. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78191. + update_urb_state_xfer_intr(hc, hc_regs,
  78192. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78193. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78194. + } else if (hc->ep_is_in) {
  78195. + /* An unmasked data toggle error on a non-split DMA transaction is
  78196. + * for the sole purpose of resetting error counts. Disable other
  78197. + * interrupts unmasked for the same reason.
  78198. + */
  78199. + if(hcd->core_if->dma_enable) {
  78200. + disable_hc_int(hc_regs, ack);
  78201. + disable_hc_int(hc_regs, nak);
  78202. + }
  78203. + qtd->error_count = 0;
  78204. + }
  78205. +
  78206. + disable_hc_int(hc_regs, datatglerr);
  78207. +
  78208. + return 1;
  78209. +}
  78210. +
  78211. +#ifdef DEBUG
  78212. +/**
  78213. + * This function is for debug only. It checks that a valid halt status is set
  78214. + * and that HCCHARn.chdis is clear. If there's a problem, corrective action is
  78215. + * taken and a warning is issued.
  78216. + * @return 1 if halt status is ok, 0 otherwise.
  78217. + */
  78218. +static inline int halt_status_ok(dwc_otg_hcd_t * hcd,
  78219. + dwc_hc_t * hc,
  78220. + dwc_otg_hc_regs_t * hc_regs,
  78221. + dwc_otg_qtd_t * qtd)
  78222. +{
  78223. + hcchar_data_t hcchar;
  78224. + hctsiz_data_t hctsiz;
  78225. + hcint_data_t hcint;
  78226. + hcintmsk_data_t hcintmsk;
  78227. + hcsplt_data_t hcsplt;
  78228. +
  78229. + if (hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS) {
  78230. + /*
  78231. + * This code is here only as a check. This condition should
  78232. + * never happen. Ignore the halt if it does occur.
  78233. + */
  78234. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78235. + hctsiz.d32 = DWC_READ_REG32(&hc_regs->hctsiz);
  78236. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78237. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78238. + hcsplt.d32 = DWC_READ_REG32(&hc_regs->hcsplt);
  78239. + DWC_WARN
  78240. + ("%s: hc->halt_status == DWC_OTG_HC_XFER_NO_HALT_STATUS, "
  78241. + "channel %d, hcchar 0x%08x, hctsiz 0x%08x, "
  78242. + "hcint 0x%08x, hcintmsk 0x%08x, "
  78243. + "hcsplt 0x%08x, qtd->complete_split %d\n", __func__,
  78244. + hc->hc_num, hcchar.d32, hctsiz.d32, hcint.d32,
  78245. + hcintmsk.d32, hcsplt.d32, qtd->complete_split);
  78246. +
  78247. + DWC_WARN("%s: no halt status, channel %d, ignoring interrupt\n",
  78248. + __func__, hc->hc_num);
  78249. + DWC_WARN("\n");
  78250. + clear_hc_int(hc_regs, chhltd);
  78251. + return 0;
  78252. + }
  78253. +
  78254. + /*
  78255. + * This code is here only as a check. hcchar.chdis should
  78256. + * never be set when the halt interrupt occurs. Halt the
  78257. + * channel again if it does occur.
  78258. + */
  78259. + hcchar.d32 = DWC_READ_REG32(&hc_regs->hcchar);
  78260. + if (hcchar.b.chdis) {
  78261. + DWC_WARN("%s: hcchar.chdis set unexpectedly, "
  78262. + "hcchar 0x%08x, trying to halt again\n",
  78263. + __func__, hcchar.d32);
  78264. + clear_hc_int(hc_regs, chhltd);
  78265. + hc->halt_pending = 0;
  78266. + halt_channel(hcd, hc, qtd, hc->halt_status);
  78267. + return 0;
  78268. + }
  78269. +
  78270. + return 1;
  78271. +}
  78272. +#endif
  78273. +
  78274. +/**
  78275. + * Handles a host Channel Halted interrupt in DMA mode. This handler
  78276. + * determines the reason the channel halted and proceeds accordingly.
  78277. + */
  78278. +static void handle_hc_chhltd_intr_dma(dwc_otg_hcd_t * hcd,
  78279. + dwc_hc_t * hc,
  78280. + dwc_otg_hc_regs_t * hc_regs,
  78281. + dwc_otg_qtd_t * qtd)
  78282. +{
  78283. + int out_nak_enh = 0;
  78284. + hcint_data_t hcint;
  78285. + hcintmsk_data_t hcintmsk;
  78286. + /* For core with OUT NAK enhancement, the flow for high-
  78287. + * speed CONTROL/BULK OUT is handled a little differently.
  78288. + */
  78289. + if (hcd->core_if->snpsid >= OTG_CORE_REV_2_71a) {
  78290. + if (hc->speed == DWC_OTG_EP_SPEED_HIGH && !hc->ep_is_in &&
  78291. + (hc->ep_type == DWC_OTG_EP_TYPE_CONTROL ||
  78292. + hc->ep_type == DWC_OTG_EP_TYPE_BULK)) {
  78293. + out_nak_enh = 1;
  78294. + }
  78295. + }
  78296. +
  78297. + if (hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE ||
  78298. + (hc->halt_status == DWC_OTG_HC_XFER_AHB_ERR
  78299. + && !hcd->core_if->dma_desc_enable)) {
  78300. + /*
  78301. + * Just release the channel. A dequeue can happen on a
  78302. + * transfer timeout. In the case of an AHB Error, the channel
  78303. + * was forced to halt because there's no way to gracefully
  78304. + * recover.
  78305. + */
  78306. + if (hcd->core_if->dma_desc_enable)
  78307. + dwc_otg_hcd_complete_xfer_ddma(hcd, hc, hc_regs,
  78308. + hc->halt_status);
  78309. + else
  78310. + release_channel(hcd, hc, qtd, hc->halt_status);
  78311. + return;
  78312. + }
  78313. +
  78314. + /* Read the HCINTn register to determine the cause for the halt. */
  78315. +
  78316. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78317. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78318. +
  78319. + if (hcint.b.xfercomp) {
  78320. + /** @todo This is here because of a possible hardware bug. Spec
  78321. + * says that on SPLIT-ISOC OUT transfers in DMA mode that a HALT
  78322. + * interrupt w/ACK bit set should occur, but I only see the
  78323. + * XFERCOMP bit, even with it masked out. This is a workaround
  78324. + * for that behavior. Should fix this when hardware is fixed.
  78325. + */
  78326. + if (hc->ep_type == DWC_OTG_EP_TYPE_ISOC && !hc->ep_is_in) {
  78327. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  78328. + }
  78329. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  78330. + } else if (hcint.b.stall) {
  78331. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  78332. + } else if (hcint.b.xacterr && !hcd->core_if->dma_desc_enable) {
  78333. + if (out_nak_enh) {
  78334. + if (hcint.b.nyet || hcint.b.nak || hcint.b.ack) {
  78335. + DWC_DEBUGPL(DBG_HCD, "XactErr with NYET/NAK/ACK\n");
  78336. + qtd->error_count = 0;
  78337. + } else {
  78338. + DWC_DEBUGPL(DBG_HCD, "XactErr without NYET/NAK/ACK\n");
  78339. + }
  78340. + }
  78341. +
  78342. + /*
  78343. + * Must handle xacterr before nak or ack. Could get a xacterr
  78344. + * at the same time as either of these on a BULK/CONTROL OUT
  78345. + * that started with a PING. The xacterr takes precedence.
  78346. + */
  78347. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78348. + } else if (hcint.b.xcs_xact && hcd->core_if->dma_desc_enable) {
  78349. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78350. + } else if (hcint.b.ahberr && hcd->core_if->dma_desc_enable) {
  78351. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78352. + } else if (hcint.b.bblerr) {
  78353. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  78354. + } else if (hcint.b.frmovrun) {
  78355. + handle_hc_frmovrun_intr(hcd, hc, hc_regs, qtd);
  78356. + } else if (hcint.b.datatglerr) {
  78357. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  78358. + } else if (!out_nak_enh) {
  78359. + if (hcint.b.nyet) {
  78360. + /*
  78361. + * Must handle nyet before nak or ack. Could get a nyet at the
  78362. + * same time as either of those on a BULK/CONTROL OUT that
  78363. + * started with a PING. The nyet takes precedence.
  78364. + */
  78365. + handle_hc_nyet_intr(hcd, hc, hc_regs, qtd);
  78366. + } else if (hcint.b.nak && !hcintmsk.b.nak) {
  78367. + /*
  78368. + * If nak is not masked, it's because a non-split IN transfer
  78369. + * is in an error state. In that case, the nak is handled by
  78370. + * the nak interrupt handler, not here. Handle nak here for
  78371. + * BULK/CONTROL OUT transfers, which halt on a NAK to allow
  78372. + * rewinding the buffer pointer.
  78373. + */
  78374. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78375. + } else if (hcint.b.ack && !hcintmsk.b.ack) {
  78376. + /*
  78377. + * If ack is not masked, it's because a non-split IN transfer
  78378. + * is in an error state. In that case, the ack is handled by
  78379. + * the ack interrupt handler, not here. Handle ack here for
  78380. + * split transfers. Start splits halt on ACK.
  78381. + */
  78382. + handle_hc_ack_intr(hcd, hc, hc_regs, qtd);
  78383. + } else {
  78384. + if (hc->ep_type == DWC_OTG_EP_TYPE_INTR ||
  78385. + hc->ep_type == DWC_OTG_EP_TYPE_ISOC) {
  78386. + /*
  78387. + * A periodic transfer halted with no other channel
  78388. + * interrupts set. Assume it was halted by the core
  78389. + * because it could not be completed in its scheduled
  78390. + * (micro)frame.
  78391. + */
  78392. +#ifdef DEBUG
  78393. + DWC_PRINTF
  78394. + ("%s: Halt channel %d (assume incomplete periodic transfer)\n",
  78395. + __func__, hc->hc_num);
  78396. +#endif
  78397. + halt_channel(hcd, hc, qtd,
  78398. + DWC_OTG_HC_XFER_PERIODIC_INCOMPLETE);
  78399. + } else {
  78400. + DWC_ERROR
  78401. + ("%s: Channel %d, DMA Mode -- ChHltd set, but reason "
  78402. + "for halting is unknown, hcint 0x%08x, intsts 0x%08x\n",
  78403. + __func__, hc->hc_num, hcint.d32,
  78404. + DWC_READ_REG32(&hcd->
  78405. + core_if->core_global_regs->
  78406. + gintsts));
  78407. + /* Failthrough: use 3-strikes rule */
  78408. + qtd->error_count++;
  78409. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78410. + update_urb_state_xfer_intr(hc, hc_regs,
  78411. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78412. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78413. + }
  78414. +
  78415. + }
  78416. + } else {
  78417. + DWC_PRINTF("NYET/NAK/ACK/other in non-error case, 0x%08x\n",
  78418. + hcint.d32);
  78419. + /* Failthrough: use 3-strikes rule */
  78420. + qtd->error_count++;
  78421. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78422. + update_urb_state_xfer_intr(hc, hc_regs,
  78423. + qtd->urb, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78424. + halt_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_XACT_ERR);
  78425. + }
  78426. +}
  78427. +
  78428. +/**
  78429. + * Handles a host channel Channel Halted interrupt.
  78430. + *
  78431. + * In slave mode, this handler is called only when the driver specifically
  78432. + * requests a halt. This occurs during handling other host channel interrupts
  78433. + * (e.g. nak, xacterr, stall, nyet, etc.).
  78434. + *
  78435. + * In DMA mode, this is the interrupt that occurs when the core has finished
  78436. + * processing a transfer on a channel. Other host channel interrupts (except
  78437. + * ahberr) are disabled in DMA mode.
  78438. + */
  78439. +static int32_t handle_hc_chhltd_intr(dwc_otg_hcd_t * hcd,
  78440. + dwc_hc_t * hc,
  78441. + dwc_otg_hc_regs_t * hc_regs,
  78442. + dwc_otg_qtd_t * qtd)
  78443. +{
  78444. + DWC_DEBUGPL(DBG_HCDI, "--Host Channel %d Interrupt: "
  78445. + "Channel Halted--\n", hc->hc_num);
  78446. +
  78447. + if (hcd->core_if->dma_enable) {
  78448. + handle_hc_chhltd_intr_dma(hcd, hc, hc_regs, qtd);
  78449. + } else {
  78450. +#ifdef DEBUG
  78451. + if (!halt_status_ok(hcd, hc, hc_regs, qtd)) {
  78452. + return 1;
  78453. + }
  78454. +#endif
  78455. + release_channel(hcd, hc, qtd, hc->halt_status);
  78456. + }
  78457. +
  78458. + return 1;
  78459. +}
  78460. +
  78461. +
  78462. +/**
  78463. + * dwc_otg_fiq_unmangle_isoc() - Update the iso_frame_desc structure on
  78464. + * FIQ transfer completion
  78465. + * @hcd: Pointer to dwc_otg_hcd struct
  78466. + * @num: Host channel number
  78467. + *
  78468. + * 1. Un-mangle the status as recorded in each iso_frame_desc status
  78469. + * 2. Copy it from the dwc_otg_urb into the real URB
  78470. + */
  78471. +void dwc_otg_fiq_unmangle_isoc(dwc_otg_hcd_t *hcd, dwc_otg_qh_t *qh, dwc_otg_qtd_t *qtd, uint32_t num)
  78472. +{
  78473. + struct dwc_otg_hcd_urb *dwc_urb = qtd->urb;
  78474. + int nr_frames = dwc_urb->packet_count;
  78475. + int i;
  78476. + hcint_data_t frame_hcint;
  78477. +
  78478. + for (i = 0; i < nr_frames; i++) {
  78479. + frame_hcint.d32 = dwc_urb->iso_descs[i].status;
  78480. + if (frame_hcint.b.xfercomp) {
  78481. + dwc_urb->iso_descs[i].status = 0;
  78482. + dwc_urb->actual_length += dwc_urb->iso_descs[i].actual_length;
  78483. + } else if (frame_hcint.b.frmovrun) {
  78484. + if (qh->ep_is_in)
  78485. + dwc_urb->iso_descs[i].status = -DWC_E_NO_STREAM_RES;
  78486. + else
  78487. + dwc_urb->iso_descs[i].status = -DWC_E_COMMUNICATION;
  78488. + dwc_urb->error_count++;
  78489. + dwc_urb->iso_descs[i].actual_length = 0;
  78490. + } else if (frame_hcint.b.xacterr) {
  78491. + dwc_urb->iso_descs[i].status = -DWC_E_PROTOCOL;
  78492. + dwc_urb->error_count++;
  78493. + dwc_urb->iso_descs[i].actual_length = 0;
  78494. + } else if (frame_hcint.b.bblerr) {
  78495. + dwc_urb->iso_descs[i].status = -DWC_E_OVERFLOW;
  78496. + dwc_urb->error_count++;
  78497. + dwc_urb->iso_descs[i].actual_length = 0;
  78498. + } else {
  78499. + /* Something went wrong */
  78500. + dwc_urb->iso_descs[i].status = -1;
  78501. + dwc_urb->iso_descs[i].actual_length = 0;
  78502. + dwc_urb->error_count++;
  78503. + }
  78504. + }
  78505. + //printk_ratelimited(KERN_INFO "%s: HS isochronous of %d/%d frames with %d errors complete\n",
  78506. + // __FUNCTION__, i, dwc_urb->packet_count, dwc_urb->error_count);
  78507. + hcd->fops->complete(hcd, dwc_urb->priv, dwc_urb, 0);
  78508. + release_channel(hcd, qh->channel, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78509. +}
  78510. +
  78511. +/**
  78512. + * dwc_otg_fiq_unsetup_per_dma() - Remove data from bounce buffers for split transactions
  78513. + * @hcd: Pointer to dwc_otg_hcd struct
  78514. + * @num: Host channel number
  78515. + *
  78516. + * Copies data from the FIQ bounce buffers into the URB's transfer buffer. Does not modify URB state.
  78517. + * Returns total length of data or -1 if the buffers were not used.
  78518. + *
  78519. + */
  78520. +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)
  78521. +{
  78522. + dwc_hc_t *hc = qh->channel;
  78523. + struct fiq_dma_blob *blob = hcd->fiq_dmab;
  78524. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  78525. + uint8_t *ptr = NULL;
  78526. + int index = 0, len = 0;
  78527. + int i = 0;
  78528. + if (hc->ep_is_in) {
  78529. + /* Copy data out of the DMA bounce buffers to the URB's buffer.
  78530. + * The align_buf is ignored as this is ignored on FSM enqueue. */
  78531. + ptr = qtd->urb->buf;
  78532. + if (qh->ep_type == UE_ISOCHRONOUS) {
  78533. + /* Isoc IN transactions - grab the offset of the iso_frame_desc into the URB transfer buffer */
  78534. + index = qtd->isoc_frame_index;
  78535. + ptr += qtd->urb->iso_descs[index].offset;
  78536. + } else {
  78537. + /* Need to increment by actual_length for interrupt IN */
  78538. + ptr += qtd->urb->actual_length;
  78539. + }
  78540. +
  78541. + for (i = 0; i < st->dma_info.index; i++) {
  78542. + len += st->dma_info.slot_len[i];
  78543. + dwc_memcpy(ptr, &blob->channel[num].index[i].buf[0], st->dma_info.slot_len[i]);
  78544. + ptr += st->dma_info.slot_len[i];
  78545. + }
  78546. + return len;
  78547. + } else {
  78548. + /* OUT endpoints - nothing to do. */
  78549. + return -1;
  78550. + }
  78551. +
  78552. +}
  78553. +/**
  78554. + * dwc_otg_hcd_handle_hc_fsm() - handle an unmasked channel interrupt
  78555. + * from a channel handled in the FIQ
  78556. + * @hcd: Pointer to dwc_otg_hcd struct
  78557. + * @num: Host channel number
  78558. + *
  78559. + * If a host channel interrupt was received by the IRQ and this was a channel
  78560. + * used by the FIQ, the execution flow for transfer completion is substantially
  78561. + * different from the normal (messy) path. This function and its friends handles
  78562. + * channel cleanup and transaction completion from a FIQ transaction.
  78563. + */
  78564. +int32_t dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd_t *hcd, uint32_t num)
  78565. +{
  78566. + struct fiq_channel_state *st = &hcd->fiq_state->channel[num];
  78567. + dwc_hc_t *hc = hcd->hc_ptr_array[num];
  78568. + dwc_otg_qtd_t *qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  78569. + dwc_otg_qh_t *qh = hc->qh;
  78570. + dwc_otg_hc_regs_t *hc_regs = hcd->core_if->host_if->hc_regs[num];
  78571. + hcint_data_t hcint = hcd->fiq_state->channel[num].hcint_copy;
  78572. + int hostchannels = 0;
  78573. + int ret = 0;
  78574. + fiq_print(FIQDBG_INT, hcd->fiq_state, "OUT %01d %01d ", num , st->fsm);
  78575. +
  78576. + hostchannels = hcd->available_host_channels;
  78577. + switch (st->fsm) {
  78578. + case FIQ_TEST:
  78579. + break;
  78580. +
  78581. + case FIQ_DEQUEUE_ISSUED:
  78582. + /* hc_halt was called. QTD no longer exists. */
  78583. + /* TODO: for a nonperiodic split transaction, need to issue a
  78584. + * CLEAR_TT_BUFFER hub command if we were in the start-split phase.
  78585. + */
  78586. + release_channel(hcd, hc, NULL, hc->halt_status);
  78587. + ret = 1;
  78588. + break;
  78589. +
  78590. + case FIQ_NP_SPLIT_DONE:
  78591. + /* Nonperiodic transaction complete. */
  78592. + if (!hc->ep_is_in) {
  78593. + qtd->ssplit_out_xfer_count = hc->xfer_len;
  78594. + }
  78595. + if (hcint.b.xfercomp) {
  78596. + handle_hc_xfercomp_intr(hcd, hc, hc_regs, qtd);
  78597. + } else if (hcint.b.nak) {
  78598. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78599. + }
  78600. + ret = 1;
  78601. + break;
  78602. +
  78603. + case FIQ_NP_SPLIT_HS_ABORTED:
  78604. + /* A HS abort is a 3-strikes on the HS bus at any point in the transaction.
  78605. + * Normally a CLEAR_TT_BUFFER hub command would be required: we can't do that
  78606. + * because there's no guarantee which order a non-periodic split happened in.
  78607. + * We could end up clearing a perfectly good transaction out of the buffer.
  78608. + */
  78609. + if (hcint.b.xacterr) {
  78610. + qtd->error_count += st->nr_errors;
  78611. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78612. + } else if (hcint.b.ahberr) {
  78613. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78614. + } else {
  78615. + local_fiq_disable();
  78616. + BUG();
  78617. + }
  78618. + break;
  78619. +
  78620. + case FIQ_NP_SPLIT_LS_ABORTED:
  78621. + /* A few cases can cause this - either an unknown state on a SSPLIT or
  78622. + * STALL/data toggle error response on a CSPLIT */
  78623. + if (hcint.b.stall) {
  78624. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  78625. + } else if (hcint.b.datatglerr) {
  78626. + handle_hc_datatglerr_intr(hcd, hc, hc_regs, qtd);
  78627. + } else if (hcint.b.bblerr) {
  78628. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  78629. + } else if (hcint.b.ahberr) {
  78630. + handle_hc_ahberr_intr(hcd, hc, hc_regs, qtd);
  78631. + } else {
  78632. + local_fiq_disable();
  78633. + BUG();
  78634. + }
  78635. + break;
  78636. +
  78637. + case FIQ_PER_SPLIT_DONE:
  78638. + /* Isoc IN or Interrupt IN/OUT */
  78639. +
  78640. + /* Flow control here is different from the normal execution by the driver.
  78641. + * We need to completely ignore most of the driver's method of handling
  78642. + * split transactions and do it ourselves.
  78643. + */
  78644. + if (hc->ep_type == UE_INTERRUPT) {
  78645. + if (hcint.b.nak) {
  78646. + handle_hc_nak_intr(hcd, hc, hc_regs, qtd);
  78647. + } else if (hc->ep_is_in) {
  78648. + int len;
  78649. + len = dwc_otg_fiq_unsetup_per_dma(hcd, hc->qh, qtd, num);
  78650. + //printk(KERN_NOTICE "FIQ Transaction: hc=%d len=%d urb_len = %d\n", num, len, qtd->urb->length);
  78651. + qtd->urb->actual_length += len;
  78652. + if (qtd->urb->actual_length >= qtd->urb->length) {
  78653. + qtd->urb->status = 0;
  78654. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78655. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78656. + } else {
  78657. + /* Interrupt transfer not complete yet - is it a short read? */
  78658. + if (len < hc->max_packet) {
  78659. + /* Interrupt transaction complete */
  78660. + qtd->urb->status = 0;
  78661. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78662. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78663. + } else {
  78664. + /* Further transactions required */
  78665. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78666. + }
  78667. + }
  78668. + } else {
  78669. + /* Interrupt OUT complete. */
  78670. + dwc_otg_hcd_save_data_toggle(hc, hc_regs, qtd);
  78671. + qtd->urb->actual_length += hc->xfer_len;
  78672. + if (qtd->urb->actual_length >= qtd->urb->length) {
  78673. + qtd->urb->status = 0;
  78674. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, qtd->urb->status);
  78675. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78676. + } else {
  78677. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78678. + }
  78679. + }
  78680. + } else {
  78681. + /* ISOC IN complete. */
  78682. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78683. + int len = 0;
  78684. + /* Record errors, update qtd. */
  78685. + if (st->nr_errors) {
  78686. + frame_desc->actual_length = 0;
  78687. + frame_desc->status = -DWC_E_PROTOCOL;
  78688. + } else {
  78689. + frame_desc->status = 0;
  78690. + /* Unswizzle dma */
  78691. + len = dwc_otg_fiq_unsetup_per_dma(hcd, qh, qtd, num);
  78692. + frame_desc->actual_length = len;
  78693. + }
  78694. + qtd->isoc_frame_index++;
  78695. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78696. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78697. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78698. + } else {
  78699. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78700. + }
  78701. + }
  78702. + break;
  78703. +
  78704. + case FIQ_PER_ISO_OUT_DONE: {
  78705. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78706. + /* Record errors, update qtd. */
  78707. + if (st->nr_errors) {
  78708. + frame_desc->actual_length = 0;
  78709. + frame_desc->status = -DWC_E_PROTOCOL;
  78710. + } else {
  78711. + frame_desc->status = 0;
  78712. + frame_desc->actual_length = frame_desc->length;
  78713. + }
  78714. + qtd->isoc_frame_index++;
  78715. + qtd->isoc_split_offset = 0;
  78716. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78717. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78718. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78719. + } else {
  78720. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78721. + }
  78722. + }
  78723. + break;
  78724. +
  78725. + case FIQ_PER_SPLIT_NYET_ABORTED:
  78726. + /* Doh. lost the data. */
  78727. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  78728. + "- FIQ reported NYET. Data may have been lost.\n",
  78729. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  78730. + if (hc->ep_type == UE_ISOCHRONOUS) {
  78731. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78732. + /* Record errors, update qtd. */
  78733. + frame_desc->actual_length = 0;
  78734. + frame_desc->status = -DWC_E_PROTOCOL;
  78735. + qtd->isoc_frame_index++;
  78736. + qtd->isoc_split_offset = 0;
  78737. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78738. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78739. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78740. + } else {
  78741. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78742. + }
  78743. + } else {
  78744. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78745. + }
  78746. + break;
  78747. +
  78748. + case FIQ_HS_ISOC_DONE:
  78749. + /* The FIQ has performed a whole pile of isochronous transactions.
  78750. + * The status is recorded as the interrupt state should the transaction
  78751. + * fail.
  78752. + */
  78753. + dwc_otg_fiq_unmangle_isoc(hcd, qh, qtd, num);
  78754. + break;
  78755. +
  78756. + case FIQ_PER_SPLIT_LS_ABORTED:
  78757. + if (hcint.b.xacterr) {
  78758. + /* Hub has responded with an ERR packet. Device
  78759. + * has been unplugged or the port has been disabled.
  78760. + * TODO: need to issue a reset to the hub port. */
  78761. + qtd->error_count += 3;
  78762. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78763. + } else if (hcint.b.stall) {
  78764. + handle_hc_stall_intr(hcd, hc, hc_regs, qtd);
  78765. + } else if (hcint.b.bblerr) {
  78766. + handle_hc_babble_intr(hcd, hc, hc_regs, qtd);
  78767. + } else {
  78768. + printk_ratelimited(KERN_INFO "Transfer to device %d endpoint 0x%x failed "
  78769. + "- FIQ reported FSM=%d. Data may have been lost.\n",
  78770. + st->fsm, hc->dev_addr, hc->ep_num);
  78771. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78772. + }
  78773. + break;
  78774. +
  78775. + case FIQ_PER_SPLIT_HS_ABORTED:
  78776. + /* Either the SSPLIT phase suffered transaction errors or something
  78777. + * unexpected happened.
  78778. + */
  78779. + qtd->error_count += 3;
  78780. + handle_hc_xacterr_intr(hcd, hc, hc_regs, qtd);
  78781. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78782. + break;
  78783. +
  78784. + case FIQ_PER_SPLIT_TIMEOUT:
  78785. + /* Couldn't complete in the nominated frame */
  78786. + printk(KERN_INFO "Transfer to device %d endpoint 0x%x frame %d failed "
  78787. + "- FIQ timed out. Data may have been lost.\n",
  78788. + hc->dev_addr, hc->ep_num, dwc_otg_hcd_get_frame_number(hcd) >> 3);
  78789. + if (hc->ep_type == UE_ISOCHRONOUS) {
  78790. + struct dwc_otg_hcd_iso_packet_desc *frame_desc = &qtd->urb->iso_descs[qtd->isoc_frame_index];
  78791. + /* Record errors, update qtd. */
  78792. + frame_desc->actual_length = 0;
  78793. + if (hc->ep_is_in) {
  78794. + frame_desc->status = -DWC_E_NO_STREAM_RES;
  78795. + } else {
  78796. + frame_desc->status = -DWC_E_COMMUNICATION;
  78797. + }
  78798. + qtd->isoc_frame_index++;
  78799. + if (qtd->isoc_frame_index == qtd->urb->packet_count) {
  78800. + hcd->fops->complete(hcd, qtd->urb->priv, qtd->urb, 0);
  78801. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_URB_COMPLETE);
  78802. + } else {
  78803. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_COMPLETE);
  78804. + }
  78805. + } else {
  78806. + release_channel(hcd, hc, qtd, DWC_OTG_HC_XFER_NO_HALT_STATUS);
  78807. + }
  78808. + break;
  78809. +
  78810. + default:
  78811. + local_fiq_disable();
  78812. + DWC_WARN("unexpected state received on hc=%d fsm=%d", hc->hc_num, st->fsm);
  78813. + BUG();
  78814. + }
  78815. + //if (hostchannels != hcd->available_host_channels) {
  78816. + /* should have incremented by now! */
  78817. + // BUG();
  78818. +// }
  78819. + return ret;
  78820. +}
  78821. +
  78822. +/** Handles interrupt for a specific Host Channel */
  78823. +int32_t dwc_otg_hcd_handle_hc_n_intr(dwc_otg_hcd_t * dwc_otg_hcd, uint32_t num)
  78824. +{
  78825. + int retval = 0;
  78826. + hcint_data_t hcint;
  78827. + hcintmsk_data_t hcintmsk;
  78828. + dwc_hc_t *hc;
  78829. + dwc_otg_hc_regs_t *hc_regs;
  78830. + dwc_otg_qtd_t *qtd;
  78831. +
  78832. + DWC_DEBUGPL(DBG_HCDV, "--Host Channel Interrupt--, Channel %d\n", num);
  78833. +
  78834. + hc = dwc_otg_hcd->hc_ptr_array[num];
  78835. + hc_regs = dwc_otg_hcd->core_if->host_if->hc_regs[num];
  78836. + if(hc->halt_status == DWC_OTG_HC_XFER_URB_DEQUEUE) {
  78837. + /* We are responding to a channel disable. Driver
  78838. + * state is cleared - our qtd has gone away.
  78839. + */
  78840. + release_channel(dwc_otg_hcd, hc, NULL, hc->halt_status);
  78841. + return 1;
  78842. + }
  78843. + qtd = DWC_CIRCLEQ_FIRST(&hc->qh->qtd_list);
  78844. +
  78845. + /*
  78846. + * FSM mode: Check to see if this is a HC interrupt from a channel handled by the FIQ.
  78847. + * Execution path is fundamentally different for the channels after a FIQ has completed
  78848. + * a split transaction.
  78849. + */
  78850. + if (fiq_fsm_enable) {
  78851. + switch (dwc_otg_hcd->fiq_state->channel[num].fsm) {
  78852. + case FIQ_PASSTHROUGH:
  78853. + break;
  78854. + case FIQ_PASSTHROUGH_ERRORSTATE:
  78855. + /* Hook into the error count */
  78856. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "HCDERR%02d", num);
  78857. + if (dwc_otg_hcd->fiq_state->channel[num].nr_errors) {
  78858. + qtd->error_count = 0;
  78859. + fiq_print(FIQDBG_ERR, dwc_otg_hcd->fiq_state, "RESET ");
  78860. + }
  78861. + break;
  78862. + default:
  78863. + dwc_otg_hcd_handle_hc_fsm(dwc_otg_hcd, num);
  78864. + return 1;
  78865. + }
  78866. + }
  78867. +
  78868. + hcint.d32 = DWC_READ_REG32(&hc_regs->hcint);
  78869. + hcintmsk.d32 = DWC_READ_REG32(&hc_regs->hcintmsk);
  78870. + hcint.d32 = hcint.d32 & hcintmsk.d32;
  78871. + if (!dwc_otg_hcd->core_if->dma_enable) {
  78872. + if (hcint.b.chhltd && hcint.d32 != 0x2) {
  78873. + hcint.b.chhltd = 0;
  78874. + }
  78875. + }
  78876. +
  78877. + if (hcint.b.xfercomp) {
  78878. + retval |=
  78879. + handle_hc_xfercomp_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78880. + /*
  78881. + * If NYET occurred at same time as Xfer Complete, the NYET is
  78882. + * handled by the Xfer Complete interrupt handler. Don't want
  78883. + * to call the NYET interrupt handler in this case.
  78884. + */
  78885. + hcint.b.nyet = 0;
  78886. + }
  78887. + if (hcint.b.chhltd) {
  78888. + retval |= handle_hc_chhltd_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78889. + }
  78890. + if (hcint.b.ahberr) {
  78891. + retval |= handle_hc_ahberr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78892. + }
  78893. + if (hcint.b.stall) {
  78894. + retval |= handle_hc_stall_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78895. + }
  78896. + if (hcint.b.nak) {
  78897. + retval |= handle_hc_nak_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78898. + }
  78899. + if (hcint.b.ack) {
  78900. + if(!hcint.b.chhltd)
  78901. + retval |= handle_hc_ack_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78902. + }
  78903. + if (hcint.b.nyet) {
  78904. + retval |= handle_hc_nyet_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78905. + }
  78906. + if (hcint.b.xacterr) {
  78907. + retval |= handle_hc_xacterr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78908. + }
  78909. + if (hcint.b.bblerr) {
  78910. + retval |= handle_hc_babble_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78911. + }
  78912. + if (hcint.b.frmovrun) {
  78913. + retval |=
  78914. + handle_hc_frmovrun_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78915. + }
  78916. + if (hcint.b.datatglerr) {
  78917. + retval |=
  78918. + handle_hc_datatglerr_intr(dwc_otg_hcd, hc, hc_regs, qtd);
  78919. + }
  78920. +
  78921. + return retval;
  78922. +}
  78923. +#endif /* DWC_DEVICE_ONLY */
  78924. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c
  78925. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  78926. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_linux.c 2014-06-11 21:05:32.000000000 +0200
  78927. @@ -0,0 +1,985 @@
  78928. +
  78929. +/* ==========================================================================
  78930. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_linux.c $
  78931. + * $Revision: #20 $
  78932. + * $Date: 2011/10/26 $
  78933. + * $Change: 1872981 $
  78934. + *
  78935. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  78936. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  78937. + * otherwise expressly agreed to in writing between Synopsys and you.
  78938. + *
  78939. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  78940. + * any End User Software License Agreement or Agreement for Licensed Product
  78941. + * with Synopsys or any supplement thereto. You are permitted to use and
  78942. + * redistribute this Software in source and binary forms, with or without
  78943. + * modification, provided that redistributions of source code must retain this
  78944. + * notice. You may not view, use, disclose, copy or distribute this file or
  78945. + * any information contained herein except pursuant to this license grant from
  78946. + * Synopsys. If you do not agree with this notice, including the disclaimer
  78947. + * below, then you are not authorized to use the Software.
  78948. + *
  78949. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  78950. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  78951. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78952. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  78953. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  78954. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  78955. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  78956. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  78957. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  78958. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  78959. + * DAMAGE.
  78960. + * ========================================================================== */
  78961. +#ifndef DWC_DEVICE_ONLY
  78962. +
  78963. +/**
  78964. + * @file
  78965. + *
  78966. + * This file contains the implementation of the HCD. In Linux, the HCD
  78967. + * implements the hc_driver API.
  78968. + */
  78969. +#include <linux/kernel.h>
  78970. +#include <linux/module.h>
  78971. +#include <linux/moduleparam.h>
  78972. +#include <linux/init.h>
  78973. +#include <linux/device.h>
  78974. +#include <linux/errno.h>
  78975. +#include <linux/list.h>
  78976. +#include <linux/interrupt.h>
  78977. +#include <linux/string.h>
  78978. +#include <linux/dma-mapping.h>
  78979. +#include <linux/version.h>
  78980. +#include <asm/io.h>
  78981. +#include <asm/fiq.h>
  78982. +#include <linux/usb.h>
  78983. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)
  78984. +#include <../drivers/usb/core/hcd.h>
  78985. +#else
  78986. +#include <linux/usb/hcd.h>
  78987. +#endif
  78988. +#include <asm/bug.h>
  78989. +
  78990. +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  78991. +#define USB_URB_EP_LINKING 1
  78992. +#else
  78993. +#define USB_URB_EP_LINKING 0
  78994. +#endif
  78995. +
  78996. +#include "dwc_otg_hcd_if.h"
  78997. +#include "dwc_otg_dbg.h"
  78998. +#include "dwc_otg_driver.h"
  78999. +#include "dwc_otg_hcd.h"
  79000. +
  79001. +extern unsigned char _dwc_otg_fiq_stub, _dwc_otg_fiq_stub_end;
  79002. +
  79003. +/**
  79004. + * Gets the endpoint number from a _bEndpointAddress argument. The endpoint is
  79005. + * qualified with its direction (possible 32 endpoints per device).
  79006. + */
  79007. +#define dwc_ep_addr_to_endpoint(_bEndpointAddress_) ((_bEndpointAddress_ & USB_ENDPOINT_NUMBER_MASK) | \
  79008. + ((_bEndpointAddress_ & USB_DIR_IN) != 0) << 4)
  79009. +
  79010. +static const char dwc_otg_hcd_name[] = "dwc_otg_hcd";
  79011. +
  79012. +extern bool fiq_enable;
  79013. +
  79014. +/** @name Linux HC Driver API Functions */
  79015. +/** @{ */
  79016. +/* manage i/o requests, device state */
  79017. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  79018. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79019. + struct usb_host_endpoint *ep,
  79020. +#endif
  79021. + struct urb *urb, gfp_t mem_flags);
  79022. +
  79023. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  79024. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79025. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb);
  79026. +#endif
  79027. +#else /* kernels at or post 2.6.30 */
  79028. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd,
  79029. + struct urb *urb, int status);
  79030. +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) */
  79031. +
  79032. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  79033. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79034. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep);
  79035. +#endif
  79036. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd);
  79037. +extern int hcd_start(struct usb_hcd *hcd);
  79038. +extern void hcd_stop(struct usb_hcd *hcd);
  79039. +static int get_frame_number(struct usb_hcd *hcd);
  79040. +extern int hub_status_data(struct usb_hcd *hcd, char *buf);
  79041. +extern int hub_control(struct usb_hcd *hcd,
  79042. + u16 typeReq,
  79043. + u16 wValue, u16 wIndex, char *buf, u16 wLength);
  79044. +
  79045. +struct wrapper_priv_data {
  79046. + dwc_otg_hcd_t *dwc_otg_hcd;
  79047. +};
  79048. +
  79049. +/** @} */
  79050. +
  79051. +static struct hc_driver dwc_otg_hc_driver = {
  79052. +
  79053. + .description = dwc_otg_hcd_name,
  79054. + .product_desc = "DWC OTG Controller",
  79055. + .hcd_priv_size = sizeof(struct wrapper_priv_data),
  79056. +
  79057. + .irq = dwc_otg_hcd_irq,
  79058. +
  79059. + .flags = HCD_MEMORY | HCD_USB2,
  79060. +
  79061. + //.reset =
  79062. + .start = hcd_start,
  79063. + //.suspend =
  79064. + //.resume =
  79065. + .stop = hcd_stop,
  79066. +
  79067. + .urb_enqueue = dwc_otg_urb_enqueue,
  79068. + .urb_dequeue = dwc_otg_urb_dequeue,
  79069. + .endpoint_disable = endpoint_disable,
  79070. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79071. + .endpoint_reset = endpoint_reset,
  79072. +#endif
  79073. + .get_frame_number = get_frame_number,
  79074. +
  79075. + .hub_status_data = hub_status_data,
  79076. + .hub_control = hub_control,
  79077. + //.bus_suspend =
  79078. + //.bus_resume =
  79079. +};
  79080. +
  79081. +/** Gets the dwc_otg_hcd from a struct usb_hcd */
  79082. +static inline dwc_otg_hcd_t *hcd_to_dwc_otg_hcd(struct usb_hcd *hcd)
  79083. +{
  79084. + struct wrapper_priv_data *p;
  79085. + p = (struct wrapper_priv_data *)(hcd->hcd_priv);
  79086. + return p->dwc_otg_hcd;
  79087. +}
  79088. +
  79089. +/** Gets the struct usb_hcd that contains a dwc_otg_hcd_t. */
  79090. +static inline struct usb_hcd *dwc_otg_hcd_to_hcd(dwc_otg_hcd_t * dwc_otg_hcd)
  79091. +{
  79092. + return dwc_otg_hcd_get_priv_data(dwc_otg_hcd);
  79093. +}
  79094. +
  79095. +/** Gets the usb_host_endpoint associated with an URB. */
  79096. +inline struct usb_host_endpoint *dwc_urb_to_endpoint(struct urb *urb)
  79097. +{
  79098. + struct usb_device *dev = urb->dev;
  79099. + int ep_num = usb_pipeendpoint(urb->pipe);
  79100. +
  79101. + if (usb_pipein(urb->pipe))
  79102. + return dev->ep_in[ep_num];
  79103. + else
  79104. + return dev->ep_out[ep_num];
  79105. +}
  79106. +
  79107. +static int _disconnect(dwc_otg_hcd_t * hcd)
  79108. +{
  79109. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79110. +
  79111. + usb_hcd->self.is_b_host = 0;
  79112. + return 0;
  79113. +}
  79114. +
  79115. +static int _start(dwc_otg_hcd_t * hcd)
  79116. +{
  79117. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79118. +
  79119. + usb_hcd->self.is_b_host = dwc_otg_hcd_is_b_host(hcd);
  79120. + hcd_start(usb_hcd);
  79121. +
  79122. + return 0;
  79123. +}
  79124. +
  79125. +static int _hub_info(dwc_otg_hcd_t * hcd, void *urb_handle, uint32_t * hub_addr,
  79126. + uint32_t * port_addr)
  79127. +{
  79128. + struct urb *urb = (struct urb *)urb_handle;
  79129. + struct usb_bus *bus;
  79130. +#if 1 //GRAYG - temporary
  79131. + if (NULL == urb_handle)
  79132. + DWC_ERROR("**** %s - NULL URB handle\n", __func__);//GRAYG
  79133. + if (NULL == urb->dev)
  79134. + DWC_ERROR("**** %s - URB has no device\n", __func__);//GRAYG
  79135. + if (NULL == port_addr)
  79136. + DWC_ERROR("**** %s - NULL port_address\n", __func__);//GRAYG
  79137. +#endif
  79138. + if (urb->dev->tt) {
  79139. + if (NULL == urb->dev->tt->hub) {
  79140. + DWC_ERROR("**** %s - (URB's transactor has no TT - giving no hub)\n",
  79141. + __func__); //GRAYG
  79142. + //*hub_addr = (u8)usb_pipedevice(urb->pipe); //GRAYG
  79143. + *hub_addr = 0; //GRAYG
  79144. + // we probably shouldn't have a transaction translator if
  79145. + // there's no associated hub?
  79146. + } else {
  79147. + bus = hcd_to_bus(dwc_otg_hcd_to_hcd(hcd));
  79148. + if (urb->dev->tt->hub == bus->root_hub)
  79149. + *hub_addr = 0;
  79150. + else
  79151. + *hub_addr = urb->dev->tt->hub->devnum;
  79152. + }
  79153. + *port_addr = urb->dev->tt->multi ? urb->dev->ttport : 1;
  79154. + } else {
  79155. + *hub_addr = 0;
  79156. + *port_addr = urb->dev->ttport;
  79157. + }
  79158. + return 0;
  79159. +}
  79160. +
  79161. +static int _speed(dwc_otg_hcd_t * hcd, void *urb_handle)
  79162. +{
  79163. + struct urb *urb = (struct urb *)urb_handle;
  79164. + return urb->dev->speed;
  79165. +}
  79166. +
  79167. +static int _get_b_hnp_enable(dwc_otg_hcd_t * hcd)
  79168. +{
  79169. + struct usb_hcd *usb_hcd = dwc_otg_hcd_to_hcd(hcd);
  79170. + return usb_hcd->self.b_hnp_enable;
  79171. +}
  79172. +
  79173. +static void allocate_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  79174. + struct urb *urb)
  79175. +{
  79176. + hcd_to_bus(hcd)->bandwidth_allocated += bw / urb->interval;
  79177. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79178. + hcd_to_bus(hcd)->bandwidth_isoc_reqs++;
  79179. + } else {
  79180. + hcd_to_bus(hcd)->bandwidth_int_reqs++;
  79181. + }
  79182. +}
  79183. +
  79184. +static void free_bus_bandwidth(struct usb_hcd *hcd, uint32_t bw,
  79185. + struct urb *urb)
  79186. +{
  79187. + hcd_to_bus(hcd)->bandwidth_allocated -= bw / urb->interval;
  79188. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79189. + hcd_to_bus(hcd)->bandwidth_isoc_reqs--;
  79190. + } else {
  79191. + hcd_to_bus(hcd)->bandwidth_int_reqs--;
  79192. + }
  79193. +}
  79194. +
  79195. +/**
  79196. + * Sets the final status of an URB and returns it to the device driver. Any
  79197. + * required cleanup of the URB is performed. The HCD lock should be held on
  79198. + * entry.
  79199. + */
  79200. +static int _complete(dwc_otg_hcd_t * hcd, void *urb_handle,
  79201. + dwc_otg_hcd_urb_t * dwc_otg_urb, int32_t status)
  79202. +{
  79203. + struct urb *urb = (struct urb *)urb_handle;
  79204. + urb_tq_entry_t *new_entry;
  79205. + int rc = 0;
  79206. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79207. + DWC_PRINTF("%s: urb %p, device %d, ep %d %s, status=%d\n",
  79208. + __func__, urb, usb_pipedevice(urb->pipe),
  79209. + usb_pipeendpoint(urb->pipe),
  79210. + usb_pipein(urb->pipe) ? "IN" : "OUT", status);
  79211. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79212. + int i;
  79213. + for (i = 0; i < urb->number_of_packets; i++) {
  79214. + DWC_PRINTF(" ISO Desc %d status: %d\n",
  79215. + i, urb->iso_frame_desc[i].status);
  79216. + }
  79217. + }
  79218. + }
  79219. + new_entry = DWC_ALLOC_ATOMIC(sizeof(urb_tq_entry_t));
  79220. + urb->actual_length = dwc_otg_hcd_urb_get_actual_length(dwc_otg_urb);
  79221. + /* Convert status value. */
  79222. + switch (status) {
  79223. + case -DWC_E_PROTOCOL:
  79224. + status = -EPROTO;
  79225. + break;
  79226. + case -DWC_E_IN_PROGRESS:
  79227. + status = -EINPROGRESS;
  79228. + break;
  79229. + case -DWC_E_PIPE:
  79230. + status = -EPIPE;
  79231. + break;
  79232. + case -DWC_E_IO:
  79233. + status = -EIO;
  79234. + break;
  79235. + case -DWC_E_TIMEOUT:
  79236. + status = -ETIMEDOUT;
  79237. + break;
  79238. + case -DWC_E_OVERFLOW:
  79239. + status = -EOVERFLOW;
  79240. + break;
  79241. + case -DWC_E_SHUTDOWN:
  79242. + status = -ESHUTDOWN;
  79243. + break;
  79244. + default:
  79245. + if (status) {
  79246. + DWC_PRINTF("Uknown urb status %d\n", status);
  79247. +
  79248. + }
  79249. + }
  79250. +
  79251. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79252. + int i;
  79253. +
  79254. + urb->error_count = dwc_otg_hcd_urb_get_error_count(dwc_otg_urb);
  79255. + for (i = 0; i < urb->number_of_packets; ++i) {
  79256. + urb->iso_frame_desc[i].actual_length =
  79257. + dwc_otg_hcd_urb_get_iso_desc_actual_length
  79258. + (dwc_otg_urb, i);
  79259. + urb->iso_frame_desc[i].status =
  79260. + dwc_otg_hcd_urb_get_iso_desc_status(dwc_otg_urb, i);
  79261. + }
  79262. + }
  79263. +
  79264. + urb->status = status;
  79265. + urb->hcpriv = NULL;
  79266. + if (!status) {
  79267. + if ((urb->transfer_flags & URB_SHORT_NOT_OK) &&
  79268. + (urb->actual_length < urb->transfer_buffer_length)) {
  79269. + urb->status = -EREMOTEIO;
  79270. + }
  79271. + }
  79272. +
  79273. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) ||
  79274. + (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  79275. + struct usb_host_endpoint *ep = dwc_urb_to_endpoint(urb);
  79276. + if (ep) {
  79277. + free_bus_bandwidth(dwc_otg_hcd_to_hcd(hcd),
  79278. + dwc_otg_hcd_get_ep_bandwidth(hcd,
  79279. + ep->hcpriv),
  79280. + urb);
  79281. + }
  79282. + }
  79283. + DWC_FREE(dwc_otg_urb);
  79284. + if (!new_entry) {
  79285. + DWC_ERROR("dwc_otg_hcd: complete: cannot allocate URB TQ entry\n");
  79286. + urb->status = -EPROTO;
  79287. + /* don't schedule the tasklet -
  79288. + * directly return the packet here with error. */
  79289. +#if USB_URB_EP_LINKING
  79290. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  79291. +#endif
  79292. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79293. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb);
  79294. +#else
  79295. + usb_hcd_giveback_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  79296. +#endif
  79297. + } else {
  79298. + new_entry->urb = urb;
  79299. +#if USB_URB_EP_LINKING
  79300. + rc = usb_hcd_check_unlink_urb(dwc_otg_hcd_to_hcd(hcd), urb, urb->status);
  79301. + if(0 == rc) {
  79302. + usb_hcd_unlink_urb_from_ep(dwc_otg_hcd_to_hcd(hcd), urb);
  79303. + }
  79304. +#endif
  79305. + if(0 == rc) {
  79306. + DWC_TAILQ_INSERT_TAIL(&hcd->completed_urb_list, new_entry,
  79307. + urb_tq_entries);
  79308. + DWC_TASK_HI_SCHEDULE(hcd->completion_tasklet);
  79309. + }
  79310. + }
  79311. + return 0;
  79312. +}
  79313. +
  79314. +static struct dwc_otg_hcd_function_ops hcd_fops = {
  79315. + .start = _start,
  79316. + .disconnect = _disconnect,
  79317. + .hub_info = _hub_info,
  79318. + .speed = _speed,
  79319. + .complete = _complete,
  79320. + .get_b_hnp_enable = _get_b_hnp_enable,
  79321. +};
  79322. +
  79323. +static struct fiq_handler fh = {
  79324. + .name = "usb_fiq",
  79325. +};
  79326. +
  79327. +
  79328. +
  79329. +/**
  79330. + * Initializes the HCD. This function allocates memory for and initializes the
  79331. + * static parts of the usb_hcd and dwc_otg_hcd structures. It also registers the
  79332. + * USB bus with the core and calls the hc_driver->start() function. It returns
  79333. + * a negative error on failure.
  79334. + */
  79335. +int hcd_init(dwc_bus_dev_t *_dev)
  79336. +{
  79337. + struct usb_hcd *hcd = NULL;
  79338. + dwc_otg_hcd_t *dwc_otg_hcd = NULL;
  79339. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  79340. + int retval = 0;
  79341. + u64 dmamask;
  79342. + struct pt_regs regs;
  79343. +
  79344. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD INIT otg_dev=%p\n", otg_dev);
  79345. +
  79346. + /* Set device flags indicating whether the HCD supports DMA. */
  79347. + if (dwc_otg_is_dma_enable(otg_dev->core_if))
  79348. + dmamask = DMA_BIT_MASK(32);
  79349. + else
  79350. + dmamask = 0;
  79351. +
  79352. +#if defined(LM_INTERFACE) || defined(PLATFORM_INTERFACE)
  79353. + dma_set_mask(&_dev->dev, dmamask);
  79354. + dma_set_coherent_mask(&_dev->dev, dmamask);
  79355. +#elif defined(PCI_INTERFACE)
  79356. + pci_set_dma_mask(_dev, dmamask);
  79357. + pci_set_consistent_dma_mask(_dev, dmamask);
  79358. +#endif
  79359. +
  79360. + /*
  79361. + * Allocate memory for the base HCD plus the DWC OTG HCD.
  79362. + * Initialize the base HCD.
  79363. + */
  79364. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  79365. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, _dev->dev.bus_id);
  79366. +#else
  79367. + hcd = usb_create_hcd(&dwc_otg_hc_driver, &_dev->dev, dev_name(&_dev->dev));
  79368. + hcd->has_tt = 1;
  79369. +// hcd->uses_new_polling = 1;
  79370. +// hcd->poll_rh = 0;
  79371. +#endif
  79372. + if (!hcd) {
  79373. + retval = -ENOMEM;
  79374. + goto error1;
  79375. + }
  79376. +
  79377. + hcd->regs = otg_dev->os_dep.base;
  79378. +
  79379. +
  79380. + /* Initialize the DWC OTG HCD. */
  79381. + dwc_otg_hcd = dwc_otg_hcd_alloc_hcd();
  79382. + if (!dwc_otg_hcd) {
  79383. + goto error2;
  79384. + }
  79385. + ((struct wrapper_priv_data *)(hcd->hcd_priv))->dwc_otg_hcd =
  79386. + dwc_otg_hcd;
  79387. + otg_dev->hcd = dwc_otg_hcd;
  79388. +
  79389. + if (dwc_otg_hcd_init(dwc_otg_hcd, otg_dev->core_if)) {
  79390. + goto error2;
  79391. + }
  79392. +
  79393. + if (fiq_enable)
  79394. + {
  79395. + if (claim_fiq(&fh)) {
  79396. + DWC_ERROR("Can't claim FIQ");
  79397. + goto error2;
  79398. + }
  79399. +
  79400. + DWC_WARN("FIQ at 0x%08x", (fiq_fsm_enable ? (int)&dwc_otg_fiq_fsm : (int)&dwc_otg_fiq_nop));
  79401. + DWC_WARN("FIQ ASM at 0x%08x length %d", (int)&_dwc_otg_fiq_stub, (int)(&_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub));
  79402. +
  79403. + set_fiq_handler((void *) &_dwc_otg_fiq_stub, &_dwc_otg_fiq_stub_end - &_dwc_otg_fiq_stub);
  79404. + memset(&regs,0,sizeof(regs));
  79405. +
  79406. + regs.ARM_r8 = (long) dwc_otg_hcd->fiq_state;
  79407. + if (fiq_fsm_enable) {
  79408. + regs.ARM_r9 = dwc_otg_hcd->core_if->core_params->host_channels;
  79409. + //regs.ARM_r10 = dwc_otg_hcd->dma;
  79410. + regs.ARM_fp = (long) dwc_otg_fiq_fsm;
  79411. + } else {
  79412. + regs.ARM_fp = (long) dwc_otg_fiq_nop;
  79413. + }
  79414. +
  79415. + regs.ARM_sp = (long) dwc_otg_hcd->fiq_stack + (sizeof(struct fiq_stack) - 4);
  79416. +
  79417. +// __show_regs(&regs);
  79418. + set_fiq_regs(&regs);
  79419. +
  79420. + //Set the mphi periph to the required registers
  79421. + dwc_otg_hcd->fiq_state->mphi_regs.base = otg_dev->os_dep.mphi_base;
  79422. + dwc_otg_hcd->fiq_state->mphi_regs.ctrl = otg_dev->os_dep.mphi_base + 0x4c;
  79423. + dwc_otg_hcd->fiq_state->mphi_regs.outdda = otg_dev->os_dep.mphi_base + 0x28;
  79424. + dwc_otg_hcd->fiq_state->mphi_regs.outddb = otg_dev->os_dep.mphi_base + 0x2c;
  79425. + dwc_otg_hcd->fiq_state->mphi_regs.intstat = otg_dev->os_dep.mphi_base + 0x50;
  79426. + dwc_otg_hcd->fiq_state->dwc_regs_base = otg_dev->os_dep.base;
  79427. + DWC_WARN("MPHI regs_base at 0x%08x", (int)dwc_otg_hcd->fiq_state->mphi_regs.base);
  79428. + //Enable mphi peripheral
  79429. + writel((1<<31),dwc_otg_hcd->fiq_state->mphi_regs.ctrl);
  79430. +#ifdef DEBUG
  79431. + if (readl(dwc_otg_hcd->fiq_state->mphi_regs.ctrl) & 0x80000000)
  79432. + DWC_WARN("MPHI periph has been enabled");
  79433. + else
  79434. + DWC_WARN("MPHI periph has NOT been enabled");
  79435. +#endif
  79436. + // Enable FIQ interrupt from USB peripheral
  79437. + enable_fiq(INTERRUPT_VC_USB);
  79438. + local_fiq_enable();
  79439. + }
  79440. +
  79441. +
  79442. + otg_dev->hcd->otg_dev = otg_dev;
  79443. + hcd->self.otg_port = dwc_otg_hcd_otg_port(dwc_otg_hcd);
  79444. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) //don't support for LM(with 2.6.20.1 kernel)
  79445. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) //version field absent later
  79446. + hcd->self.otg_version = dwc_otg_get_otg_version(otg_dev->core_if);
  79447. +#endif
  79448. + /* Don't support SG list at this point */
  79449. + hcd->self.sg_tablesize = 0;
  79450. +#endif
  79451. + /*
  79452. + * Finish generic HCD initialization and start the HCD. This function
  79453. + * allocates the DMA buffer pool, registers the USB bus, requests the
  79454. + * IRQ line, and calls hcd_start method.
  79455. + */
  79456. +#ifdef PLATFORM_INTERFACE
  79457. + retval = usb_add_hcd(hcd, platform_get_irq(_dev, fiq_enable ? 0 : 1), IRQF_SHARED | IRQF_DISABLED);
  79458. +#else
  79459. + retval = usb_add_hcd(hcd, _dev->irq, IRQF_SHARED | IRQF_DISABLED);
  79460. +#endif
  79461. + if (retval < 0) {
  79462. + goto error2;
  79463. + }
  79464. +
  79465. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, hcd);
  79466. + return 0;
  79467. +
  79468. +error2:
  79469. + usb_put_hcd(hcd);
  79470. +error1:
  79471. + return retval;
  79472. +}
  79473. +
  79474. +/**
  79475. + * Removes the HCD.
  79476. + * Frees memory and resources associated with the HCD and deregisters the bus.
  79477. + */
  79478. +void hcd_remove(dwc_bus_dev_t *_dev)
  79479. +{
  79480. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  79481. + dwc_otg_hcd_t *dwc_otg_hcd;
  79482. + struct usb_hcd *hcd;
  79483. +
  79484. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD REMOVE otg_dev=%p\n", otg_dev);
  79485. +
  79486. + if (!otg_dev) {
  79487. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev NULL!\n", __func__);
  79488. + return;
  79489. + }
  79490. +
  79491. + dwc_otg_hcd = otg_dev->hcd;
  79492. +
  79493. + if (!dwc_otg_hcd) {
  79494. + DWC_DEBUGPL(DBG_ANY, "%s: otg_dev->hcd NULL!\n", __func__);
  79495. + return;
  79496. + }
  79497. +
  79498. + hcd = dwc_otg_hcd_to_hcd(dwc_otg_hcd);
  79499. +
  79500. + if (!hcd) {
  79501. + DWC_DEBUGPL(DBG_ANY,
  79502. + "%s: dwc_otg_hcd_to_hcd(dwc_otg_hcd) NULL!\n",
  79503. + __func__);
  79504. + return;
  79505. + }
  79506. + usb_remove_hcd(hcd);
  79507. + dwc_otg_hcd_set_priv_data(dwc_otg_hcd, NULL);
  79508. + dwc_otg_hcd_remove(dwc_otg_hcd);
  79509. + usb_put_hcd(hcd);
  79510. +}
  79511. +
  79512. +/* =========================================================================
  79513. + * Linux HC Driver Functions
  79514. + * ========================================================================= */
  79515. +
  79516. +/** Initializes the DWC_otg controller and its root hub and prepares it for host
  79517. + * mode operation. Activates the root port. Returns 0 on success and a negative
  79518. + * error code on failure. */
  79519. +int hcd_start(struct usb_hcd *hcd)
  79520. +{
  79521. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79522. + struct usb_bus *bus;
  79523. +
  79524. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD START\n");
  79525. + bus = hcd_to_bus(hcd);
  79526. +
  79527. + hcd->state = HC_STATE_RUNNING;
  79528. + if (dwc_otg_hcd_start(dwc_otg_hcd, &hcd_fops)) {
  79529. + return 0;
  79530. + }
  79531. +
  79532. + /* Initialize and connect root hub if one is not already attached */
  79533. + if (bus->root_hub) {
  79534. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD Has Root Hub\n");
  79535. + /* Inform the HUB driver to resume. */
  79536. + usb_hcd_resume_root_hub(hcd);
  79537. + }
  79538. +
  79539. + return 0;
  79540. +}
  79541. +
  79542. +/**
  79543. + * Halts the DWC_otg host mode operations in a clean manner. USB transfers are
  79544. + * stopped.
  79545. + */
  79546. +void hcd_stop(struct usb_hcd *hcd)
  79547. +{
  79548. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79549. +
  79550. + dwc_otg_hcd_stop(dwc_otg_hcd);
  79551. +}
  79552. +
  79553. +/** Returns the current frame number. */
  79554. +static int get_frame_number(struct usb_hcd *hcd)
  79555. +{
  79556. + hprt0_data_t hprt0;
  79557. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79558. + hprt0.d32 = DWC_READ_REG32(dwc_otg_hcd->core_if->host_if->hprt0);
  79559. + if (hprt0.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED)
  79560. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd) >> 3;
  79561. + else
  79562. + return dwc_otg_hcd_get_frame_number(dwc_otg_hcd);
  79563. +}
  79564. +
  79565. +#ifdef DEBUG
  79566. +static void dump_urb_info(struct urb *urb, char *fn_name)
  79567. +{
  79568. + DWC_PRINTF("%s, urb %p\n", fn_name, urb);
  79569. + DWC_PRINTF(" Device address: %d\n", usb_pipedevice(urb->pipe));
  79570. + DWC_PRINTF(" Endpoint: %d, %s\n", usb_pipeendpoint(urb->pipe),
  79571. + (usb_pipein(urb->pipe) ? "IN" : "OUT"));
  79572. + DWC_PRINTF(" Endpoint type: %s\n", ( {
  79573. + char *pipetype;
  79574. + switch (usb_pipetype(urb->pipe)) {
  79575. +case PIPE_CONTROL:
  79576. +pipetype = "CONTROL"; break; case PIPE_BULK:
  79577. +pipetype = "BULK"; break; case PIPE_INTERRUPT:
  79578. +pipetype = "INTERRUPT"; break; case PIPE_ISOCHRONOUS:
  79579. +pipetype = "ISOCHRONOUS"; break; default:
  79580. + pipetype = "UNKNOWN"; break;};
  79581. + pipetype;}
  79582. + )) ;
  79583. + DWC_PRINTF(" Speed: %s\n", ( {
  79584. + char *speed; switch (urb->dev->speed) {
  79585. +case USB_SPEED_HIGH:
  79586. +speed = "HIGH"; break; case USB_SPEED_FULL:
  79587. +speed = "FULL"; break; case USB_SPEED_LOW:
  79588. +speed = "LOW"; break; default:
  79589. + speed = "UNKNOWN"; break;};
  79590. + speed;}
  79591. + )) ;
  79592. + DWC_PRINTF(" Max packet size: %d\n",
  79593. + usb_maxpacket(urb->dev, urb->pipe, usb_pipeout(urb->pipe)));
  79594. + DWC_PRINTF(" Data buffer length: %d\n", urb->transfer_buffer_length);
  79595. + DWC_PRINTF(" Transfer buffer: %p, Transfer DMA: %p\n",
  79596. + urb->transfer_buffer, (void *)urb->transfer_dma);
  79597. + DWC_PRINTF(" Setup buffer: %p, Setup DMA: %p\n",
  79598. + urb->setup_packet, (void *)urb->setup_dma);
  79599. + DWC_PRINTF(" Interval: %d\n", urb->interval);
  79600. + if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
  79601. + int i;
  79602. + for (i = 0; i < urb->number_of_packets; i++) {
  79603. + DWC_PRINTF(" ISO Desc %d:\n", i);
  79604. + DWC_PRINTF(" offset: %d, length %d\n",
  79605. + urb->iso_frame_desc[i].offset,
  79606. + urb->iso_frame_desc[i].length);
  79607. + }
  79608. + }
  79609. +}
  79610. +#endif
  79611. +
  79612. +/** Starts processing a USB transfer request specified by a USB Request Block
  79613. + * (URB). mem_flags indicates the type of memory allocation to use while
  79614. + * processing this URB. */
  79615. +static int dwc_otg_urb_enqueue(struct usb_hcd *hcd,
  79616. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79617. + struct usb_host_endpoint *ep,
  79618. +#endif
  79619. + struct urb *urb, gfp_t mem_flags)
  79620. +{
  79621. + int retval = 0;
  79622. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
  79623. + struct usb_host_endpoint *ep = urb->ep;
  79624. +#endif
  79625. + dwc_irqflags_t irqflags;
  79626. + void **ref_ep_hcpriv = &ep->hcpriv;
  79627. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79628. + dwc_otg_hcd_urb_t *dwc_otg_urb;
  79629. + int i;
  79630. + int alloc_bandwidth = 0;
  79631. + uint8_t ep_type = 0;
  79632. + uint32_t flags = 0;
  79633. + void *buf;
  79634. +
  79635. +#ifdef DEBUG
  79636. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79637. + dump_urb_info(urb, "dwc_otg_urb_enqueue");
  79638. + }
  79639. +#endif
  79640. +
  79641. + if (!urb->transfer_buffer && urb->transfer_buffer_length)
  79642. + return -EINVAL;
  79643. +
  79644. + if ((usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS)
  79645. + || (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)) {
  79646. + if (!dwc_otg_hcd_is_bandwidth_allocated
  79647. + (dwc_otg_hcd, ref_ep_hcpriv)) {
  79648. + alloc_bandwidth = 1;
  79649. + }
  79650. + }
  79651. +
  79652. + switch (usb_pipetype(urb->pipe)) {
  79653. + case PIPE_CONTROL:
  79654. + ep_type = USB_ENDPOINT_XFER_CONTROL;
  79655. + break;
  79656. + case PIPE_ISOCHRONOUS:
  79657. + ep_type = USB_ENDPOINT_XFER_ISOC;
  79658. + break;
  79659. + case PIPE_BULK:
  79660. + ep_type = USB_ENDPOINT_XFER_BULK;
  79661. + break;
  79662. + case PIPE_INTERRUPT:
  79663. + ep_type = USB_ENDPOINT_XFER_INT;
  79664. + break;
  79665. + default:
  79666. + DWC_WARN("Wrong EP type - %d\n", usb_pipetype(urb->pipe));
  79667. + }
  79668. +
  79669. + /* # of packets is often 0 - do we really need to call this then? */
  79670. + dwc_otg_urb = dwc_otg_hcd_urb_alloc(dwc_otg_hcd,
  79671. + urb->number_of_packets,
  79672. + mem_flags == GFP_ATOMIC ? 1 : 0);
  79673. +
  79674. + if(dwc_otg_urb == NULL)
  79675. + return -ENOMEM;
  79676. +
  79677. + if (!dwc_otg_urb && urb->number_of_packets)
  79678. + return -ENOMEM;
  79679. +
  79680. + dwc_otg_hcd_urb_set_pipeinfo(dwc_otg_urb, usb_pipedevice(urb->pipe),
  79681. + usb_pipeendpoint(urb->pipe), ep_type,
  79682. + usb_pipein(urb->pipe),
  79683. + usb_maxpacket(urb->dev, urb->pipe,
  79684. + !(usb_pipein(urb->pipe))));
  79685. +
  79686. + buf = urb->transfer_buffer;
  79687. + if (hcd->self.uses_dma) {
  79688. + /*
  79689. + * Calculate virtual address from physical address,
  79690. + * because some class driver may not fill transfer_buffer.
  79691. + * In Buffer DMA mode virual address is used,
  79692. + * when handling non DWORD aligned buffers.
  79693. + */
  79694. + //buf = phys_to_virt(urb->transfer_dma);
  79695. + // DMA addresses are bus addresses not physical addresses!
  79696. + buf = dma_to_virt(&urb->dev->dev, urb->transfer_dma);
  79697. + }
  79698. +
  79699. + if (!(urb->transfer_flags & URB_NO_INTERRUPT))
  79700. + flags |= URB_GIVEBACK_ASAP;
  79701. + if (urb->transfer_flags & URB_ZERO_PACKET)
  79702. + flags |= URB_SEND_ZERO_PACKET;
  79703. +
  79704. + dwc_otg_hcd_urb_set_params(dwc_otg_urb, urb, buf,
  79705. + urb->transfer_dma,
  79706. + urb->transfer_buffer_length,
  79707. + urb->setup_packet,
  79708. + urb->setup_dma, flags, urb->interval);
  79709. +
  79710. + for (i = 0; i < urb->number_of_packets; ++i) {
  79711. + dwc_otg_hcd_urb_set_iso_desc_params(dwc_otg_urb, i,
  79712. + urb->
  79713. + iso_frame_desc[i].offset,
  79714. + urb->
  79715. + iso_frame_desc[i].length);
  79716. + }
  79717. +
  79718. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &irqflags);
  79719. + urb->hcpriv = dwc_otg_urb;
  79720. +#if USB_URB_EP_LINKING
  79721. + retval = usb_hcd_link_urb_to_ep(hcd, urb);
  79722. + if (0 == retval)
  79723. +#endif
  79724. + {
  79725. + retval = dwc_otg_hcd_urb_enqueue(dwc_otg_hcd, dwc_otg_urb,
  79726. + /*(dwc_otg_qh_t **)*/
  79727. + ref_ep_hcpriv, 1);
  79728. + if (0 == retval) {
  79729. + if (alloc_bandwidth) {
  79730. + allocate_bus_bandwidth(hcd,
  79731. + dwc_otg_hcd_get_ep_bandwidth(
  79732. + dwc_otg_hcd, *ref_ep_hcpriv),
  79733. + urb);
  79734. + }
  79735. + } else {
  79736. + DWC_DEBUGPL(DBG_HCD, "DWC OTG dwc_otg_hcd_urb_enqueue failed rc %d\n", retval);
  79737. +#if USB_URB_EP_LINKING
  79738. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  79739. +#endif
  79740. + DWC_FREE(dwc_otg_urb);
  79741. + urb->hcpriv = NULL;
  79742. + if (retval == -DWC_E_NO_DEVICE)
  79743. + retval = -ENODEV;
  79744. + }
  79745. + }
  79746. +#if USB_URB_EP_LINKING
  79747. + else
  79748. + {
  79749. + DWC_FREE(dwc_otg_urb);
  79750. + urb->hcpriv = NULL;
  79751. + }
  79752. +#endif
  79753. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, irqflags);
  79754. + return retval;
  79755. +}
  79756. +
  79757. +/** Aborts/cancels a USB transfer request. Always returns 0 to indicate
  79758. + * success. */
  79759. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79760. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
  79761. +#else
  79762. +static int dwc_otg_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
  79763. +#endif
  79764. +{
  79765. + dwc_irqflags_t flags;
  79766. + dwc_otg_hcd_t *dwc_otg_hcd;
  79767. + int rc;
  79768. +
  79769. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue\n");
  79770. +
  79771. + dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79772. +
  79773. +#ifdef DEBUG
  79774. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79775. + dump_urb_info(urb, "dwc_otg_urb_dequeue");
  79776. + }
  79777. +#endif
  79778. +
  79779. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  79780. + rc = usb_hcd_check_unlink_urb(hcd, urb, status);
  79781. + if (0 == rc) {
  79782. + if(urb->hcpriv != NULL) {
  79783. + dwc_otg_hcd_urb_dequeue(dwc_otg_hcd,
  79784. + (dwc_otg_hcd_urb_t *)urb->hcpriv);
  79785. +
  79786. + DWC_FREE(urb->hcpriv);
  79787. + urb->hcpriv = NULL;
  79788. + }
  79789. + }
  79790. +
  79791. + if (0 == rc) {
  79792. + /* Higher layer software sets URB status. */
  79793. +#if USB_URB_EP_LINKING
  79794. + usb_hcd_unlink_urb_from_ep(hcd, urb);
  79795. +#endif
  79796. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79797. +
  79798. +
  79799. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  79800. + usb_hcd_giveback_urb(hcd, urb);
  79801. +#else
  79802. + usb_hcd_giveback_urb(hcd, urb, status);
  79803. +#endif
  79804. + if (CHK_DEBUG_LEVEL(DBG_HCDV | DBG_HCD_URB)) {
  79805. + DWC_PRINTF("Called usb_hcd_giveback_urb() \n");
  79806. + DWC_PRINTF(" 1urb->status = %d\n", urb->status);
  79807. + }
  79808. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue OK\n");
  79809. + } else {
  79810. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79811. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD URB Dequeue failed - rc %d\n",
  79812. + rc);
  79813. + }
  79814. +
  79815. + return rc;
  79816. +}
  79817. +
  79818. +/* Frees resources in the DWC_otg controller related to a given endpoint. Also
  79819. + * clears state in the HCD related to the endpoint. Any URBs for the endpoint
  79820. + * must already be dequeued. */
  79821. +static void endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  79822. +{
  79823. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79824. +
  79825. + DWC_DEBUGPL(DBG_HCD,
  79826. + "DWC OTG HCD EP DISABLE: _bEndpointAddress=0x%02x, "
  79827. + "endpoint=%d\n", ep->desc.bEndpointAddress,
  79828. + dwc_ep_addr_to_endpoint(ep->desc.bEndpointAddress));
  79829. + dwc_otg_hcd_endpoint_disable(dwc_otg_hcd, ep->hcpriv, 250);
  79830. + ep->hcpriv = NULL;
  79831. +}
  79832. +
  79833. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30)
  79834. +/* Resets endpoint specific parameter values, in current version used to reset
  79835. + * the data toggle(as a WA). This function can be called from usb_clear_halt routine */
  79836. +static void endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
  79837. +{
  79838. + dwc_irqflags_t flags;
  79839. + struct usb_device *udev = NULL;
  79840. + int epnum = usb_endpoint_num(&ep->desc);
  79841. + int is_out = usb_endpoint_dir_out(&ep->desc);
  79842. + int is_control = usb_endpoint_xfer_control(&ep->desc);
  79843. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79844. + struct device *dev = DWC_OTG_OS_GETDEV(dwc_otg_hcd->otg_dev->os_dep);
  79845. +
  79846. + if (dev)
  79847. + udev = to_usb_device(dev);
  79848. + else
  79849. + return;
  79850. +
  79851. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD EP RESET: Endpoint Num=0x%02d\n", epnum);
  79852. +
  79853. + DWC_SPINLOCK_IRQSAVE(dwc_otg_hcd->lock, &flags);
  79854. + usb_settoggle(udev, epnum, is_out, 0);
  79855. + if (is_control)
  79856. + usb_settoggle(udev, epnum, !is_out, 0);
  79857. +
  79858. + if (ep->hcpriv) {
  79859. + dwc_otg_hcd_endpoint_reset(dwc_otg_hcd, ep->hcpriv);
  79860. + }
  79861. + DWC_SPINUNLOCK_IRQRESTORE(dwc_otg_hcd->lock, flags);
  79862. +}
  79863. +#endif
  79864. +
  79865. +/** Handles host mode interrupts for the DWC_otg controller. Returns IRQ_NONE if
  79866. + * there was no interrupt to handle. Returns IRQ_HANDLED if there was a valid
  79867. + * interrupt.
  79868. + *
  79869. + * This function is called by the USB core when an interrupt occurs */
  79870. +static irqreturn_t dwc_otg_hcd_irq(struct usb_hcd *hcd)
  79871. +{
  79872. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79873. + int32_t retval = dwc_otg_hcd_handle_intr(dwc_otg_hcd);
  79874. + if (retval != 0) {
  79875. + S3C2410X_CLEAR_EINTPEND();
  79876. + }
  79877. + return IRQ_RETVAL(retval);
  79878. +}
  79879. +
  79880. +/** Creates Status Change bitmap for the root hub and root port. The bitmap is
  79881. + * returned in buf. Bit 0 is the status change indicator for the root hub. Bit 1
  79882. + * is the status change indicator for the single root port. Returns 1 if either
  79883. + * change indicator is 1, otherwise returns 0. */
  79884. +int hub_status_data(struct usb_hcd *hcd, char *buf)
  79885. +{
  79886. + dwc_otg_hcd_t *dwc_otg_hcd = hcd_to_dwc_otg_hcd(hcd);
  79887. +
  79888. + buf[0] = 0;
  79889. + buf[0] |= (dwc_otg_hcd_is_status_changed(dwc_otg_hcd, 1)) << 1;
  79890. +
  79891. + return (buf[0] != 0);
  79892. +}
  79893. +
  79894. +/** Handles hub class-specific requests. */
  79895. +int hub_control(struct usb_hcd *hcd,
  79896. + u16 typeReq, u16 wValue, u16 wIndex, char *buf, u16 wLength)
  79897. +{
  79898. + int retval;
  79899. +
  79900. + retval = dwc_otg_hcd_hub_control(hcd_to_dwc_otg_hcd(hcd),
  79901. + typeReq, wValue, wIndex, buf, wLength);
  79902. +
  79903. + switch (retval) {
  79904. + case -DWC_E_INVALID:
  79905. + retval = -EINVAL;
  79906. + break;
  79907. + }
  79908. +
  79909. + return retval;
  79910. +}
  79911. +
  79912. +#endif /* DWC_DEVICE_ONLY */
  79913. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c
  79914. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 1970-01-01 01:00:00.000000000 +0100
  79915. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_hcd_queue.c 2014-06-11 21:03:43.000000000 +0200
  79916. @@ -0,0 +1,942 @@
  79917. +/* ==========================================================================
  79918. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_hcd_queue.c $
  79919. + * $Revision: #44 $
  79920. + * $Date: 2011/10/26 $
  79921. + * $Change: 1873028 $
  79922. + *
  79923. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  79924. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  79925. + * otherwise expressly agreed to in writing between Synopsys and you.
  79926. + *
  79927. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  79928. + * any End User Software License Agreement or Agreement for Licensed Product
  79929. + * with Synopsys or any supplement thereto. You are permitted to use and
  79930. + * redistribute this Software in source and binary forms, with or without
  79931. + * modification, provided that redistributions of source code must retain this
  79932. + * notice. You may not view, use, disclose, copy or distribute this file or
  79933. + * any information contained herein except pursuant to this license grant from
  79934. + * Synopsys. If you do not agree with this notice, including the disclaimer
  79935. + * below, then you are not authorized to use the Software.
  79936. + *
  79937. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  79938. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  79939. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  79940. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  79941. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  79942. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  79943. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  79944. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  79945. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  79946. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  79947. + * DAMAGE.
  79948. + * ========================================================================== */
  79949. +#ifndef DWC_DEVICE_ONLY
  79950. +
  79951. +/**
  79952. + * @file
  79953. + *
  79954. + * This file contains the functions to manage Queue Heads and Queue
  79955. + * Transfer Descriptors.
  79956. + */
  79957. +
  79958. +#include "dwc_otg_hcd.h"
  79959. +#include "dwc_otg_regs.h"
  79960. +
  79961. +extern bool microframe_schedule;
  79962. +
  79963. +/**
  79964. + * Free each QTD in the QH's QTD-list then free the QH. QH should already be
  79965. + * removed from a list. QTD list should already be empty if called from URB
  79966. + * Dequeue.
  79967. + *
  79968. + * @param hcd HCD instance.
  79969. + * @param qh The QH to free.
  79970. + */
  79971. +void dwc_otg_hcd_qh_free(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  79972. +{
  79973. + dwc_otg_qtd_t *qtd, *qtd_tmp;
  79974. +
  79975. + /* Free each QTD in the QTD list */
  79976. + DWC_SPINLOCK(hcd->lock);
  79977. + DWC_CIRCLEQ_FOREACH_SAFE(qtd, qtd_tmp, &qh->qtd_list, qtd_list_entry) {
  79978. + DWC_CIRCLEQ_REMOVE(&qh->qtd_list, qtd, qtd_list_entry);
  79979. + dwc_otg_hcd_qtd_free(qtd);
  79980. + }
  79981. +
  79982. + if (hcd->core_if->dma_desc_enable) {
  79983. + dwc_otg_hcd_qh_free_ddma(hcd, qh);
  79984. + } else if (qh->dw_align_buf) {
  79985. + uint32_t buf_size;
  79986. + if (qh->ep_type == UE_ISOCHRONOUS) {
  79987. + buf_size = 4096;
  79988. + } else {
  79989. + buf_size = hcd->core_if->core_params->max_transfer_size;
  79990. + }
  79991. + DWC_DMA_FREE(buf_size, qh->dw_align_buf, qh->dw_align_buf_dma);
  79992. + }
  79993. +
  79994. + DWC_FREE(qh);
  79995. + DWC_SPINUNLOCK(hcd->lock);
  79996. + return;
  79997. +}
  79998. +
  79999. +#define BitStuffTime(bytecount) ((8 * 7* bytecount) / 6)
  80000. +#define HS_HOST_DELAY 5 /* nanoseconds */
  80001. +#define FS_LS_HOST_DELAY 1000 /* nanoseconds */
  80002. +#define HUB_LS_SETUP 333 /* nanoseconds */
  80003. +#define NS_TO_US(ns) ((ns + 500) / 1000)
  80004. + /* convert & round nanoseconds to microseconds */
  80005. +
  80006. +static uint32_t calc_bus_time(int speed, int is_in, int is_isoc, int bytecount)
  80007. +{
  80008. + unsigned long retval;
  80009. +
  80010. + switch (speed) {
  80011. + case USB_SPEED_HIGH:
  80012. + if (is_isoc) {
  80013. + retval =
  80014. + ((38 * 8 * 2083) +
  80015. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  80016. + HS_HOST_DELAY;
  80017. + } else {
  80018. + retval =
  80019. + ((55 * 8 * 2083) +
  80020. + (2083 * (3 + BitStuffTime(bytecount)))) / 1000 +
  80021. + HS_HOST_DELAY;
  80022. + }
  80023. + break;
  80024. + case USB_SPEED_FULL:
  80025. + if (is_isoc) {
  80026. + retval =
  80027. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  80028. + if (is_in) {
  80029. + retval = 7268 + FS_LS_HOST_DELAY + retval;
  80030. + } else {
  80031. + retval = 6265 + FS_LS_HOST_DELAY + retval;
  80032. + }
  80033. + } else {
  80034. + retval =
  80035. + (8354 * (31 + 10 * BitStuffTime(bytecount))) / 1000;
  80036. + retval = 9107 + FS_LS_HOST_DELAY + retval;
  80037. + }
  80038. + break;
  80039. + case USB_SPEED_LOW:
  80040. + if (is_in) {
  80041. + retval =
  80042. + (67667 * (31 + 10 * BitStuffTime(bytecount))) /
  80043. + 1000;
  80044. + retval =
  80045. + 64060 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  80046. + retval;
  80047. + } else {
  80048. + retval =
  80049. + (66700 * (31 + 10 * BitStuffTime(bytecount))) /
  80050. + 1000;
  80051. + retval =
  80052. + 64107 + (2 * HUB_LS_SETUP) + FS_LS_HOST_DELAY +
  80053. + retval;
  80054. + }
  80055. + break;
  80056. + default:
  80057. + DWC_WARN("Unknown device speed\n");
  80058. + retval = -1;
  80059. + }
  80060. +
  80061. + return NS_TO_US(retval);
  80062. +}
  80063. +
  80064. +/**
  80065. + * Initializes a QH structure.
  80066. + *
  80067. + * @param hcd The HCD state structure for the DWC OTG controller.
  80068. + * @param qh The QH to init.
  80069. + * @param urb Holds the information about the device/endpoint that we need
  80070. + * to initialize the QH.
  80071. + */
  80072. +#define SCHEDULE_SLOP 10
  80073. +void qh_init(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh, dwc_otg_hcd_urb_t * urb)
  80074. +{
  80075. + char *speed, *type;
  80076. + int dev_speed;
  80077. + uint32_t hub_addr, hub_port;
  80078. +
  80079. + dwc_memset(qh, 0, sizeof(dwc_otg_qh_t));
  80080. +
  80081. + /* Initialize QH */
  80082. + qh->ep_type = dwc_otg_hcd_get_pipe_type(&urb->pipe_info);
  80083. + qh->ep_is_in = dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? 1 : 0;
  80084. +
  80085. + qh->data_toggle = DWC_OTG_HC_PID_DATA0;
  80086. + qh->maxp = dwc_otg_hcd_get_mps(&urb->pipe_info);
  80087. + DWC_CIRCLEQ_INIT(&qh->qtd_list);
  80088. + DWC_LIST_INIT(&qh->qh_list_entry);
  80089. + qh->channel = NULL;
  80090. +
  80091. + /* FS/LS Enpoint on HS Hub
  80092. + * NOT virtual root hub */
  80093. + dev_speed = hcd->fops->speed(hcd, urb->priv);
  80094. +
  80095. + hcd->fops->hub_info(hcd, urb->priv, &hub_addr, &hub_port);
  80096. + qh->do_split = 0;
  80097. + if (microframe_schedule)
  80098. + qh->speed = dev_speed;
  80099. +
  80100. + qh->nak_frame = 0xffff;
  80101. +
  80102. + if (((dev_speed == USB_SPEED_LOW) ||
  80103. + (dev_speed == USB_SPEED_FULL)) &&
  80104. + (hub_addr != 0 && hub_addr != 1)) {
  80105. + DWC_DEBUGPL(DBG_HCD,
  80106. + "QH init: EP %d: TT found at hub addr %d, for port %d\n",
  80107. + dwc_otg_hcd_get_ep_num(&urb->pipe_info), hub_addr,
  80108. + hub_port);
  80109. + qh->do_split = 1;
  80110. + qh->skip_count = 0;
  80111. + }
  80112. +
  80113. + if (qh->ep_type == UE_INTERRUPT || qh->ep_type == UE_ISOCHRONOUS) {
  80114. + /* Compute scheduling parameters once and save them. */
  80115. + hprt0_data_t hprt;
  80116. +
  80117. + /** @todo Account for split transfers in the bus time. */
  80118. + int bytecount =
  80119. + dwc_hb_mult(qh->maxp) * dwc_max_packet(qh->maxp);
  80120. +
  80121. + qh->usecs =
  80122. + calc_bus_time((qh->do_split ? USB_SPEED_HIGH : dev_speed),
  80123. + qh->ep_is_in, (qh->ep_type == UE_ISOCHRONOUS),
  80124. + bytecount);
  80125. + /* Start in a slightly future (micro)frame. */
  80126. + qh->sched_frame = dwc_frame_num_inc(hcd->frame_number,
  80127. + SCHEDULE_SLOP);
  80128. + qh->interval = urb->interval;
  80129. +
  80130. +#if 0
  80131. + /* Increase interrupt polling rate for debugging. */
  80132. + if (qh->ep_type == UE_INTERRUPT) {
  80133. + qh->interval = 8;
  80134. + }
  80135. +#endif
  80136. + hprt.d32 = DWC_READ_REG32(hcd->core_if->host_if->hprt0);
  80137. + if ((hprt.b.prtspd == DWC_HPRT0_PRTSPD_HIGH_SPEED) &&
  80138. + ((dev_speed == USB_SPEED_LOW) ||
  80139. + (dev_speed == USB_SPEED_FULL))) {
  80140. + qh->interval *= 8;
  80141. + qh->sched_frame |= 0x7;
  80142. + qh->start_split_frame = qh->sched_frame;
  80143. + }
  80144. +
  80145. + }
  80146. +
  80147. + DWC_DEBUGPL(DBG_HCD, "DWC OTG HCD QH Initialized\n");
  80148. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - qh = %p\n", qh);
  80149. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Device Address = %d\n",
  80150. + dwc_otg_hcd_get_dev_addr(&urb->pipe_info));
  80151. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Endpoint %d, %s\n",
  80152. + dwc_otg_hcd_get_ep_num(&urb->pipe_info),
  80153. + dwc_otg_hcd_is_pipe_in(&urb->pipe_info) ? "IN" : "OUT");
  80154. + switch (dev_speed) {
  80155. + case USB_SPEED_LOW:
  80156. + qh->dev_speed = DWC_OTG_EP_SPEED_LOW;
  80157. + speed = "low";
  80158. + break;
  80159. + case USB_SPEED_FULL:
  80160. + qh->dev_speed = DWC_OTG_EP_SPEED_FULL;
  80161. + speed = "full";
  80162. + break;
  80163. + case USB_SPEED_HIGH:
  80164. + qh->dev_speed = DWC_OTG_EP_SPEED_HIGH;
  80165. + speed = "high";
  80166. + break;
  80167. + default:
  80168. + speed = "?";
  80169. + break;
  80170. + }
  80171. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Speed = %s\n", speed);
  80172. +
  80173. + switch (qh->ep_type) {
  80174. + case UE_ISOCHRONOUS:
  80175. + type = "isochronous";
  80176. + break;
  80177. + case UE_INTERRUPT:
  80178. + type = "interrupt";
  80179. + break;
  80180. + case UE_CONTROL:
  80181. + type = "control";
  80182. + break;
  80183. + case UE_BULK:
  80184. + type = "bulk";
  80185. + break;
  80186. + default:
  80187. + type = "?";
  80188. + break;
  80189. + }
  80190. +
  80191. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - Type = %s\n", type);
  80192. +
  80193. +#ifdef DEBUG
  80194. + if (qh->ep_type == UE_INTERRUPT) {
  80195. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - usecs = %d\n",
  80196. + qh->usecs);
  80197. + DWC_DEBUGPL(DBG_HCDV, "DWC OTG HCD QH - interval = %d\n",
  80198. + qh->interval);
  80199. + }
  80200. +#endif
  80201. +
  80202. +}
  80203. +
  80204. +/**
  80205. + * This function allocates and initializes a QH.
  80206. + *
  80207. + * @param hcd The HCD state structure for the DWC OTG controller.
  80208. + * @param urb Holds the information about the device/endpoint that we need
  80209. + * to initialize the QH.
  80210. + * @param atomic_alloc Flag to do atomic allocation if needed
  80211. + *
  80212. + * @return Returns pointer to the newly allocated QH, or NULL on error. */
  80213. +dwc_otg_qh_t *dwc_otg_hcd_qh_create(dwc_otg_hcd_t * hcd,
  80214. + dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  80215. +{
  80216. + dwc_otg_qh_t *qh;
  80217. +
  80218. + /* Allocate memory */
  80219. + /** @todo add memflags argument */
  80220. + qh = dwc_otg_hcd_qh_alloc(atomic_alloc);
  80221. + if (qh == NULL) {
  80222. + DWC_ERROR("qh allocation failed");
  80223. + return NULL;
  80224. + }
  80225. +
  80226. + qh_init(hcd, qh, urb);
  80227. +
  80228. + if (hcd->core_if->dma_desc_enable
  80229. + && (dwc_otg_hcd_qh_init_ddma(hcd, qh) < 0)) {
  80230. + dwc_otg_hcd_qh_free(hcd, qh);
  80231. + return NULL;
  80232. + }
  80233. +
  80234. + return qh;
  80235. +}
  80236. +
  80237. +/* microframe_schedule=0 start */
  80238. +
  80239. +/**
  80240. + * Checks that a channel is available for a periodic transfer.
  80241. + *
  80242. + * @return 0 if successful, negative error code otherise.
  80243. + */
  80244. +static int periodic_channel_available(dwc_otg_hcd_t * hcd)
  80245. +{
  80246. + /*
  80247. + * Currently assuming that there is a dedicated host channnel for each
  80248. + * periodic transaction plus at least one host channel for
  80249. + * non-periodic transactions.
  80250. + */
  80251. + int status;
  80252. + int num_channels;
  80253. +
  80254. + num_channels = hcd->core_if->core_params->host_channels;
  80255. + if ((hcd->periodic_channels + hcd->non_periodic_channels < num_channels)
  80256. + && (hcd->periodic_channels < num_channels - 1)) {
  80257. + status = 0;
  80258. + } else {
  80259. + DWC_INFO("%s: Total channels: %d, Periodic: %d, Non-periodic: %d\n",
  80260. + __func__, num_channels, hcd->periodic_channels, hcd->non_periodic_channels); //NOTICE
  80261. + status = -DWC_E_NO_SPACE;
  80262. + }
  80263. +
  80264. + return status;
  80265. +}
  80266. +
  80267. +/**
  80268. + * Checks that there is sufficient bandwidth for the specified QH in the
  80269. + * periodic schedule. For simplicity, this calculation assumes that all the
  80270. + * transfers in the periodic schedule may occur in the same (micro)frame.
  80271. + *
  80272. + * @param hcd The HCD state structure for the DWC OTG controller.
  80273. + * @param qh QH containing periodic bandwidth required.
  80274. + *
  80275. + * @return 0 if successful, negative error code otherwise.
  80276. + */
  80277. +static int check_periodic_bandwidth(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80278. +{
  80279. + int status;
  80280. + int16_t max_claimed_usecs;
  80281. +
  80282. + status = 0;
  80283. +
  80284. + if ((qh->dev_speed == DWC_OTG_EP_SPEED_HIGH) || qh->do_split) {
  80285. + /*
  80286. + * High speed mode.
  80287. + * Max periodic usecs is 80% x 125 usec = 100 usec.
  80288. + */
  80289. +
  80290. + max_claimed_usecs = 100 - qh->usecs;
  80291. + } else {
  80292. + /*
  80293. + * Full speed mode.
  80294. + * Max periodic usecs is 90% x 1000 usec = 900 usec.
  80295. + */
  80296. + max_claimed_usecs = 900 - qh->usecs;
  80297. + }
  80298. +
  80299. + if (hcd->periodic_usecs > max_claimed_usecs) {
  80300. + DWC_INFO("%s: already claimed usecs %d, required usecs %d\n", __func__, hcd->periodic_usecs, qh->usecs); //NOTICE
  80301. + status = -DWC_E_NO_SPACE;
  80302. + }
  80303. +
  80304. + return status;
  80305. +}
  80306. +
  80307. +/* microframe_schedule=0 end */
  80308. +
  80309. +/**
  80310. + * Microframe scheduler
  80311. + * track the total use in hcd->frame_usecs
  80312. + * keep each qh use in qh->frame_usecs
  80313. + * when surrendering the qh then donate the time back
  80314. + */
  80315. +const unsigned short max_uframe_usecs[]={ 100, 100, 100, 100, 100, 100, 30, 0 };
  80316. +
  80317. +/*
  80318. + * called from dwc_otg_hcd.c:dwc_otg_hcd_init
  80319. + */
  80320. +int init_hcd_usecs(dwc_otg_hcd_t *_hcd)
  80321. +{
  80322. + int i;
  80323. + for (i=0; i<8; i++) {
  80324. + _hcd->frame_usecs[i] = max_uframe_usecs[i];
  80325. + }
  80326. + return 0;
  80327. +}
  80328. +
  80329. +static int find_single_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80330. +{
  80331. + int i;
  80332. + unsigned short utime;
  80333. + int t_left;
  80334. + int ret;
  80335. + int done;
  80336. +
  80337. + ret = -1;
  80338. + utime = _qh->usecs;
  80339. + t_left = utime;
  80340. + i = 0;
  80341. + done = 0;
  80342. + while (done == 0) {
  80343. + /* At the start _hcd->frame_usecs[i] = max_uframe_usecs[i]; */
  80344. + if (utime <= _hcd->frame_usecs[i]) {
  80345. + _hcd->frame_usecs[i] -= utime;
  80346. + _qh->frame_usecs[i] += utime;
  80347. + t_left -= utime;
  80348. + ret = i;
  80349. + done = 1;
  80350. + return ret;
  80351. + } else {
  80352. + i++;
  80353. + if (i == 8) {
  80354. + done = 1;
  80355. + ret = -1;
  80356. + }
  80357. + }
  80358. + }
  80359. + return ret;
  80360. + }
  80361. +
  80362. +/*
  80363. + * use this for FS apps that can span multiple uframes
  80364. + */
  80365. +static int find_multi_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80366. +{
  80367. + int i;
  80368. + int j;
  80369. + unsigned short utime;
  80370. + int t_left;
  80371. + int ret;
  80372. + int done;
  80373. + unsigned short xtime;
  80374. +
  80375. + ret = -1;
  80376. + utime = _qh->usecs;
  80377. + t_left = utime;
  80378. + i = 0;
  80379. + done = 0;
  80380. +loop:
  80381. + while (done == 0) {
  80382. + if(_hcd->frame_usecs[i] <= 0) {
  80383. + i++;
  80384. + if (i == 8) {
  80385. + done = 1;
  80386. + ret = -1;
  80387. + }
  80388. + goto loop;
  80389. + }
  80390. +
  80391. + /*
  80392. + * we need n consecutive slots
  80393. + * so use j as a start slot j plus j+1 must be enough time (for now)
  80394. + */
  80395. + xtime= _hcd->frame_usecs[i];
  80396. + for (j = i+1 ; j < 8 ; j++ ) {
  80397. + /*
  80398. + * if we add this frame remaining time to xtime we may
  80399. + * be OK, if not we need to test j for a complete frame
  80400. + */
  80401. + if ((xtime+_hcd->frame_usecs[j]) < utime) {
  80402. + if (_hcd->frame_usecs[j] < max_uframe_usecs[j]) {
  80403. + j = 8;
  80404. + ret = -1;
  80405. + continue;
  80406. + }
  80407. + }
  80408. + if (xtime >= utime) {
  80409. + ret = i;
  80410. + j = 8; /* stop loop with a good value ret */
  80411. + continue;
  80412. + }
  80413. + /* add the frame time to x time */
  80414. + xtime += _hcd->frame_usecs[j];
  80415. + /* we must have a fully available next frame or break */
  80416. + if ((xtime < utime)
  80417. + && (_hcd->frame_usecs[j] == max_uframe_usecs[j])) {
  80418. + ret = -1;
  80419. + j = 8; /* stop loop with a bad value ret */
  80420. + continue;
  80421. + }
  80422. + }
  80423. + if (ret >= 0) {
  80424. + t_left = utime;
  80425. + for (j = i; (t_left>0) && (j < 8); j++ ) {
  80426. + t_left -= _hcd->frame_usecs[j];
  80427. + if ( t_left <= 0 ) {
  80428. + _qh->frame_usecs[j] += _hcd->frame_usecs[j] + t_left;
  80429. + _hcd->frame_usecs[j]= -t_left;
  80430. + ret = i;
  80431. + done = 1;
  80432. + } else {
  80433. + _qh->frame_usecs[j] += _hcd->frame_usecs[j];
  80434. + _hcd->frame_usecs[j] = 0;
  80435. + }
  80436. + }
  80437. + } else {
  80438. + i++;
  80439. + if (i == 8) {
  80440. + done = 1;
  80441. + ret = -1;
  80442. + }
  80443. + }
  80444. + }
  80445. + return ret;
  80446. +}
  80447. +
  80448. +static int find_uframe(dwc_otg_hcd_t * _hcd, dwc_otg_qh_t * _qh)
  80449. +{
  80450. + int ret;
  80451. + ret = -1;
  80452. +
  80453. + if (_qh->speed == USB_SPEED_HIGH) {
  80454. + /* if this is a hs transaction we need a full frame */
  80455. + ret = find_single_uframe(_hcd, _qh);
  80456. + } else {
  80457. + /* if this is a fs transaction we may need a sequence of frames */
  80458. + ret = find_multi_uframe(_hcd, _qh);
  80459. + }
  80460. + return ret;
  80461. +}
  80462. +
  80463. +/**
  80464. + * Checks that the max transfer size allowed in a host channel is large enough
  80465. + * to handle the maximum data transfer in a single (micro)frame for a periodic
  80466. + * transfer.
  80467. + *
  80468. + * @param hcd The HCD state structure for the DWC OTG controller.
  80469. + * @param qh QH for a periodic endpoint.
  80470. + *
  80471. + * @return 0 if successful, negative error code otherwise.
  80472. + */
  80473. +static int check_max_xfer_size(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80474. +{
  80475. + int status;
  80476. + uint32_t max_xfer_size;
  80477. + uint32_t max_channel_xfer_size;
  80478. +
  80479. + status = 0;
  80480. +
  80481. + max_xfer_size = dwc_max_packet(qh->maxp) * dwc_hb_mult(qh->maxp);
  80482. + max_channel_xfer_size = hcd->core_if->core_params->max_transfer_size;
  80483. +
  80484. + if (max_xfer_size > max_channel_xfer_size) {
  80485. + DWC_INFO("%s: Periodic xfer length %d > " "max xfer length for channel %d\n",
  80486. + __func__, max_xfer_size, max_channel_xfer_size); //NOTICE
  80487. + status = -DWC_E_NO_SPACE;
  80488. + }
  80489. +
  80490. + return status;
  80491. +}
  80492. +
  80493. +
  80494. +
  80495. +/**
  80496. + * Schedules an interrupt or isochronous transfer in the periodic schedule.
  80497. + *
  80498. + * @param hcd The HCD state structure for the DWC OTG controller.
  80499. + * @param qh QH for the periodic transfer. The QH should already contain the
  80500. + * scheduling information.
  80501. + *
  80502. + * @return 0 if successful, negative error code otherwise.
  80503. + */
  80504. +static int schedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80505. +{
  80506. + int status = 0;
  80507. +
  80508. + if (microframe_schedule) {
  80509. + int frame;
  80510. + status = find_uframe(hcd, qh);
  80511. + frame = -1;
  80512. + if (status == 0) {
  80513. + frame = 7;
  80514. + } else {
  80515. + if (status > 0 )
  80516. + frame = status-1;
  80517. + }
  80518. +
  80519. + /* Set the new frame up */
  80520. + if (frame > -1) {
  80521. + qh->sched_frame &= ~0x7;
  80522. + qh->sched_frame |= (frame & 7);
  80523. + }
  80524. +
  80525. + if (status != -1)
  80526. + status = 0;
  80527. + } else {
  80528. + status = periodic_channel_available(hcd);
  80529. + if (status) {
  80530. + DWC_INFO("%s: No host channel available for periodic " "transfer.\n", __func__); //NOTICE
  80531. + return status;
  80532. + }
  80533. +
  80534. + status = check_periodic_bandwidth(hcd, qh);
  80535. + }
  80536. + if (status) {
  80537. + DWC_INFO("%s: Insufficient periodic bandwidth for "
  80538. + "periodic transfer.\n", __func__);
  80539. + return status;
  80540. + }
  80541. + status = check_max_xfer_size(hcd, qh);
  80542. + if (status) {
  80543. + DWC_INFO("%s: Channel max transfer size too small "
  80544. + "for periodic transfer.\n", __func__);
  80545. + return status;
  80546. + }
  80547. +
  80548. + if (hcd->core_if->dma_desc_enable) {
  80549. + /* Don't rely on SOF and start in ready schedule */
  80550. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_ready, &qh->qh_list_entry);
  80551. + }
  80552. + else {
  80553. + if(fiq_enable && (DWC_LIST_EMPTY(&hcd->periodic_sched_inactive) || dwc_frame_num_le(qh->sched_frame, hcd->fiq_state->next_sched_frame)))
  80554. + {
  80555. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  80556. +
  80557. + }
  80558. + /* Always start in the inactive schedule. */
  80559. + DWC_LIST_INSERT_TAIL(&hcd->periodic_sched_inactive, &qh->qh_list_entry);
  80560. + }
  80561. +
  80562. + if (!microframe_schedule) {
  80563. + /* Reserve the periodic channel. */
  80564. + hcd->periodic_channels++;
  80565. + }
  80566. +
  80567. + /* Update claimed usecs per (micro)frame. */
  80568. + hcd->periodic_usecs += qh->usecs;
  80569. +
  80570. + return status;
  80571. +}
  80572. +
  80573. +
  80574. +/**
  80575. + * This function adds a QH to either the non periodic or periodic schedule if
  80576. + * it is not already in the schedule. If the QH is already in the schedule, no
  80577. + * action is taken.
  80578. + *
  80579. + * @return 0 if successful, negative error code otherwise.
  80580. + */
  80581. +int dwc_otg_hcd_qh_add(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80582. +{
  80583. + int status = 0;
  80584. + gintmsk_data_t intr_mask = {.d32 = 0 };
  80585. +
  80586. + if (!DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  80587. + /* QH already in a schedule. */
  80588. + return status;
  80589. + }
  80590. +
  80591. + /* Add the new QH to the appropriate schedule */
  80592. + if (dwc_qh_is_non_per(qh)) {
  80593. + /* Always start in the inactive schedule. */
  80594. + DWC_LIST_INSERT_TAIL(&hcd->non_periodic_sched_inactive,
  80595. + &qh->qh_list_entry);
  80596. + //hcd->fiq_state->kick_np_queues = 1;
  80597. + } else {
  80598. + status = schedule_periodic(hcd, qh);
  80599. + if ( !hcd->periodic_qh_count ) {
  80600. + intr_mask.b.sofintr = 1;
  80601. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  80602. + intr_mask.d32, intr_mask.d32);
  80603. + }
  80604. + hcd->periodic_qh_count++;
  80605. + }
  80606. +
  80607. + return status;
  80608. +}
  80609. +
  80610. +/**
  80611. + * Removes an interrupt or isochronous transfer from the periodic schedule.
  80612. + *
  80613. + * @param hcd The HCD state structure for the DWC OTG controller.
  80614. + * @param qh QH for the periodic transfer.
  80615. + */
  80616. +static void deschedule_periodic(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80617. +{
  80618. + int i;
  80619. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  80620. +
  80621. + /* Update claimed usecs per (micro)frame. */
  80622. + hcd->periodic_usecs -= qh->usecs;
  80623. +
  80624. + if (!microframe_schedule) {
  80625. + /* Release the periodic channel reservation. */
  80626. + hcd->periodic_channels--;
  80627. + } else {
  80628. + for (i = 0; i < 8; i++) {
  80629. + hcd->frame_usecs[i] += qh->frame_usecs[i];
  80630. + qh->frame_usecs[i] = 0;
  80631. + }
  80632. + }
  80633. +}
  80634. +
  80635. +/**
  80636. + * Removes a QH from either the non-periodic or periodic schedule. Memory is
  80637. + * not freed.
  80638. + *
  80639. + * @param hcd The HCD state structure.
  80640. + * @param qh QH to remove from schedule. */
  80641. +void dwc_otg_hcd_qh_remove(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh)
  80642. +{
  80643. + gintmsk_data_t intr_mask = {.d32 = 0 };
  80644. +
  80645. + if (DWC_LIST_EMPTY(&qh->qh_list_entry)) {
  80646. + /* QH is not in a schedule. */
  80647. + return;
  80648. + }
  80649. +
  80650. + if (dwc_qh_is_non_per(qh)) {
  80651. + if (hcd->non_periodic_qh_ptr == &qh->qh_list_entry) {
  80652. + hcd->non_periodic_qh_ptr =
  80653. + hcd->non_periodic_qh_ptr->next;
  80654. + }
  80655. + DWC_LIST_REMOVE_INIT(&qh->qh_list_entry);
  80656. + //if (!DWC_LIST_EMPTY(&hcd->non_periodic_sched_inactive))
  80657. + // hcd->fiq_state->kick_np_queues = 1;
  80658. + } else {
  80659. + deschedule_periodic(hcd, qh);
  80660. + hcd->periodic_qh_count--;
  80661. + if( !hcd->periodic_qh_count && !fiq_fsm_enable ) {
  80662. + intr_mask.b.sofintr = 1;
  80663. + DWC_MODIFY_REG32(&hcd->core_if->core_global_regs->gintmsk,
  80664. + intr_mask.d32, 0);
  80665. + }
  80666. + }
  80667. +}
  80668. +
  80669. +/**
  80670. + * Deactivates a QH. For non-periodic QHs, removes the QH from the active
  80671. + * non-periodic schedule. The QH is added to the inactive non-periodic
  80672. + * schedule if any QTDs are still attached to the QH.
  80673. + *
  80674. + * For periodic QHs, the QH is removed from the periodic queued schedule. If
  80675. + * there are any QTDs still attached to the QH, the QH is added to either the
  80676. + * periodic inactive schedule or the periodic ready schedule and its next
  80677. + * scheduled frame is calculated. The QH is placed in the ready schedule if
  80678. + * the scheduled frame has been reached already. Otherwise it's placed in the
  80679. + * inactive schedule. If there are no QTDs attached to the QH, the QH is
  80680. + * completely removed from the periodic schedule.
  80681. + */
  80682. +void dwc_otg_hcd_qh_deactivate(dwc_otg_hcd_t * hcd, dwc_otg_qh_t * qh,
  80683. + int sched_next_periodic_split)
  80684. +{
  80685. + if (dwc_qh_is_non_per(qh)) {
  80686. + dwc_otg_hcd_qh_remove(hcd, qh);
  80687. + if (!DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  80688. + /* Add back to inactive non-periodic schedule. */
  80689. + dwc_otg_hcd_qh_add(hcd, qh);
  80690. + //hcd->fiq_state->kick_np_queues = 1;
  80691. + }
  80692. + } else {
  80693. + uint16_t frame_number = dwc_otg_hcd_get_frame_number(hcd);
  80694. +
  80695. + if (qh->do_split) {
  80696. + /* Schedule the next continuing periodic split transfer */
  80697. + if (sched_next_periodic_split) {
  80698. +
  80699. + qh->sched_frame = frame_number;
  80700. +
  80701. + if (dwc_frame_num_le(frame_number,
  80702. + dwc_frame_num_inc
  80703. + (qh->start_split_frame,
  80704. + 1))) {
  80705. + /*
  80706. + * Allow one frame to elapse after start
  80707. + * split microframe before scheduling
  80708. + * complete split, but DONT if we are
  80709. + * doing the next start split in the
  80710. + * same frame for an ISOC out.
  80711. + */
  80712. + if ((qh->ep_type != UE_ISOCHRONOUS) ||
  80713. + (qh->ep_is_in != 0)) {
  80714. + qh->sched_frame =
  80715. + dwc_frame_num_inc(qh->sched_frame, 1);
  80716. + }
  80717. + }
  80718. + } else {
  80719. + qh->sched_frame =
  80720. + dwc_frame_num_inc(qh->start_split_frame,
  80721. + qh->interval);
  80722. + if (dwc_frame_num_le
  80723. + (qh->sched_frame, frame_number)) {
  80724. + qh->sched_frame = frame_number;
  80725. + }
  80726. + qh->sched_frame |= 0x7;
  80727. + qh->start_split_frame = qh->sched_frame;
  80728. + }
  80729. + } else {
  80730. + qh->sched_frame =
  80731. + dwc_frame_num_inc(qh->sched_frame, qh->interval);
  80732. + if (dwc_frame_num_le(qh->sched_frame, frame_number)) {
  80733. + qh->sched_frame = frame_number;
  80734. + }
  80735. + }
  80736. +
  80737. + if (DWC_CIRCLEQ_EMPTY(&qh->qtd_list)) {
  80738. + dwc_otg_hcd_qh_remove(hcd, qh);
  80739. + } else {
  80740. + /*
  80741. + * Remove from periodic_sched_queued and move to
  80742. + * appropriate queue.
  80743. + */
  80744. + if ((microframe_schedule && dwc_frame_num_le(qh->sched_frame, frame_number)) ||
  80745. + (!microframe_schedule && qh->sched_frame == frame_number)) {
  80746. + DWC_LIST_MOVE_HEAD(&hcd->periodic_sched_ready,
  80747. + &qh->qh_list_entry);
  80748. + } else {
  80749. + if(fiq_enable && !dwc_frame_num_le(hcd->fiq_state->next_sched_frame, qh->sched_frame))
  80750. + {
  80751. + hcd->fiq_state->next_sched_frame = qh->sched_frame;
  80752. + }
  80753. +
  80754. + DWC_LIST_MOVE_HEAD
  80755. + (&hcd->periodic_sched_inactive,
  80756. + &qh->qh_list_entry);
  80757. + }
  80758. + }
  80759. + }
  80760. +}
  80761. +
  80762. +/**
  80763. + * This function allocates and initializes a QTD.
  80764. + *
  80765. + * @param urb The URB to create a QTD from. Each URB-QTD pair will end up
  80766. + * pointing to each other so each pair should have a unique correlation.
  80767. + * @param atomic_alloc Flag to do atomic alloc if needed
  80768. + *
  80769. + * @return Returns pointer to the newly allocated QTD, or NULL on error. */
  80770. +dwc_otg_qtd_t *dwc_otg_hcd_qtd_create(dwc_otg_hcd_urb_t * urb, int atomic_alloc)
  80771. +{
  80772. + dwc_otg_qtd_t *qtd;
  80773. +
  80774. + qtd = dwc_otg_hcd_qtd_alloc(atomic_alloc);
  80775. + if (qtd == NULL) {
  80776. + return NULL;
  80777. + }
  80778. +
  80779. + dwc_otg_hcd_qtd_init(qtd, urb);
  80780. + return qtd;
  80781. +}
  80782. +
  80783. +/**
  80784. + * Initializes a QTD structure.
  80785. + *
  80786. + * @param qtd The QTD to initialize.
  80787. + * @param urb The URB to use for initialization. */
  80788. +void dwc_otg_hcd_qtd_init(dwc_otg_qtd_t * qtd, dwc_otg_hcd_urb_t * urb)
  80789. +{
  80790. + dwc_memset(qtd, 0, sizeof(dwc_otg_qtd_t));
  80791. + qtd->urb = urb;
  80792. + if (dwc_otg_hcd_get_pipe_type(&urb->pipe_info) == UE_CONTROL) {
  80793. + /*
  80794. + * The only time the QTD data toggle is used is on the data
  80795. + * phase of control transfers. This phase always starts with
  80796. + * DATA1.
  80797. + */
  80798. + qtd->data_toggle = DWC_OTG_HC_PID_DATA1;
  80799. + qtd->control_phase = DWC_OTG_CONTROL_SETUP;
  80800. + }
  80801. +
  80802. + /* start split */
  80803. + qtd->complete_split = 0;
  80804. + qtd->isoc_split_pos = DWC_HCSPLIT_XACTPOS_ALL;
  80805. + qtd->isoc_split_offset = 0;
  80806. + qtd->in_process = 0;
  80807. +
  80808. + /* Store the qtd ptr in the urb to reference what QTD. */
  80809. + urb->qtd = qtd;
  80810. + return;
  80811. +}
  80812. +
  80813. +/**
  80814. + * This function adds a QTD to the QTD-list of a QH. It will find the correct
  80815. + * QH to place the QTD into. If it does not find a QH, then it will create a
  80816. + * new QH. If the QH to which the QTD is added is not currently scheduled, it
  80817. + * is placed into the proper schedule based on its EP type.
  80818. + * HCD lock must be held and interrupts must be disabled on entry
  80819. + *
  80820. + * @param[in] qtd The QTD to add
  80821. + * @param[in] hcd The DWC HCD structure
  80822. + * @param[out] qh out parameter to return queue head
  80823. + * @param atomic_alloc Flag to do atomic alloc if needed
  80824. + *
  80825. + * @return 0 if successful, negative error code otherwise.
  80826. + */
  80827. +int dwc_otg_hcd_qtd_add(dwc_otg_qtd_t * qtd,
  80828. + dwc_otg_hcd_t * hcd, dwc_otg_qh_t ** qh, int atomic_alloc)
  80829. +{
  80830. + int retval = 0;
  80831. + dwc_otg_hcd_urb_t *urb = qtd->urb;
  80832. +
  80833. + /*
  80834. + * Get the QH which holds the QTD-list to insert to. Create QH if it
  80835. + * doesn't exist.
  80836. + */
  80837. + if (*qh == NULL) {
  80838. + *qh = dwc_otg_hcd_qh_create(hcd, urb, atomic_alloc);
  80839. + if (*qh == NULL) {
  80840. + retval = -DWC_E_NO_MEMORY;
  80841. + goto done;
  80842. + } else {
  80843. + if (fiq_enable)
  80844. + hcd->fiq_state->kick_np_queues = 1;
  80845. + }
  80846. + }
  80847. + retval = dwc_otg_hcd_qh_add(hcd, *qh);
  80848. + if (retval == 0) {
  80849. + DWC_CIRCLEQ_INSERT_TAIL(&((*qh)->qtd_list), qtd,
  80850. + qtd_list_entry);
  80851. + qtd->qh = *qh;
  80852. + }
  80853. +done:
  80854. +
  80855. + return retval;
  80856. +}
  80857. +
  80858. +#endif /* DWC_DEVICE_ONLY */
  80859. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h
  80860. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 1970-01-01 01:00:00.000000000 +0100
  80861. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_os_dep.h 2014-06-11 21:03:43.000000000 +0200
  80862. @@ -0,0 +1,188 @@
  80863. +#ifndef _DWC_OS_DEP_H_
  80864. +#define _DWC_OS_DEP_H_
  80865. +
  80866. +/**
  80867. + * @file
  80868. + *
  80869. + * This file contains OS dependent structures.
  80870. + *
  80871. + */
  80872. +
  80873. +#include <linux/kernel.h>
  80874. +#include <linux/module.h>
  80875. +#include <linux/moduleparam.h>
  80876. +#include <linux/init.h>
  80877. +#include <linux/device.h>
  80878. +#include <linux/errno.h>
  80879. +#include <linux/types.h>
  80880. +#include <linux/slab.h>
  80881. +#include <linux/list.h>
  80882. +#include <linux/interrupt.h>
  80883. +#include <linux/ctype.h>
  80884. +#include <linux/string.h>
  80885. +#include <linux/dma-mapping.h>
  80886. +#include <linux/jiffies.h>
  80887. +#include <linux/delay.h>
  80888. +#include <linux/timer.h>
  80889. +#include <linux/workqueue.h>
  80890. +#include <linux/stat.h>
  80891. +#include <linux/pci.h>
  80892. +
  80893. +#include <linux/version.h>
  80894. +
  80895. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
  80896. +# include <linux/irq.h>
  80897. +#endif
  80898. +
  80899. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
  80900. +# include <linux/usb/ch9.h>
  80901. +#else
  80902. +# include <linux/usb_ch9.h>
  80903. +#endif
  80904. +
  80905. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
  80906. +# include <linux/usb/gadget.h>
  80907. +#else
  80908. +# include <linux/usb_gadget.h>
  80909. +#endif
  80910. +
  80911. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)
  80912. +# include <asm/irq.h>
  80913. +#endif
  80914. +
  80915. +#ifdef PCI_INTERFACE
  80916. +# include <asm/io.h>
  80917. +#endif
  80918. +
  80919. +#ifdef LM_INTERFACE
  80920. +# include <asm/unaligned.h>
  80921. +# include <asm/sizes.h>
  80922. +# include <asm/param.h>
  80923. +# include <asm/io.h>
  80924. +# if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30))
  80925. +# include <asm/arch/hardware.h>
  80926. +# include <asm/arch/lm.h>
  80927. +# include <asm/arch/irqs.h>
  80928. +# include <asm/arch/regs-irq.h>
  80929. +# else
  80930. +/* in 2.6.31, at least, we seem to have lost the generic LM infrastructure -
  80931. + here we assume that the machine architecture provides definitions
  80932. + in its own header
  80933. +*/
  80934. +# include <mach/lm.h>
  80935. +# include <mach/hardware.h>
  80936. +# endif
  80937. +#endif
  80938. +
  80939. +#ifdef PLATFORM_INTERFACE
  80940. +#include <linux/platform_device.h>
  80941. +#include <asm/mach/map.h>
  80942. +#endif
  80943. +
  80944. +/** The OS page size */
  80945. +#define DWC_OS_PAGE_SIZE PAGE_SIZE
  80946. +
  80947. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14)
  80948. +typedef int gfp_t;
  80949. +#endif
  80950. +
  80951. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
  80952. +# define IRQF_SHARED SA_SHIRQ
  80953. +#endif
  80954. +
  80955. +typedef struct os_dependent {
  80956. + /** Base address returned from ioremap() */
  80957. + void *base;
  80958. +
  80959. + /** Register offset for Diagnostic API */
  80960. + uint32_t reg_offset;
  80961. +
  80962. + /** Base address for MPHI peripheral */
  80963. + void *mphi_base;
  80964. +
  80965. +#ifdef LM_INTERFACE
  80966. + struct lm_device *lmdev;
  80967. +#elif defined(PCI_INTERFACE)
  80968. + struct pci_dev *pcidev;
  80969. +
  80970. + /** Start address of a PCI region */
  80971. + resource_size_t rsrc_start;
  80972. +
  80973. + /** Length address of a PCI region */
  80974. + resource_size_t rsrc_len;
  80975. +#elif defined(PLATFORM_INTERFACE)
  80976. + struct platform_device *platformdev;
  80977. +#endif
  80978. +
  80979. +} os_dependent_t;
  80980. +
  80981. +#ifdef __cplusplus
  80982. +}
  80983. +#endif
  80984. +
  80985. +
  80986. +
  80987. +/* Type for the our device on the chosen bus */
  80988. +#if defined(LM_INTERFACE)
  80989. +typedef struct lm_device dwc_bus_dev_t;
  80990. +#elif defined(PCI_INTERFACE)
  80991. +typedef struct pci_dev dwc_bus_dev_t;
  80992. +#elif defined(PLATFORM_INTERFACE)
  80993. +typedef struct platform_device dwc_bus_dev_t;
  80994. +#endif
  80995. +
  80996. +/* Helper macro to retrieve drvdata from the device on the chosen bus */
  80997. +#if defined(LM_INTERFACE)
  80998. +#define DWC_OTG_BUSDRVDATA(_dev) lm_get_drvdata(_dev)
  80999. +#elif defined(PCI_INTERFACE)
  81000. +#define DWC_OTG_BUSDRVDATA(_dev) pci_get_drvdata(_dev)
  81001. +#elif defined(PLATFORM_INTERFACE)
  81002. +#define DWC_OTG_BUSDRVDATA(_dev) platform_get_drvdata(_dev)
  81003. +#endif
  81004. +
  81005. +/**
  81006. + * Helper macro returning the otg_device structure of a given struct device
  81007. + *
  81008. + * c.f. static dwc_otg_device_t *dwc_otg_drvdev(struct device *_dev)
  81009. + */
  81010. +#ifdef LM_INTERFACE
  81011. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81012. + struct lm_device *lm_dev = \
  81013. + container_of(_dev, struct lm_device, dev); \
  81014. + _var = lm_get_drvdata(lm_dev); \
  81015. + } while (0)
  81016. +
  81017. +#elif defined(PCI_INTERFACE)
  81018. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81019. + _var = dev_get_drvdata(_dev); \
  81020. + } while (0)
  81021. +
  81022. +#elif defined(PLATFORM_INTERFACE)
  81023. +#define DWC_OTG_GETDRVDEV(_var, _dev) do { \
  81024. + struct platform_device *platform_dev = \
  81025. + container_of(_dev, struct platform_device, dev); \
  81026. + _var = platform_get_drvdata(platform_dev); \
  81027. + } while (0)
  81028. +#endif
  81029. +
  81030. +
  81031. +/**
  81032. + * Helper macro returning the struct dev of the given struct os_dependent
  81033. + *
  81034. + * c.f. static struct device *dwc_otg_getdev(struct os_dependent *osdep)
  81035. + */
  81036. +#ifdef LM_INTERFACE
  81037. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81038. + ((_osdep).lmdev == NULL? NULL: &(_osdep).lmdev->dev)
  81039. +#elif defined(PCI_INTERFACE)
  81040. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81041. + ((_osdep).pci_dev == NULL? NULL: &(_osdep).pci_dev->dev)
  81042. +#elif defined(PLATFORM_INTERFACE)
  81043. +#define DWC_OTG_OS_GETDEV(_osdep) \
  81044. + ((_osdep).platformdev == NULL? NULL: &(_osdep).platformdev->dev)
  81045. +#endif
  81046. +
  81047. +
  81048. +
  81049. +
  81050. +#endif /* _DWC_OS_DEP_H_ */
  81051. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c
  81052. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 1970-01-01 01:00:00.000000000 +0100
  81053. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.c 2014-06-11 21:03:43.000000000 +0200
  81054. @@ -0,0 +1,2708 @@
  81055. +/* ==========================================================================
  81056. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.c $
  81057. + * $Revision: #101 $
  81058. + * $Date: 2012/08/10 $
  81059. + * $Change: 2047372 $
  81060. + *
  81061. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  81062. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  81063. + * otherwise expressly agreed to in writing between Synopsys and you.
  81064. + *
  81065. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  81066. + * any End User Software License Agreement or Agreement for Licensed Product
  81067. + * with Synopsys or any supplement thereto. You are permitted to use and
  81068. + * redistribute this Software in source and binary forms, with or without
  81069. + * modification, provided that redistributions of source code must retain this
  81070. + * notice. You may not view, use, disclose, copy or distribute this file or
  81071. + * any information contained herein except pursuant to this license grant from
  81072. + * Synopsys. If you do not agree with this notice, including the disclaimer
  81073. + * below, then you are not authorized to use the Software.
  81074. + *
  81075. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  81076. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  81077. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  81078. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  81079. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  81080. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  81081. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81082. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  81083. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  81084. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  81085. + * DAMAGE.
  81086. + * ========================================================================== */
  81087. +#ifndef DWC_HOST_ONLY
  81088. +
  81089. +/** @file
  81090. + * This file implements PCD Core. All code in this file is portable and doesn't
  81091. + * use any OS specific functions.
  81092. + * PCD Core provides Interface, defined in <code><dwc_otg_pcd_if.h></code>
  81093. + * header file, which can be used to implement OS specific PCD interface.
  81094. + *
  81095. + * An important function of the PCD is managing interrupts generated
  81096. + * by the DWC_otg controller. The implementation of the DWC_otg device
  81097. + * mode interrupt service routines is in dwc_otg_pcd_intr.c.
  81098. + *
  81099. + * @todo Add Device Mode test modes (Test J mode, Test K mode, etc).
  81100. + * @todo Does it work when the request size is greater than DEPTSIZ
  81101. + * transfer size
  81102. + *
  81103. + */
  81104. +
  81105. +#include "dwc_otg_pcd.h"
  81106. +
  81107. +#ifdef DWC_UTE_CFI
  81108. +#include "dwc_otg_cfi.h"
  81109. +
  81110. +extern int init_cfi(cfiobject_t * cfiobj);
  81111. +#endif
  81112. +
  81113. +/**
  81114. + * Choose endpoint from ep arrays using usb_ep structure.
  81115. + */
  81116. +static dwc_otg_pcd_ep_t *get_ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  81117. +{
  81118. + int i;
  81119. + if (pcd->ep0.priv == handle) {
  81120. + return &pcd->ep0;
  81121. + }
  81122. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  81123. + if (pcd->in_ep[i].priv == handle)
  81124. + return &pcd->in_ep[i];
  81125. + if (pcd->out_ep[i].priv == handle)
  81126. + return &pcd->out_ep[i];
  81127. + }
  81128. +
  81129. + return NULL;
  81130. +}
  81131. +
  81132. +/**
  81133. + * This function completes a request. It call's the request call back.
  81134. + */
  81135. +void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req,
  81136. + int32_t status)
  81137. +{
  81138. + unsigned stopped = ep->stopped;
  81139. +
  81140. + DWC_DEBUGPL(DBG_PCDV, "%s(ep %p req %p)\n", __func__, ep, req);
  81141. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  81142. +
  81143. + /* don't modify queue heads during completion callback */
  81144. + ep->stopped = 1;
  81145. + /* spin_unlock/spin_lock now done in fops->complete() */
  81146. + ep->pcd->fops->complete(ep->pcd, ep->priv, req->priv, status,
  81147. + req->actual);
  81148. +
  81149. + if (ep->pcd->request_pending > 0) {
  81150. + --ep->pcd->request_pending;
  81151. + }
  81152. +
  81153. + ep->stopped = stopped;
  81154. + DWC_FREE(req);
  81155. +}
  81156. +
  81157. +/**
  81158. + * This function terminates all the requsts in the EP request queue.
  81159. + */
  81160. +void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep)
  81161. +{
  81162. + dwc_otg_pcd_request_t *req;
  81163. +
  81164. + ep->stopped = 1;
  81165. +
  81166. + /* called with irqs blocked?? */
  81167. + while (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  81168. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  81169. + dwc_otg_request_done(ep, req, -DWC_E_SHUTDOWN);
  81170. + }
  81171. +}
  81172. +
  81173. +void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  81174. + const struct dwc_otg_pcd_function_ops *fops)
  81175. +{
  81176. + pcd->fops = fops;
  81177. +}
  81178. +
  81179. +/**
  81180. + * PCD Callback function for initializing the PCD when switching to
  81181. + * device mode.
  81182. + *
  81183. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81184. + */
  81185. +static int32_t dwc_otg_pcd_start_cb(void *p)
  81186. +{
  81187. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81188. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  81189. +
  81190. + /*
  81191. + * Initialized the Core for Device mode.
  81192. + */
  81193. + if (dwc_otg_is_device_mode(core_if)) {
  81194. + dwc_otg_core_dev_init(core_if);
  81195. + /* Set core_if's lock pointer to the pcd->lock */
  81196. + core_if->lock = pcd->lock;
  81197. + }
  81198. + return 1;
  81199. +}
  81200. +
  81201. +/** CFI-specific buffer allocation function for EP */
  81202. +#ifdef DWC_UTE_CFI
  81203. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  81204. + size_t buflen, int flags)
  81205. +{
  81206. + dwc_otg_pcd_ep_t *ep;
  81207. + ep = get_ep_from_handle(pcd, pep);
  81208. + if (!ep) {
  81209. + DWC_WARN("bad ep\n");
  81210. + return -DWC_E_INVALID;
  81211. + }
  81212. +
  81213. + return pcd->cfi->ops.ep_alloc_buf(pcd->cfi, pcd, ep, addr, buflen,
  81214. + flags);
  81215. +}
  81216. +#else
  81217. +uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep, dwc_dma_t * addr,
  81218. + size_t buflen, int flags);
  81219. +#endif
  81220. +
  81221. +/**
  81222. + * PCD Callback function for notifying the PCD when resuming from
  81223. + * suspend.
  81224. + *
  81225. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81226. + */
  81227. +static int32_t dwc_otg_pcd_resume_cb(void *p)
  81228. +{
  81229. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81230. +
  81231. + if (pcd->fops->resume) {
  81232. + pcd->fops->resume(pcd);
  81233. + }
  81234. +
  81235. + /* Stop the SRP timeout timer. */
  81236. + if ((GET_CORE_IF(pcd)->core_params->phy_type != DWC_PHY_TYPE_PARAM_FS)
  81237. + || (!GET_CORE_IF(pcd)->core_params->i2c_enable)) {
  81238. + if (GET_CORE_IF(pcd)->srp_timer_started) {
  81239. + GET_CORE_IF(pcd)->srp_timer_started = 0;
  81240. + DWC_TIMER_CANCEL(GET_CORE_IF(pcd)->srp_timer);
  81241. + }
  81242. + }
  81243. + return 1;
  81244. +}
  81245. +
  81246. +/**
  81247. + * PCD Callback function for notifying the PCD device is suspended.
  81248. + *
  81249. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81250. + */
  81251. +static int32_t dwc_otg_pcd_suspend_cb(void *p)
  81252. +{
  81253. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81254. +
  81255. + if (pcd->fops->suspend) {
  81256. + DWC_SPINUNLOCK(pcd->lock);
  81257. + pcd->fops->suspend(pcd);
  81258. + DWC_SPINLOCK(pcd->lock);
  81259. + }
  81260. +
  81261. + return 1;
  81262. +}
  81263. +
  81264. +/**
  81265. + * PCD Callback function for stopping the PCD when switching to Host
  81266. + * mode.
  81267. + *
  81268. + * @param p void pointer to the <code>dwc_otg_pcd_t</code>
  81269. + */
  81270. +static int32_t dwc_otg_pcd_stop_cb(void *p)
  81271. +{
  81272. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) p;
  81273. + extern void dwc_otg_pcd_stop(dwc_otg_pcd_t * _pcd);
  81274. +
  81275. + dwc_otg_pcd_stop(pcd);
  81276. + return 1;
  81277. +}
  81278. +
  81279. +/**
  81280. + * PCD Callback structure for handling mode switching.
  81281. + */
  81282. +static dwc_otg_cil_callbacks_t pcd_callbacks = {
  81283. + .start = dwc_otg_pcd_start_cb,
  81284. + .stop = dwc_otg_pcd_stop_cb,
  81285. + .suspend = dwc_otg_pcd_suspend_cb,
  81286. + .resume_wakeup = dwc_otg_pcd_resume_cb,
  81287. + .p = 0, /* Set at registration */
  81288. +};
  81289. +
  81290. +/**
  81291. + * This function allocates a DMA Descriptor chain for the Endpoint
  81292. + * buffer to be used for a transfer to/from the specified endpoint.
  81293. + */
  81294. +dwc_otg_dev_dma_desc_t *dwc_otg_ep_alloc_desc_chain(dwc_dma_t * dma_desc_addr,
  81295. + uint32_t count)
  81296. +{
  81297. + return DWC_DMA_ALLOC_ATOMIC(count * sizeof(dwc_otg_dev_dma_desc_t),
  81298. + dma_desc_addr);
  81299. +}
  81300. +
  81301. +/**
  81302. + * This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
  81303. + */
  81304. +void dwc_otg_ep_free_desc_chain(dwc_otg_dev_dma_desc_t * desc_addr,
  81305. + uint32_t dma_desc_addr, uint32_t count)
  81306. +{
  81307. + DWC_DMA_FREE(count * sizeof(dwc_otg_dev_dma_desc_t), desc_addr,
  81308. + dma_desc_addr);
  81309. +}
  81310. +
  81311. +#ifdef DWC_EN_ISOC
  81312. +
  81313. +/**
  81314. + * This function initializes a descriptor chain for Isochronous transfer
  81315. + *
  81316. + * @param core_if Programming view of DWC_otg controller.
  81317. + * @param dwc_ep The EP to start the transfer on.
  81318. + *
  81319. + */
  81320. +void dwc_otg_iso_ep_start_ddma_transfer(dwc_otg_core_if_t * core_if,
  81321. + dwc_ep_t * dwc_ep)
  81322. +{
  81323. +
  81324. + dsts_data_t dsts = {.d32 = 0 };
  81325. + depctl_data_t depctl = {.d32 = 0 };
  81326. + volatile uint32_t *addr;
  81327. + int i, j;
  81328. + uint32_t len;
  81329. +
  81330. + if (dwc_ep->is_in)
  81331. + dwc_ep->desc_cnt = dwc_ep->buf_proc_intrvl / dwc_ep->bInterval;
  81332. + else
  81333. + dwc_ep->desc_cnt =
  81334. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81335. + dwc_ep->bInterval;
  81336. +
  81337. + /** Allocate descriptors for double buffering */
  81338. + dwc_ep->iso_desc_addr =
  81339. + dwc_otg_ep_alloc_desc_chain(&dwc_ep->iso_dma_desc_addr,
  81340. + dwc_ep->desc_cnt * 2);
  81341. + if (dwc_ep->desc_addr) {
  81342. + DWC_WARN("%s, can't allocate DMA descriptor chain\n", __func__);
  81343. + return;
  81344. + }
  81345. +
  81346. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81347. +
  81348. + /** ISO OUT EP */
  81349. + if (dwc_ep->is_in == 0) {
  81350. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  81351. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  81352. + dma_addr_t dma_ad;
  81353. + uint32_t data_per_desc;
  81354. + dwc_otg_dev_out_ep_regs_t *out_regs =
  81355. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  81356. + int offset;
  81357. +
  81358. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  81359. + dma_ad = (dma_addr_t) DWC_READ_REG32(&(out_regs->doepdma));
  81360. +
  81361. + /** Buffer 0 descriptors setup */
  81362. + dma_ad = dwc_ep->dma_addr0;
  81363. +
  81364. + sts.b_iso_out.bs = BS_HOST_READY;
  81365. + sts.b_iso_out.rxsts = 0;
  81366. + sts.b_iso_out.l = 0;
  81367. + sts.b_iso_out.sp = 0;
  81368. + sts.b_iso_out.ioc = 0;
  81369. + sts.b_iso_out.pid = 0;
  81370. + sts.b_iso_out.framenum = 0;
  81371. +
  81372. + offset = 0;
  81373. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81374. + i += dwc_ep->pkt_per_frm) {
  81375. +
  81376. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  81377. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81378. + if (len > dwc_ep->data_per_frame)
  81379. + data_per_desc =
  81380. + dwc_ep->data_per_frame -
  81381. + j * dwc_ep->maxpacket;
  81382. + else
  81383. + data_per_desc = dwc_ep->maxpacket;
  81384. + len = data_per_desc % 4;
  81385. + if (len)
  81386. + data_per_desc += 4 - len;
  81387. +
  81388. + sts.b_iso_out.rxbytes = data_per_desc;
  81389. + dma_desc->buf = dma_ad;
  81390. + dma_desc->status.d32 = sts.d32;
  81391. +
  81392. + offset += data_per_desc;
  81393. + dma_desc++;
  81394. + dma_ad += data_per_desc;
  81395. + }
  81396. + }
  81397. +
  81398. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  81399. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81400. + if (len > dwc_ep->data_per_frame)
  81401. + data_per_desc =
  81402. + dwc_ep->data_per_frame -
  81403. + j * dwc_ep->maxpacket;
  81404. + else
  81405. + data_per_desc = dwc_ep->maxpacket;
  81406. + len = data_per_desc % 4;
  81407. + if (len)
  81408. + data_per_desc += 4 - len;
  81409. + sts.b_iso_out.rxbytes = data_per_desc;
  81410. + dma_desc->buf = dma_ad;
  81411. + dma_desc->status.d32 = sts.d32;
  81412. +
  81413. + offset += data_per_desc;
  81414. + dma_desc++;
  81415. + dma_ad += data_per_desc;
  81416. + }
  81417. +
  81418. + sts.b_iso_out.ioc = 1;
  81419. + len = (j + 1) * dwc_ep->maxpacket;
  81420. + if (len > dwc_ep->data_per_frame)
  81421. + data_per_desc =
  81422. + dwc_ep->data_per_frame - j * dwc_ep->maxpacket;
  81423. + else
  81424. + data_per_desc = dwc_ep->maxpacket;
  81425. + len = data_per_desc % 4;
  81426. + if (len)
  81427. + data_per_desc += 4 - len;
  81428. + sts.b_iso_out.rxbytes = data_per_desc;
  81429. +
  81430. + dma_desc->buf = dma_ad;
  81431. + dma_desc->status.d32 = sts.d32;
  81432. + dma_desc++;
  81433. +
  81434. + /** Buffer 1 descriptors setup */
  81435. + sts.b_iso_out.ioc = 0;
  81436. + dma_ad = dwc_ep->dma_addr1;
  81437. +
  81438. + offset = 0;
  81439. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81440. + i += dwc_ep->pkt_per_frm) {
  81441. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  81442. + uint32_t len = (j + 1) * dwc_ep->maxpacket;
  81443. + if (len > dwc_ep->data_per_frame)
  81444. + data_per_desc =
  81445. + dwc_ep->data_per_frame -
  81446. + j * dwc_ep->maxpacket;
  81447. + else
  81448. + data_per_desc = dwc_ep->maxpacket;
  81449. + len = data_per_desc % 4;
  81450. + if (len)
  81451. + data_per_desc += 4 - len;
  81452. +
  81453. + data_per_desc =
  81454. + sts.b_iso_out.rxbytes = data_per_desc;
  81455. + dma_desc->buf = dma_ad;
  81456. + dma_desc->status.d32 = sts.d32;
  81457. +
  81458. + offset += data_per_desc;
  81459. + dma_desc++;
  81460. + dma_ad += data_per_desc;
  81461. + }
  81462. + }
  81463. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  81464. + data_per_desc =
  81465. + ((j + 1) * dwc_ep->maxpacket >
  81466. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  81467. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  81468. + data_per_desc +=
  81469. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  81470. + sts.b_iso_out.rxbytes = data_per_desc;
  81471. + dma_desc->buf = dma_ad;
  81472. + dma_desc->status.d32 = sts.d32;
  81473. +
  81474. + offset += data_per_desc;
  81475. + dma_desc++;
  81476. + dma_ad += data_per_desc;
  81477. + }
  81478. +
  81479. + sts.b_iso_out.ioc = 1;
  81480. + sts.b_iso_out.l = 1;
  81481. + data_per_desc =
  81482. + ((j + 1) * dwc_ep->maxpacket >
  81483. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  81484. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  81485. + data_per_desc +=
  81486. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  81487. + sts.b_iso_out.rxbytes = data_per_desc;
  81488. +
  81489. + dma_desc->buf = dma_ad;
  81490. + dma_desc->status.d32 = sts.d32;
  81491. +
  81492. + dwc_ep->next_frame = 0;
  81493. +
  81494. + /** Write dma_ad into DOEPDMA register */
  81495. + DWC_WRITE_REG32(&(out_regs->doepdma),
  81496. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  81497. +
  81498. + }
  81499. + /** ISO IN EP */
  81500. + else {
  81501. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  81502. + dwc_otg_dev_dma_desc_t *dma_desc = dwc_ep->iso_desc_addr;
  81503. + dma_addr_t dma_ad;
  81504. + dwc_otg_dev_in_ep_regs_t *in_regs =
  81505. + core_if->dev_if->in_ep_regs[dwc_ep->num];
  81506. + unsigned int frmnumber;
  81507. + fifosize_data_t txfifosize, rxfifosize;
  81508. +
  81509. + txfifosize.d32 =
  81510. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[dwc_ep->num]->
  81511. + dtxfsts);
  81512. + rxfifosize.d32 =
  81513. + DWC_READ_REG32(&core_if->core_global_regs->grxfsiz);
  81514. +
  81515. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  81516. +
  81517. + dma_ad = dwc_ep->dma_addr0;
  81518. +
  81519. + dsts.d32 =
  81520. + DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81521. +
  81522. + sts.b_iso_in.bs = BS_HOST_READY;
  81523. + sts.b_iso_in.txsts = 0;
  81524. + sts.b_iso_in.sp =
  81525. + (dwc_ep->data_per_frame % dwc_ep->maxpacket) ? 1 : 0;
  81526. + sts.b_iso_in.ioc = 0;
  81527. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  81528. +
  81529. + frmnumber = dwc_ep->next_frame;
  81530. +
  81531. + sts.b_iso_in.framenum = frmnumber;
  81532. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  81533. + sts.b_iso_in.l = 0;
  81534. +
  81535. + /** Buffer 0 descriptors setup */
  81536. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  81537. + dma_desc->buf = dma_ad;
  81538. + dma_desc->status.d32 = sts.d32;
  81539. + dma_desc++;
  81540. +
  81541. + dma_ad += dwc_ep->data_per_frame;
  81542. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  81543. + }
  81544. +
  81545. + sts.b_iso_in.ioc = 1;
  81546. + dma_desc->buf = dma_ad;
  81547. + dma_desc->status.d32 = sts.d32;
  81548. + ++dma_desc;
  81549. +
  81550. + /** Buffer 1 descriptors setup */
  81551. + sts.b_iso_in.ioc = 0;
  81552. + dma_ad = dwc_ep->dma_addr1;
  81553. +
  81554. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  81555. + i += dwc_ep->pkt_per_frm) {
  81556. + dma_desc->buf = dma_ad;
  81557. + dma_desc->status.d32 = sts.d32;
  81558. + dma_desc++;
  81559. +
  81560. + dma_ad += dwc_ep->data_per_frame;
  81561. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  81562. +
  81563. + sts.b_iso_in.ioc = 0;
  81564. + }
  81565. + sts.b_iso_in.ioc = 1;
  81566. + sts.b_iso_in.l = 1;
  81567. +
  81568. + dma_desc->buf = dma_ad;
  81569. + dma_desc->status.d32 = sts.d32;
  81570. +
  81571. + dwc_ep->next_frame = sts.b_iso_in.framenum + dwc_ep->bInterval;
  81572. +
  81573. + /** Write dma_ad into diepdma register */
  81574. + DWC_WRITE_REG32(&(in_regs->diepdma),
  81575. + (uint32_t) dwc_ep->iso_dma_desc_addr);
  81576. + }
  81577. + /** Enable endpoint, clear nak */
  81578. + depctl.d32 = 0;
  81579. + depctl.b.epena = 1;
  81580. + depctl.b.usbactep = 1;
  81581. + depctl.b.cnak = 1;
  81582. +
  81583. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  81584. + depctl.d32 = DWC_READ_REG32(addr);
  81585. +}
  81586. +
  81587. +/**
  81588. + * This function initializes a descriptor chain for Isochronous transfer
  81589. + *
  81590. + * @param core_if Programming view of DWC_otg controller.
  81591. + * @param ep The EP to start the transfer on.
  81592. + *
  81593. + */
  81594. +void dwc_otg_iso_ep_start_buf_transfer(dwc_otg_core_if_t * core_if,
  81595. + dwc_ep_t * ep)
  81596. +{
  81597. + depctl_data_t depctl = {.d32 = 0 };
  81598. + volatile uint32_t *addr;
  81599. +
  81600. + if (ep->is_in) {
  81601. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  81602. + } else {
  81603. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  81604. + }
  81605. +
  81606. + if (core_if->dma_enable == 0 || core_if->dma_desc_enable != 0) {
  81607. + return;
  81608. + } else {
  81609. + deptsiz_data_t deptsiz = {.d32 = 0 };
  81610. +
  81611. + ep->xfer_len =
  81612. + ep->data_per_frame * ep->buf_proc_intrvl / ep->bInterval;
  81613. + ep->pkt_cnt =
  81614. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  81615. + ep->xfer_count = 0;
  81616. + ep->xfer_buff =
  81617. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  81618. + ep->dma_addr =
  81619. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  81620. +
  81621. + if (ep->is_in) {
  81622. + /* Program the transfer size and packet count
  81623. + * as follows: xfersize = N * maxpacket +
  81624. + * short_packet pktcnt = N + (short_packet
  81625. + * exist ? 1 : 0)
  81626. + */
  81627. + deptsiz.b.mc = ep->pkt_per_frm;
  81628. + deptsiz.b.xfersize = ep->xfer_len;
  81629. + deptsiz.b.pktcnt =
  81630. + (ep->xfer_len - 1 + ep->maxpacket) / ep->maxpacket;
  81631. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  81632. + dieptsiz, deptsiz.d32);
  81633. +
  81634. + /* Write the DMA register */
  81635. + DWC_WRITE_REG32(&
  81636. + (core_if->dev_if->in_ep_regs[ep->num]->
  81637. + diepdma), (uint32_t) ep->dma_addr);
  81638. +
  81639. + } else {
  81640. + deptsiz.b.pktcnt =
  81641. + (ep->xfer_len + (ep->maxpacket - 1)) /
  81642. + ep->maxpacket;
  81643. + deptsiz.b.xfersize = deptsiz.b.pktcnt * ep->maxpacket;
  81644. +
  81645. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  81646. + doeptsiz, deptsiz.d32);
  81647. +
  81648. + /* Write the DMA register */
  81649. + DWC_WRITE_REG32(&
  81650. + (core_if->dev_if->out_ep_regs[ep->num]->
  81651. + doepdma), (uint32_t) ep->dma_addr);
  81652. +
  81653. + }
  81654. + /** Enable endpoint, clear nak */
  81655. + depctl.d32 = 0;
  81656. + depctl.b.epena = 1;
  81657. + depctl.b.cnak = 1;
  81658. +
  81659. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  81660. + }
  81661. +}
  81662. +
  81663. +/**
  81664. + * This function does the setup for a data transfer for an EP and
  81665. + * starts the transfer. For an IN transfer, the packets will be
  81666. + * loaded into the appropriate Tx FIFO in the ISR. For OUT transfers,
  81667. + * the packets are unloaded from the Rx FIFO in the ISR.
  81668. + *
  81669. + * @param core_if Programming view of DWC_otg controller.
  81670. + * @param ep The EP to start the transfer on.
  81671. + */
  81672. +
  81673. +static void dwc_otg_iso_ep_start_transfer(dwc_otg_core_if_t * core_if,
  81674. + dwc_ep_t * ep)
  81675. +{
  81676. + if (core_if->dma_enable) {
  81677. + if (core_if->dma_desc_enable) {
  81678. + if (ep->is_in) {
  81679. + ep->desc_cnt = ep->pkt_cnt / ep->pkt_per_frm;
  81680. + } else {
  81681. + ep->desc_cnt = ep->pkt_cnt;
  81682. + }
  81683. + dwc_otg_iso_ep_start_ddma_transfer(core_if, ep);
  81684. + } else {
  81685. + if (core_if->pti_enh_enable) {
  81686. + dwc_otg_iso_ep_start_buf_transfer(core_if, ep);
  81687. + } else {
  81688. + ep->cur_pkt_addr =
  81689. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->
  81690. + xfer_buff0;
  81691. + ep->cur_pkt_dma_addr =
  81692. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->
  81693. + dma_addr0;
  81694. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  81695. + }
  81696. + }
  81697. + } else {
  81698. + ep->cur_pkt_addr =
  81699. + (ep->proc_buf_num) ? ep->xfer_buff1 : ep->xfer_buff0;
  81700. + ep->cur_pkt_dma_addr =
  81701. + (ep->proc_buf_num) ? ep->dma_addr1 : ep->dma_addr0;
  81702. + dwc_otg_iso_ep_start_frm_transfer(core_if, ep);
  81703. + }
  81704. +}
  81705. +
  81706. +/**
  81707. + * This function stops transfer for an EP and
  81708. + * resets the ep's variables.
  81709. + *
  81710. + * @param core_if Programming view of DWC_otg controller.
  81711. + * @param ep The EP to start the transfer on.
  81712. + */
  81713. +
  81714. +void dwc_otg_iso_ep_stop_transfer(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  81715. +{
  81716. + depctl_data_t depctl = {.d32 = 0 };
  81717. + volatile uint32_t *addr;
  81718. +
  81719. + if (ep->is_in == 1) {
  81720. + addr = &core_if->dev_if->in_ep_regs[ep->num]->diepctl;
  81721. + } else {
  81722. + addr = &core_if->dev_if->out_ep_regs[ep->num]->doepctl;
  81723. + }
  81724. +
  81725. + /* disable the ep */
  81726. + depctl.d32 = DWC_READ_REG32(addr);
  81727. +
  81728. + depctl.b.epdis = 1;
  81729. + depctl.b.snak = 1;
  81730. +
  81731. + DWC_WRITE_REG32(addr, depctl.d32);
  81732. +
  81733. + if (core_if->dma_desc_enable &&
  81734. + ep->iso_desc_addr && ep->iso_dma_desc_addr) {
  81735. + dwc_otg_ep_free_desc_chain(ep->iso_desc_addr,
  81736. + ep->iso_dma_desc_addr,
  81737. + ep->desc_cnt * 2);
  81738. + }
  81739. +
  81740. + /* reset varibales */
  81741. + ep->dma_addr0 = 0;
  81742. + ep->dma_addr1 = 0;
  81743. + ep->xfer_buff0 = 0;
  81744. + ep->xfer_buff1 = 0;
  81745. + ep->data_per_frame = 0;
  81746. + ep->data_pattern_frame = 0;
  81747. + ep->sync_frame = 0;
  81748. + ep->buf_proc_intrvl = 0;
  81749. + ep->bInterval = 0;
  81750. + ep->proc_buf_num = 0;
  81751. + ep->pkt_per_frm = 0;
  81752. + ep->pkt_per_frm = 0;
  81753. + ep->desc_cnt = 0;
  81754. + ep->iso_desc_addr = 0;
  81755. + ep->iso_dma_desc_addr = 0;
  81756. +}
  81757. +
  81758. +int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  81759. + uint8_t * buf0, uint8_t * buf1, dwc_dma_t dma0,
  81760. + dwc_dma_t dma1, int sync_frame, int dp_frame,
  81761. + int data_per_frame, int start_frame,
  81762. + int buf_proc_intrvl, void *req_handle,
  81763. + int atomic_alloc)
  81764. +{
  81765. + dwc_otg_pcd_ep_t *ep;
  81766. + dwc_irqflags_t flags = 0;
  81767. + dwc_ep_t *dwc_ep;
  81768. + int32_t frm_data;
  81769. + dsts_data_t dsts;
  81770. + dwc_otg_core_if_t *core_if;
  81771. +
  81772. + ep = get_ep_from_handle(pcd, ep_handle);
  81773. +
  81774. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  81775. + DWC_WARN("bad ep\n");
  81776. + return -DWC_E_INVALID;
  81777. + }
  81778. +
  81779. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81780. + core_if = GET_CORE_IF(pcd);
  81781. + dwc_ep = &ep->dwc_ep;
  81782. +
  81783. + if (ep->iso_req_handle) {
  81784. + DWC_WARN("ISO request in progress\n");
  81785. + }
  81786. +
  81787. + dwc_ep->dma_addr0 = dma0;
  81788. + dwc_ep->dma_addr1 = dma1;
  81789. +
  81790. + dwc_ep->xfer_buff0 = buf0;
  81791. + dwc_ep->xfer_buff1 = buf1;
  81792. +
  81793. + dwc_ep->data_per_frame = data_per_frame;
  81794. +
  81795. + /** @todo - pattern data support is to be implemented in the future */
  81796. + dwc_ep->data_pattern_frame = dp_frame;
  81797. + dwc_ep->sync_frame = sync_frame;
  81798. +
  81799. + dwc_ep->buf_proc_intrvl = buf_proc_intrvl;
  81800. +
  81801. + dwc_ep->bInterval = 1 << (ep->desc->bInterval - 1);
  81802. +
  81803. + dwc_ep->proc_buf_num = 0;
  81804. +
  81805. + dwc_ep->pkt_per_frm = 0;
  81806. + frm_data = ep->dwc_ep.data_per_frame;
  81807. + while (frm_data > 0) {
  81808. + dwc_ep->pkt_per_frm++;
  81809. + frm_data -= ep->dwc_ep.maxpacket;
  81810. + }
  81811. +
  81812. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  81813. +
  81814. + if (start_frame == -1) {
  81815. + dwc_ep->next_frame = dsts.b.soffn + 1;
  81816. + if (dwc_ep->bInterval != 1) {
  81817. + dwc_ep->next_frame =
  81818. + dwc_ep->next_frame + (dwc_ep->bInterval - 1 -
  81819. + dwc_ep->next_frame %
  81820. + dwc_ep->bInterval);
  81821. + }
  81822. + } else {
  81823. + dwc_ep->next_frame = start_frame;
  81824. + }
  81825. +
  81826. + if (!core_if->pti_enh_enable) {
  81827. + dwc_ep->pkt_cnt =
  81828. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81829. + dwc_ep->bInterval;
  81830. + } else {
  81831. + dwc_ep->pkt_cnt =
  81832. + (dwc_ep->data_per_frame *
  81833. + (dwc_ep->buf_proc_intrvl / dwc_ep->bInterval)
  81834. + - 1 + dwc_ep->maxpacket) / dwc_ep->maxpacket;
  81835. + }
  81836. +
  81837. + if (core_if->dma_desc_enable) {
  81838. + dwc_ep->desc_cnt =
  81839. + dwc_ep->buf_proc_intrvl * dwc_ep->pkt_per_frm /
  81840. + dwc_ep->bInterval;
  81841. + }
  81842. +
  81843. + if (atomic_alloc) {
  81844. + dwc_ep->pkt_info =
  81845. + DWC_ALLOC_ATOMIC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81846. + } else {
  81847. + dwc_ep->pkt_info =
  81848. + DWC_ALLOC(sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81849. + }
  81850. + if (!dwc_ep->pkt_info) {
  81851. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81852. + return -DWC_E_NO_MEMORY;
  81853. + }
  81854. + if (core_if->pti_enh_enable) {
  81855. + dwc_memset(dwc_ep->pkt_info, 0,
  81856. + sizeof(iso_pkt_info_t) * dwc_ep->pkt_cnt);
  81857. + }
  81858. +
  81859. + dwc_ep->cur_pkt = 0;
  81860. + ep->iso_req_handle = req_handle;
  81861. +
  81862. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81863. + dwc_otg_iso_ep_start_transfer(core_if, dwc_ep);
  81864. + return 0;
  81865. +}
  81866. +
  81867. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  81868. + void *req_handle)
  81869. +{
  81870. + dwc_irqflags_t flags = 0;
  81871. + dwc_otg_pcd_ep_t *ep;
  81872. + dwc_ep_t *dwc_ep;
  81873. +
  81874. + ep = get_ep_from_handle(pcd, ep_handle);
  81875. + if (!ep || !ep->desc || ep->dwc_ep.num == 0) {
  81876. + DWC_WARN("bad ep\n");
  81877. + return -DWC_E_INVALID;
  81878. + }
  81879. + dwc_ep = &ep->dwc_ep;
  81880. +
  81881. + dwc_otg_iso_ep_stop_transfer(GET_CORE_IF(pcd), dwc_ep);
  81882. +
  81883. + DWC_FREE(dwc_ep->pkt_info);
  81884. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  81885. + if (ep->iso_req_handle != req_handle) {
  81886. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81887. + return -DWC_E_INVALID;
  81888. + }
  81889. +
  81890. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  81891. +
  81892. + ep->iso_req_handle = 0;
  81893. + return 0;
  81894. +}
  81895. +
  81896. +/**
  81897. + * This function is used for perodical data exchnage between PCD and gadget drivers.
  81898. + * for Isochronous EPs
  81899. + *
  81900. + * - Every time a sync period completes this function is called to
  81901. + * perform data exchange between PCD and gadget
  81902. + */
  81903. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  81904. + void *req_handle)
  81905. +{
  81906. + int i;
  81907. + dwc_ep_t *dwc_ep;
  81908. +
  81909. + dwc_ep = &ep->dwc_ep;
  81910. +
  81911. + DWC_SPINUNLOCK(ep->pcd->lock);
  81912. + pcd->fops->isoc_complete(pcd, ep->priv, ep->iso_req_handle,
  81913. + dwc_ep->proc_buf_num ^ 0x1);
  81914. + DWC_SPINLOCK(ep->pcd->lock);
  81915. +
  81916. + for (i = 0; i < dwc_ep->pkt_cnt; ++i) {
  81917. + dwc_ep->pkt_info[i].status = 0;
  81918. + dwc_ep->pkt_info[i].offset = 0;
  81919. + dwc_ep->pkt_info[i].length = 0;
  81920. + }
  81921. +}
  81922. +
  81923. +int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd, void *ep_handle,
  81924. + void *iso_req_handle)
  81925. +{
  81926. + dwc_otg_pcd_ep_t *ep;
  81927. + dwc_ep_t *dwc_ep;
  81928. +
  81929. + ep = get_ep_from_handle(pcd, ep_handle);
  81930. + if (!ep->desc || ep->dwc_ep.num == 0) {
  81931. + DWC_WARN("bad ep\n");
  81932. + return -DWC_E_INVALID;
  81933. + }
  81934. + dwc_ep = &ep->dwc_ep;
  81935. +
  81936. + return dwc_ep->pkt_cnt;
  81937. +}
  81938. +
  81939. +void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd, void *ep_handle,
  81940. + void *iso_req_handle, int packet,
  81941. + int *status, int *actual, int *offset)
  81942. +{
  81943. + dwc_otg_pcd_ep_t *ep;
  81944. + dwc_ep_t *dwc_ep;
  81945. +
  81946. + ep = get_ep_from_handle(pcd, ep_handle);
  81947. + if (!ep)
  81948. + DWC_WARN("bad ep\n");
  81949. +
  81950. + dwc_ep = &ep->dwc_ep;
  81951. +
  81952. + *status = dwc_ep->pkt_info[packet].status;
  81953. + *actual = dwc_ep->pkt_info[packet].length;
  81954. + *offset = dwc_ep->pkt_info[packet].offset;
  81955. +}
  81956. +
  81957. +#endif /* DWC_EN_ISOC */
  81958. +
  81959. +static void dwc_otg_pcd_init_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * pcd_ep,
  81960. + uint32_t is_in, uint32_t ep_num)
  81961. +{
  81962. + /* Init EP structure */
  81963. + pcd_ep->desc = 0;
  81964. + pcd_ep->pcd = pcd;
  81965. + pcd_ep->stopped = 1;
  81966. + pcd_ep->queue_sof = 0;
  81967. +
  81968. + /* Init DWC ep structure */
  81969. + pcd_ep->dwc_ep.is_in = is_in;
  81970. + pcd_ep->dwc_ep.num = ep_num;
  81971. + pcd_ep->dwc_ep.active = 0;
  81972. + pcd_ep->dwc_ep.tx_fifo_num = 0;
  81973. + /* Control until ep is actvated */
  81974. + pcd_ep->dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  81975. + pcd_ep->dwc_ep.maxpacket = MAX_PACKET_SIZE;
  81976. + pcd_ep->dwc_ep.dma_addr = 0;
  81977. + pcd_ep->dwc_ep.start_xfer_buff = 0;
  81978. + pcd_ep->dwc_ep.xfer_buff = 0;
  81979. + pcd_ep->dwc_ep.xfer_len = 0;
  81980. + pcd_ep->dwc_ep.xfer_count = 0;
  81981. + pcd_ep->dwc_ep.sent_zlp = 0;
  81982. + pcd_ep->dwc_ep.total_len = 0;
  81983. + pcd_ep->dwc_ep.desc_addr = 0;
  81984. + pcd_ep->dwc_ep.dma_desc_addr = 0;
  81985. + DWC_CIRCLEQ_INIT(&pcd_ep->queue);
  81986. +}
  81987. +
  81988. +/**
  81989. + * Initialize ep's
  81990. + */
  81991. +static void dwc_otg_pcd_reinit(dwc_otg_pcd_t * pcd)
  81992. +{
  81993. + int i;
  81994. + uint32_t hwcfg1;
  81995. + dwc_otg_pcd_ep_t *ep;
  81996. + int in_ep_cntr, out_ep_cntr;
  81997. + uint32_t num_in_eps = (GET_CORE_IF(pcd))->dev_if->num_in_eps;
  81998. + uint32_t num_out_eps = (GET_CORE_IF(pcd))->dev_if->num_out_eps;
  81999. +
  82000. + /**
  82001. + * Initialize the EP0 structure.
  82002. + */
  82003. + ep = &pcd->ep0;
  82004. + dwc_otg_pcd_init_ep(pcd, ep, 0, 0);
  82005. +
  82006. + in_ep_cntr = 0;
  82007. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 3;
  82008. + for (i = 1; in_ep_cntr < num_in_eps; i++) {
  82009. + if ((hwcfg1 & 0x1) == 0) {
  82010. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[in_ep_cntr];
  82011. + in_ep_cntr++;
  82012. + /**
  82013. + * @todo NGS: Add direction to EP, based on contents
  82014. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  82015. + * sprintf(";r
  82016. + */
  82017. + dwc_otg_pcd_init_ep(pcd, ep, 1 /* IN */ , i);
  82018. +
  82019. + DWC_CIRCLEQ_INIT(&ep->queue);
  82020. + }
  82021. + hwcfg1 >>= 2;
  82022. + }
  82023. +
  82024. + out_ep_cntr = 0;
  82025. + hwcfg1 = (GET_CORE_IF(pcd))->hwcfg1.d32 >> 2;
  82026. + for (i = 1; out_ep_cntr < num_out_eps; i++) {
  82027. + if ((hwcfg1 & 0x1) == 0) {
  82028. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[out_ep_cntr];
  82029. + out_ep_cntr++;
  82030. + /**
  82031. + * @todo NGS: Add direction to EP, based on contents
  82032. + * of HWCFG1. Need a copy of HWCFG1 in pcd structure?
  82033. + * sprintf(";r
  82034. + */
  82035. + dwc_otg_pcd_init_ep(pcd, ep, 0 /* OUT */ , i);
  82036. + DWC_CIRCLEQ_INIT(&ep->queue);
  82037. + }
  82038. + hwcfg1 >>= 2;
  82039. + }
  82040. +
  82041. + pcd->ep0state = EP0_DISCONNECT;
  82042. + pcd->ep0.dwc_ep.maxpacket = MAX_EP0_SIZE;
  82043. + pcd->ep0.dwc_ep.type = DWC_OTG_EP_TYPE_CONTROL;
  82044. +}
  82045. +
  82046. +/**
  82047. + * This function is called when the SRP timer expires. The SRP should
  82048. + * complete within 6 seconds.
  82049. + */
  82050. +static void srp_timeout(void *ptr)
  82051. +{
  82052. + gotgctl_data_t gotgctl;
  82053. + dwc_otg_core_if_t *core_if = (dwc_otg_core_if_t *) ptr;
  82054. + volatile uint32_t *addr = &core_if->core_global_regs->gotgctl;
  82055. +
  82056. + gotgctl.d32 = DWC_READ_REG32(addr);
  82057. +
  82058. + core_if->srp_timer_started = 0;
  82059. +
  82060. + if (core_if->adp_enable) {
  82061. + if (gotgctl.b.bsesvld == 0) {
  82062. + gpwrdn_data_t gpwrdn = {.d32 = 0 };
  82063. + DWC_PRINTF("SRP Timeout BSESSVLD = 0\n");
  82064. + /* Power off the core */
  82065. + if (core_if->power_down == 2) {
  82066. + gpwrdn.b.pwrdnswtch = 1;
  82067. + DWC_MODIFY_REG32(&core_if->
  82068. + core_global_regs->gpwrdn,
  82069. + gpwrdn.d32, 0);
  82070. + }
  82071. +
  82072. + gpwrdn.d32 = 0;
  82073. + gpwrdn.b.pmuintsel = 1;
  82074. + gpwrdn.b.pmuactv = 1;
  82075. + DWC_MODIFY_REG32(&core_if->core_global_regs->gpwrdn, 0,
  82076. + gpwrdn.d32);
  82077. + dwc_otg_adp_probe_start(core_if);
  82078. + } else {
  82079. + DWC_PRINTF("SRP Timeout BSESSVLD = 1\n");
  82080. + core_if->op_state = B_PERIPHERAL;
  82081. + dwc_otg_core_init(core_if);
  82082. + dwc_otg_enable_global_interrupts(core_if);
  82083. + cil_pcd_start(core_if);
  82084. + }
  82085. + }
  82086. +
  82087. + if ((core_if->core_params->phy_type == DWC_PHY_TYPE_PARAM_FS) &&
  82088. + (core_if->core_params->i2c_enable)) {
  82089. + DWC_PRINTF("SRP Timeout\n");
  82090. +
  82091. + if ((core_if->srp_success) && (gotgctl.b.bsesvld)) {
  82092. + if (core_if->pcd_cb && core_if->pcd_cb->resume_wakeup) {
  82093. + core_if->pcd_cb->resume_wakeup(core_if->pcd_cb->p);
  82094. + }
  82095. +
  82096. + /* Clear Session Request */
  82097. + gotgctl.d32 = 0;
  82098. + gotgctl.b.sesreq = 1;
  82099. + DWC_MODIFY_REG32(&core_if->core_global_regs->gotgctl,
  82100. + gotgctl.d32, 0);
  82101. +
  82102. + core_if->srp_success = 0;
  82103. + } else {
  82104. + __DWC_ERROR("Device not connected/responding\n");
  82105. + gotgctl.b.sesreq = 0;
  82106. + DWC_WRITE_REG32(addr, gotgctl.d32);
  82107. + }
  82108. + } else if (gotgctl.b.sesreq) {
  82109. + DWC_PRINTF("SRP Timeout\n");
  82110. +
  82111. + __DWC_ERROR("Device not connected/responding\n");
  82112. + gotgctl.b.sesreq = 0;
  82113. + DWC_WRITE_REG32(addr, gotgctl.d32);
  82114. + } else {
  82115. + DWC_PRINTF(" SRP GOTGCTL=%0x\n", gotgctl.d32);
  82116. + }
  82117. +}
  82118. +
  82119. +/**
  82120. + * Tasklet
  82121. + *
  82122. + */
  82123. +extern void start_next_request(dwc_otg_pcd_ep_t * ep);
  82124. +
  82125. +static void start_xfer_tasklet_func(void *data)
  82126. +{
  82127. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  82128. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82129. +
  82130. + int i;
  82131. + depctl_data_t diepctl;
  82132. +
  82133. + DWC_DEBUGPL(DBG_PCDV, "Start xfer tasklet\n");
  82134. +
  82135. + diepctl.d32 = DWC_READ_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl);
  82136. +
  82137. + if (pcd->ep0.queue_sof) {
  82138. + pcd->ep0.queue_sof = 0;
  82139. + start_next_request(&pcd->ep0);
  82140. + // break;
  82141. + }
  82142. +
  82143. + for (i = 0; i < core_if->dev_if->num_in_eps; i++) {
  82144. + depctl_data_t diepctl;
  82145. + diepctl.d32 =
  82146. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[i]->diepctl);
  82147. +
  82148. + if (pcd->in_ep[i].queue_sof) {
  82149. + pcd->in_ep[i].queue_sof = 0;
  82150. + start_next_request(&pcd->in_ep[i]);
  82151. + // break;
  82152. + }
  82153. + }
  82154. +
  82155. + return;
  82156. +}
  82157. +
  82158. +/**
  82159. + * This function initialized the PCD portion of the driver.
  82160. + *
  82161. + */
  82162. +dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if)
  82163. +{
  82164. + dwc_otg_pcd_t *pcd = NULL;
  82165. + dwc_otg_dev_if_t *dev_if;
  82166. + int i;
  82167. +
  82168. + /*
  82169. + * Allocate PCD structure
  82170. + */
  82171. + pcd = DWC_ALLOC(sizeof(dwc_otg_pcd_t));
  82172. +
  82173. + if (pcd == NULL) {
  82174. + return NULL;
  82175. + }
  82176. +
  82177. + pcd->lock = DWC_SPINLOCK_ALLOC();
  82178. + DWC_DEBUGPL(DBG_HCDV, "Init of PCD %p given core_if %p\n",
  82179. + pcd, core_if);//GRAYG
  82180. + if (!pcd->lock) {
  82181. + DWC_ERROR("Could not allocate lock for pcd");
  82182. + DWC_FREE(pcd);
  82183. + return NULL;
  82184. + }
  82185. + /* Set core_if's lock pointer to hcd->lock */
  82186. + core_if->lock = pcd->lock;
  82187. + pcd->core_if = core_if;
  82188. +
  82189. + dev_if = core_if->dev_if;
  82190. + dev_if->isoc_ep = NULL;
  82191. +
  82192. + if (core_if->hwcfg4.b.ded_fifo_en) {
  82193. + DWC_PRINTF("Dedicated Tx FIFOs mode\n");
  82194. + } else {
  82195. + DWC_PRINTF("Shared Tx FIFO mode\n");
  82196. + }
  82197. +
  82198. + /*
  82199. + * Initialized the Core for Device mode here if there is nod ADP support.
  82200. + * Otherwise it will be done later in dwc_otg_adp_start routine.
  82201. + */
  82202. + if (dwc_otg_is_device_mode(core_if) /*&& !core_if->adp_enable*/) {
  82203. + dwc_otg_core_dev_init(core_if);
  82204. + }
  82205. +
  82206. + /*
  82207. + * Register the PCD Callbacks.
  82208. + */
  82209. + dwc_otg_cil_register_pcd_callbacks(core_if, &pcd_callbacks, pcd);
  82210. +
  82211. + /*
  82212. + * Initialize the DMA buffer for SETUP packets
  82213. + */
  82214. + if (GET_CORE_IF(pcd)->dma_enable) {
  82215. + pcd->setup_pkt =
  82216. + DWC_DMA_ALLOC(sizeof(*pcd->setup_pkt) * 5,
  82217. + &pcd->setup_pkt_dma_handle);
  82218. + if (pcd->setup_pkt == NULL) {
  82219. + DWC_FREE(pcd);
  82220. + return NULL;
  82221. + }
  82222. +
  82223. + pcd->status_buf =
  82224. + DWC_DMA_ALLOC(sizeof(uint16_t),
  82225. + &pcd->status_buf_dma_handle);
  82226. + if (pcd->status_buf == NULL) {
  82227. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  82228. + pcd->setup_pkt, pcd->setup_pkt_dma_handle);
  82229. + DWC_FREE(pcd);
  82230. + return NULL;
  82231. + }
  82232. +
  82233. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82234. + dev_if->setup_desc_addr[0] =
  82235. + dwc_otg_ep_alloc_desc_chain
  82236. + (&dev_if->dma_setup_desc_addr[0], 1);
  82237. + dev_if->setup_desc_addr[1] =
  82238. + dwc_otg_ep_alloc_desc_chain
  82239. + (&dev_if->dma_setup_desc_addr[1], 1);
  82240. + dev_if->in_desc_addr =
  82241. + dwc_otg_ep_alloc_desc_chain
  82242. + (&dev_if->dma_in_desc_addr, 1);
  82243. + dev_if->out_desc_addr =
  82244. + dwc_otg_ep_alloc_desc_chain
  82245. + (&dev_if->dma_out_desc_addr, 1);
  82246. + pcd->data_terminated = 0;
  82247. +
  82248. + if (dev_if->setup_desc_addr[0] == 0
  82249. + || dev_if->setup_desc_addr[1] == 0
  82250. + || dev_if->in_desc_addr == 0
  82251. + || dev_if->out_desc_addr == 0) {
  82252. +
  82253. + if (dev_if->out_desc_addr)
  82254. + dwc_otg_ep_free_desc_chain
  82255. + (dev_if->out_desc_addr,
  82256. + dev_if->dma_out_desc_addr, 1);
  82257. + if (dev_if->in_desc_addr)
  82258. + dwc_otg_ep_free_desc_chain
  82259. + (dev_if->in_desc_addr,
  82260. + dev_if->dma_in_desc_addr, 1);
  82261. + if (dev_if->setup_desc_addr[1])
  82262. + dwc_otg_ep_free_desc_chain
  82263. + (dev_if->setup_desc_addr[1],
  82264. + dev_if->dma_setup_desc_addr[1], 1);
  82265. + if (dev_if->setup_desc_addr[0])
  82266. + dwc_otg_ep_free_desc_chain
  82267. + (dev_if->setup_desc_addr[0],
  82268. + dev_if->dma_setup_desc_addr[0], 1);
  82269. +
  82270. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5,
  82271. + pcd->setup_pkt,
  82272. + pcd->setup_pkt_dma_handle);
  82273. + DWC_DMA_FREE(sizeof(*pcd->status_buf),
  82274. + pcd->status_buf,
  82275. + pcd->status_buf_dma_handle);
  82276. +
  82277. + DWC_FREE(pcd);
  82278. +
  82279. + return NULL;
  82280. + }
  82281. + }
  82282. + } else {
  82283. + pcd->setup_pkt = DWC_ALLOC(sizeof(*pcd->setup_pkt) * 5);
  82284. + if (pcd->setup_pkt == NULL) {
  82285. + DWC_FREE(pcd);
  82286. + return NULL;
  82287. + }
  82288. +
  82289. + pcd->status_buf = DWC_ALLOC(sizeof(uint16_t));
  82290. + if (pcd->status_buf == NULL) {
  82291. + DWC_FREE(pcd->setup_pkt);
  82292. + DWC_FREE(pcd);
  82293. + return NULL;
  82294. + }
  82295. + }
  82296. +
  82297. + dwc_otg_pcd_reinit(pcd);
  82298. +
  82299. + /* Allocate the cfi object for the PCD */
  82300. +#ifdef DWC_UTE_CFI
  82301. + pcd->cfi = DWC_ALLOC(sizeof(cfiobject_t));
  82302. + if (NULL == pcd->cfi)
  82303. + goto fail;
  82304. + if (init_cfi(pcd->cfi)) {
  82305. + CFI_INFO("%s: Failed to init the CFI object\n", __func__);
  82306. + goto fail;
  82307. + }
  82308. +#endif
  82309. +
  82310. + /* Initialize tasklets */
  82311. + pcd->start_xfer_tasklet = DWC_TASK_ALLOC("xfer_tasklet",
  82312. + start_xfer_tasklet_func, pcd);
  82313. + pcd->test_mode_tasklet = DWC_TASK_ALLOC("test_mode_tasklet",
  82314. + do_test_mode, pcd);
  82315. +
  82316. + /* Initialize SRP timer */
  82317. + core_if->srp_timer = DWC_TIMER_ALLOC("SRP TIMER", srp_timeout, core_if);
  82318. +
  82319. + if (core_if->core_params->dev_out_nak) {
  82320. + /**
  82321. + * Initialize xfer timeout timer. Implemented for
  82322. + * 2.93a feature "Device DDMA OUT NAK Enhancement"
  82323. + */
  82324. + for(i = 0; i < MAX_EPS_CHANNELS; i++) {
  82325. + pcd->core_if->ep_xfer_timer[i] =
  82326. + DWC_TIMER_ALLOC("ep timer", ep_xfer_timeout,
  82327. + &pcd->core_if->ep_xfer_info[i]);
  82328. + }
  82329. + }
  82330. +
  82331. + return pcd;
  82332. +#ifdef DWC_UTE_CFI
  82333. +fail:
  82334. +#endif
  82335. + if (pcd->setup_pkt)
  82336. + DWC_FREE(pcd->setup_pkt);
  82337. + if (pcd->status_buf)
  82338. + DWC_FREE(pcd->status_buf);
  82339. +#ifdef DWC_UTE_CFI
  82340. + if (pcd->cfi)
  82341. + DWC_FREE(pcd->cfi);
  82342. +#endif
  82343. + if (pcd)
  82344. + DWC_FREE(pcd);
  82345. + return NULL;
  82346. +
  82347. +}
  82348. +
  82349. +/**
  82350. + * Remove PCD specific data
  82351. + */
  82352. +void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd)
  82353. +{
  82354. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  82355. + int i;
  82356. + if (pcd->core_if->core_params->dev_out_nak) {
  82357. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82358. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[i]);
  82359. + pcd->core_if->ep_xfer_info[i].state = 0;
  82360. + }
  82361. + }
  82362. +
  82363. + if (GET_CORE_IF(pcd)->dma_enable) {
  82364. + DWC_DMA_FREE(sizeof(*pcd->setup_pkt) * 5, pcd->setup_pkt,
  82365. + pcd->setup_pkt_dma_handle);
  82366. + DWC_DMA_FREE(sizeof(uint16_t), pcd->status_buf,
  82367. + pcd->status_buf_dma_handle);
  82368. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82369. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[0],
  82370. + dev_if->dma_setup_desc_addr
  82371. + [0], 1);
  82372. + dwc_otg_ep_free_desc_chain(dev_if->setup_desc_addr[1],
  82373. + dev_if->dma_setup_desc_addr
  82374. + [1], 1);
  82375. + dwc_otg_ep_free_desc_chain(dev_if->in_desc_addr,
  82376. + dev_if->dma_in_desc_addr, 1);
  82377. + dwc_otg_ep_free_desc_chain(dev_if->out_desc_addr,
  82378. + dev_if->dma_out_desc_addr,
  82379. + 1);
  82380. + }
  82381. + } else {
  82382. + DWC_FREE(pcd->setup_pkt);
  82383. + DWC_FREE(pcd->status_buf);
  82384. + }
  82385. + DWC_SPINLOCK_FREE(pcd->lock);
  82386. + /* Set core_if's lock pointer to NULL */
  82387. + pcd->core_if->lock = NULL;
  82388. +
  82389. + DWC_TASK_FREE(pcd->start_xfer_tasklet);
  82390. + DWC_TASK_FREE(pcd->test_mode_tasklet);
  82391. + if (pcd->core_if->core_params->dev_out_nak) {
  82392. + for (i = 0; i < MAX_EPS_CHANNELS; i++) {
  82393. + if (pcd->core_if->ep_xfer_timer[i]) {
  82394. + DWC_TIMER_FREE(pcd->core_if->ep_xfer_timer[i]);
  82395. + }
  82396. + }
  82397. + }
  82398. +
  82399. +/* Release the CFI object's dynamic memory */
  82400. +#ifdef DWC_UTE_CFI
  82401. + if (pcd->cfi->ops.release) {
  82402. + pcd->cfi->ops.release(pcd->cfi);
  82403. + }
  82404. +#endif
  82405. +
  82406. + DWC_FREE(pcd);
  82407. +}
  82408. +
  82409. +/**
  82410. + * Returns whether registered pcd is dual speed or not
  82411. + */
  82412. +uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd)
  82413. +{
  82414. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82415. +
  82416. + if ((core_if->core_params->speed == DWC_SPEED_PARAM_FULL) ||
  82417. + ((core_if->hwcfg2.b.hs_phy_type == 2) &&
  82418. + (core_if->hwcfg2.b.fs_phy_type == 1) &&
  82419. + (core_if->core_params->ulpi_fs_ls))) {
  82420. + return 0;
  82421. + }
  82422. +
  82423. + return 1;
  82424. +}
  82425. +
  82426. +/**
  82427. + * Returns whether registered pcd is OTG capable or not
  82428. + */
  82429. +uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd)
  82430. +{
  82431. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  82432. + gusbcfg_data_t usbcfg = {.d32 = 0 };
  82433. +
  82434. + usbcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->gusbcfg);
  82435. + if (!usbcfg.b.srpcap || !usbcfg.b.hnpcap) {
  82436. + return 0;
  82437. + }
  82438. +
  82439. + return 1;
  82440. +}
  82441. +
  82442. +/**
  82443. + * This function assigns periodic Tx FIFO to an periodic EP
  82444. + * in shared Tx FIFO mode
  82445. + */
  82446. +static uint32_t assign_tx_fifo(dwc_otg_core_if_t * core_if)
  82447. +{
  82448. + uint32_t TxMsk = 1;
  82449. + int i;
  82450. +
  82451. + for (i = 0; i < core_if->hwcfg4.b.num_in_eps; ++i) {
  82452. + if ((TxMsk & core_if->tx_msk) == 0) {
  82453. + core_if->tx_msk |= TxMsk;
  82454. + return i + 1;
  82455. + }
  82456. + TxMsk <<= 1;
  82457. + }
  82458. + return 0;
  82459. +}
  82460. +
  82461. +/**
  82462. + * This function assigns periodic Tx FIFO to an periodic EP
  82463. + * in shared Tx FIFO mode
  82464. + */
  82465. +static uint32_t assign_perio_tx_fifo(dwc_otg_core_if_t * core_if)
  82466. +{
  82467. + uint32_t PerTxMsk = 1;
  82468. + int i;
  82469. + for (i = 0; i < core_if->hwcfg4.b.num_dev_perio_in_ep; ++i) {
  82470. + if ((PerTxMsk & core_if->p_tx_msk) == 0) {
  82471. + core_if->p_tx_msk |= PerTxMsk;
  82472. + return i + 1;
  82473. + }
  82474. + PerTxMsk <<= 1;
  82475. + }
  82476. + return 0;
  82477. +}
  82478. +
  82479. +/**
  82480. + * This function releases periodic Tx FIFO
  82481. + * in shared Tx FIFO mode
  82482. + */
  82483. +static void release_perio_tx_fifo(dwc_otg_core_if_t * core_if,
  82484. + uint32_t fifo_num)
  82485. +{
  82486. + core_if->p_tx_msk =
  82487. + (core_if->p_tx_msk & (1 << (fifo_num - 1))) ^ core_if->p_tx_msk;
  82488. +}
  82489. +
  82490. +/**
  82491. + * This function releases periodic Tx FIFO
  82492. + * in shared Tx FIFO mode
  82493. + */
  82494. +static void release_tx_fifo(dwc_otg_core_if_t * core_if, uint32_t fifo_num)
  82495. +{
  82496. + core_if->tx_msk =
  82497. + (core_if->tx_msk & (1 << (fifo_num - 1))) ^ core_if->tx_msk;
  82498. +}
  82499. +
  82500. +/**
  82501. + * This function is being called from gadget
  82502. + * to enable PCD endpoint.
  82503. + */
  82504. +int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  82505. + const uint8_t * ep_desc, void *usb_ep)
  82506. +{
  82507. + int num, dir;
  82508. + dwc_otg_pcd_ep_t *ep = NULL;
  82509. + const usb_endpoint_descriptor_t *desc;
  82510. + dwc_irqflags_t flags;
  82511. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  82512. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  82513. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  82514. + int retval = 0;
  82515. + int i, epcount;
  82516. +
  82517. + desc = (const usb_endpoint_descriptor_t *)ep_desc;
  82518. +
  82519. + if (!desc) {
  82520. + pcd->ep0.priv = usb_ep;
  82521. + ep = &pcd->ep0;
  82522. + retval = -DWC_E_INVALID;
  82523. + goto out;
  82524. + }
  82525. +
  82526. + num = UE_GET_ADDR(desc->bEndpointAddress);
  82527. + dir = UE_GET_DIR(desc->bEndpointAddress);
  82528. +
  82529. + if (!desc->wMaxPacketSize) {
  82530. + DWC_WARN("bad maxpacketsize\n");
  82531. + retval = -DWC_E_INVALID;
  82532. + goto out;
  82533. + }
  82534. +
  82535. + if (dir == UE_DIR_IN) {
  82536. + epcount = pcd->core_if->dev_if->num_in_eps;
  82537. + for (i = 0; i < epcount; i++) {
  82538. + if (num == pcd->in_ep[i].dwc_ep.num) {
  82539. + ep = &pcd->in_ep[i];
  82540. + break;
  82541. + }
  82542. + }
  82543. + } else {
  82544. + epcount = pcd->core_if->dev_if->num_out_eps;
  82545. + for (i = 0; i < epcount; i++) {
  82546. + if (num == pcd->out_ep[i].dwc_ep.num) {
  82547. + ep = &pcd->out_ep[i];
  82548. + break;
  82549. + }
  82550. + }
  82551. + }
  82552. +
  82553. + if (!ep) {
  82554. + DWC_WARN("bad address\n");
  82555. + retval = -DWC_E_INVALID;
  82556. + goto out;
  82557. + }
  82558. +
  82559. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82560. +
  82561. + ep->desc = desc;
  82562. + ep->priv = usb_ep;
  82563. +
  82564. + /*
  82565. + * Activate the EP
  82566. + */
  82567. + ep->stopped = 0;
  82568. +
  82569. + ep->dwc_ep.is_in = (dir == UE_DIR_IN);
  82570. + ep->dwc_ep.maxpacket = UGETW(desc->wMaxPacketSize);
  82571. +
  82572. + ep->dwc_ep.type = desc->bmAttributes & UE_XFERTYPE;
  82573. +
  82574. + if (ep->dwc_ep.is_in) {
  82575. + if (!GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82576. + ep->dwc_ep.tx_fifo_num = 0;
  82577. +
  82578. + if (ep->dwc_ep.type == UE_ISOCHRONOUS) {
  82579. + /*
  82580. + * if ISOC EP then assign a Periodic Tx FIFO.
  82581. + */
  82582. + ep->dwc_ep.tx_fifo_num =
  82583. + assign_perio_tx_fifo(GET_CORE_IF(pcd));
  82584. + }
  82585. + } else {
  82586. + /*
  82587. + * if Dedicated FIFOs mode is on then assign a Tx FIFO.
  82588. + */
  82589. + ep->dwc_ep.tx_fifo_num =
  82590. + assign_tx_fifo(GET_CORE_IF(pcd));
  82591. + }
  82592. +
  82593. + /* Calculating EP info controller base address */
  82594. + if (ep->dwc_ep.tx_fifo_num
  82595. + && GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82596. + gdfifocfg.d32 =
  82597. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  82598. + core_global_regs->gdfifocfg);
  82599. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  82600. + dptxfsiz.d32 =
  82601. + (DWC_READ_REG32
  82602. + (&GET_CORE_IF(pcd)->core_global_regs->
  82603. + dtxfsiz[ep->dwc_ep.tx_fifo_num - 1]) >> 16);
  82604. + gdfifocfg.b.epinfobase =
  82605. + gdfifocfgbase.d32 + dptxfsiz.d32;
  82606. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  82607. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  82608. + core_global_regs->gdfifocfg,
  82609. + gdfifocfg.d32);
  82610. + }
  82611. + }
  82612. + }
  82613. + /* Set initial data PID. */
  82614. + if (ep->dwc_ep.type == UE_BULK) {
  82615. + ep->dwc_ep.data_pid_start = 0;
  82616. + }
  82617. +
  82618. + /* Alloc DMA Descriptors */
  82619. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82620. +#ifndef DWC_UTE_PER_IO
  82621. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  82622. +#endif
  82623. + ep->dwc_ep.desc_addr =
  82624. + dwc_otg_ep_alloc_desc_chain(&ep->
  82625. + dwc_ep.dma_desc_addr,
  82626. + MAX_DMA_DESC_CNT);
  82627. + if (!ep->dwc_ep.desc_addr) {
  82628. + DWC_WARN("%s, can't allocate DMA descriptor\n",
  82629. + __func__);
  82630. + retval = -DWC_E_SHUTDOWN;
  82631. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82632. + goto out;
  82633. + }
  82634. +#ifndef DWC_UTE_PER_IO
  82635. + }
  82636. +#endif
  82637. + }
  82638. +
  82639. + DWC_DEBUGPL(DBG_PCD, "Activate %s: type=%d, mps=%d desc=%p\n",
  82640. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  82641. + ep->dwc_ep.type, ep->dwc_ep.maxpacket, ep->desc);
  82642. +#ifdef DWC_UTE_PER_IO
  82643. + ep->dwc_ep.xiso_bInterval = 1 << (ep->desc->bInterval - 1);
  82644. +#endif
  82645. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  82646. + ep->dwc_ep.bInterval = 1 << (ep->desc->bInterval - 1);
  82647. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  82648. + }
  82649. +
  82650. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  82651. +
  82652. +#ifdef DWC_UTE_CFI
  82653. + if (pcd->cfi->ops.ep_enable) {
  82654. + pcd->cfi->ops.ep_enable(pcd->cfi, pcd, ep);
  82655. + }
  82656. +#endif
  82657. +
  82658. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82659. +
  82660. +out:
  82661. + return retval;
  82662. +}
  82663. +
  82664. +/**
  82665. + * This function is being called from gadget
  82666. + * to disable PCD endpoint.
  82667. + */
  82668. +int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle)
  82669. +{
  82670. + dwc_otg_pcd_ep_t *ep;
  82671. + dwc_irqflags_t flags;
  82672. + dwc_otg_dev_dma_desc_t *desc_addr;
  82673. + dwc_dma_t dma_desc_addr;
  82674. + gdfifocfg_data_t gdfifocfgbase = {.d32 = 0 };
  82675. + gdfifocfg_data_t gdfifocfg = {.d32 = 0 };
  82676. + fifosize_data_t dptxfsiz = {.d32 = 0 };
  82677. +
  82678. + ep = get_ep_from_handle(pcd, ep_handle);
  82679. +
  82680. + if (!ep || !ep->desc) {
  82681. + DWC_DEBUGPL(DBG_PCD, "bad ep address\n");
  82682. + return -DWC_E_INVALID;
  82683. + }
  82684. +
  82685. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  82686. +
  82687. + dwc_otg_request_nuke(ep);
  82688. +
  82689. + dwc_otg_ep_deactivate(GET_CORE_IF(pcd), &ep->dwc_ep);
  82690. + if (pcd->core_if->core_params->dev_out_nak) {
  82691. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[ep->dwc_ep.num]);
  82692. + pcd->core_if->ep_xfer_info[ep->dwc_ep.num].state = 0;
  82693. + }
  82694. + ep->desc = NULL;
  82695. + ep->stopped = 1;
  82696. +
  82697. + gdfifocfg.d32 =
  82698. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg);
  82699. + gdfifocfgbase.d32 = gdfifocfg.d32 >> 16;
  82700. +
  82701. + if (ep->dwc_ep.is_in) {
  82702. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82703. + /* Flush the Tx FIFO */
  82704. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd),
  82705. + ep->dwc_ep.tx_fifo_num);
  82706. + }
  82707. + release_perio_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  82708. + release_tx_fifo(GET_CORE_IF(pcd), ep->dwc_ep.tx_fifo_num);
  82709. + if (GET_CORE_IF(pcd)->en_multiple_tx_fifo) {
  82710. + /* Decreasing EPinfo Base Addr */
  82711. + dptxfsiz.d32 =
  82712. + (DWC_READ_REG32
  82713. + (&GET_CORE_IF(pcd)->
  82714. + core_global_regs->dtxfsiz[ep->dwc_ep.tx_fifo_num-1]) >> 16);
  82715. + gdfifocfg.b.epinfobase = gdfifocfgbase.d32 - dptxfsiz.d32;
  82716. + if (GET_CORE_IF(pcd)->snpsid <= OTG_CORE_REV_2_94a) {
  82717. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gdfifocfg,
  82718. + gdfifocfg.d32);
  82719. + }
  82720. + }
  82721. + }
  82722. +
  82723. + /* Free DMA Descriptors */
  82724. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  82725. + if (ep->dwc_ep.type != UE_ISOCHRONOUS) {
  82726. + desc_addr = ep->dwc_ep.desc_addr;
  82727. + dma_desc_addr = ep->dwc_ep.dma_desc_addr;
  82728. +
  82729. + /* Cannot call dma_free_coherent() with IRQs disabled */
  82730. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82731. + dwc_otg_ep_free_desc_chain(desc_addr, dma_desc_addr,
  82732. + MAX_DMA_DESC_CNT);
  82733. +
  82734. + goto out_unlocked;
  82735. + }
  82736. + }
  82737. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  82738. +
  82739. +out_unlocked:
  82740. + DWC_DEBUGPL(DBG_PCD, "%d %s disabled\n", ep->dwc_ep.num,
  82741. + ep->dwc_ep.is_in ? "IN" : "OUT");
  82742. + return 0;
  82743. +
  82744. +}
  82745. +
  82746. +/******************************************************************************/
  82747. +#ifdef DWC_UTE_PER_IO
  82748. +
  82749. +/**
  82750. + * Free the request and its extended parts
  82751. + *
  82752. + */
  82753. +void dwc_pcd_xiso_ereq_free(dwc_otg_pcd_ep_t * ep, dwc_otg_pcd_request_t * req)
  82754. +{
  82755. + DWC_FREE(req->ext_req.per_io_frame_descs);
  82756. + DWC_FREE(req);
  82757. +}
  82758. +
  82759. +/**
  82760. + * Start the next request in the endpoint's queue.
  82761. + *
  82762. + */
  82763. +int dwc_otg_pcd_xiso_start_next_request(dwc_otg_pcd_t * pcd,
  82764. + dwc_otg_pcd_ep_t * ep)
  82765. +{
  82766. + int i;
  82767. + dwc_otg_pcd_request_t *req = NULL;
  82768. + dwc_ep_t *dwcep = NULL;
  82769. + struct dwc_iso_xreq_port *ereq = NULL;
  82770. + struct dwc_iso_pkt_desc_port *ddesc_iso;
  82771. + uint16_t nat;
  82772. + depctl_data_t diepctl;
  82773. +
  82774. + dwcep = &ep->dwc_ep;
  82775. +
  82776. + if (dwcep->xiso_active_xfers > 0) {
  82777. +#if 0 //Disable this to decrease s/w overhead that is crucial for Isoc transfers
  82778. + DWC_WARN("There are currently active transfers for EP%d \
  82779. + (active=%d; queued=%d)", dwcep->num, dwcep->xiso_active_xfers,
  82780. + dwcep->xiso_queued_xfers);
  82781. +#endif
  82782. + return 0;
  82783. + }
  82784. +
  82785. + nat = UGETW(ep->desc->wMaxPacketSize);
  82786. + nat = (nat >> 11) & 0x03;
  82787. +
  82788. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82789. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82790. + ereq = &req->ext_req;
  82791. + ep->stopped = 0;
  82792. +
  82793. + /* Get the frame number */
  82794. + dwcep->xiso_frame_num =
  82795. + dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  82796. + DWC_DEBUG("FRM_NUM=%d", dwcep->xiso_frame_num);
  82797. +
  82798. + ddesc_iso = ereq->per_io_frame_descs;
  82799. +
  82800. + if (dwcep->is_in) {
  82801. + /* Setup DMA Descriptor chain for IN Isoc request */
  82802. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82803. + //if ((i % (nat + 1)) == 0)
  82804. + if ( i > 0 )
  82805. + dwcep->xiso_frame_num =
  82806. + (dwcep->xiso_bInterval +
  82807. + dwcep->xiso_frame_num) & 0x3FFF;
  82808. + dwcep->desc_addr[i].buf =
  82809. + req->dma + ddesc_iso[i].offset;
  82810. + dwcep->desc_addr[i].status.b_iso_in.txbytes =
  82811. + ddesc_iso[i].length;
  82812. + dwcep->desc_addr[i].status.b_iso_in.framenum =
  82813. + dwcep->xiso_frame_num;
  82814. + dwcep->desc_addr[i].status.b_iso_in.bs =
  82815. + BS_HOST_READY;
  82816. + dwcep->desc_addr[i].status.b_iso_in.txsts = 0;
  82817. + dwcep->desc_addr[i].status.b_iso_in.sp =
  82818. + (ddesc_iso[i].length %
  82819. + dwcep->maxpacket) ? 1 : 0;
  82820. + dwcep->desc_addr[i].status.b_iso_in.ioc = 0;
  82821. + dwcep->desc_addr[i].status.b_iso_in.pid = nat + 1;
  82822. + dwcep->desc_addr[i].status.b_iso_in.l = 0;
  82823. +
  82824. + /* Process the last descriptor */
  82825. + if (i == ereq->pio_pkt_count - 1) {
  82826. + dwcep->desc_addr[i].status.b_iso_in.ioc = 1;
  82827. + dwcep->desc_addr[i].status.b_iso_in.l = 1;
  82828. + }
  82829. + }
  82830. +
  82831. + /* Setup and start the transfer for this endpoint */
  82832. + dwcep->xiso_active_xfers++;
  82833. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->dev_if->
  82834. + in_ep_regs[dwcep->num]->diepdma,
  82835. + dwcep->dma_desc_addr);
  82836. + diepctl.d32 = 0;
  82837. + diepctl.b.epena = 1;
  82838. + diepctl.b.cnak = 1;
  82839. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->dev_if->
  82840. + in_ep_regs[dwcep->num]->diepctl, 0,
  82841. + diepctl.d32);
  82842. + } else {
  82843. + /* Setup DMA Descriptor chain for OUT Isoc request */
  82844. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82845. + //if ((i % (nat + 1)) == 0)
  82846. + dwcep->xiso_frame_num = (dwcep->xiso_bInterval +
  82847. + dwcep->xiso_frame_num) & 0x3FFF;
  82848. + dwcep->desc_addr[i].buf =
  82849. + req->dma + ddesc_iso[i].offset;
  82850. + dwcep->desc_addr[i].status.b_iso_out.rxbytes =
  82851. + ddesc_iso[i].length;
  82852. + dwcep->desc_addr[i].status.b_iso_out.framenum =
  82853. + dwcep->xiso_frame_num;
  82854. + dwcep->desc_addr[i].status.b_iso_out.bs =
  82855. + BS_HOST_READY;
  82856. + dwcep->desc_addr[i].status.b_iso_out.rxsts = 0;
  82857. + dwcep->desc_addr[i].status.b_iso_out.sp =
  82858. + (ddesc_iso[i].length %
  82859. + dwcep->maxpacket) ? 1 : 0;
  82860. + dwcep->desc_addr[i].status.b_iso_out.ioc = 0;
  82861. + dwcep->desc_addr[i].status.b_iso_out.pid = nat + 1;
  82862. + dwcep->desc_addr[i].status.b_iso_out.l = 0;
  82863. +
  82864. + /* Process the last descriptor */
  82865. + if (i == ereq->pio_pkt_count - 1) {
  82866. + dwcep->desc_addr[i].status.b_iso_out.ioc = 1;
  82867. + dwcep->desc_addr[i].status.b_iso_out.l = 1;
  82868. + }
  82869. + }
  82870. +
  82871. + /* Setup and start the transfer for this endpoint */
  82872. + dwcep->xiso_active_xfers++;
  82873. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->
  82874. + dev_if->out_ep_regs[dwcep->num]->
  82875. + doepdma, dwcep->dma_desc_addr);
  82876. + diepctl.d32 = 0;
  82877. + diepctl.b.epena = 1;
  82878. + diepctl.b.cnak = 1;
  82879. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  82880. + dev_if->out_ep_regs[dwcep->num]->
  82881. + doepctl, 0, diepctl.d32);
  82882. + }
  82883. +
  82884. + } else {
  82885. + ep->stopped = 1;
  82886. + }
  82887. +
  82888. + return 0;
  82889. +}
  82890. +
  82891. +/**
  82892. + * - Remove the request from the queue
  82893. + */
  82894. +void complete_xiso_ep(dwc_otg_pcd_ep_t * ep)
  82895. +{
  82896. + dwc_otg_pcd_request_t *req = NULL;
  82897. + struct dwc_iso_xreq_port *ereq = NULL;
  82898. + struct dwc_iso_pkt_desc_port *ddesc_iso = NULL;
  82899. + dwc_ep_t *dwcep = NULL;
  82900. + int i;
  82901. +
  82902. + //DWC_DEBUG();
  82903. + dwcep = &ep->dwc_ep;
  82904. +
  82905. + /* Get the first pending request from the queue */
  82906. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  82907. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  82908. + if (!req) {
  82909. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  82910. + return;
  82911. + }
  82912. + dwcep->xiso_active_xfers--;
  82913. + dwcep->xiso_queued_xfers--;
  82914. + /* Remove this request from the queue */
  82915. + DWC_CIRCLEQ_REMOVE_INIT(&ep->queue, req, queue_entry);
  82916. + } else {
  82917. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  82918. + return;
  82919. + }
  82920. +
  82921. + ep->stopped = 1;
  82922. + ereq = &req->ext_req;
  82923. + ddesc_iso = ereq->per_io_frame_descs;
  82924. +
  82925. + if (dwcep->xiso_active_xfers < 0) {
  82926. + DWC_WARN("EP#%d (xiso_active_xfers=%d)", dwcep->num,
  82927. + dwcep->xiso_active_xfers);
  82928. + }
  82929. +
  82930. + /* Fill the Isoc descs of portable extended req from dma descriptors */
  82931. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  82932. + if (dwcep->is_in) { /* IN endpoints */
  82933. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  82934. + dwcep->desc_addr[i].status.b_iso_in.txbytes;
  82935. + ddesc_iso[i].status =
  82936. + dwcep->desc_addr[i].status.b_iso_in.txsts;
  82937. + } else { /* OUT endpoints */
  82938. + ddesc_iso[i].actual_length = ddesc_iso[i].length -
  82939. + dwcep->desc_addr[i].status.b_iso_out.rxbytes;
  82940. + ddesc_iso[i].status =
  82941. + dwcep->desc_addr[i].status.b_iso_out.rxsts;
  82942. + }
  82943. + }
  82944. +
  82945. + DWC_SPINUNLOCK(ep->pcd->lock);
  82946. +
  82947. + /* Call the completion function in the non-portable logic */
  82948. + ep->pcd->fops->xisoc_complete(ep->pcd, ep->priv, req->priv, 0,
  82949. + &req->ext_req);
  82950. +
  82951. + DWC_SPINLOCK(ep->pcd->lock);
  82952. +
  82953. + /* Free the request - specific freeing needed for extended request object */
  82954. + dwc_pcd_xiso_ereq_free(ep, req);
  82955. +
  82956. + /* Start the next request */
  82957. + dwc_otg_pcd_xiso_start_next_request(ep->pcd, ep);
  82958. +
  82959. + return;
  82960. +}
  82961. +
  82962. +/**
  82963. + * Create and initialize the Isoc pkt descriptors of the extended request.
  82964. + *
  82965. + */
  82966. +static int dwc_otg_pcd_xiso_create_pkt_descs(dwc_otg_pcd_request_t * req,
  82967. + void *ereq_nonport,
  82968. + int atomic_alloc)
  82969. +{
  82970. + struct dwc_iso_xreq_port *ereq = NULL;
  82971. + struct dwc_iso_xreq_port *req_mapped = NULL;
  82972. + struct dwc_iso_pkt_desc_port *ipds = NULL; /* To be created in this function */
  82973. + uint32_t pkt_count;
  82974. + int i;
  82975. +
  82976. + ereq = &req->ext_req;
  82977. + req_mapped = (struct dwc_iso_xreq_port *)ereq_nonport;
  82978. + pkt_count = req_mapped->pio_pkt_count;
  82979. +
  82980. + /* Create the isoc descs */
  82981. + if (atomic_alloc) {
  82982. + ipds = DWC_ALLOC_ATOMIC(sizeof(*ipds) * pkt_count);
  82983. + } else {
  82984. + ipds = DWC_ALLOC(sizeof(*ipds) * pkt_count);
  82985. + }
  82986. +
  82987. + if (!ipds) {
  82988. + DWC_ERROR("Failed to allocate isoc descriptors");
  82989. + return -DWC_E_NO_MEMORY;
  82990. + }
  82991. +
  82992. + /* Initialize the extended request fields */
  82993. + ereq->per_io_frame_descs = ipds;
  82994. + ereq->error_count = 0;
  82995. + ereq->pio_alloc_pkt_count = pkt_count;
  82996. + ereq->pio_pkt_count = pkt_count;
  82997. + ereq->tr_sub_flags = req_mapped->tr_sub_flags;
  82998. +
  82999. + /* Init the Isoc descriptors */
  83000. + for (i = 0; i < pkt_count; i++) {
  83001. + ipds[i].length = req_mapped->per_io_frame_descs[i].length;
  83002. + ipds[i].offset = req_mapped->per_io_frame_descs[i].offset;
  83003. + ipds[i].status = req_mapped->per_io_frame_descs[i].status; /* 0 */
  83004. + ipds[i].actual_length =
  83005. + req_mapped->per_io_frame_descs[i].actual_length;
  83006. + }
  83007. +
  83008. + return 0;
  83009. +}
  83010. +
  83011. +static void prn_ext_request(struct dwc_iso_xreq_port *ereq)
  83012. +{
  83013. + struct dwc_iso_pkt_desc_port *xfd = NULL;
  83014. + int i;
  83015. +
  83016. + DWC_DEBUG("per_io_frame_descs=%p", ereq->per_io_frame_descs);
  83017. + DWC_DEBUG("tr_sub_flags=%d", ereq->tr_sub_flags);
  83018. + DWC_DEBUG("error_count=%d", ereq->error_count);
  83019. + DWC_DEBUG("pio_alloc_pkt_count=%d", ereq->pio_alloc_pkt_count);
  83020. + DWC_DEBUG("pio_pkt_count=%d", ereq->pio_pkt_count);
  83021. + DWC_DEBUG("res=%d", ereq->res);
  83022. +
  83023. + for (i = 0; i < ereq->pio_pkt_count; i++) {
  83024. + xfd = &ereq->per_io_frame_descs[0];
  83025. + DWC_DEBUG("FD #%d", i);
  83026. +
  83027. + DWC_DEBUG("xfd->actual_length=%d", xfd->actual_length);
  83028. + DWC_DEBUG("xfd->length=%d", xfd->length);
  83029. + DWC_DEBUG("xfd->offset=%d", xfd->offset);
  83030. + DWC_DEBUG("xfd->status=%d", xfd->status);
  83031. + }
  83032. +}
  83033. +
  83034. +/**
  83035. + *
  83036. + */
  83037. +int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83038. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  83039. + int zero, void *req_handle, int atomic_alloc,
  83040. + void *ereq_nonport)
  83041. +{
  83042. + dwc_otg_pcd_request_t *req = NULL;
  83043. + dwc_otg_pcd_ep_t *ep;
  83044. + dwc_irqflags_t flags;
  83045. + int res;
  83046. +
  83047. + ep = get_ep_from_handle(pcd, ep_handle);
  83048. + if (!ep) {
  83049. + DWC_WARN("bad ep\n");
  83050. + return -DWC_E_INVALID;
  83051. + }
  83052. +
  83053. + /* We support this extension only for DDMA mode */
  83054. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  83055. + if (!GET_CORE_IF(pcd)->dma_desc_enable)
  83056. + return -DWC_E_INVALID;
  83057. +
  83058. + /* Create a dwc_otg_pcd_request_t object */
  83059. + if (atomic_alloc) {
  83060. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  83061. + } else {
  83062. + req = DWC_ALLOC(sizeof(*req));
  83063. + }
  83064. +
  83065. + if (!req) {
  83066. + return -DWC_E_NO_MEMORY;
  83067. + }
  83068. +
  83069. + /* Create the Isoc descs for this request which shall be the exact match
  83070. + * of the structure sent to us from the non-portable logic */
  83071. + res =
  83072. + dwc_otg_pcd_xiso_create_pkt_descs(req, ereq_nonport, atomic_alloc);
  83073. + if (res) {
  83074. + DWC_WARN("Failed to init the Isoc descriptors");
  83075. + DWC_FREE(req);
  83076. + return res;
  83077. + }
  83078. +
  83079. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83080. +
  83081. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  83082. + req->buf = buf;
  83083. + req->dma = dma_buf;
  83084. + req->length = buflen;
  83085. + req->sent_zlp = zero;
  83086. + req->priv = req_handle;
  83087. +
  83088. + //DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83089. + ep->dwc_ep.dma_addr = dma_buf;
  83090. + ep->dwc_ep.start_xfer_buff = buf;
  83091. + ep->dwc_ep.xfer_buff = buf;
  83092. + ep->dwc_ep.xfer_len = 0;
  83093. + ep->dwc_ep.xfer_count = 0;
  83094. + ep->dwc_ep.sent_zlp = 0;
  83095. + ep->dwc_ep.total_len = buflen;
  83096. +
  83097. + /* Add this request to the tail */
  83098. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83099. + ep->dwc_ep.xiso_queued_xfers++;
  83100. +
  83101. +//DWC_DEBUG("CP_0");
  83102. +//DWC_DEBUG("req->ext_req.tr_sub_flags=%d", req->ext_req.tr_sub_flags);
  83103. +//prn_ext_request((struct dwc_iso_xreq_port *) ereq_nonport);
  83104. +//prn_ext_request(&req->ext_req);
  83105. +
  83106. + //DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83107. +
  83108. + /* If the req->status == ASAP then check if there is any active transfer
  83109. + * for this endpoint. If no active transfers, then get the first entry
  83110. + * from the queue and start that transfer
  83111. + */
  83112. + if (req->ext_req.tr_sub_flags == DWC_EREQ_TF_ASAP) {
  83113. + res = dwc_otg_pcd_xiso_start_next_request(pcd, ep);
  83114. + if (res) {
  83115. + DWC_WARN("Failed to start the next Isoc transfer");
  83116. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83117. + DWC_FREE(req);
  83118. + return res;
  83119. + }
  83120. + }
  83121. +
  83122. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83123. + return 0;
  83124. +}
  83125. +
  83126. +#endif
  83127. +/* END ifdef DWC_UTE_PER_IO ***************************************************/
  83128. +int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83129. + uint8_t * buf, dwc_dma_t dma_buf, uint32_t buflen,
  83130. + int zero, void *req_handle, int atomic_alloc)
  83131. +{
  83132. + dwc_irqflags_t flags;
  83133. + dwc_otg_pcd_request_t *req;
  83134. + dwc_otg_pcd_ep_t *ep;
  83135. + uint32_t max_transfer;
  83136. +
  83137. + ep = get_ep_from_handle(pcd, ep_handle);
  83138. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  83139. + DWC_WARN("bad ep\n");
  83140. + return -DWC_E_INVALID;
  83141. + }
  83142. +
  83143. + if (atomic_alloc) {
  83144. + req = DWC_ALLOC_ATOMIC(sizeof(*req));
  83145. + } else {
  83146. + req = DWC_ALLOC(sizeof(*req));
  83147. + }
  83148. +
  83149. + if (!req) {
  83150. + return -DWC_E_NO_MEMORY;
  83151. + }
  83152. + DWC_CIRCLEQ_INIT_ENTRY(req, queue_entry);
  83153. + if (!GET_CORE_IF(pcd)->core_params->opt) {
  83154. + if (ep->dwc_ep.num != 0) {
  83155. + DWC_ERROR("queue req %p, len %d buf %p\n",
  83156. + req_handle, buflen, buf);
  83157. + }
  83158. + }
  83159. +
  83160. + req->buf = buf;
  83161. + req->dma = dma_buf;
  83162. + req->length = buflen;
  83163. + req->sent_zlp = zero;
  83164. + req->priv = req_handle;
  83165. + req->dw_align_buf = NULL;
  83166. + if ((dma_buf & 0x3) && GET_CORE_IF(pcd)->dma_enable
  83167. + && !GET_CORE_IF(pcd)->dma_desc_enable)
  83168. + req->dw_align_buf = DWC_DMA_ALLOC(buflen,
  83169. + &req->dw_align_buf_dma);
  83170. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83171. +
  83172. + /*
  83173. + * After adding request to the queue for IN ISOC wait for In Token Received
  83174. + * when TX FIFO is empty interrupt and for OUT ISOC wait for OUT Token
  83175. + * Received when EP is disabled interrupt to obtain starting microframe
  83176. + * (odd/even) start transfer
  83177. + */
  83178. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  83179. + if (req != 0) {
  83180. + depctl_data_t depctl = {.d32 =
  83181. + DWC_READ_REG32(&pcd->core_if->dev_if->
  83182. + in_ep_regs[ep->dwc_ep.num]->
  83183. + diepctl) };
  83184. + ++pcd->request_pending;
  83185. +
  83186. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83187. + if (ep->dwc_ep.is_in) {
  83188. + depctl.b.cnak = 1;
  83189. + DWC_WRITE_REG32(&pcd->core_if->dev_if->
  83190. + in_ep_regs[ep->dwc_ep.num]->
  83191. + diepctl, depctl.d32);
  83192. + }
  83193. +
  83194. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83195. + }
  83196. + return 0;
  83197. + }
  83198. +
  83199. + /*
  83200. + * For EP0 IN without premature status, zlp is required?
  83201. + */
  83202. + if (ep->dwc_ep.num == 0 && ep->dwc_ep.is_in) {
  83203. + DWC_DEBUGPL(DBG_PCDV, "%d-OUT ZLP\n", ep->dwc_ep.num);
  83204. + //_req->zero = 1;
  83205. + }
  83206. +
  83207. + /* Start the transfer */
  83208. + if (DWC_CIRCLEQ_EMPTY(&ep->queue) && !ep->stopped) {
  83209. + /* EP0 Transfer? */
  83210. + if (ep->dwc_ep.num == 0) {
  83211. + switch (pcd->ep0state) {
  83212. + case EP0_IN_DATA_PHASE:
  83213. + DWC_DEBUGPL(DBG_PCD,
  83214. + "%s ep0: EP0_IN_DATA_PHASE\n",
  83215. + __func__);
  83216. + break;
  83217. +
  83218. + case EP0_OUT_DATA_PHASE:
  83219. + DWC_DEBUGPL(DBG_PCD,
  83220. + "%s ep0: EP0_OUT_DATA_PHASE\n",
  83221. + __func__);
  83222. + if (pcd->request_config) {
  83223. + /* Complete STATUS PHASE */
  83224. + ep->dwc_ep.is_in = 1;
  83225. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  83226. + }
  83227. + break;
  83228. +
  83229. + case EP0_IN_STATUS_PHASE:
  83230. + DWC_DEBUGPL(DBG_PCD,
  83231. + "%s ep0: EP0_IN_STATUS_PHASE\n",
  83232. + __func__);
  83233. + break;
  83234. +
  83235. + default:
  83236. + DWC_DEBUGPL(DBG_ANY, "ep0: odd state %d\n",
  83237. + pcd->ep0state);
  83238. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83239. + return -DWC_E_SHUTDOWN;
  83240. + }
  83241. +
  83242. + ep->dwc_ep.dma_addr = dma_buf;
  83243. + ep->dwc_ep.start_xfer_buff = buf;
  83244. + ep->dwc_ep.xfer_buff = buf;
  83245. + ep->dwc_ep.xfer_len = buflen;
  83246. + ep->dwc_ep.xfer_count = 0;
  83247. + ep->dwc_ep.sent_zlp = 0;
  83248. + ep->dwc_ep.total_len = ep->dwc_ep.xfer_len;
  83249. +
  83250. + if (zero) {
  83251. + if ((ep->dwc_ep.xfer_len %
  83252. + ep->dwc_ep.maxpacket == 0)
  83253. + && (ep->dwc_ep.xfer_len != 0)) {
  83254. + ep->dwc_ep.sent_zlp = 1;
  83255. + }
  83256. +
  83257. + }
  83258. +
  83259. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  83260. + &ep->dwc_ep);
  83261. + } // non-ep0 endpoints
  83262. + else {
  83263. +#ifdef DWC_UTE_CFI
  83264. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  83265. + /* store the request length */
  83266. + ep->dwc_ep.cfi_req_len = buflen;
  83267. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd,
  83268. + ep, req);
  83269. + } else {
  83270. +#endif
  83271. + max_transfer =
  83272. + GET_CORE_IF(ep->pcd)->core_params->
  83273. + max_transfer_size;
  83274. +
  83275. + /* Setup and start the Transfer */
  83276. + if (req->dw_align_buf){
  83277. + if (ep->dwc_ep.is_in)
  83278. + dwc_memcpy(req->dw_align_buf,
  83279. + buf, buflen);
  83280. + ep->dwc_ep.dma_addr =
  83281. + req->dw_align_buf_dma;
  83282. + ep->dwc_ep.start_xfer_buff =
  83283. + req->dw_align_buf;
  83284. + ep->dwc_ep.xfer_buff =
  83285. + req->dw_align_buf;
  83286. + } else {
  83287. + ep->dwc_ep.dma_addr = dma_buf;
  83288. + ep->dwc_ep.start_xfer_buff = buf;
  83289. + ep->dwc_ep.xfer_buff = buf;
  83290. + }
  83291. + ep->dwc_ep.xfer_len = 0;
  83292. + ep->dwc_ep.xfer_count = 0;
  83293. + ep->dwc_ep.sent_zlp = 0;
  83294. + ep->dwc_ep.total_len = buflen;
  83295. +
  83296. + ep->dwc_ep.maxxfer = max_transfer;
  83297. + if (GET_CORE_IF(pcd)->dma_desc_enable) {
  83298. + uint32_t out_max_xfer =
  83299. + DDMA_MAX_TRANSFER_SIZE -
  83300. + (DDMA_MAX_TRANSFER_SIZE % 4);
  83301. + if (ep->dwc_ep.is_in) {
  83302. + if (ep->dwc_ep.maxxfer >
  83303. + DDMA_MAX_TRANSFER_SIZE) {
  83304. + ep->dwc_ep.maxxfer =
  83305. + DDMA_MAX_TRANSFER_SIZE;
  83306. + }
  83307. + } else {
  83308. + if (ep->dwc_ep.maxxfer >
  83309. + out_max_xfer) {
  83310. + ep->dwc_ep.maxxfer =
  83311. + out_max_xfer;
  83312. + }
  83313. + }
  83314. + }
  83315. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  83316. + ep->dwc_ep.maxxfer -=
  83317. + (ep->dwc_ep.maxxfer %
  83318. + ep->dwc_ep.maxpacket);
  83319. + }
  83320. +
  83321. + if (zero) {
  83322. + if ((ep->dwc_ep.total_len %
  83323. + ep->dwc_ep.maxpacket == 0)
  83324. + && (ep->dwc_ep.total_len != 0)) {
  83325. + ep->dwc_ep.sent_zlp = 1;
  83326. + }
  83327. + }
  83328. +#ifdef DWC_UTE_CFI
  83329. + }
  83330. +#endif
  83331. + dwc_otg_ep_start_transfer(GET_CORE_IF(pcd),
  83332. + &ep->dwc_ep);
  83333. + }
  83334. + }
  83335. +
  83336. + if (req != 0) {
  83337. + ++pcd->request_pending;
  83338. + DWC_CIRCLEQ_INSERT_TAIL(&ep->queue, req, queue_entry);
  83339. + if (ep->dwc_ep.is_in && ep->stopped
  83340. + && !(GET_CORE_IF(pcd)->dma_enable)) {
  83341. + /** @todo NGS Create a function for this. */
  83342. + diepmsk_data_t diepmsk = {.d32 = 0 };
  83343. + diepmsk.b.intktxfemp = 1;
  83344. + if (GET_CORE_IF(pcd)->multiproc_int_enable) {
  83345. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83346. + dev_if->dev_global_regs->diepeachintmsk
  83347. + [ep->dwc_ep.num], 0,
  83348. + diepmsk.d32);
  83349. + } else {
  83350. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->
  83351. + dev_if->dev_global_regs->
  83352. + diepmsk, 0, diepmsk.d32);
  83353. + }
  83354. +
  83355. + }
  83356. + }
  83357. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83358. +
  83359. + return 0;
  83360. +}
  83361. +
  83362. +int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  83363. + void *req_handle)
  83364. +{
  83365. + dwc_irqflags_t flags;
  83366. + dwc_otg_pcd_request_t *req;
  83367. + dwc_otg_pcd_ep_t *ep;
  83368. +
  83369. + ep = get_ep_from_handle(pcd, ep_handle);
  83370. + if (!ep || (!ep->desc && ep->dwc_ep.num != 0)) {
  83371. + DWC_WARN("bad argument\n");
  83372. + return -DWC_E_INVALID;
  83373. + }
  83374. +
  83375. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83376. +
  83377. + /* make sure it's actually queued on this endpoint */
  83378. + DWC_CIRCLEQ_FOREACH(req, &ep->queue, queue_entry) {
  83379. + if (req->priv == (void *)req_handle) {
  83380. + break;
  83381. + }
  83382. + }
  83383. +
  83384. + if (req->priv != (void *)req_handle) {
  83385. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83386. + return -DWC_E_INVALID;
  83387. + }
  83388. +
  83389. + if (!DWC_CIRCLEQ_EMPTY_ENTRY(req, queue_entry)) {
  83390. + dwc_otg_request_done(ep, req, -DWC_E_RESTART);
  83391. + } else {
  83392. + req = NULL;
  83393. + }
  83394. +
  83395. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83396. +
  83397. + return req ? 0 : -DWC_E_SHUTDOWN;
  83398. +
  83399. +}
  83400. +
  83401. +/**
  83402. + * dwc_otg_pcd_ep_wedge - sets the halt feature and ignores clear requests
  83403. + *
  83404. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  83405. + * requests. If the gadget driver clears the halt status, it will
  83406. + * automatically unwedge the endpoint.
  83407. + *
  83408. + * Returns zero on success, else negative DWC error code.
  83409. + */
  83410. +int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle)
  83411. +{
  83412. + dwc_otg_pcd_ep_t *ep;
  83413. + dwc_irqflags_t flags;
  83414. + int retval = 0;
  83415. +
  83416. + ep = get_ep_from_handle(pcd, ep_handle);
  83417. +
  83418. + if ((!ep->desc && ep != &pcd->ep0) ||
  83419. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  83420. + DWC_WARN("%s, bad ep\n", __func__);
  83421. + return -DWC_E_INVALID;
  83422. + }
  83423. +
  83424. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83425. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83426. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  83427. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83428. + retval = -DWC_E_AGAIN;
  83429. + } else {
  83430. + /* This code needs to be reviewed */
  83431. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  83432. + dtxfsts_data_t txstatus;
  83433. + fifosize_data_t txfifosize;
  83434. +
  83435. + txfifosize.d32 =
  83436. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83437. + core_global_regs->dtxfsiz[ep->dwc_ep.
  83438. + tx_fifo_num]);
  83439. + txstatus.d32 =
  83440. + DWC_READ_REG32(&GET_CORE_IF(pcd)->
  83441. + dev_if->in_ep_regs[ep->dwc_ep.num]->
  83442. + dtxfsts);
  83443. +
  83444. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  83445. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  83446. + retval = -DWC_E_AGAIN;
  83447. + } else {
  83448. + if (ep->dwc_ep.num == 0) {
  83449. + pcd->ep0state = EP0_STALL;
  83450. + }
  83451. +
  83452. + ep->stopped = 1;
  83453. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  83454. + &ep->dwc_ep);
  83455. + }
  83456. + } else {
  83457. + if (ep->dwc_ep.num == 0) {
  83458. + pcd->ep0state = EP0_STALL;
  83459. + }
  83460. +
  83461. + ep->stopped = 1;
  83462. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83463. + }
  83464. + }
  83465. +
  83466. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83467. +
  83468. + return retval;
  83469. +}
  83470. +
  83471. +int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value)
  83472. +{
  83473. + dwc_otg_pcd_ep_t *ep;
  83474. + dwc_irqflags_t flags;
  83475. + int retval = 0;
  83476. +
  83477. + ep = get_ep_from_handle(pcd, ep_handle);
  83478. +
  83479. + if (!ep || (!ep->desc && ep != &pcd->ep0) ||
  83480. + (ep->desc && (ep->desc->bmAttributes == UE_ISOCHRONOUS))) {
  83481. + DWC_WARN("%s, bad ep\n", __func__);
  83482. + return -DWC_E_INVALID;
  83483. + }
  83484. +
  83485. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83486. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  83487. + DWC_WARN("%d %s XFer In process\n", ep->dwc_ep.num,
  83488. + ep->dwc_ep.is_in ? "IN" : "OUT");
  83489. + retval = -DWC_E_AGAIN;
  83490. + } else if (value == 0) {
  83491. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83492. + } else if (value == 1) {
  83493. + if (ep->dwc_ep.is_in == 1 && GET_CORE_IF(pcd)->dma_desc_enable) {
  83494. + dtxfsts_data_t txstatus;
  83495. + fifosize_data_t txfifosize;
  83496. +
  83497. + txfifosize.d32 =
  83498. + DWC_READ_REG32(&GET_CORE_IF(pcd)->core_global_regs->
  83499. + dtxfsiz[ep->dwc_ep.tx_fifo_num]);
  83500. + txstatus.d32 =
  83501. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  83502. + in_ep_regs[ep->dwc_ep.num]->dtxfsts);
  83503. +
  83504. + if (txstatus.b.txfspcavail < txfifosize.b.depth) {
  83505. + DWC_WARN("%s() Data In Tx Fifo\n", __func__);
  83506. + retval = -DWC_E_AGAIN;
  83507. + } else {
  83508. + if (ep->dwc_ep.num == 0) {
  83509. + pcd->ep0state = EP0_STALL;
  83510. + }
  83511. +
  83512. + ep->stopped = 1;
  83513. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd),
  83514. + &ep->dwc_ep);
  83515. + }
  83516. + } else {
  83517. + if (ep->dwc_ep.num == 0) {
  83518. + pcd->ep0state = EP0_STALL;
  83519. + }
  83520. +
  83521. + ep->stopped = 1;
  83522. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  83523. + }
  83524. + } else if (value == 2) {
  83525. + ep->dwc_ep.stall_clear_flag = 0;
  83526. + } else if (value == 3) {
  83527. + ep->dwc_ep.stall_clear_flag = 1;
  83528. + }
  83529. +
  83530. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83531. +
  83532. + return retval;
  83533. +}
  83534. +
  83535. +/**
  83536. + * This function initiates remote wakeup of the host from suspend state.
  83537. + */
  83538. +void dwc_otg_pcd_rem_wkup_from_suspend(dwc_otg_pcd_t * pcd, int set)
  83539. +{
  83540. + dctl_data_t dctl = { 0 };
  83541. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83542. + dsts_data_t dsts;
  83543. +
  83544. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  83545. + if (!dsts.b.suspsts) {
  83546. + DWC_WARN("Remote wakeup while is not in suspend state\n");
  83547. + }
  83548. + /* Check if DEVICE_REMOTE_WAKEUP feature enabled */
  83549. + if (pcd->remote_wakeup_enable) {
  83550. + if (set) {
  83551. +
  83552. + if (core_if->adp_enable) {
  83553. + gpwrdn_data_t gpwrdn;
  83554. +
  83555. + dwc_otg_adp_probe_stop(core_if);
  83556. +
  83557. + /* Mask SRP detected interrupt from Power Down Logic */
  83558. + gpwrdn.d32 = 0;
  83559. + gpwrdn.b.srp_det_msk = 1;
  83560. + DWC_MODIFY_REG32(&core_if->
  83561. + core_global_regs->gpwrdn,
  83562. + gpwrdn.d32, 0);
  83563. +
  83564. + /* Disable Power Down Logic */
  83565. + gpwrdn.d32 = 0;
  83566. + gpwrdn.b.pmuactv = 1;
  83567. + DWC_MODIFY_REG32(&core_if->
  83568. + core_global_regs->gpwrdn,
  83569. + gpwrdn.d32, 0);
  83570. +
  83571. + /*
  83572. + * Initialize the Core for Device mode.
  83573. + */
  83574. + core_if->op_state = B_PERIPHERAL;
  83575. + dwc_otg_core_init(core_if);
  83576. + dwc_otg_enable_global_interrupts(core_if);
  83577. + cil_pcd_start(core_if);
  83578. +
  83579. + dwc_otg_initiate_srp(core_if);
  83580. + }
  83581. +
  83582. + dctl.b.rmtwkupsig = 1;
  83583. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  83584. + dctl, 0, dctl.d32);
  83585. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  83586. +
  83587. + dwc_mdelay(2);
  83588. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  83589. + dctl, dctl.d32, 0);
  83590. + DWC_DEBUGPL(DBG_PCD, "Clear Remote Wakeup\n");
  83591. + }
  83592. + } else {
  83593. + DWC_DEBUGPL(DBG_PCD, "Remote Wakeup is disabled\n");
  83594. + }
  83595. +}
  83596. +
  83597. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83598. +/**
  83599. + * This function initiates remote wakeup of the host from L1 sleep state.
  83600. + */
  83601. +void dwc_otg_pcd_rem_wkup_from_sleep(dwc_otg_pcd_t * pcd, int set)
  83602. +{
  83603. + glpmcfg_data_t lpmcfg;
  83604. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83605. +
  83606. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  83607. +
  83608. + /* Check if we are in L1 state */
  83609. + if (!lpmcfg.b.prt_sleep_sts) {
  83610. + DWC_DEBUGPL(DBG_PCD, "Device is not in sleep state\n");
  83611. + return;
  83612. + }
  83613. +
  83614. + /* Check if host allows remote wakeup */
  83615. + if (!lpmcfg.b.rem_wkup_en) {
  83616. + DWC_DEBUGPL(DBG_PCD, "Host does not allow remote wakeup\n");
  83617. + return;
  83618. + }
  83619. +
  83620. + /* Check if Resume OK */
  83621. + if (!lpmcfg.b.sleep_state_resumeok) {
  83622. + DWC_DEBUGPL(DBG_PCD, "Sleep state resume is not OK\n");
  83623. + return;
  83624. + }
  83625. +
  83626. + lpmcfg.d32 = DWC_READ_REG32(&core_if->core_global_regs->glpmcfg);
  83627. + lpmcfg.b.en_utmi_sleep = 0;
  83628. + lpmcfg.b.hird_thres &= (~(1 << 4));
  83629. + DWC_WRITE_REG32(&core_if->core_global_regs->glpmcfg, lpmcfg.d32);
  83630. +
  83631. + if (set) {
  83632. + dctl_data_t dctl = {.d32 = 0 };
  83633. + dctl.b.rmtwkupsig = 1;
  83634. + /* Set RmtWkUpSig bit to start remote wakup signaling.
  83635. + * Hardware will automatically clear this bit.
  83636. + */
  83637. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl,
  83638. + 0, dctl.d32);
  83639. + DWC_DEBUGPL(DBG_PCD, "Set Remote Wakeup\n");
  83640. + }
  83641. +
  83642. +}
  83643. +#endif
  83644. +
  83645. +/**
  83646. + * Performs remote wakeup.
  83647. + */
  83648. +void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set)
  83649. +{
  83650. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83651. + dwc_irqflags_t flags;
  83652. + if (dwc_otg_is_device_mode(core_if)) {
  83653. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83654. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83655. + if (core_if->lx_state == DWC_OTG_L1) {
  83656. + dwc_otg_pcd_rem_wkup_from_sleep(pcd, set);
  83657. + } else {
  83658. +#endif
  83659. + dwc_otg_pcd_rem_wkup_from_suspend(pcd, set);
  83660. +#ifdef CONFIG_USB_DWC_OTG_LPM
  83661. + }
  83662. +#endif
  83663. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83664. + }
  83665. + return;
  83666. +}
  83667. +
  83668. +void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs)
  83669. +{
  83670. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  83671. + dctl_data_t dctl = { 0 };
  83672. +
  83673. + if (dwc_otg_is_device_mode(core_if)) {
  83674. + dctl.b.sftdiscon = 1;
  83675. + DWC_PRINTF("Soft disconnect for %d useconds\n",no_of_usecs);
  83676. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, 0, dctl.d32);
  83677. + dwc_udelay(no_of_usecs);
  83678. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32,0);
  83679. +
  83680. + } else{
  83681. + DWC_PRINTF("NOT SUPPORTED IN HOST MODE\n");
  83682. + }
  83683. + return;
  83684. +
  83685. +}
  83686. +
  83687. +int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd)
  83688. +{
  83689. + dsts_data_t dsts;
  83690. + gotgctl_data_t gotgctl;
  83691. +
  83692. + /*
  83693. + * This function starts the Protocol if no session is in progress. If
  83694. + * a session is already in progress, but the device is suspended,
  83695. + * remote wakeup signaling is started.
  83696. + */
  83697. +
  83698. + /* Check if valid session */
  83699. + gotgctl.d32 =
  83700. + DWC_READ_REG32(&(GET_CORE_IF(pcd)->core_global_regs->gotgctl));
  83701. + if (gotgctl.b.bsesvld) {
  83702. + /* Check if suspend state */
  83703. + dsts.d32 =
  83704. + DWC_READ_REG32(&
  83705. + (GET_CORE_IF(pcd)->dev_if->
  83706. + dev_global_regs->dsts));
  83707. + if (dsts.b.suspsts) {
  83708. + dwc_otg_pcd_remote_wakeup(pcd, 1);
  83709. + }
  83710. + } else {
  83711. + dwc_otg_pcd_initiate_srp(pcd);
  83712. + }
  83713. +
  83714. + return 0;
  83715. +
  83716. +}
  83717. +
  83718. +/**
  83719. + * Start the SRP timer to detect when the SRP does not complete within
  83720. + * 6 seconds.
  83721. + *
  83722. + * @param pcd the pcd structure.
  83723. + */
  83724. +void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd)
  83725. +{
  83726. + dwc_irqflags_t flags;
  83727. + DWC_SPINLOCK_IRQSAVE(pcd->lock, &flags);
  83728. + dwc_otg_initiate_srp(GET_CORE_IF(pcd));
  83729. + DWC_SPINUNLOCK_IRQRESTORE(pcd->lock, flags);
  83730. +}
  83731. +
  83732. +int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd)
  83733. +{
  83734. + return dwc_otg_get_frame_number(GET_CORE_IF(pcd));
  83735. +}
  83736. +
  83737. +int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd)
  83738. +{
  83739. + return GET_CORE_IF(pcd)->core_params->lpm_enable;
  83740. +}
  83741. +
  83742. +uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd)
  83743. +{
  83744. + return pcd->b_hnp_enable;
  83745. +}
  83746. +
  83747. +uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd)
  83748. +{
  83749. + return pcd->a_hnp_support;
  83750. +}
  83751. +
  83752. +uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd)
  83753. +{
  83754. + return pcd->a_alt_hnp_support;
  83755. +}
  83756. +
  83757. +int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd)
  83758. +{
  83759. + return pcd->remote_wakeup_enable;
  83760. +}
  83761. +
  83762. +#endif /* DWC_HOST_ONLY */
  83763. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h
  83764. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 1970-01-01 01:00:00.000000000 +0100
  83765. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd.h 2014-06-11 21:03:43.000000000 +0200
  83766. @@ -0,0 +1,266 @@
  83767. +/* ==========================================================================
  83768. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd.h $
  83769. + * $Revision: #48 $
  83770. + * $Date: 2012/08/10 $
  83771. + * $Change: 2047372 $
  83772. + *
  83773. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  83774. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  83775. + * otherwise expressly agreed to in writing between Synopsys and you.
  83776. + *
  83777. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  83778. + * any End User Software License Agreement or Agreement for Licensed Product
  83779. + * with Synopsys or any supplement thereto. You are permitted to use and
  83780. + * redistribute this Software in source and binary forms, with or without
  83781. + * modification, provided that redistributions of source code must retain this
  83782. + * notice. You may not view, use, disclose, copy or distribute this file or
  83783. + * any information contained herein except pursuant to this license grant from
  83784. + * Synopsys. If you do not agree with this notice, including the disclaimer
  83785. + * below, then you are not authorized to use the Software.
  83786. + *
  83787. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  83788. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  83789. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  83790. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  83791. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  83792. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  83793. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  83794. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83795. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  83796. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  83797. + * DAMAGE.
  83798. + * ========================================================================== */
  83799. +#ifndef DWC_HOST_ONLY
  83800. +#if !defined(__DWC_PCD_H__)
  83801. +#define __DWC_PCD_H__
  83802. +
  83803. +#include "dwc_otg_os_dep.h"
  83804. +#include "usb.h"
  83805. +#include "dwc_otg_cil.h"
  83806. +#include "dwc_otg_pcd_if.h"
  83807. +struct cfiobject;
  83808. +
  83809. +/**
  83810. + * @file
  83811. + *
  83812. + * This file contains the structures, constants, and interfaces for
  83813. + * the Perpherial Contoller Driver (PCD).
  83814. + *
  83815. + * The Peripheral Controller Driver (PCD) for Linux will implement the
  83816. + * Gadget API, so that the existing Gadget drivers can be used. For
  83817. + * the Mass Storage Function driver the File-backed USB Storage Gadget
  83818. + * (FBS) driver will be used. The FBS driver supports the
  83819. + * Control-Bulk (CB), Control-Bulk-Interrupt (CBI), and Bulk-Only
  83820. + * transports.
  83821. + *
  83822. + */
  83823. +
  83824. +/** Invalid DMA Address */
  83825. +#define DWC_DMA_ADDR_INVALID (~(dwc_dma_t)0)
  83826. +
  83827. +/** Max Transfer size for any EP */
  83828. +#define DDMA_MAX_TRANSFER_SIZE 65535
  83829. +
  83830. +/**
  83831. + * Get the pointer to the core_if from the pcd pointer.
  83832. + */
  83833. +#define GET_CORE_IF( _pcd ) (_pcd->core_if)
  83834. +
  83835. +/**
  83836. + * States of EP0.
  83837. + */
  83838. +typedef enum ep0_state {
  83839. + EP0_DISCONNECT, /* no host */
  83840. + EP0_IDLE,
  83841. + EP0_IN_DATA_PHASE,
  83842. + EP0_OUT_DATA_PHASE,
  83843. + EP0_IN_STATUS_PHASE,
  83844. + EP0_OUT_STATUS_PHASE,
  83845. + EP0_STALL,
  83846. +} ep0state_e;
  83847. +
  83848. +/** Fordward declaration.*/
  83849. +struct dwc_otg_pcd;
  83850. +
  83851. +/** DWC_otg iso request structure.
  83852. + *
  83853. + */
  83854. +typedef struct usb_iso_request dwc_otg_pcd_iso_request_t;
  83855. +
  83856. +#ifdef DWC_UTE_PER_IO
  83857. +
  83858. +/**
  83859. + * This shall be the exact analogy of the same type structure defined in the
  83860. + * usb_gadget.h. Each descriptor contains
  83861. + */
  83862. +struct dwc_iso_pkt_desc_port {
  83863. + uint32_t offset;
  83864. + uint32_t length; /* expected length */
  83865. + uint32_t actual_length;
  83866. + uint32_t status;
  83867. +};
  83868. +
  83869. +struct dwc_iso_xreq_port {
  83870. + /** transfer/submission flag */
  83871. + uint32_t tr_sub_flags;
  83872. + /** Start the request ASAP */
  83873. +#define DWC_EREQ_TF_ASAP 0x00000002
  83874. + /** Just enqueue the request w/o initiating a transfer */
  83875. +#define DWC_EREQ_TF_ENQUEUE 0x00000004
  83876. +
  83877. + /**
  83878. + * count of ISO packets attached to this request - shall
  83879. + * not exceed the pio_alloc_pkt_count
  83880. + */
  83881. + uint32_t pio_pkt_count;
  83882. + /** count of ISO packets allocated for this request */
  83883. + uint32_t pio_alloc_pkt_count;
  83884. + /** number of ISO packet errors */
  83885. + uint32_t error_count;
  83886. + /** reserved for future extension */
  83887. + uint32_t res;
  83888. + /** Will be allocated and freed in the UTE gadget and based on the CFC value */
  83889. + struct dwc_iso_pkt_desc_port *per_io_frame_descs;
  83890. +};
  83891. +#endif
  83892. +/** DWC_otg request structure.
  83893. + * This structure is a list of requests.
  83894. + */
  83895. +typedef struct dwc_otg_pcd_request {
  83896. + void *priv;
  83897. + void *buf;
  83898. + dwc_dma_t dma;
  83899. + uint32_t length;
  83900. + uint32_t actual;
  83901. + unsigned sent_zlp:1;
  83902. + /**
  83903. + * Used instead of original buffer if
  83904. + * it(physical address) is not dword-aligned.
  83905. + **/
  83906. + uint8_t *dw_align_buf;
  83907. + dwc_dma_t dw_align_buf_dma;
  83908. +
  83909. + DWC_CIRCLEQ_ENTRY(dwc_otg_pcd_request) queue_entry;
  83910. +#ifdef DWC_UTE_PER_IO
  83911. + struct dwc_iso_xreq_port ext_req;
  83912. + //void *priv_ereq_nport; /* */
  83913. +#endif
  83914. +} dwc_otg_pcd_request_t;
  83915. +
  83916. +DWC_CIRCLEQ_HEAD(req_list, dwc_otg_pcd_request);
  83917. +
  83918. +/** PCD EP structure.
  83919. + * This structure describes an EP, there is an array of EPs in the PCD
  83920. + * structure.
  83921. + */
  83922. +typedef struct dwc_otg_pcd_ep {
  83923. + /** USB EP Descriptor */
  83924. + const usb_endpoint_descriptor_t *desc;
  83925. +
  83926. + /** queue of dwc_otg_pcd_requests. */
  83927. + struct req_list queue;
  83928. + unsigned stopped:1;
  83929. + unsigned disabling:1;
  83930. + unsigned dma:1;
  83931. + unsigned queue_sof:1;
  83932. +
  83933. +#ifdef DWC_EN_ISOC
  83934. + /** ISOC req handle passed */
  83935. + void *iso_req_handle;
  83936. +#endif //_EN_ISOC_
  83937. +
  83938. + /** DWC_otg ep data. */
  83939. + dwc_ep_t dwc_ep;
  83940. +
  83941. + /** Pointer to PCD */
  83942. + struct dwc_otg_pcd *pcd;
  83943. +
  83944. + void *priv;
  83945. +} dwc_otg_pcd_ep_t;
  83946. +
  83947. +/** DWC_otg PCD Structure.
  83948. + * This structure encapsulates the data for the dwc_otg PCD.
  83949. + */
  83950. +struct dwc_otg_pcd {
  83951. + const struct dwc_otg_pcd_function_ops *fops;
  83952. + /** The DWC otg device pointer */
  83953. + struct dwc_otg_device *otg_dev;
  83954. + /** Core Interface */
  83955. + dwc_otg_core_if_t *core_if;
  83956. + /** State of EP0 */
  83957. + ep0state_e ep0state;
  83958. + /** EP0 Request is pending */
  83959. + unsigned ep0_pending:1;
  83960. + /** Indicates when SET CONFIGURATION Request is in process */
  83961. + unsigned request_config:1;
  83962. + /** The state of the Remote Wakeup Enable. */
  83963. + unsigned remote_wakeup_enable:1;
  83964. + /** The state of the B-Device HNP Enable. */
  83965. + unsigned b_hnp_enable:1;
  83966. + /** The state of A-Device HNP Support. */
  83967. + unsigned a_hnp_support:1;
  83968. + /** The state of the A-Device Alt HNP support. */
  83969. + unsigned a_alt_hnp_support:1;
  83970. + /** Count of pending Requests */
  83971. + unsigned request_pending;
  83972. +
  83973. + /** SETUP packet for EP0
  83974. + * This structure is allocated as a DMA buffer on PCD initialization
  83975. + * with enough space for up to 3 setup packets.
  83976. + */
  83977. + union {
  83978. + usb_device_request_t req;
  83979. + uint32_t d32[2];
  83980. + } *setup_pkt;
  83981. +
  83982. + dwc_dma_t setup_pkt_dma_handle;
  83983. +
  83984. + /* Additional buffer and flag for CTRL_WR premature case */
  83985. + uint8_t *backup_buf;
  83986. + unsigned data_terminated;
  83987. +
  83988. + /** 2-byte dma buffer used to return status from GET_STATUS */
  83989. + uint16_t *status_buf;
  83990. + dwc_dma_t status_buf_dma_handle;
  83991. +
  83992. + /** EP0 */
  83993. + dwc_otg_pcd_ep_t ep0;
  83994. +
  83995. + /** Array of IN EPs. */
  83996. + dwc_otg_pcd_ep_t in_ep[MAX_EPS_CHANNELS - 1];
  83997. + /** Array of OUT EPs. */
  83998. + dwc_otg_pcd_ep_t out_ep[MAX_EPS_CHANNELS - 1];
  83999. + /** number of valid EPs in the above array. */
  84000. +// unsigned num_eps : 4;
  84001. + dwc_spinlock_t *lock;
  84002. +
  84003. + /** Tasklet to defer starting of TEST mode transmissions until
  84004. + * Status Phase has been completed.
  84005. + */
  84006. + dwc_tasklet_t *test_mode_tasklet;
  84007. +
  84008. + /** Tasklet to delay starting of xfer in DMA mode */
  84009. + dwc_tasklet_t *start_xfer_tasklet;
  84010. +
  84011. + /** The test mode to enter when the tasklet is executed. */
  84012. + unsigned test_mode;
  84013. + /** The cfi_api structure that implements most of the CFI API
  84014. + * and OTG specific core configuration functionality
  84015. + */
  84016. +#ifdef DWC_UTE_CFI
  84017. + struct cfiobject *cfi;
  84018. +#endif
  84019. +
  84020. +};
  84021. +
  84022. +//FIXME this functions should be static, and this prototypes should be removed
  84023. +extern void dwc_otg_request_nuke(dwc_otg_pcd_ep_t * ep);
  84024. +extern void dwc_otg_request_done(dwc_otg_pcd_ep_t * ep,
  84025. + dwc_otg_pcd_request_t * req, int32_t status);
  84026. +
  84027. +void dwc_otg_iso_buffer_done(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep,
  84028. + void *req_handle);
  84029. +
  84030. +extern void do_test_mode(void *data);
  84031. +#endif
  84032. +#endif /* DWC_HOST_ONLY */
  84033. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h
  84034. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 1970-01-01 01:00:00.000000000 +0100
  84035. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_if.h 2014-06-11 21:03:43.000000000 +0200
  84036. @@ -0,0 +1,360 @@
  84037. +/* ==========================================================================
  84038. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_if.h $
  84039. + * $Revision: #11 $
  84040. + * $Date: 2011/10/26 $
  84041. + * $Change: 1873028 $
  84042. + *
  84043. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84044. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84045. + * otherwise expressly agreed to in writing between Synopsys and you.
  84046. + *
  84047. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84048. + * any End User Software License Agreement or Agreement for Licensed Product
  84049. + * with Synopsys or any supplement thereto. You are permitted to use and
  84050. + * redistribute this Software in source and binary forms, with or without
  84051. + * modification, provided that redistributions of source code must retain this
  84052. + * notice. You may not view, use, disclose, copy or distribute this file or
  84053. + * any information contained herein except pursuant to this license grant from
  84054. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84055. + * below, then you are not authorized to use the Software.
  84056. + *
  84057. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84058. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84059. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84060. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84061. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84062. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84063. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84064. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84065. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84066. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84067. + * DAMAGE.
  84068. + * ========================================================================== */
  84069. +#ifndef DWC_HOST_ONLY
  84070. +
  84071. +#if !defined(__DWC_PCD_IF_H__)
  84072. +#define __DWC_PCD_IF_H__
  84073. +
  84074. +//#include "dwc_os.h"
  84075. +#include "dwc_otg_core_if.h"
  84076. +
  84077. +/** @file
  84078. + * This file defines DWC_OTG PCD Core API.
  84079. + */
  84080. +
  84081. +struct dwc_otg_pcd;
  84082. +typedef struct dwc_otg_pcd dwc_otg_pcd_t;
  84083. +
  84084. +/** Maxpacket size for EP0 */
  84085. +#define MAX_EP0_SIZE 64
  84086. +/** Maxpacket size for any EP */
  84087. +#define MAX_PACKET_SIZE 1024
  84088. +
  84089. +/** @name Function Driver Callbacks */
  84090. +/** @{ */
  84091. +
  84092. +/** This function will be called whenever a previously queued request has
  84093. + * completed. The status value will be set to -DWC_E_SHUTDOWN to indicated a
  84094. + * failed or aborted transfer, or -DWC_E_RESTART to indicate the device was reset,
  84095. + * or -DWC_E_TIMEOUT to indicate it timed out, or -DWC_E_INVALID to indicate invalid
  84096. + * parameters. */
  84097. +typedef int (*dwc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84098. + void *req_handle, int32_t status,
  84099. + uint32_t actual);
  84100. +/**
  84101. + * This function will be called whenever a previousle queued ISOC request has
  84102. + * completed. Count of ISOC packets could be read using dwc_otg_pcd_get_iso_packet_count
  84103. + * function.
  84104. + * The status of each ISOC packet could be read using dwc_otg_pcd_get_iso_packet_*
  84105. + * functions.
  84106. + */
  84107. +typedef int (*dwc_isoc_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84108. + void *req_handle, int proc_buf_num);
  84109. +/** This function should handle any SETUP request that cannot be handled by the
  84110. + * PCD Core. This includes most GET_DESCRIPTORs, SET_CONFIGS, Any
  84111. + * class-specific requests, etc. The function must non-blocking.
  84112. + *
  84113. + * Returns 0 on success.
  84114. + * Returns -DWC_E_NOT_SUPPORTED if the request is not supported.
  84115. + * Returns -DWC_E_INVALID if the setup request had invalid parameters or bytes.
  84116. + * Returns -DWC_E_SHUTDOWN on any other error. */
  84117. +typedef int (*dwc_setup_cb_t) (dwc_otg_pcd_t * pcd, uint8_t * bytes);
  84118. +/** This is called whenever the device has been disconnected. The function
  84119. + * driver should take appropriate action to clean up all pending requests in the
  84120. + * PCD Core, remove all endpoints (except ep0), and initialize back to reset
  84121. + * state. */
  84122. +typedef int (*dwc_disconnect_cb_t) (dwc_otg_pcd_t * pcd);
  84123. +/** This function is called when device has been connected. */
  84124. +typedef int (*dwc_connect_cb_t) (dwc_otg_pcd_t * pcd, int speed);
  84125. +/** This function is called when device has been suspended */
  84126. +typedef int (*dwc_suspend_cb_t) (dwc_otg_pcd_t * pcd);
  84127. +/** This function is called when device has received LPM tokens, i.e.
  84128. + * device has been sent to sleep state. */
  84129. +typedef int (*dwc_sleep_cb_t) (dwc_otg_pcd_t * pcd);
  84130. +/** This function is called when device has been resumed
  84131. + * from suspend(L2) or L1 sleep state. */
  84132. +typedef int (*dwc_resume_cb_t) (dwc_otg_pcd_t * pcd);
  84133. +/** This function is called whenever hnp params has been changed.
  84134. + * User can call get_b_hnp_enable, get_a_hnp_support, get_a_alt_hnp_support functions
  84135. + * to get hnp parameters. */
  84136. +typedef int (*dwc_hnp_params_changed_cb_t) (dwc_otg_pcd_t * pcd);
  84137. +/** This function is called whenever USB RESET is detected. */
  84138. +typedef int (*dwc_reset_cb_t) (dwc_otg_pcd_t * pcd);
  84139. +
  84140. +typedef int (*cfi_setup_cb_t) (dwc_otg_pcd_t * pcd, void *ctrl_req_bytes);
  84141. +
  84142. +/**
  84143. + *
  84144. + * @param ep_handle Void pointer to the usb_ep structure
  84145. + * @param ereq_port Pointer to the extended request structure created in the
  84146. + * portable part.
  84147. + */
  84148. +typedef int (*xiso_completion_cb_t) (dwc_otg_pcd_t * pcd, void *ep_handle,
  84149. + void *req_handle, int32_t status,
  84150. + void *ereq_port);
  84151. +/** Function Driver Ops Data Structure */
  84152. +struct dwc_otg_pcd_function_ops {
  84153. + dwc_connect_cb_t connect;
  84154. + dwc_disconnect_cb_t disconnect;
  84155. + dwc_setup_cb_t setup;
  84156. + dwc_completion_cb_t complete;
  84157. + dwc_isoc_completion_cb_t isoc_complete;
  84158. + dwc_suspend_cb_t suspend;
  84159. + dwc_sleep_cb_t sleep;
  84160. + dwc_resume_cb_t resume;
  84161. + dwc_reset_cb_t reset;
  84162. + dwc_hnp_params_changed_cb_t hnp_changed;
  84163. + cfi_setup_cb_t cfi_setup;
  84164. +#ifdef DWC_UTE_PER_IO
  84165. + xiso_completion_cb_t xisoc_complete;
  84166. +#endif
  84167. +};
  84168. +/** @} */
  84169. +
  84170. +/** @name Function Driver Functions */
  84171. +/** @{ */
  84172. +
  84173. +/** Call this function to get pointer on dwc_otg_pcd_t,
  84174. + * this pointer will be used for all PCD API functions.
  84175. + *
  84176. + * @param core_if The DWC_OTG Core
  84177. + */
  84178. +extern dwc_otg_pcd_t *dwc_otg_pcd_init(dwc_otg_core_if_t * core_if);
  84179. +
  84180. +/** Frees PCD allocated by dwc_otg_pcd_init
  84181. + *
  84182. + * @param pcd The PCD
  84183. + */
  84184. +extern void dwc_otg_pcd_remove(dwc_otg_pcd_t * pcd);
  84185. +
  84186. +/** Call this to bind the function driver to the PCD Core.
  84187. + *
  84188. + * @param pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
  84189. + * @param fops The Function Driver Ops data structure containing pointers to all callbacks.
  84190. + */
  84191. +extern void dwc_otg_pcd_start(dwc_otg_pcd_t * pcd,
  84192. + const struct dwc_otg_pcd_function_ops *fops);
  84193. +
  84194. +/** Enables an endpoint for use. This function enables an endpoint in
  84195. + * the PCD. The endpoint is described by the ep_desc which has the
  84196. + * same format as a USB ep descriptor. The ep_handle parameter is used to refer
  84197. + * to the endpoint from other API functions and in callbacks. Normally this
  84198. + * should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the
  84199. + * core for that interface.
  84200. + *
  84201. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84202. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84203. + * Returns 0 on success.
  84204. + *
  84205. + * @param pcd The PCD
  84206. + * @param ep_desc Endpoint descriptor
  84207. + * @param usb_ep Handle on endpoint, that will be used to identify endpoint.
  84208. + */
  84209. +extern int dwc_otg_pcd_ep_enable(dwc_otg_pcd_t * pcd,
  84210. + const uint8_t * ep_desc, void *usb_ep);
  84211. +
  84212. +/** Disable the endpoint referenced by ep_handle.
  84213. + *
  84214. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84215. + * Returns -DWC_E_SHUTDOWN if any other error occurred.
  84216. + * Returns 0 on success. */
  84217. +extern int dwc_otg_pcd_ep_disable(dwc_otg_pcd_t * pcd, void *ep_handle);
  84218. +
  84219. +/** Queue a data transfer request on the endpoint referenced by ep_handle.
  84220. + * After the transfer is completes, the complete callback will be called with
  84221. + * the request status.
  84222. + *
  84223. + * @param pcd The PCD
  84224. + * @param ep_handle The handle of the endpoint
  84225. + * @param buf The buffer for the data
  84226. + * @param dma_buf The DMA buffer for the data
  84227. + * @param buflen The length of the data transfer
  84228. + * @param zero Specifies whether to send zero length last packet.
  84229. + * @param req_handle Set this handle to any value to use to reference this
  84230. + * request in the ep_dequeue function or from the complete callback
  84231. + * @param atomic_alloc If driver need to perform atomic allocations
  84232. + * for internal data structures.
  84233. + *
  84234. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84235. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84236. + * Returns 0 on success. */
  84237. +extern int dwc_otg_pcd_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84238. + uint8_t * buf, dwc_dma_t dma_buf,
  84239. + uint32_t buflen, int zero, void *req_handle,
  84240. + int atomic_alloc);
  84241. +#ifdef DWC_UTE_PER_IO
  84242. +/**
  84243. + *
  84244. + * @param ereq_nonport Pointer to the extended request part of the
  84245. + * usb_request structure defined in usb_gadget.h file.
  84246. + */
  84247. +extern int dwc_otg_pcd_xiso_ep_queue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84248. + uint8_t * buf, dwc_dma_t dma_buf,
  84249. + uint32_t buflen, int zero,
  84250. + void *req_handle, int atomic_alloc,
  84251. + void *ereq_nonport);
  84252. +
  84253. +#endif
  84254. +
  84255. +/** De-queue the specified data transfer that has not yet completed.
  84256. + *
  84257. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84258. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84259. + * Returns 0 on success. */
  84260. +extern int dwc_otg_pcd_ep_dequeue(dwc_otg_pcd_t * pcd, void *ep_handle,
  84261. + void *req_handle);
  84262. +
  84263. +/** Halt (STALL) an endpoint or clear it.
  84264. + *
  84265. + * Returns -DWC_E_INVALID if invalid parameters were passed.
  84266. + * Returns -DWC_E_SHUTDOWN if any other error ocurred.
  84267. + * Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later
  84268. + * Returns 0 on success. */
  84269. +extern int dwc_otg_pcd_ep_halt(dwc_otg_pcd_t * pcd, void *ep_handle, int value);
  84270. +
  84271. +/** This function */
  84272. +extern int dwc_otg_pcd_ep_wedge(dwc_otg_pcd_t * pcd, void *ep_handle);
  84273. +
  84274. +/** This function should be called on every hardware interrupt */
  84275. +extern int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd);
  84276. +
  84277. +/** This function returns current frame number */
  84278. +extern int dwc_otg_pcd_get_frame_number(dwc_otg_pcd_t * pcd);
  84279. +
  84280. +/**
  84281. + * Start isochronous transfers on the endpoint referenced by ep_handle.
  84282. + * For isochronous transfers duble buffering is used.
  84283. + * After processing each of buffers comlete callback will be called with
  84284. + * status for each transaction.
  84285. + *
  84286. + * @param pcd The PCD
  84287. + * @param ep_handle The handle of the endpoint
  84288. + * @param buf0 The virtual address of first data buffer
  84289. + * @param buf1 The virtual address of second data buffer
  84290. + * @param dma0 The DMA address of first data buffer
  84291. + * @param dma1 The DMA address of second data buffer
  84292. + * @param sync_frame Data pattern frame number
  84293. + * @param dp_frame Data size for pattern frame
  84294. + * @param data_per_frame Data size for regular frame
  84295. + * @param start_frame Frame number to start transfers, if -1 then start transfers ASAP.
  84296. + * @param buf_proc_intrvl Interval of ISOC Buffer processing
  84297. + * @param req_handle Handle of ISOC request
  84298. + * @param atomic_alloc Specefies whether to perform atomic allocation for
  84299. + * internal data structures.
  84300. + *
  84301. + * Returns -DWC_E_NO_MEMORY if there is no enough memory.
  84302. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function.
  84303. + * Returns -DW_E_SHUTDOWN for any other error.
  84304. + * Returns 0 on success
  84305. + */
  84306. +extern int dwc_otg_pcd_iso_ep_start(dwc_otg_pcd_t * pcd, void *ep_handle,
  84307. + uint8_t * buf0, uint8_t * buf1,
  84308. + dwc_dma_t dma0, dwc_dma_t dma1,
  84309. + int sync_frame, int dp_frame,
  84310. + int data_per_frame, int start_frame,
  84311. + int buf_proc_intrvl, void *req_handle,
  84312. + int atomic_alloc);
  84313. +
  84314. +/** Stop ISOC transfers on endpoint referenced by ep_handle.
  84315. + *
  84316. + * @param pcd The PCD
  84317. + * @param ep_handle The handle of the endpoint
  84318. + * @param req_handle Handle of ISOC request
  84319. + *
  84320. + * Returns -DWC_E_INVALID if incorrect arguments are passed to the function
  84321. + * Returns 0 on success
  84322. + */
  84323. +int dwc_otg_pcd_iso_ep_stop(dwc_otg_pcd_t * pcd, void *ep_handle,
  84324. + void *req_handle);
  84325. +
  84326. +/** Get ISOC packet status.
  84327. + *
  84328. + * @param pcd The PCD
  84329. + * @param ep_handle The handle of the endpoint
  84330. + * @param iso_req_handle Isochronoush request handle
  84331. + * @param packet Number of packet
  84332. + * @param status Out parameter for returning status
  84333. + * @param actual Out parameter for returning actual length
  84334. + * @param offset Out parameter for returning offset
  84335. + *
  84336. + */
  84337. +extern void dwc_otg_pcd_get_iso_packet_params(dwc_otg_pcd_t * pcd,
  84338. + void *ep_handle,
  84339. + void *iso_req_handle, int packet,
  84340. + int *status, int *actual,
  84341. + int *offset);
  84342. +
  84343. +/** Get ISOC packet count.
  84344. + *
  84345. + * @param pcd The PCD
  84346. + * @param ep_handle The handle of the endpoint
  84347. + * @param iso_req_handle
  84348. + */
  84349. +extern int dwc_otg_pcd_get_iso_packet_count(dwc_otg_pcd_t * pcd,
  84350. + void *ep_handle,
  84351. + void *iso_req_handle);
  84352. +
  84353. +/** This function starts the SRP Protocol if no session is in progress. If
  84354. + * a session is already in progress, but the device is suspended,
  84355. + * remote wakeup signaling is started.
  84356. + */
  84357. +extern int dwc_otg_pcd_wakeup(dwc_otg_pcd_t * pcd);
  84358. +
  84359. +/** This function returns 1 if LPM support is enabled, and 0 otherwise. */
  84360. +extern int dwc_otg_pcd_is_lpm_enabled(dwc_otg_pcd_t * pcd);
  84361. +
  84362. +/** This function returns 1 if remote wakeup is allowed and 0, otherwise. */
  84363. +extern int dwc_otg_pcd_get_rmwkup_enable(dwc_otg_pcd_t * pcd);
  84364. +
  84365. +/** Initiate SRP */
  84366. +extern void dwc_otg_pcd_initiate_srp(dwc_otg_pcd_t * pcd);
  84367. +
  84368. +/** Starts remote wakeup signaling. */
  84369. +extern void dwc_otg_pcd_remote_wakeup(dwc_otg_pcd_t * pcd, int set);
  84370. +
  84371. +/** Starts micorsecond soft disconnect. */
  84372. +extern void dwc_otg_pcd_disconnect_us(dwc_otg_pcd_t * pcd, int no_of_usecs);
  84373. +/** This function returns whether device is dualspeed.*/
  84374. +extern uint32_t dwc_otg_pcd_is_dualspeed(dwc_otg_pcd_t * pcd);
  84375. +
  84376. +/** This function returns whether device is otg. */
  84377. +extern uint32_t dwc_otg_pcd_is_otg(dwc_otg_pcd_t * pcd);
  84378. +
  84379. +/** These functions allow to get hnp parameters */
  84380. +extern uint32_t get_b_hnp_enable(dwc_otg_pcd_t * pcd);
  84381. +extern uint32_t get_a_hnp_support(dwc_otg_pcd_t * pcd);
  84382. +extern uint32_t get_a_alt_hnp_support(dwc_otg_pcd_t * pcd);
  84383. +
  84384. +/** CFI specific Interface functions */
  84385. +/** Allocate a cfi buffer */
  84386. +extern uint8_t *cfiw_ep_alloc_buffer(dwc_otg_pcd_t * pcd, void *pep,
  84387. + dwc_dma_t * addr, size_t buflen,
  84388. + int flags);
  84389. +
  84390. +/******************************************************************************/
  84391. +
  84392. +/** @} */
  84393. +
  84394. +#endif /* __DWC_PCD_IF_H__ */
  84395. +
  84396. +#endif /* DWC_HOST_ONLY */
  84397. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c
  84398. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 1970-01-01 01:00:00.000000000 +0100
  84399. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_intr.c 2014-06-11 21:03:43.000000000 +0200
  84400. @@ -0,0 +1,5147 @@
  84401. +/* ==========================================================================
  84402. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_intr.c $
  84403. + * $Revision: #116 $
  84404. + * $Date: 2012/08/10 $
  84405. + * $Change: 2047372 $
  84406. + *
  84407. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  84408. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  84409. + * otherwise expressly agreed to in writing between Synopsys and you.
  84410. + *
  84411. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  84412. + * any End User Software License Agreement or Agreement for Licensed Product
  84413. + * with Synopsys or any supplement thereto. You are permitted to use and
  84414. + * redistribute this Software in source and binary forms, with or without
  84415. + * modification, provided that redistributions of source code must retain this
  84416. + * notice. You may not view, use, disclose, copy or distribute this file or
  84417. + * any information contained herein except pursuant to this license grant from
  84418. + * Synopsys. If you do not agree with this notice, including the disclaimer
  84419. + * below, then you are not authorized to use the Software.
  84420. + *
  84421. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  84422. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  84423. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  84424. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  84425. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  84426. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  84427. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  84428. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  84429. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84430. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  84431. + * DAMAGE.
  84432. + * ========================================================================== */
  84433. +#ifndef DWC_HOST_ONLY
  84434. +
  84435. +#include "dwc_otg_pcd.h"
  84436. +
  84437. +#ifdef DWC_UTE_CFI
  84438. +#include "dwc_otg_cfi.h"
  84439. +#endif
  84440. +
  84441. +#ifdef DWC_UTE_PER_IO
  84442. +extern void complete_xiso_ep(dwc_otg_pcd_ep_t * ep);
  84443. +#endif
  84444. +//#define PRINT_CFI_DMA_DESCS
  84445. +
  84446. +#define DEBUG_EP0
  84447. +
  84448. +/**
  84449. + * This function updates OTG.
  84450. + */
  84451. +static void dwc_otg_pcd_update_otg(dwc_otg_pcd_t * pcd, const unsigned reset)
  84452. +{
  84453. +
  84454. + if (reset) {
  84455. + pcd->b_hnp_enable = 0;
  84456. + pcd->a_hnp_support = 0;
  84457. + pcd->a_alt_hnp_support = 0;
  84458. + }
  84459. +
  84460. + if (pcd->fops->hnp_changed) {
  84461. + pcd->fops->hnp_changed(pcd);
  84462. + }
  84463. +}
  84464. +
  84465. +/** @file
  84466. + * This file contains the implementation of the PCD Interrupt handlers.
  84467. + *
  84468. + * The PCD handles the device interrupts. Many conditions can cause a
  84469. + * device interrupt. When an interrupt occurs, the device interrupt
  84470. + * service routine determines the cause of the interrupt and
  84471. + * dispatches handling to the appropriate function. These interrupt
  84472. + * handling functions are described below.
  84473. + * All interrupt registers are processed from LSB to MSB.
  84474. + */
  84475. +
  84476. +/**
  84477. + * This function prints the ep0 state for debug purposes.
  84478. + */
  84479. +static inline void print_ep0_state(dwc_otg_pcd_t * pcd)
  84480. +{
  84481. +#ifdef DEBUG
  84482. + char str[40];
  84483. +
  84484. + switch (pcd->ep0state) {
  84485. + case EP0_DISCONNECT:
  84486. + dwc_strcpy(str, "EP0_DISCONNECT");
  84487. + break;
  84488. + case EP0_IDLE:
  84489. + dwc_strcpy(str, "EP0_IDLE");
  84490. + break;
  84491. + case EP0_IN_DATA_PHASE:
  84492. + dwc_strcpy(str, "EP0_IN_DATA_PHASE");
  84493. + break;
  84494. + case EP0_OUT_DATA_PHASE:
  84495. + dwc_strcpy(str, "EP0_OUT_DATA_PHASE");
  84496. + break;
  84497. + case EP0_IN_STATUS_PHASE:
  84498. + dwc_strcpy(str, "EP0_IN_STATUS_PHASE");
  84499. + break;
  84500. + case EP0_OUT_STATUS_PHASE:
  84501. + dwc_strcpy(str, "EP0_OUT_STATUS_PHASE");
  84502. + break;
  84503. + case EP0_STALL:
  84504. + dwc_strcpy(str, "EP0_STALL");
  84505. + break;
  84506. + default:
  84507. + dwc_strcpy(str, "EP0_INVALID");
  84508. + }
  84509. +
  84510. + DWC_DEBUGPL(DBG_ANY, "%s(%d)\n", str, pcd->ep0state);
  84511. +#endif
  84512. +}
  84513. +
  84514. +/**
  84515. + * This function calculate the size of the payload in the memory
  84516. + * for out endpoints and prints size for debug purposes(used in
  84517. + * 2.93a DevOutNak feature).
  84518. + */
  84519. +static inline void print_memory_payload(dwc_otg_pcd_t * pcd, dwc_ep_t * ep)
  84520. +{
  84521. +#ifdef DEBUG
  84522. + deptsiz_data_t deptsiz_init = {.d32 = 0 };
  84523. + deptsiz_data_t deptsiz_updt = {.d32 = 0 };
  84524. + int pack_num;
  84525. + unsigned payload;
  84526. +
  84527. + deptsiz_init.d32 = pcd->core_if->start_doeptsiz_val[ep->num];
  84528. + deptsiz_updt.d32 =
  84529. + DWC_READ_REG32(&pcd->core_if->dev_if->
  84530. + out_ep_regs[ep->num]->doeptsiz);
  84531. + /* Payload will be */
  84532. + payload = deptsiz_init.b.xfersize - deptsiz_updt.b.xfersize;
  84533. + /* Packet count is decremented every time a packet
  84534. + * is written to the RxFIFO not in to the external memory
  84535. + * So, if payload == 0, then it means no packet was sent to ext memory*/
  84536. + pack_num = (!payload) ? 0 : (deptsiz_init.b.pktcnt - deptsiz_updt.b.pktcnt);
  84537. + DWC_DEBUGPL(DBG_PCDV,
  84538. + "Payload for EP%d-%s\n",
  84539. + ep->num, (ep->is_in ? "IN" : "OUT"));
  84540. + DWC_DEBUGPL(DBG_PCDV,
  84541. + "Number of transfered bytes = 0x%08x\n", payload);
  84542. + DWC_DEBUGPL(DBG_PCDV,
  84543. + "Number of transfered packets = %d\n", pack_num);
  84544. +#endif
  84545. +}
  84546. +
  84547. +
  84548. +#ifdef DWC_UTE_CFI
  84549. +static inline void print_desc(struct dwc_otg_dma_desc *ddesc,
  84550. + const uint8_t * epname, int descnum)
  84551. +{
  84552. + CFI_INFO
  84553. + ("%s DMA_DESC(%d) buf=0x%08x bytes=0x%04x; sp=0x%x; l=0x%x; sts=0x%02x; bs=0x%02x\n",
  84554. + epname, descnum, ddesc->buf, ddesc->status.b.bytes,
  84555. + ddesc->status.b.sp, ddesc->status.b.l, ddesc->status.b.sts,
  84556. + ddesc->status.b.bs);
  84557. +}
  84558. +#endif
  84559. +
  84560. +/**
  84561. + * This function returns pointer to in ep struct with number ep_num
  84562. + */
  84563. +static inline dwc_otg_pcd_ep_t *get_in_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  84564. +{
  84565. + int i;
  84566. + int num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  84567. + if (ep_num == 0) {
  84568. + return &pcd->ep0;
  84569. + } else {
  84570. + for (i = 0; i < num_in_eps; ++i) {
  84571. + if (pcd->in_ep[i].dwc_ep.num == ep_num)
  84572. + return &pcd->in_ep[i];
  84573. + }
  84574. + return 0;
  84575. + }
  84576. +}
  84577. +
  84578. +/**
  84579. + * This function returns pointer to out ep struct with number ep_num
  84580. + */
  84581. +static inline dwc_otg_pcd_ep_t *get_out_ep(dwc_otg_pcd_t * pcd, uint32_t ep_num)
  84582. +{
  84583. + int i;
  84584. + int num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  84585. + if (ep_num == 0) {
  84586. + return &pcd->ep0;
  84587. + } else {
  84588. + for (i = 0; i < num_out_eps; ++i) {
  84589. + if (pcd->out_ep[i].dwc_ep.num == ep_num)
  84590. + return &pcd->out_ep[i];
  84591. + }
  84592. + return 0;
  84593. + }
  84594. +}
  84595. +
  84596. +/**
  84597. + * This functions gets a pointer to an EP from the wIndex address
  84598. + * value of the control request.
  84599. + */
  84600. +dwc_otg_pcd_ep_t *get_ep_by_addr(dwc_otg_pcd_t * pcd, u16 wIndex)
  84601. +{
  84602. + dwc_otg_pcd_ep_t *ep;
  84603. + uint32_t ep_num = UE_GET_ADDR(wIndex);
  84604. +
  84605. + if (ep_num == 0) {
  84606. + ep = &pcd->ep0;
  84607. + } else if (UE_GET_DIR(wIndex) == UE_DIR_IN) { /* in ep */
  84608. + ep = &pcd->in_ep[ep_num - 1];
  84609. + } else {
  84610. + ep = &pcd->out_ep[ep_num - 1];
  84611. + }
  84612. +
  84613. + return ep;
  84614. +}
  84615. +
  84616. +/**
  84617. + * This function checks the EP request queue, if the queue is not
  84618. + * empty the next request is started.
  84619. + */
  84620. +void start_next_request(dwc_otg_pcd_ep_t * ep)
  84621. +{
  84622. + dwc_otg_pcd_request_t *req = 0;
  84623. + uint32_t max_transfer =
  84624. + GET_CORE_IF(ep->pcd)->core_params->max_transfer_size;
  84625. +
  84626. +#ifdef DWC_UTE_CFI
  84627. + struct dwc_otg_pcd *pcd;
  84628. + pcd = ep->pcd;
  84629. +#endif
  84630. +
  84631. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  84632. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  84633. +
  84634. +#ifdef DWC_UTE_CFI
  84635. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  84636. + ep->dwc_ep.cfi_req_len = req->length;
  84637. + pcd->cfi->ops.build_descriptors(pcd->cfi, pcd, ep, req);
  84638. + } else {
  84639. +#endif
  84640. + /* Setup and start the Transfer */
  84641. + if (req->dw_align_buf) {
  84642. + ep->dwc_ep.dma_addr = req->dw_align_buf_dma;
  84643. + ep->dwc_ep.start_xfer_buff = req->dw_align_buf;
  84644. + ep->dwc_ep.xfer_buff = req->dw_align_buf;
  84645. + } else {
  84646. + ep->dwc_ep.dma_addr = req->dma;
  84647. + ep->dwc_ep.start_xfer_buff = req->buf;
  84648. + ep->dwc_ep.xfer_buff = req->buf;
  84649. + }
  84650. + ep->dwc_ep.sent_zlp = 0;
  84651. + ep->dwc_ep.total_len = req->length;
  84652. + ep->dwc_ep.xfer_len = 0;
  84653. + ep->dwc_ep.xfer_count = 0;
  84654. +
  84655. + ep->dwc_ep.maxxfer = max_transfer;
  84656. + if (GET_CORE_IF(ep->pcd)->dma_desc_enable) {
  84657. + uint32_t out_max_xfer = DDMA_MAX_TRANSFER_SIZE
  84658. + - (DDMA_MAX_TRANSFER_SIZE % 4);
  84659. + if (ep->dwc_ep.is_in) {
  84660. + if (ep->dwc_ep.maxxfer >
  84661. + DDMA_MAX_TRANSFER_SIZE) {
  84662. + ep->dwc_ep.maxxfer =
  84663. + DDMA_MAX_TRANSFER_SIZE;
  84664. + }
  84665. + } else {
  84666. + if (ep->dwc_ep.maxxfer > out_max_xfer) {
  84667. + ep->dwc_ep.maxxfer =
  84668. + out_max_xfer;
  84669. + }
  84670. + }
  84671. + }
  84672. + if (ep->dwc_ep.maxxfer < ep->dwc_ep.total_len) {
  84673. + ep->dwc_ep.maxxfer -=
  84674. + (ep->dwc_ep.maxxfer % ep->dwc_ep.maxpacket);
  84675. + }
  84676. + if (req->sent_zlp) {
  84677. + if ((ep->dwc_ep.total_len %
  84678. + ep->dwc_ep.maxpacket == 0)
  84679. + && (ep->dwc_ep.total_len != 0)) {
  84680. + ep->dwc_ep.sent_zlp = 1;
  84681. + }
  84682. +
  84683. + }
  84684. +#ifdef DWC_UTE_CFI
  84685. + }
  84686. +#endif
  84687. + dwc_otg_ep_start_transfer(GET_CORE_IF(ep->pcd), &ep->dwc_ep);
  84688. + } else if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  84689. + DWC_PRINTF("There are no more ISOC requests \n");
  84690. + ep->dwc_ep.frame_num = 0xFFFFFFFF;
  84691. + }
  84692. +}
  84693. +
  84694. +/**
  84695. + * This function handles the SOF Interrupts. At this time the SOF
  84696. + * Interrupt is disabled.
  84697. + */
  84698. +int32_t dwc_otg_pcd_handle_sof_intr(dwc_otg_pcd_t * pcd)
  84699. +{
  84700. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84701. +
  84702. + gintsts_data_t gintsts;
  84703. +
  84704. + DWC_DEBUGPL(DBG_PCD, "SOF\n");
  84705. +
  84706. + /* Clear interrupt */
  84707. + gintsts.d32 = 0;
  84708. + gintsts.b.sofintr = 1;
  84709. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  84710. +
  84711. + return 1;
  84712. +}
  84713. +
  84714. +/**
  84715. + * This function handles the Rx Status Queue Level Interrupt, which
  84716. + * indicates that there is a least one packet in the Rx FIFO. The
  84717. + * packets are moved from the FIFO to memory, where they will be
  84718. + * processed when the Endpoint Interrupt Register indicates Transfer
  84719. + * Complete or SETUP Phase Done.
  84720. + *
  84721. + * Repeat the following until the Rx Status Queue is empty:
  84722. + * -# Read the Receive Status Pop Register (GRXSTSP) to get Packet
  84723. + * info
  84724. + * -# If Receive FIFO is empty then skip to step Clear the interrupt
  84725. + * and exit
  84726. + * -# If SETUP Packet call dwc_otg_read_setup_packet to copy the
  84727. + * SETUP data to the buffer
  84728. + * -# If OUT Data Packet call dwc_otg_read_packet to copy the data
  84729. + * to the destination buffer
  84730. + */
  84731. +int32_t dwc_otg_pcd_handle_rx_status_q_level_intr(dwc_otg_pcd_t * pcd)
  84732. +{
  84733. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84734. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84735. + gintmsk_data_t gintmask = {.d32 = 0 };
  84736. + device_grxsts_data_t status;
  84737. + dwc_otg_pcd_ep_t *ep;
  84738. + gintsts_data_t gintsts;
  84739. +#ifdef DEBUG
  84740. + static char *dpid_str[] = { "D0", "D2", "D1", "MDATA" };
  84741. +#endif
  84742. +
  84743. + //DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, _pcd);
  84744. + /* Disable the Rx Status Queue Level interrupt */
  84745. + gintmask.b.rxstsqlvl = 1;
  84746. + DWC_MODIFY_REG32(&global_regs->gintmsk, gintmask.d32, 0);
  84747. +
  84748. + /* Get the Status from the top of the FIFO */
  84749. + status.d32 = DWC_READ_REG32(&global_regs->grxstsp);
  84750. +
  84751. + DWC_DEBUGPL(DBG_PCD, "EP:%d BCnt:%d DPID:%s "
  84752. + "pktsts:%x Frame:%d(0x%0x)\n",
  84753. + status.b.epnum, status.b.bcnt,
  84754. + dpid_str[status.b.dpid],
  84755. + status.b.pktsts, status.b.fn, status.b.fn);
  84756. + /* Get pointer to EP structure */
  84757. + ep = get_out_ep(pcd, status.b.epnum);
  84758. +
  84759. + switch (status.b.pktsts) {
  84760. + case DWC_DSTS_GOUT_NAK:
  84761. + DWC_DEBUGPL(DBG_PCDV, "Global OUT NAK\n");
  84762. + break;
  84763. + case DWC_STS_DATA_UPDT:
  84764. + DWC_DEBUGPL(DBG_PCDV, "OUT Data Packet\n");
  84765. + if (status.b.bcnt && ep->dwc_ep.xfer_buff) {
  84766. + /** @todo NGS Check for buffer overflow? */
  84767. + dwc_otg_read_packet(core_if,
  84768. + ep->dwc_ep.xfer_buff,
  84769. + status.b.bcnt);
  84770. + ep->dwc_ep.xfer_count += status.b.bcnt;
  84771. + ep->dwc_ep.xfer_buff += status.b.bcnt;
  84772. + }
  84773. + break;
  84774. + case DWC_STS_XFER_COMP:
  84775. + DWC_DEBUGPL(DBG_PCDV, "OUT Complete\n");
  84776. + break;
  84777. + case DWC_DSTS_SETUP_COMP:
  84778. +#ifdef DEBUG_EP0
  84779. + DWC_DEBUGPL(DBG_PCDV, "Setup Complete\n");
  84780. +#endif
  84781. + break;
  84782. + case DWC_DSTS_SETUP_UPDT:
  84783. + dwc_otg_read_setup_packet(core_if, pcd->setup_pkt->d32);
  84784. +#ifdef DEBUG_EP0
  84785. + DWC_DEBUGPL(DBG_PCD,
  84786. + "SETUP PKT: %02x.%02x v%04x i%04x l%04x\n",
  84787. + pcd->setup_pkt->req.bmRequestType,
  84788. + pcd->setup_pkt->req.bRequest,
  84789. + UGETW(pcd->setup_pkt->req.wValue),
  84790. + UGETW(pcd->setup_pkt->req.wIndex),
  84791. + UGETW(pcd->setup_pkt->req.wLength));
  84792. +#endif
  84793. + ep->dwc_ep.xfer_count += status.b.bcnt;
  84794. + break;
  84795. + default:
  84796. + DWC_DEBUGPL(DBG_PCDV, "Invalid Packet Status (0x%0x)\n",
  84797. + status.b.pktsts);
  84798. + break;
  84799. + }
  84800. +
  84801. + /* Enable the Rx Status Queue Level interrupt */
  84802. + DWC_MODIFY_REG32(&global_regs->gintmsk, 0, gintmask.d32);
  84803. + /* Clear interrupt */
  84804. + gintsts.d32 = 0;
  84805. + gintsts.b.rxstsqlvl = 1;
  84806. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  84807. +
  84808. + //DWC_DEBUGPL(DBG_PCDV, "EXIT: %s\n", __func__);
  84809. + return 1;
  84810. +}
  84811. +
  84812. +/**
  84813. + * This function examines the Device IN Token Learning Queue to
  84814. + * determine the EP number of the last IN token received. This
  84815. + * implementation is for the Mass Storage device where there are only
  84816. + * 2 IN EPs (Control-IN and BULK-IN).
  84817. + *
  84818. + * The EP numbers for the first six IN Tokens are in DTKNQR1 and there
  84819. + * are 8 EP Numbers in each of the other possible DTKNQ Registers.
  84820. + *
  84821. + * @param core_if Programming view of DWC_otg controller.
  84822. + *
  84823. + */
  84824. +static inline int get_ep_of_last_in_token(dwc_otg_core_if_t * core_if)
  84825. +{
  84826. + dwc_otg_device_global_regs_t *dev_global_regs =
  84827. + core_if->dev_if->dev_global_regs;
  84828. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  84829. + /* Number of Token Queue Registers */
  84830. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  84831. + dtknq1_data_t dtknqr1;
  84832. + uint32_t in_tkn_epnums[4];
  84833. + int ndx = 0;
  84834. + int i = 0;
  84835. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  84836. + int epnum = 0;
  84837. +
  84838. + //DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  84839. +
  84840. + /* Read the DTKNQ Registers */
  84841. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  84842. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  84843. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  84844. + in_tkn_epnums[i]);
  84845. + if (addr == &dev_global_regs->dvbusdis) {
  84846. + addr = &dev_global_regs->dtknqr3_dthrctl;
  84847. + } else {
  84848. + ++addr;
  84849. + }
  84850. +
  84851. + }
  84852. +
  84853. + /* Copy the DTKNQR1 data to the bit field. */
  84854. + dtknqr1.d32 = in_tkn_epnums[0];
  84855. + /* Get the EP numbers */
  84856. + in_tkn_epnums[0] = dtknqr1.b.epnums0_5;
  84857. + ndx = dtknqr1.b.intknwptr - 1;
  84858. +
  84859. + //DWC_DEBUGPL(DBG_PCDV,"ndx=%d\n",ndx);
  84860. + if (ndx == -1) {
  84861. + /** @todo Find a simpler way to calculate the max
  84862. + * queue position.*/
  84863. + int cnt = TOKEN_Q_DEPTH;
  84864. + if (TOKEN_Q_DEPTH <= 6) {
  84865. + cnt = TOKEN_Q_DEPTH - 1;
  84866. + } else if (TOKEN_Q_DEPTH <= 14) {
  84867. + cnt = TOKEN_Q_DEPTH - 7;
  84868. + } else if (TOKEN_Q_DEPTH <= 22) {
  84869. + cnt = TOKEN_Q_DEPTH - 15;
  84870. + } else {
  84871. + cnt = TOKEN_Q_DEPTH - 23;
  84872. + }
  84873. + epnum = (in_tkn_epnums[DTKNQ_REG_CNT - 1] >> (cnt * 4)) & 0xF;
  84874. + } else {
  84875. + if (ndx <= 5) {
  84876. + epnum = (in_tkn_epnums[0] >> (ndx * 4)) & 0xF;
  84877. + } else if (ndx <= 13) {
  84878. + ndx -= 6;
  84879. + epnum = (in_tkn_epnums[1] >> (ndx * 4)) & 0xF;
  84880. + } else if (ndx <= 21) {
  84881. + ndx -= 14;
  84882. + epnum = (in_tkn_epnums[2] >> (ndx * 4)) & 0xF;
  84883. + } else if (ndx <= 29) {
  84884. + ndx -= 22;
  84885. + epnum = (in_tkn_epnums[3] >> (ndx * 4)) & 0xF;
  84886. + }
  84887. + }
  84888. + //DWC_DEBUGPL(DBG_PCD,"epnum=%d\n",epnum);
  84889. + return epnum;
  84890. +}
  84891. +
  84892. +/**
  84893. + * This interrupt occurs when the non-periodic Tx FIFO is half-empty.
  84894. + * The active request is checked for the next packet to be loaded into
  84895. + * the non-periodic Tx FIFO.
  84896. + */
  84897. +int32_t dwc_otg_pcd_handle_np_tx_fifo_empty_intr(dwc_otg_pcd_t * pcd)
  84898. +{
  84899. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84900. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  84901. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  84902. + gnptxsts_data_t txstatus = {.d32 = 0 };
  84903. + gintsts_data_t gintsts;
  84904. +
  84905. + int epnum = 0;
  84906. + dwc_otg_pcd_ep_t *ep = 0;
  84907. + uint32_t len = 0;
  84908. + int dwords;
  84909. +
  84910. + /* Get the epnum from the IN Token Learning Queue. */
  84911. + epnum = get_ep_of_last_in_token(core_if);
  84912. + ep = get_in_ep(pcd, epnum);
  84913. +
  84914. + DWC_DEBUGPL(DBG_PCD, "NP TxFifo Empty: %d \n", epnum);
  84915. +
  84916. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  84917. +
  84918. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84919. + if (len > ep->dwc_ep.maxpacket) {
  84920. + len = ep->dwc_ep.maxpacket;
  84921. + }
  84922. + dwords = (len + 3) / 4;
  84923. +
  84924. + /* While there is space in the queue and space in the FIFO and
  84925. + * More data to tranfer, Write packets to the Tx FIFO */
  84926. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  84927. + DWC_DEBUGPL(DBG_PCDV, "b4 GNPTXSTS=0x%08x\n", txstatus.d32);
  84928. +
  84929. + while (txstatus.b.nptxqspcavail > 0 &&
  84930. + txstatus.b.nptxfspcavail > dwords &&
  84931. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len) {
  84932. + /* Write the FIFO */
  84933. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  84934. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84935. +
  84936. + if (len > ep->dwc_ep.maxpacket) {
  84937. + len = ep->dwc_ep.maxpacket;
  84938. + }
  84939. +
  84940. + dwords = (len + 3) / 4;
  84941. + txstatus.d32 = DWC_READ_REG32(&global_regs->gnptxsts);
  84942. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n", txstatus.d32);
  84943. + }
  84944. +
  84945. + DWC_DEBUGPL(DBG_PCDV, "GNPTXSTS=0x%08x\n",
  84946. + DWC_READ_REG32(&global_regs->gnptxsts));
  84947. +
  84948. + /* Clear interrupt */
  84949. + gintsts.d32 = 0;
  84950. + gintsts.b.nptxfempty = 1;
  84951. + DWC_WRITE_REG32(&global_regs->gintsts, gintsts.d32);
  84952. +
  84953. + return 1;
  84954. +}
  84955. +
  84956. +/**
  84957. + * This function is called when dedicated Tx FIFO Empty interrupt occurs.
  84958. + * The active request is checked for the next packet to be loaded into
  84959. + * apropriate Tx FIFO.
  84960. + */
  84961. +static int32_t write_empty_tx_fifo(dwc_otg_pcd_t * pcd, uint32_t epnum)
  84962. +{
  84963. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  84964. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  84965. + dwc_otg_dev_in_ep_regs_t *ep_regs;
  84966. + dtxfsts_data_t txstatus = {.d32 = 0 };
  84967. + dwc_otg_pcd_ep_t *ep = 0;
  84968. + uint32_t len = 0;
  84969. + int dwords;
  84970. +
  84971. + ep = get_in_ep(pcd, epnum);
  84972. +
  84973. + DWC_DEBUGPL(DBG_PCD, "Dedicated TxFifo Empty: %d \n", epnum);
  84974. +
  84975. + ep_regs = core_if->dev_if->in_ep_regs[epnum];
  84976. +
  84977. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84978. +
  84979. + if (len > ep->dwc_ep.maxpacket) {
  84980. + len = ep->dwc_ep.maxpacket;
  84981. + }
  84982. +
  84983. + dwords = (len + 3) / 4;
  84984. +
  84985. + /* While there is space in the queue and space in the FIFO and
  84986. + * More data to tranfer, Write packets to the Tx FIFO */
  84987. + txstatus.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  84988. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum, txstatus.d32);
  84989. +
  84990. + while (txstatus.b.txfspcavail > dwords &&
  84991. + ep->dwc_ep.xfer_count < ep->dwc_ep.xfer_len &&
  84992. + ep->dwc_ep.xfer_len != 0) {
  84993. + /* Write the FIFO */
  84994. + dwc_otg_ep_write_packet(core_if, &ep->dwc_ep, 0);
  84995. +
  84996. + len = ep->dwc_ep.xfer_len - ep->dwc_ep.xfer_count;
  84997. + if (len > ep->dwc_ep.maxpacket) {
  84998. + len = ep->dwc_ep.maxpacket;
  84999. + }
  85000. +
  85001. + dwords = (len + 3) / 4;
  85002. + txstatus.d32 =
  85003. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts);
  85004. + DWC_DEBUGPL(DBG_PCDV, "dtxfsts[%d]=0x%08x\n", epnum,
  85005. + txstatus.d32);
  85006. + }
  85007. +
  85008. + DWC_DEBUGPL(DBG_PCDV, "b4 dtxfsts[%d]=0x%08x\n", epnum,
  85009. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dtxfsts));
  85010. +
  85011. + return 1;
  85012. +}
  85013. +
  85014. +/**
  85015. + * This function is called when the Device is disconnected. It stops
  85016. + * any active requests and informs the Gadget driver of the
  85017. + * disconnect.
  85018. + */
  85019. +void dwc_otg_pcd_stop(dwc_otg_pcd_t * pcd)
  85020. +{
  85021. + int i, num_in_eps, num_out_eps;
  85022. + dwc_otg_pcd_ep_t *ep;
  85023. +
  85024. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85025. +
  85026. + DWC_SPINLOCK(pcd->lock);
  85027. +
  85028. + num_in_eps = GET_CORE_IF(pcd)->dev_if->num_in_eps;
  85029. + num_out_eps = GET_CORE_IF(pcd)->dev_if->num_out_eps;
  85030. +
  85031. + DWC_DEBUGPL(DBG_PCDV, "%s() \n", __func__);
  85032. + /* don't disconnect drivers more than once */
  85033. + if (pcd->ep0state == EP0_DISCONNECT) {
  85034. + DWC_DEBUGPL(DBG_ANY, "%s() Already Disconnected\n", __func__);
  85035. + DWC_SPINUNLOCK(pcd->lock);
  85036. + return;
  85037. + }
  85038. + pcd->ep0state = EP0_DISCONNECT;
  85039. +
  85040. + /* Reset the OTG state. */
  85041. + dwc_otg_pcd_update_otg(pcd, 1);
  85042. +
  85043. + /* Disable the NP Tx Fifo Empty Interrupt. */
  85044. + intr_mask.b.nptxfempty = 1;
  85045. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85046. + intr_mask.d32, 0);
  85047. +
  85048. + /* Flush the FIFOs */
  85049. + /**@todo NGS Flush Periodic FIFOs */
  85050. + dwc_otg_flush_tx_fifo(GET_CORE_IF(pcd), 0x10);
  85051. + dwc_otg_flush_rx_fifo(GET_CORE_IF(pcd));
  85052. +
  85053. + /* prevent new request submissions, kill any outstanding requests */
  85054. + ep = &pcd->ep0;
  85055. + dwc_otg_request_nuke(ep);
  85056. + /* prevent new request submissions, kill any outstanding requests */
  85057. + for (i = 0; i < num_in_eps; i++) {
  85058. + dwc_otg_pcd_ep_t *ep = &pcd->in_ep[i];
  85059. + dwc_otg_request_nuke(ep);
  85060. + }
  85061. + /* prevent new request submissions, kill any outstanding requests */
  85062. + for (i = 0; i < num_out_eps; i++) {
  85063. + dwc_otg_pcd_ep_t *ep = &pcd->out_ep[i];
  85064. + dwc_otg_request_nuke(ep);
  85065. + }
  85066. +
  85067. + /* report disconnect; the driver is already quiesced */
  85068. + if (pcd->fops->disconnect) {
  85069. + DWC_SPINUNLOCK(pcd->lock);
  85070. + pcd->fops->disconnect(pcd);
  85071. + DWC_SPINLOCK(pcd->lock);
  85072. + }
  85073. + DWC_SPINUNLOCK(pcd->lock);
  85074. +}
  85075. +
  85076. +/**
  85077. + * This interrupt indicates that ...
  85078. + */
  85079. +int32_t dwc_otg_pcd_handle_i2c_intr(dwc_otg_pcd_t * pcd)
  85080. +{
  85081. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85082. + gintsts_data_t gintsts;
  85083. +
  85084. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "i2cintr");
  85085. + intr_mask.b.i2cintr = 1;
  85086. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85087. + intr_mask.d32, 0);
  85088. +
  85089. + /* Clear interrupt */
  85090. + gintsts.d32 = 0;
  85091. + gintsts.b.i2cintr = 1;
  85092. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85093. + gintsts.d32);
  85094. + return 1;
  85095. +}
  85096. +
  85097. +/**
  85098. + * This interrupt indicates that ...
  85099. + */
  85100. +int32_t dwc_otg_pcd_handle_early_suspend_intr(dwc_otg_pcd_t * pcd)
  85101. +{
  85102. + gintsts_data_t gintsts;
  85103. +#if defined(VERBOSE)
  85104. + DWC_PRINTF("Early Suspend Detected\n");
  85105. +#endif
  85106. +
  85107. + /* Clear interrupt */
  85108. + gintsts.d32 = 0;
  85109. + gintsts.b.erlysuspend = 1;
  85110. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85111. + gintsts.d32);
  85112. + return 1;
  85113. +}
  85114. +
  85115. +/**
  85116. + * This function configures EPO to receive SETUP packets.
  85117. + *
  85118. + * @todo NGS: Update the comments from the HW FS.
  85119. + *
  85120. + * -# Program the following fields in the endpoint specific registers
  85121. + * for Control OUT EP 0, in order to receive a setup packet
  85122. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  85123. + * setup packets)
  85124. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  85125. + * to back setup packets)
  85126. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  85127. + * store any setup packets received
  85128. + *
  85129. + * @param core_if Programming view of DWC_otg controller.
  85130. + * @param pcd Programming view of the PCD.
  85131. + */
  85132. +static inline void ep0_out_start(dwc_otg_core_if_t * core_if,
  85133. + dwc_otg_pcd_t * pcd)
  85134. +{
  85135. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85136. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  85137. + dwc_otg_dev_dma_desc_t *dma_desc;
  85138. + depctl_data_t doepctl = {.d32 = 0 };
  85139. +
  85140. +#ifdef VERBOSE
  85141. + DWC_DEBUGPL(DBG_PCDV, "%s() doepctl0=%0x\n", __func__,
  85142. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  85143. +#endif
  85144. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85145. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl);
  85146. + if (doepctl.b.epena) {
  85147. + return;
  85148. + }
  85149. + }
  85150. +
  85151. + doeptsize0.b.supcnt = 3;
  85152. + doeptsize0.b.pktcnt = 1;
  85153. + doeptsize0.b.xfersize = 8 * 3;
  85154. +
  85155. + if (core_if->dma_enable) {
  85156. + if (!core_if->dma_desc_enable) {
  85157. + /** put here as for Hermes mode deptisz register should not be written */
  85158. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  85159. + doeptsize0.d32);
  85160. +
  85161. + /** @todo dma needs to handle multiple setup packets (up to 3) */
  85162. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  85163. + pcd->setup_pkt_dma_handle);
  85164. + } else {
  85165. + dev_if->setup_desc_index =
  85166. + (dev_if->setup_desc_index + 1) & 1;
  85167. + dma_desc =
  85168. + dev_if->setup_desc_addr[dev_if->setup_desc_index];
  85169. +
  85170. + /** DMA Descriptor Setup */
  85171. + dma_desc->status.b.bs = BS_HOST_BUSY;
  85172. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  85173. + dma_desc->status.b.sr = 0;
  85174. + dma_desc->status.b.mtrf = 0;
  85175. + }
  85176. + dma_desc->status.b.l = 1;
  85177. + dma_desc->status.b.ioc = 1;
  85178. + dma_desc->status.b.bytes = pcd->ep0.dwc_ep.maxpacket;
  85179. + dma_desc->buf = pcd->setup_pkt_dma_handle;
  85180. + dma_desc->status.b.sts = 0;
  85181. + dma_desc->status.b.bs = BS_HOST_READY;
  85182. +
  85183. + /** DOEPDMA0 Register write */
  85184. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepdma,
  85185. + dev_if->dma_setup_desc_addr
  85186. + [dev_if->setup_desc_index]);
  85187. + }
  85188. +
  85189. + } else {
  85190. + /** put here as for Hermes mode deptisz register should not be written */
  85191. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doeptsiz,
  85192. + doeptsize0.d32);
  85193. + }
  85194. +
  85195. + /** DOEPCTL0 Register write cnak will be set after setup interrupt */
  85196. + doepctl.d32 = 0;
  85197. + doepctl.b.epena = 1;
  85198. + if (core_if->snpsid <= OTG_CORE_REV_2_94a) {
  85199. + doepctl.b.cnak = 1;
  85200. + DWC_WRITE_REG32(&dev_if->out_ep_regs[0]->doepctl, doepctl.d32);
  85201. + } else {
  85202. + DWC_MODIFY_REG32(&dev_if->out_ep_regs[0]->doepctl, 0, doepctl.d32);
  85203. + }
  85204. +
  85205. +#ifdef VERBOSE
  85206. + DWC_DEBUGPL(DBG_PCDV, "doepctl0=%0x\n",
  85207. + DWC_READ_REG32(&dev_if->out_ep_regs[0]->doepctl));
  85208. + DWC_DEBUGPL(DBG_PCDV, "diepctl0=%0x\n",
  85209. + DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl));
  85210. +#endif
  85211. +}
  85212. +
  85213. +/**
  85214. + * This interrupt occurs when a USB Reset is detected. When the USB
  85215. + * Reset Interrupt occurs the device state is set to DEFAULT and the
  85216. + * EP0 state is set to IDLE.
  85217. + * -# Set the NAK bit for all OUT endpoints (DOEPCTLn.SNAK = 1)
  85218. + * -# Unmask the following interrupt bits
  85219. + * - DAINTMSK.INEP0 = 1 (Control 0 IN endpoint)
  85220. + * - DAINTMSK.OUTEP0 = 1 (Control 0 OUT endpoint)
  85221. + * - DOEPMSK.SETUP = 1
  85222. + * - DOEPMSK.XferCompl = 1
  85223. + * - DIEPMSK.XferCompl = 1
  85224. + * - DIEPMSK.TimeOut = 1
  85225. + * -# Program the following fields in the endpoint specific registers
  85226. + * for Control OUT EP 0, in order to receive a setup packet
  85227. + * - DOEPTSIZ0.Packet Count = 3 (To receive up to 3 back to back
  85228. + * setup packets)
  85229. + * - DOEPTSIZE0.Transfer Size = 24 Bytes (To receive up to 3 back
  85230. + * to back setup packets)
  85231. + * - In DMA mode, DOEPDMA0 Register with a memory address to
  85232. + * store any setup packets received
  85233. + * At this point, all the required initialization, except for enabling
  85234. + * the control 0 OUT endpoint is done, for receiving SETUP packets.
  85235. + */
  85236. +int32_t dwc_otg_pcd_handle_usb_reset_intr(dwc_otg_pcd_t * pcd)
  85237. +{
  85238. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85239. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  85240. + depctl_data_t doepctl = {.d32 = 0 };
  85241. + depctl_data_t diepctl = {.d32 = 0 };
  85242. + daint_data_t daintmsk = {.d32 = 0 };
  85243. + doepmsk_data_t doepmsk = {.d32 = 0 };
  85244. + diepmsk_data_t diepmsk = {.d32 = 0 };
  85245. + dcfg_data_t dcfg = {.d32 = 0 };
  85246. + grstctl_t resetctl = {.d32 = 0 };
  85247. + dctl_data_t dctl = {.d32 = 0 };
  85248. + int i = 0;
  85249. + gintsts_data_t gintsts;
  85250. + pcgcctl_data_t power = {.d32 = 0 };
  85251. +
  85252. + power.d32 = DWC_READ_REG32(core_if->pcgcctl);
  85253. + if (power.b.stoppclk) {
  85254. + power.d32 = 0;
  85255. + power.b.stoppclk = 1;
  85256. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85257. +
  85258. + power.b.pwrclmp = 1;
  85259. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85260. +
  85261. + power.b.rstpdwnmodule = 1;
  85262. + DWC_MODIFY_REG32(core_if->pcgcctl, power.d32, 0);
  85263. + }
  85264. +
  85265. + core_if->lx_state = DWC_OTG_L0;
  85266. +
  85267. + DWC_PRINTF("USB RESET\n");
  85268. +#ifdef DWC_EN_ISOC
  85269. + for (i = 1; i < 16; ++i) {
  85270. + dwc_otg_pcd_ep_t *ep;
  85271. + dwc_ep_t *dwc_ep;
  85272. + ep = get_in_ep(pcd, i);
  85273. + if (ep != 0) {
  85274. + dwc_ep = &ep->dwc_ep;
  85275. + dwc_ep->next_frame = 0xffffffff;
  85276. + }
  85277. + }
  85278. +#endif /* DWC_EN_ISOC */
  85279. +
  85280. + /* reset the HNP settings */
  85281. + dwc_otg_pcd_update_otg(pcd, 1);
  85282. +
  85283. + /* Clear the Remote Wakeup Signalling */
  85284. + dctl.b.rmtwkupsig = 1;
  85285. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, 0);
  85286. +
  85287. + /* Set NAK for all OUT EPs */
  85288. + doepctl.b.snak = 1;
  85289. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  85290. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  85291. + }
  85292. +
  85293. + /* Flush the NP Tx FIFO */
  85294. + dwc_otg_flush_tx_fifo(core_if, 0x10);
  85295. + /* Flush the Learning Queue */
  85296. + resetctl.b.intknqflsh = 1;
  85297. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  85298. +
  85299. + if (!core_if->core_params->en_multiple_tx_fifo && core_if->dma_enable) {
  85300. + core_if->start_predict = 0;
  85301. + for (i = 0; i<= core_if->dev_if->num_in_eps; ++i) {
  85302. + core_if->nextep_seq[i] = 0xff; // 0xff - EP not active
  85303. + }
  85304. + core_if->nextep_seq[0] = 0;
  85305. + core_if->first_in_nextep_seq = 0;
  85306. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[0]->diepctl);
  85307. + diepctl.b.nextep = 0;
  85308. + DWC_WRITE_REG32(&dev_if->in_ep_regs[0]->diepctl, diepctl.d32);
  85309. +
  85310. + /* Update IN Endpoint Mismatch Count by active IN NP EP count + 1 */
  85311. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  85312. + dcfg.b.epmscnt = 2;
  85313. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  85314. +
  85315. + DWC_DEBUGPL(DBG_PCDV,
  85316. + "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  85317. + __func__, core_if->first_in_nextep_seq);
  85318. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  85319. + DWC_DEBUGPL(DBG_PCDV, "%2d\n", core_if->nextep_seq[i]);
  85320. + }
  85321. + }
  85322. +
  85323. + if (core_if->multiproc_int_enable) {
  85324. + daintmsk.b.inep0 = 1;
  85325. + daintmsk.b.outep0 = 1;
  85326. + DWC_WRITE_REG32(&dev_if->dev_global_regs->deachintmsk,
  85327. + daintmsk.d32);
  85328. +
  85329. + doepmsk.b.setup = 1;
  85330. + doepmsk.b.xfercompl = 1;
  85331. + doepmsk.b.ahberr = 1;
  85332. + doepmsk.b.epdisabled = 1;
  85333. +
  85334. + if ((core_if->dma_desc_enable) ||
  85335. + (core_if->dma_enable
  85336. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  85337. + doepmsk.b.stsphsercvd = 1;
  85338. + }
  85339. + if (core_if->dma_desc_enable)
  85340. + doepmsk.b.bna = 1;
  85341. +/*
  85342. + doepmsk.b.babble = 1;
  85343. + doepmsk.b.nyet = 1;
  85344. +
  85345. + if (core_if->dma_enable) {
  85346. + doepmsk.b.nak = 1;
  85347. + }
  85348. +*/
  85349. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepeachintmsk[0],
  85350. + doepmsk.d32);
  85351. +
  85352. + diepmsk.b.xfercompl = 1;
  85353. + diepmsk.b.timeout = 1;
  85354. + diepmsk.b.epdisabled = 1;
  85355. + diepmsk.b.ahberr = 1;
  85356. + diepmsk.b.intknepmis = 1;
  85357. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  85358. + diepmsk.b.intknepmis = 0;
  85359. +
  85360. +/* if (core_if->dma_desc_enable) {
  85361. + diepmsk.b.bna = 1;
  85362. + }
  85363. +*/
  85364. +/*
  85365. + if (core_if->dma_enable) {
  85366. + diepmsk.b.nak = 1;
  85367. + }
  85368. +*/
  85369. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepeachintmsk[0],
  85370. + diepmsk.d32);
  85371. + } else {
  85372. + daintmsk.b.inep0 = 1;
  85373. + daintmsk.b.outep0 = 1;
  85374. + DWC_WRITE_REG32(&dev_if->dev_global_regs->daintmsk,
  85375. + daintmsk.d32);
  85376. +
  85377. + doepmsk.b.setup = 1;
  85378. + doepmsk.b.xfercompl = 1;
  85379. + doepmsk.b.ahberr = 1;
  85380. + doepmsk.b.epdisabled = 1;
  85381. +
  85382. + if ((core_if->dma_desc_enable) ||
  85383. + (core_if->dma_enable
  85384. + && core_if->snpsid >= OTG_CORE_REV_3_00a)) {
  85385. + doepmsk.b.stsphsercvd = 1;
  85386. + }
  85387. + if (core_if->dma_desc_enable)
  85388. + doepmsk.b.bna = 1;
  85389. + DWC_WRITE_REG32(&dev_if->dev_global_regs->doepmsk, doepmsk.d32);
  85390. +
  85391. + diepmsk.b.xfercompl = 1;
  85392. + diepmsk.b.timeout = 1;
  85393. + diepmsk.b.epdisabled = 1;
  85394. + diepmsk.b.ahberr = 1;
  85395. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable)
  85396. + diepmsk.b.intknepmis = 0;
  85397. +/*
  85398. + if (core_if->dma_desc_enable) {
  85399. + diepmsk.b.bna = 1;
  85400. + }
  85401. +*/
  85402. +
  85403. + DWC_WRITE_REG32(&dev_if->dev_global_regs->diepmsk, diepmsk.d32);
  85404. + }
  85405. +
  85406. + /* Reset Device Address */
  85407. + dcfg.d32 = DWC_READ_REG32(&dev_if->dev_global_regs->dcfg);
  85408. + dcfg.b.devaddr = 0;
  85409. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dcfg, dcfg.d32);
  85410. +
  85411. + /* setup EP0 to receive SETUP packets */
  85412. + if (core_if->snpsid <= OTG_CORE_REV_2_94a)
  85413. + ep0_out_start(core_if, pcd);
  85414. +
  85415. + /* Clear interrupt */
  85416. + gintsts.d32 = 0;
  85417. + gintsts.b.usbreset = 1;
  85418. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85419. +
  85420. + return 1;
  85421. +}
  85422. +
  85423. +/**
  85424. + * Get the device speed from the device status register and convert it
  85425. + * to USB speed constant.
  85426. + *
  85427. + * @param core_if Programming view of DWC_otg controller.
  85428. + */
  85429. +static int get_device_speed(dwc_otg_core_if_t * core_if)
  85430. +{
  85431. + dsts_data_t dsts;
  85432. + int speed = 0;
  85433. + dsts.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dsts);
  85434. +
  85435. + switch (dsts.b.enumspd) {
  85436. + case DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ:
  85437. + speed = USB_SPEED_HIGH;
  85438. + break;
  85439. + case DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ:
  85440. + case DWC_DSTS_ENUMSPD_FS_PHY_48MHZ:
  85441. + speed = USB_SPEED_FULL;
  85442. + break;
  85443. +
  85444. + case DWC_DSTS_ENUMSPD_LS_PHY_6MHZ:
  85445. + speed = USB_SPEED_LOW;
  85446. + break;
  85447. + }
  85448. +
  85449. + return speed;
  85450. +}
  85451. +
  85452. +/**
  85453. + * Read the device status register and set the device speed in the
  85454. + * data structure.
  85455. + * Set up EP0 to receive SETUP packets by calling dwc_ep0_activate.
  85456. + */
  85457. +int32_t dwc_otg_pcd_handle_enum_done_intr(dwc_otg_pcd_t * pcd)
  85458. +{
  85459. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85460. + gintsts_data_t gintsts;
  85461. + gusbcfg_data_t gusbcfg;
  85462. + dwc_otg_core_global_regs_t *global_regs =
  85463. + GET_CORE_IF(pcd)->core_global_regs;
  85464. + uint8_t utmi16b, utmi8b;
  85465. + int speed;
  85466. + DWC_DEBUGPL(DBG_PCD, "SPEED ENUM\n");
  85467. +
  85468. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_2_60a) {
  85469. + utmi16b = 6; //vahrama old value was 6;
  85470. + utmi8b = 9;
  85471. + } else {
  85472. + utmi16b = 4;
  85473. + utmi8b = 8;
  85474. + }
  85475. + dwc_otg_ep0_activate(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85476. + if (GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a) {
  85477. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85478. + }
  85479. +
  85480. +#ifdef DEBUG_EP0
  85481. + print_ep0_state(pcd);
  85482. +#endif
  85483. +
  85484. + if (pcd->ep0state == EP0_DISCONNECT) {
  85485. + pcd->ep0state = EP0_IDLE;
  85486. + } else if (pcd->ep0state == EP0_STALL) {
  85487. + pcd->ep0state = EP0_IDLE;
  85488. + }
  85489. +
  85490. + pcd->ep0state = EP0_IDLE;
  85491. +
  85492. + ep0->stopped = 0;
  85493. +
  85494. + speed = get_device_speed(GET_CORE_IF(pcd));
  85495. + pcd->fops->connect(pcd, speed);
  85496. +
  85497. + /* Set USB turnaround time based on device speed and PHY interface. */
  85498. + gusbcfg.d32 = DWC_READ_REG32(&global_regs->gusbcfg);
  85499. + if (speed == USB_SPEED_HIGH) {
  85500. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85501. + DWC_HWCFG2_HS_PHY_TYPE_ULPI) {
  85502. + /* ULPI interface */
  85503. + gusbcfg.b.usbtrdtim = 9;
  85504. + }
  85505. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85506. + DWC_HWCFG2_HS_PHY_TYPE_UTMI) {
  85507. + /* UTMI+ interface */
  85508. + if (GET_CORE_IF(pcd)->hwcfg4.b.utmi_phy_data_width == 0) {
  85509. + gusbcfg.b.usbtrdtim = utmi8b;
  85510. + } else if (GET_CORE_IF(pcd)->hwcfg4.
  85511. + b.utmi_phy_data_width == 1) {
  85512. + gusbcfg.b.usbtrdtim = utmi16b;
  85513. + } else if (GET_CORE_IF(pcd)->
  85514. + core_params->phy_utmi_width == 8) {
  85515. + gusbcfg.b.usbtrdtim = utmi8b;
  85516. + } else {
  85517. + gusbcfg.b.usbtrdtim = utmi16b;
  85518. + }
  85519. + }
  85520. + if (GET_CORE_IF(pcd)->hwcfg2.b.hs_phy_type ==
  85521. + DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI) {
  85522. + /* UTMI+ OR ULPI interface */
  85523. + if (gusbcfg.b.ulpi_utmi_sel == 1) {
  85524. + /* ULPI interface */
  85525. + gusbcfg.b.usbtrdtim = 9;
  85526. + } else {
  85527. + /* UTMI+ interface */
  85528. + if (GET_CORE_IF(pcd)->
  85529. + core_params->phy_utmi_width == 16) {
  85530. + gusbcfg.b.usbtrdtim = utmi16b;
  85531. + } else {
  85532. + gusbcfg.b.usbtrdtim = utmi8b;
  85533. + }
  85534. + }
  85535. + }
  85536. + } else {
  85537. + /* Full or low speed */
  85538. + gusbcfg.b.usbtrdtim = 9;
  85539. + }
  85540. + DWC_WRITE_REG32(&global_regs->gusbcfg, gusbcfg.d32);
  85541. +
  85542. + /* Clear interrupt */
  85543. + gintsts.d32 = 0;
  85544. + gintsts.b.enumdone = 1;
  85545. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85546. + gintsts.d32);
  85547. + return 1;
  85548. +}
  85549. +
  85550. +/**
  85551. + * This interrupt indicates that the ISO OUT Packet was dropped due to
  85552. + * Rx FIFO full or Rx Status Queue Full. If this interrupt occurs
  85553. + * read all the data from the Rx FIFO.
  85554. + */
  85555. +int32_t dwc_otg_pcd_handle_isoc_out_packet_dropped_intr(dwc_otg_pcd_t * pcd)
  85556. +{
  85557. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85558. + gintsts_data_t gintsts;
  85559. +
  85560. + DWC_WARN("INTERRUPT Handler not implemented for %s\n",
  85561. + "ISOC Out Dropped");
  85562. +
  85563. + intr_mask.b.isooutdrop = 1;
  85564. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85565. + intr_mask.d32, 0);
  85566. +
  85567. + /* Clear interrupt */
  85568. + gintsts.d32 = 0;
  85569. + gintsts.b.isooutdrop = 1;
  85570. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85571. + gintsts.d32);
  85572. +
  85573. + return 1;
  85574. +}
  85575. +
  85576. +/**
  85577. + * This interrupt indicates the end of the portion of the micro-frame
  85578. + * for periodic transactions. If there is a periodic transaction for
  85579. + * the next frame, load the packets into the EP periodic Tx FIFO.
  85580. + */
  85581. +int32_t dwc_otg_pcd_handle_end_periodic_frame_intr(dwc_otg_pcd_t * pcd)
  85582. +{
  85583. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85584. + gintsts_data_t gintsts;
  85585. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "EOP");
  85586. +
  85587. + intr_mask.b.eopframe = 1;
  85588. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  85589. + intr_mask.d32, 0);
  85590. +
  85591. + /* Clear interrupt */
  85592. + gintsts.d32 = 0;
  85593. + gintsts.b.eopframe = 1;
  85594. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  85595. + gintsts.d32);
  85596. +
  85597. + return 1;
  85598. +}
  85599. +
  85600. +/**
  85601. + * This interrupt indicates that EP of the packet on the top of the
  85602. + * non-periodic Tx FIFO does not match EP of the IN Token received.
  85603. + *
  85604. + * The "Device IN Token Queue" Registers are read to determine the
  85605. + * order the IN Tokens have been received. The non-periodic Tx FIFO
  85606. + * is flushed, so it can be reloaded in the order seen in the IN Token
  85607. + * Queue.
  85608. + */
  85609. +int32_t dwc_otg_pcd_handle_ep_mismatch_intr(dwc_otg_pcd_t * pcd)
  85610. +{
  85611. + gintsts_data_t gintsts;
  85612. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85613. + dctl_data_t dctl;
  85614. + gintmsk_data_t intr_mask = {.d32 = 0 };
  85615. +
  85616. + if (!core_if->en_multiple_tx_fifo && core_if->dma_enable) {
  85617. + core_if->start_predict = 1;
  85618. +
  85619. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  85620. +
  85621. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  85622. + if (!gintsts.b.ginnakeff) {
  85623. + /* Disable EP Mismatch interrupt */
  85624. + intr_mask.d32 = 0;
  85625. + intr_mask.b.epmismatch = 1;
  85626. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32, 0);
  85627. + /* Enable the Global IN NAK Effective Interrupt */
  85628. + intr_mask.d32 = 0;
  85629. + intr_mask.b.ginnakeff = 1;
  85630. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  85631. + /* Set the global non-periodic IN NAK handshake */
  85632. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  85633. + dctl.b.sgnpinnak = 1;
  85634. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  85635. + } else {
  85636. + DWC_PRINTF("gintsts.b.ginnakeff = 1! dctl.b.sgnpinnak not set\n");
  85637. + }
  85638. + /* Disabling of all EP's will be done in dwc_otg_pcd_handle_in_nak_effective()
  85639. + * handler after Global IN NAK Effective interrupt will be asserted */
  85640. + }
  85641. + /* Clear interrupt */
  85642. + gintsts.d32 = 0;
  85643. + gintsts.b.epmismatch = 1;
  85644. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85645. +
  85646. + return 1;
  85647. +}
  85648. +
  85649. +/**
  85650. + * This interrupt is valid only in DMA mode. This interrupt indicates that the
  85651. + * core has stopped fetching data for IN endpoints due to the unavailability of
  85652. + * TxFIFO space or Request Queue space. This interrupt is used by the
  85653. + * application for an endpoint mismatch algorithm.
  85654. + *
  85655. + * @param pcd The PCD
  85656. + */
  85657. +int32_t dwc_otg_pcd_handle_ep_fetsusp_intr(dwc_otg_pcd_t * pcd)
  85658. +{
  85659. + gintsts_data_t gintsts;
  85660. + gintmsk_data_t gintmsk_data;
  85661. + dctl_data_t dctl;
  85662. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85663. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, core_if);
  85664. +
  85665. + /* Clear the global non-periodic IN NAK handshake */
  85666. + dctl.d32 = 0;
  85667. + dctl.b.cgnpinnak = 1;
  85668. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  85669. +
  85670. + /* Mask GINTSTS.FETSUSP interrupt */
  85671. + gintmsk_data.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  85672. + gintmsk_data.b.fetsusp = 0;
  85673. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, gintmsk_data.d32);
  85674. +
  85675. + /* Clear interrupt */
  85676. + gintsts.d32 = 0;
  85677. + gintsts.b.fetsusp = 1;
  85678. + DWC_WRITE_REG32(&core_if->core_global_regs->gintsts, gintsts.d32);
  85679. +
  85680. + return 1;
  85681. +}
  85682. +/**
  85683. + * This funcion stalls EP0.
  85684. + */
  85685. +static inline void ep0_do_stall(dwc_otg_pcd_t * pcd, const int err_val)
  85686. +{
  85687. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85688. + usb_device_request_t *ctrl = &pcd->setup_pkt->req;
  85689. + DWC_WARN("req %02x.%02x protocol STALL; err %d\n",
  85690. + ctrl->bmRequestType, ctrl->bRequest, err_val);
  85691. +
  85692. + ep0->dwc_ep.is_in = 1;
  85693. + dwc_otg_ep_set_stall(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85694. + pcd->ep0.stopped = 1;
  85695. + pcd->ep0state = EP0_IDLE;
  85696. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85697. +}
  85698. +
  85699. +/**
  85700. + * This functions delegates the setup command to the gadget driver.
  85701. + */
  85702. +static inline void do_gadget_setup(dwc_otg_pcd_t * pcd,
  85703. + usb_device_request_t * ctrl)
  85704. +{
  85705. + int ret = 0;
  85706. + DWC_SPINUNLOCK(pcd->lock);
  85707. + ret = pcd->fops->setup(pcd, (uint8_t *) ctrl);
  85708. + DWC_SPINLOCK(pcd->lock);
  85709. + if (ret < 0) {
  85710. + ep0_do_stall(pcd, ret);
  85711. + }
  85712. +
  85713. + /** @todo This is a g_file_storage gadget driver specific
  85714. + * workaround: a DELAYED_STATUS result from the fsg_setup
  85715. + * routine will result in the gadget queueing a EP0 IN status
  85716. + * phase for a two-stage control transfer. Exactly the same as
  85717. + * a SET_CONFIGURATION/SET_INTERFACE except that this is a class
  85718. + * specific request. Need a generic way to know when the gadget
  85719. + * driver will queue the status phase. Can we assume when we
  85720. + * call the gadget driver setup() function that it will always
  85721. + * queue and require the following flag? Need to look into
  85722. + * this.
  85723. + */
  85724. +
  85725. + if (ret == 256 + 999) {
  85726. + pcd->request_config = 1;
  85727. + }
  85728. +}
  85729. +
  85730. +#ifdef DWC_UTE_CFI
  85731. +/**
  85732. + * This functions delegates the CFI setup commands to the gadget driver.
  85733. + * This function will return a negative value to indicate a failure.
  85734. + */
  85735. +static inline int cfi_gadget_setup(dwc_otg_pcd_t * pcd,
  85736. + struct cfi_usb_ctrlrequest *ctrl_req)
  85737. +{
  85738. + int ret = 0;
  85739. +
  85740. + if (pcd->fops && pcd->fops->cfi_setup) {
  85741. + DWC_SPINUNLOCK(pcd->lock);
  85742. + ret = pcd->fops->cfi_setup(pcd, ctrl_req);
  85743. + DWC_SPINLOCK(pcd->lock);
  85744. + if (ret < 0) {
  85745. + ep0_do_stall(pcd, ret);
  85746. + return ret;
  85747. + }
  85748. + }
  85749. +
  85750. + return ret;
  85751. +}
  85752. +#endif
  85753. +
  85754. +/**
  85755. + * This function starts the Zero-Length Packet for the IN status phase
  85756. + * of a 2 stage control transfer.
  85757. + */
  85758. +static inline void do_setup_in_status_phase(dwc_otg_pcd_t * pcd)
  85759. +{
  85760. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85761. + if (pcd->ep0state == EP0_STALL) {
  85762. + return;
  85763. + }
  85764. +
  85765. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  85766. +
  85767. + /* Prepare for more SETUP Packets */
  85768. + DWC_DEBUGPL(DBG_PCD, "EP0 IN ZLP\n");
  85769. + if ((GET_CORE_IF(pcd)->snpsid >= OTG_CORE_REV_3_00a)
  85770. + && (pcd->core_if->dma_desc_enable)
  85771. + && (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len)) {
  85772. + DWC_DEBUGPL(DBG_PCDV,
  85773. + "Data terminated wait next packet in out_desc_addr\n");
  85774. + pcd->backup_buf = phys_to_virt(ep0->dwc_ep.dma_addr);
  85775. + pcd->data_terminated = 1;
  85776. + }
  85777. + ep0->dwc_ep.xfer_len = 0;
  85778. + ep0->dwc_ep.xfer_count = 0;
  85779. + ep0->dwc_ep.is_in = 1;
  85780. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  85781. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85782. +
  85783. + /* Prepare for more SETUP Packets */
  85784. + //ep0_out_start(GET_CORE_IF(pcd), pcd);
  85785. +}
  85786. +
  85787. +/**
  85788. + * This function starts the Zero-Length Packet for the OUT status phase
  85789. + * of a 2 stage control transfer.
  85790. + */
  85791. +static inline void do_setup_out_status_phase(dwc_otg_pcd_t * pcd)
  85792. +{
  85793. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85794. + if (pcd->ep0state == EP0_STALL) {
  85795. + DWC_DEBUGPL(DBG_PCD, "EP0 STALLED\n");
  85796. + return;
  85797. + }
  85798. + pcd->ep0state = EP0_OUT_STATUS_PHASE;
  85799. +
  85800. + DWC_DEBUGPL(DBG_PCD, "EP0 OUT ZLP\n");
  85801. + ep0->dwc_ep.xfer_len = 0;
  85802. + ep0->dwc_ep.xfer_count = 0;
  85803. + ep0->dwc_ep.is_in = 0;
  85804. + ep0->dwc_ep.dma_addr = pcd->setup_pkt_dma_handle;
  85805. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85806. +
  85807. + /* Prepare for more SETUP Packets */
  85808. + if (GET_CORE_IF(pcd)->dma_enable == 0) {
  85809. + ep0_out_start(GET_CORE_IF(pcd), pcd);
  85810. + }
  85811. +}
  85812. +
  85813. +/**
  85814. + * Clear the EP halt (STALL) and if pending requests start the
  85815. + * transfer.
  85816. + */
  85817. +static inline void pcd_clear_halt(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  85818. +{
  85819. + if (ep->dwc_ep.stall_clear_flag == 0)
  85820. + dwc_otg_ep_clear_stall(GET_CORE_IF(pcd), &ep->dwc_ep);
  85821. +
  85822. + /* Reactive the EP */
  85823. + dwc_otg_ep_activate(GET_CORE_IF(pcd), &ep->dwc_ep);
  85824. + if (ep->stopped) {
  85825. + ep->stopped = 0;
  85826. + /* If there is a request in the EP queue start it */
  85827. +
  85828. + /** @todo FIXME: this causes an EP mismatch in DMA mode.
  85829. + * epmismatch not yet implemented. */
  85830. +
  85831. + /*
  85832. + * Above fixme is solved by implmenting a tasklet to call the
  85833. + * start_next_request(), outside of interrupt context at some
  85834. + * time after the current time, after a clear-halt setup packet.
  85835. + * Still need to implement ep mismatch in the future if a gadget
  85836. + * ever uses more than one endpoint at once
  85837. + */
  85838. + ep->queue_sof = 1;
  85839. + DWC_TASK_SCHEDULE(pcd->start_xfer_tasklet);
  85840. + }
  85841. + /* Start Control Status Phase */
  85842. + do_setup_in_status_phase(pcd);
  85843. +}
  85844. +
  85845. +/**
  85846. + * This function is called when the SET_FEATURE TEST_MODE Setup packet
  85847. + * is sent from the host. The Device Control register is written with
  85848. + * the Test Mode bits set to the specified Test Mode. This is done as
  85849. + * a tasklet so that the "Status" phase of the control transfer
  85850. + * completes before transmitting the TEST packets.
  85851. + *
  85852. + * @todo This has not been tested since the tasklet struct was put
  85853. + * into the PCD struct!
  85854. + *
  85855. + */
  85856. +void do_test_mode(void *data)
  85857. +{
  85858. + dctl_data_t dctl;
  85859. + dwc_otg_pcd_t *pcd = (dwc_otg_pcd_t *) data;
  85860. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85861. + int test_mode = pcd->test_mode;
  85862. +
  85863. +// DWC_WARN("%s() has not been tested since being rewritten!\n", __func__);
  85864. +
  85865. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  85866. + switch (test_mode) {
  85867. + case 1: // TEST_J
  85868. + dctl.b.tstctl = 1;
  85869. + break;
  85870. +
  85871. + case 2: // TEST_K
  85872. + dctl.b.tstctl = 2;
  85873. + break;
  85874. +
  85875. + case 3: // TEST_SE0_NAK
  85876. + dctl.b.tstctl = 3;
  85877. + break;
  85878. +
  85879. + case 4: // TEST_PACKET
  85880. + dctl.b.tstctl = 4;
  85881. + break;
  85882. +
  85883. + case 5: // TEST_FORCE_ENABLE
  85884. + dctl.b.tstctl = 5;
  85885. + break;
  85886. + }
  85887. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  85888. +}
  85889. +
  85890. +/**
  85891. + * This function process the GET_STATUS Setup Commands.
  85892. + */
  85893. +static inline void do_get_status(dwc_otg_pcd_t * pcd)
  85894. +{
  85895. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85896. + dwc_otg_pcd_ep_t *ep;
  85897. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  85898. + uint16_t *status = pcd->status_buf;
  85899. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85900. +
  85901. +#ifdef DEBUG_EP0
  85902. + DWC_DEBUGPL(DBG_PCD,
  85903. + "GET_STATUS %02x.%02x v%04x i%04x l%04x\n",
  85904. + ctrl.bmRequestType, ctrl.bRequest,
  85905. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  85906. + UGETW(ctrl.wLength));
  85907. +#endif
  85908. +
  85909. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  85910. + case UT_DEVICE:
  85911. + if(UGETW(ctrl.wIndex) == 0xF000) { /* OTG Status selector */
  85912. + DWC_PRINTF("wIndex - %d\n", UGETW(ctrl.wIndex));
  85913. + DWC_PRINTF("OTG VERSION - %d\n", core_if->otg_ver);
  85914. + DWC_PRINTF("OTG CAP - %d, %d\n",
  85915. + core_if->core_params->otg_cap,
  85916. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE);
  85917. + if (core_if->otg_ver == 1
  85918. + && core_if->core_params->otg_cap ==
  85919. + DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  85920. + uint8_t *otgsts = (uint8_t*)pcd->status_buf;
  85921. + *otgsts = (core_if->otg_sts & 0x1);
  85922. + pcd->ep0_pending = 1;
  85923. + ep0->dwc_ep.start_xfer_buff =
  85924. + (uint8_t *) otgsts;
  85925. + ep0->dwc_ep.xfer_buff = (uint8_t *) otgsts;
  85926. + ep0->dwc_ep.dma_addr =
  85927. + pcd->status_buf_dma_handle;
  85928. + ep0->dwc_ep.xfer_len = 1;
  85929. + ep0->dwc_ep.xfer_count = 0;
  85930. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  85931. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd),
  85932. + &ep0->dwc_ep);
  85933. + return;
  85934. + } else {
  85935. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85936. + return;
  85937. + }
  85938. + break;
  85939. + } else {
  85940. + *status = 0x1; /* Self powered */
  85941. + *status |= pcd->remote_wakeup_enable << 1;
  85942. + break;
  85943. + }
  85944. + case UT_INTERFACE:
  85945. + *status = 0;
  85946. + break;
  85947. +
  85948. + case UT_ENDPOINT:
  85949. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  85950. + if (ep == 0 || UGETW(ctrl.wLength) > 2) {
  85951. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  85952. + return;
  85953. + }
  85954. + /** @todo check for EP stall */
  85955. + *status = ep->stopped;
  85956. + break;
  85957. + }
  85958. + pcd->ep0_pending = 1;
  85959. + ep0->dwc_ep.start_xfer_buff = (uint8_t *) status;
  85960. + ep0->dwc_ep.xfer_buff = (uint8_t *) status;
  85961. + ep0->dwc_ep.dma_addr = pcd->status_buf_dma_handle;
  85962. + ep0->dwc_ep.xfer_len = 2;
  85963. + ep0->dwc_ep.xfer_count = 0;
  85964. + ep0->dwc_ep.total_len = ep0->dwc_ep.xfer_len;
  85965. + dwc_otg_ep0_start_transfer(GET_CORE_IF(pcd), &ep0->dwc_ep);
  85966. +}
  85967. +
  85968. +/**
  85969. + * This function process the SET_FEATURE Setup Commands.
  85970. + */
  85971. +static inline void do_set_feature(dwc_otg_pcd_t * pcd)
  85972. +{
  85973. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  85974. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  85975. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  85976. + dwc_otg_pcd_ep_t *ep = 0;
  85977. + int32_t otg_cap_param = core_if->core_params->otg_cap;
  85978. + gotgctl_data_t gotgctl = {.d32 = 0 };
  85979. +
  85980. + DWC_DEBUGPL(DBG_PCD, "SET_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  85981. + ctrl.bmRequestType, ctrl.bRequest,
  85982. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  85983. + UGETW(ctrl.wLength));
  85984. + DWC_DEBUGPL(DBG_PCD, "otg_cap=%d\n", otg_cap_param);
  85985. +
  85986. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  85987. + case UT_DEVICE:
  85988. + switch (UGETW(ctrl.wValue)) {
  85989. + case UF_DEVICE_REMOTE_WAKEUP:
  85990. + pcd->remote_wakeup_enable = 1;
  85991. + break;
  85992. +
  85993. + case UF_TEST_MODE:
  85994. + /* Setup the Test Mode tasklet to do the Test
  85995. + * Packet generation after the SETUP Status
  85996. + * phase has completed. */
  85997. +
  85998. + /** @todo This has not been tested since the
  85999. + * tasklet struct was put into the PCD
  86000. + * struct! */
  86001. + pcd->test_mode = UGETW(ctrl.wIndex) >> 8;
  86002. + DWC_TASK_SCHEDULE(pcd->test_mode_tasklet);
  86003. + break;
  86004. +
  86005. + case UF_DEVICE_B_HNP_ENABLE:
  86006. + DWC_DEBUGPL(DBG_PCDV,
  86007. + "SET_FEATURE: USB_DEVICE_B_HNP_ENABLE\n");
  86008. +
  86009. + /* dev may initiate HNP */
  86010. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86011. + pcd->b_hnp_enable = 1;
  86012. + dwc_otg_pcd_update_otg(pcd, 0);
  86013. + DWC_DEBUGPL(DBG_PCD, "Request B HNP\n");
  86014. + /**@todo Is the gotgctl.devhnpen cleared
  86015. + * by a USB Reset? */
  86016. + gotgctl.b.devhnpen = 1;
  86017. + gotgctl.b.hnpreq = 1;
  86018. + DWC_WRITE_REG32(&global_regs->gotgctl,
  86019. + gotgctl.d32);
  86020. + } else {
  86021. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86022. + return;
  86023. + }
  86024. + break;
  86025. +
  86026. + case UF_DEVICE_A_HNP_SUPPORT:
  86027. + /* RH port supports HNP */
  86028. + DWC_DEBUGPL(DBG_PCDV,
  86029. + "SET_FEATURE: USB_DEVICE_A_HNP_SUPPORT\n");
  86030. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86031. + pcd->a_hnp_support = 1;
  86032. + dwc_otg_pcd_update_otg(pcd, 0);
  86033. + } else {
  86034. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86035. + return;
  86036. + }
  86037. + break;
  86038. +
  86039. + case UF_DEVICE_A_ALT_HNP_SUPPORT:
  86040. + /* other RH port does */
  86041. + DWC_DEBUGPL(DBG_PCDV,
  86042. + "SET_FEATURE: USB_DEVICE_A_ALT_HNP_SUPPORT\n");
  86043. + if (otg_cap_param == DWC_OTG_CAP_PARAM_HNP_SRP_CAPABLE) {
  86044. + pcd->a_alt_hnp_support = 1;
  86045. + dwc_otg_pcd_update_otg(pcd, 0);
  86046. + } else {
  86047. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86048. + return;
  86049. + }
  86050. + break;
  86051. +
  86052. + default:
  86053. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86054. + return;
  86055. +
  86056. + }
  86057. + do_setup_in_status_phase(pcd);
  86058. + break;
  86059. +
  86060. + case UT_INTERFACE:
  86061. + do_gadget_setup(pcd, &ctrl);
  86062. + break;
  86063. +
  86064. + case UT_ENDPOINT:
  86065. + if (UGETW(ctrl.wValue) == UF_ENDPOINT_HALT) {
  86066. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  86067. + if (ep == 0) {
  86068. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86069. + return;
  86070. + }
  86071. + ep->stopped = 1;
  86072. + dwc_otg_ep_set_stall(core_if, &ep->dwc_ep);
  86073. + }
  86074. + do_setup_in_status_phase(pcd);
  86075. + break;
  86076. + }
  86077. +}
  86078. +
  86079. +/**
  86080. + * This function process the CLEAR_FEATURE Setup Commands.
  86081. + */
  86082. +static inline void do_clear_feature(dwc_otg_pcd_t * pcd)
  86083. +{
  86084. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86085. + dwc_otg_pcd_ep_t *ep = 0;
  86086. +
  86087. + DWC_DEBUGPL(DBG_PCD,
  86088. + "CLEAR_FEATURE:%02x.%02x v%04x i%04x l%04x\n",
  86089. + ctrl.bmRequestType, ctrl.bRequest,
  86090. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86091. + UGETW(ctrl.wLength));
  86092. +
  86093. + switch (UT_GET_RECIPIENT(ctrl.bmRequestType)) {
  86094. + case UT_DEVICE:
  86095. + switch (UGETW(ctrl.wValue)) {
  86096. + case UF_DEVICE_REMOTE_WAKEUP:
  86097. + pcd->remote_wakeup_enable = 0;
  86098. + break;
  86099. +
  86100. + case UF_TEST_MODE:
  86101. + /** @todo Add CLEAR_FEATURE for TEST modes. */
  86102. + break;
  86103. +
  86104. + default:
  86105. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86106. + return;
  86107. + }
  86108. + do_setup_in_status_phase(pcd);
  86109. + break;
  86110. +
  86111. + case UT_ENDPOINT:
  86112. + ep = get_ep_by_addr(pcd, UGETW(ctrl.wIndex));
  86113. + if (ep == 0) {
  86114. + ep0_do_stall(pcd, -DWC_E_NOT_SUPPORTED);
  86115. + return;
  86116. + }
  86117. +
  86118. + pcd_clear_halt(pcd, ep);
  86119. +
  86120. + break;
  86121. + }
  86122. +}
  86123. +
  86124. +/**
  86125. + * This function process the SET_ADDRESS Setup Commands.
  86126. + */
  86127. +static inline void do_set_address(dwc_otg_pcd_t * pcd)
  86128. +{
  86129. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  86130. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86131. +
  86132. + if (ctrl.bmRequestType == UT_DEVICE) {
  86133. + dcfg_data_t dcfg = {.d32 = 0 };
  86134. +
  86135. +#ifdef DEBUG_EP0
  86136. +// DWC_DEBUGPL(DBG_PCDV, "SET_ADDRESS:%d\n", ctrl.wValue);
  86137. +#endif
  86138. + dcfg.b.devaddr = UGETW(ctrl.wValue);
  86139. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dcfg, 0, dcfg.d32);
  86140. + do_setup_in_status_phase(pcd);
  86141. + }
  86142. +}
  86143. +
  86144. +/**
  86145. + * This function processes SETUP commands. In Linux, the USB Command
  86146. + * processing is done in two places - the first being the PCD and the
  86147. + * second in the Gadget Driver (for example, the File-Backed Storage
  86148. + * Gadget Driver).
  86149. + *
  86150. + * <table>
  86151. + * <tr><td>Command </td><td>Driver </td><td>Description</td></tr>
  86152. + *
  86153. + * <tr><td>GET_STATUS </td><td>PCD </td><td>Command is processed as
  86154. + * defined in chapter 9 of the USB 2.0 Specification chapter 9
  86155. + * </td></tr>
  86156. + *
  86157. + * <tr><td>CLEAR_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  86158. + * requests are the ENDPOINT_HALT feature is procesed, all others the
  86159. + * interface requests are ignored.</td></tr>
  86160. + *
  86161. + * <tr><td>SET_FEATURE </td><td>PCD </td><td>The Device and Endpoint
  86162. + * requests are processed by the PCD. Interface requests are passed
  86163. + * to the Gadget Driver.</td></tr>
  86164. + *
  86165. + * <tr><td>SET_ADDRESS </td><td>PCD </td><td>Program the DCFG reg,
  86166. + * with device address received </td></tr>
  86167. + *
  86168. + * <tr><td>GET_DESCRIPTOR </td><td>Gadget Driver </td><td>Return the
  86169. + * requested descriptor</td></tr>
  86170. + *
  86171. + * <tr><td>SET_DESCRIPTOR </td><td>Gadget Driver </td><td>Optional -
  86172. + * not implemented by any of the existing Gadget Drivers.</td></tr>
  86173. + *
  86174. + * <tr><td>SET_CONFIGURATION </td><td>Gadget Driver </td><td>Disable
  86175. + * all EPs and enable EPs for new configuration.</td></tr>
  86176. + *
  86177. + * <tr><td>GET_CONFIGURATION </td><td>Gadget Driver </td><td>Return
  86178. + * the current configuration</td></tr>
  86179. + *
  86180. + * <tr><td>SET_INTERFACE </td><td>Gadget Driver </td><td>Disable all
  86181. + * EPs and enable EPs for new configuration.</td></tr>
  86182. + *
  86183. + * <tr><td>GET_INTERFACE </td><td>Gadget Driver </td><td>Return the
  86184. + * current interface.</td></tr>
  86185. + *
  86186. + * <tr><td>SYNC_FRAME </td><td>PCD </td><td>Display debug
  86187. + * message.</td></tr>
  86188. + * </table>
  86189. + *
  86190. + * When the SETUP Phase Done interrupt occurs, the PCD SETUP commands are
  86191. + * processed by pcd_setup. Calling the Function Driver's setup function from
  86192. + * pcd_setup processes the gadget SETUP commands.
  86193. + */
  86194. +static inline void pcd_setup(dwc_otg_pcd_t * pcd)
  86195. +{
  86196. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  86197. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86198. + usb_device_request_t ctrl = pcd->setup_pkt->req;
  86199. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  86200. +
  86201. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  86202. +
  86203. +#ifdef DWC_UTE_CFI
  86204. + int retval = 0;
  86205. + struct cfi_usb_ctrlrequest cfi_req;
  86206. +#endif
  86207. +
  86208. + doeptsize0.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[0]->doeptsiz);
  86209. +
  86210. + /** In BDMA more then 1 setup packet is not supported till 3.00a */
  86211. + if (core_if->dma_enable && core_if->dma_desc_enable == 0
  86212. + && (doeptsize0.b.supcnt < 2)
  86213. + && (core_if->snpsid < OTG_CORE_REV_2_94a)) {
  86214. + DWC_ERROR
  86215. + ("\n\n----------- CANNOT handle > 1 setup packet in DMA mode\n\n");
  86216. + }
  86217. + if ((core_if->snpsid >= OTG_CORE_REV_3_00a)
  86218. + && (core_if->dma_enable == 1) && (core_if->dma_desc_enable == 0)) {
  86219. + ctrl =
  86220. + (pcd->setup_pkt +
  86221. + (3 - doeptsize0.b.supcnt - 1 +
  86222. + ep0->dwc_ep.stp_rollover))->req;
  86223. + }
  86224. +#ifdef DEBUG_EP0
  86225. + DWC_DEBUGPL(DBG_PCD, "SETUP %02x.%02x v%04x i%04x l%04x\n",
  86226. + ctrl.bmRequestType, ctrl.bRequest,
  86227. + UGETW(ctrl.wValue), UGETW(ctrl.wIndex),
  86228. + UGETW(ctrl.wLength));
  86229. +#endif
  86230. +
  86231. + /* Clean up the request queue */
  86232. + dwc_otg_request_nuke(ep0);
  86233. + ep0->stopped = 0;
  86234. +
  86235. + if (ctrl.bmRequestType & UE_DIR_IN) {
  86236. + ep0->dwc_ep.is_in = 1;
  86237. + pcd->ep0state = EP0_IN_DATA_PHASE;
  86238. + } else {
  86239. + ep0->dwc_ep.is_in = 0;
  86240. + pcd->ep0state = EP0_OUT_DATA_PHASE;
  86241. + }
  86242. +
  86243. + if (UGETW(ctrl.wLength) == 0) {
  86244. + ep0->dwc_ep.is_in = 1;
  86245. + pcd->ep0state = EP0_IN_STATUS_PHASE;
  86246. + }
  86247. +
  86248. + if (UT_GET_TYPE(ctrl.bmRequestType) != UT_STANDARD) {
  86249. +
  86250. +#ifdef DWC_UTE_CFI
  86251. + DWC_MEMCPY(&cfi_req, &ctrl, sizeof(usb_device_request_t));
  86252. +
  86253. + //printk(KERN_ALERT "CFI: req_type=0x%02x; req=0x%02x\n",
  86254. + ctrl.bRequestType, ctrl.bRequest);
  86255. + if (UT_GET_TYPE(cfi_req.bRequestType) == UT_VENDOR) {
  86256. + if (cfi_req.bRequest > 0xB0 && cfi_req.bRequest < 0xBF) {
  86257. + retval = cfi_setup(pcd, &cfi_req);
  86258. + if (retval < 0) {
  86259. + ep0_do_stall(pcd, retval);
  86260. + pcd->ep0_pending = 0;
  86261. + return;
  86262. + }
  86263. +
  86264. + /* if need gadget setup then call it and check the retval */
  86265. + if (pcd->cfi->need_gadget_att) {
  86266. + retval =
  86267. + cfi_gadget_setup(pcd,
  86268. + &pcd->
  86269. + cfi->ctrl_req);
  86270. + if (retval < 0) {
  86271. + pcd->ep0_pending = 0;
  86272. + return;
  86273. + }
  86274. + }
  86275. +
  86276. + if (pcd->cfi->need_status_in_complete) {
  86277. + do_setup_in_status_phase(pcd);
  86278. + }
  86279. + return;
  86280. + }
  86281. + }
  86282. +#endif
  86283. +
  86284. + /* handle non-standard (class/vendor) requests in the gadget driver */
  86285. + do_gadget_setup(pcd, &ctrl);
  86286. + return;
  86287. + }
  86288. +
  86289. + /** @todo NGS: Handle bad setup packet? */
  86290. +
  86291. +///////////////////////////////////////////
  86292. +//// --- Standard Request handling --- ////
  86293. +
  86294. + switch (ctrl.bRequest) {
  86295. + case UR_GET_STATUS:
  86296. + do_get_status(pcd);
  86297. + break;
  86298. +
  86299. + case UR_CLEAR_FEATURE:
  86300. + do_clear_feature(pcd);
  86301. + break;
  86302. +
  86303. + case UR_SET_FEATURE:
  86304. + do_set_feature(pcd);
  86305. + break;
  86306. +
  86307. + case UR_SET_ADDRESS:
  86308. + do_set_address(pcd);
  86309. + break;
  86310. +
  86311. + case UR_SET_INTERFACE:
  86312. + case UR_SET_CONFIG:
  86313. +// _pcd->request_config = 1; /* Configuration changed */
  86314. + do_gadget_setup(pcd, &ctrl);
  86315. + break;
  86316. +
  86317. + case UR_SYNCH_FRAME:
  86318. + do_gadget_setup(pcd, &ctrl);
  86319. + break;
  86320. +
  86321. + default:
  86322. + /* Call the Gadget Driver's setup functions */
  86323. + do_gadget_setup(pcd, &ctrl);
  86324. + break;
  86325. + }
  86326. +}
  86327. +
  86328. +/**
  86329. + * This function completes the ep0 control transfer.
  86330. + */
  86331. +static int32_t ep0_complete_request(dwc_otg_pcd_ep_t * ep)
  86332. +{
  86333. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  86334. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86335. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  86336. + dev_if->in_ep_regs[ep->dwc_ep.num];
  86337. +#ifdef DEBUG_EP0
  86338. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  86339. + dev_if->out_ep_regs[ep->dwc_ep.num];
  86340. +#endif
  86341. + deptsiz0_data_t deptsiz;
  86342. + dev_dma_desc_sts_t desc_sts;
  86343. + dwc_otg_pcd_request_t *req;
  86344. + int is_last = 0;
  86345. + dwc_otg_pcd_t *pcd = ep->pcd;
  86346. +
  86347. +#ifdef DWC_UTE_CFI
  86348. + struct cfi_usb_ctrlrequest *ctrlreq;
  86349. + int retval = -DWC_E_NOT_SUPPORTED;
  86350. +#endif
  86351. +
  86352. + desc_sts.b.bytes = 0;
  86353. +
  86354. + if (pcd->ep0_pending && DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86355. + if (ep->dwc_ep.is_in) {
  86356. +#ifdef DEBUG_EP0
  86357. + DWC_DEBUGPL(DBG_PCDV, "Do setup OUT status phase\n");
  86358. +#endif
  86359. + do_setup_out_status_phase(pcd);
  86360. + } else {
  86361. +#ifdef DEBUG_EP0
  86362. + DWC_DEBUGPL(DBG_PCDV, "Do setup IN status phase\n");
  86363. +#endif
  86364. +
  86365. +#ifdef DWC_UTE_CFI
  86366. + ctrlreq = &pcd->cfi->ctrl_req;
  86367. +
  86368. + if (UT_GET_TYPE(ctrlreq->bRequestType) == UT_VENDOR) {
  86369. + if (ctrlreq->bRequest > 0xB0
  86370. + && ctrlreq->bRequest < 0xBF) {
  86371. +
  86372. + /* Return if the PCD failed to handle the request */
  86373. + if ((retval =
  86374. + pcd->cfi->ops.
  86375. + ctrl_write_complete(pcd->cfi,
  86376. + pcd)) < 0) {
  86377. + CFI_INFO
  86378. + ("ERROR setting a new value in the PCD(%d)\n",
  86379. + retval);
  86380. + ep0_do_stall(pcd, retval);
  86381. + pcd->ep0_pending = 0;
  86382. + return 0;
  86383. + }
  86384. +
  86385. + /* If the gadget needs to be notified on the request */
  86386. + if (pcd->cfi->need_gadget_att == 1) {
  86387. + //retval = do_gadget_setup(pcd, &pcd->cfi->ctrl_req);
  86388. + retval =
  86389. + cfi_gadget_setup(pcd,
  86390. + &pcd->cfi->
  86391. + ctrl_req);
  86392. +
  86393. + /* Return from the function if the gadget failed to process
  86394. + * the request properly - this should never happen !!!
  86395. + */
  86396. + if (retval < 0) {
  86397. + CFI_INFO
  86398. + ("ERROR setting a new value in the gadget(%d)\n",
  86399. + retval);
  86400. + pcd->ep0_pending = 0;
  86401. + return 0;
  86402. + }
  86403. + }
  86404. +
  86405. + CFI_INFO("%s: RETVAL=%d\n", __func__,
  86406. + retval);
  86407. + /* If we hit here then the PCD and the gadget has properly
  86408. + * handled the request - so send the ZLP IN to the host.
  86409. + */
  86410. + /* @todo: MAS - decide whether we need to start the setup
  86411. + * stage based on the need_setup value of the cfi object
  86412. + */
  86413. + do_setup_in_status_phase(pcd);
  86414. + pcd->ep0_pending = 0;
  86415. + return 1;
  86416. + }
  86417. + }
  86418. +#endif
  86419. +
  86420. + do_setup_in_status_phase(pcd);
  86421. + }
  86422. + pcd->ep0_pending = 0;
  86423. + return 1;
  86424. + }
  86425. +
  86426. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86427. + return 0;
  86428. + }
  86429. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86430. +
  86431. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE
  86432. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  86433. + is_last = 1;
  86434. + } else if (ep->dwc_ep.is_in) {
  86435. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  86436. + if (core_if->dma_desc_enable != 0)
  86437. + desc_sts = dev_if->in_desc_addr->status;
  86438. +#ifdef DEBUG_EP0
  86439. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xfersize=%d pktcnt=%d\n",
  86440. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  86441. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86442. +#endif
  86443. +
  86444. + if (((core_if->dma_desc_enable == 0)
  86445. + && (deptsiz.b.xfersize == 0))
  86446. + || ((core_if->dma_desc_enable != 0)
  86447. + && (desc_sts.b.bytes == 0))) {
  86448. + req->actual = ep->dwc_ep.xfer_count;
  86449. + /* Is a Zero Len Packet needed? */
  86450. + if (req->sent_zlp) {
  86451. +#ifdef DEBUG_EP0
  86452. + DWC_DEBUGPL(DBG_PCD, "Setup Rx ZLP\n");
  86453. +#endif
  86454. + req->sent_zlp = 0;
  86455. + }
  86456. + do_setup_out_status_phase(pcd);
  86457. + }
  86458. + } else {
  86459. + /* ep0-OUT */
  86460. +#ifdef DEBUG_EP0
  86461. + deptsiz.d32 = DWC_READ_REG32(&out_ep_regs->doeptsiz);
  86462. + DWC_DEBUGPL(DBG_PCDV, "%d len=%d xsize=%d pktcnt=%d\n",
  86463. + ep->dwc_ep.num, ep->dwc_ep.xfer_len,
  86464. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86465. +#endif
  86466. + req->actual = ep->dwc_ep.xfer_count;
  86467. +
  86468. + /* Is a Zero Len Packet needed? */
  86469. + if (req->sent_zlp) {
  86470. +#ifdef DEBUG_EP0
  86471. + DWC_DEBUGPL(DBG_PCDV, "Setup Tx ZLP\n");
  86472. +#endif
  86473. + req->sent_zlp = 0;
  86474. + }
  86475. + /* For older cores do setup in status phase in Slave/BDMA modes,
  86476. + * starting from 3.00 do that only in slave, and for DMA modes
  86477. + * just re-enable ep 0 OUT here*/
  86478. + if (core_if->dma_enable == 0
  86479. + || (core_if->dma_desc_enable == 0
  86480. + && core_if->snpsid <= OTG_CORE_REV_2_94a)) {
  86481. + do_setup_in_status_phase(pcd);
  86482. + } else if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  86483. + DWC_DEBUGPL(DBG_PCDV,
  86484. + "Enable out ep before in status phase\n");
  86485. + ep0_out_start(core_if, pcd);
  86486. + }
  86487. + }
  86488. +
  86489. + /* Complete the request */
  86490. + if (is_last) {
  86491. + dwc_otg_request_done(ep, req, 0);
  86492. + ep->dwc_ep.start_xfer_buff = 0;
  86493. + ep->dwc_ep.xfer_buff = 0;
  86494. + ep->dwc_ep.xfer_len = 0;
  86495. + return 1;
  86496. + }
  86497. + return 0;
  86498. +}
  86499. +
  86500. +#ifdef DWC_UTE_CFI
  86501. +/**
  86502. + * This function calculates traverses all the CFI DMA descriptors and
  86503. + * and accumulates the bytes that are left to be transfered.
  86504. + *
  86505. + * @return The total bytes left to transfered, or a negative value as failure
  86506. + */
  86507. +static inline int cfi_calc_desc_residue(dwc_otg_pcd_ep_t * ep)
  86508. +{
  86509. + int32_t ret = 0;
  86510. + int i;
  86511. + struct dwc_otg_dma_desc *ddesc = NULL;
  86512. + struct cfi_ep *cfiep;
  86513. +
  86514. + /* See if the pcd_ep has its respective cfi_ep mapped */
  86515. + cfiep = get_cfi_ep_by_pcd_ep(ep->pcd->cfi, ep);
  86516. + if (!cfiep) {
  86517. + CFI_INFO("%s: Failed to find ep\n", __func__);
  86518. + return -1;
  86519. + }
  86520. +
  86521. + ddesc = ep->dwc_ep.descs;
  86522. +
  86523. + for (i = 0; (i < cfiep->desc_count) && (i < MAX_DMA_DESCS_PER_EP); i++) {
  86524. +
  86525. +#if defined(PRINT_CFI_DMA_DESCS)
  86526. + print_desc(ddesc, ep->ep.name, i);
  86527. +#endif
  86528. + ret += ddesc->status.b.bytes;
  86529. + ddesc++;
  86530. + }
  86531. +
  86532. + if (ret)
  86533. + CFI_INFO("!!!!!!!!!! WARNING (%s) - residue=%d\n", __func__,
  86534. + ret);
  86535. +
  86536. + return ret;
  86537. +}
  86538. +#endif
  86539. +
  86540. +/**
  86541. + * This function completes the request for the EP. If there are
  86542. + * additional requests for the EP in the queue they will be started.
  86543. + */
  86544. +static void complete_ep(dwc_otg_pcd_ep_t * ep)
  86545. +{
  86546. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  86547. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  86548. + dwc_otg_dev_in_ep_regs_t *in_ep_regs =
  86549. + dev_if->in_ep_regs[ep->dwc_ep.num];
  86550. + deptsiz_data_t deptsiz;
  86551. + dev_dma_desc_sts_t desc_sts;
  86552. + dwc_otg_pcd_request_t *req = 0;
  86553. + dwc_otg_dev_dma_desc_t *dma_desc;
  86554. + uint32_t byte_count = 0;
  86555. + int is_last = 0;
  86556. + int i;
  86557. +
  86558. + DWC_DEBUGPL(DBG_PCDV, "%s() %d-%s\n", __func__, ep->dwc_ep.num,
  86559. + (ep->dwc_ep.is_in ? "IN" : "OUT"));
  86560. +
  86561. + /* Get any pending requests */
  86562. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  86563. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  86564. + if (!req) {
  86565. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  86566. + return;
  86567. + }
  86568. + } else {
  86569. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  86570. + return;
  86571. + }
  86572. +
  86573. + DWC_DEBUGPL(DBG_PCD, "Requests %d\n", ep->pcd->request_pending);
  86574. +
  86575. + if (ep->dwc_ep.is_in) {
  86576. + deptsiz.d32 = DWC_READ_REG32(&in_ep_regs->dieptsiz);
  86577. +
  86578. + if (core_if->dma_enable) {
  86579. + if (core_if->dma_desc_enable == 0) {
  86580. + if (deptsiz.b.xfersize == 0
  86581. + && deptsiz.b.pktcnt == 0) {
  86582. + byte_count =
  86583. + ep->dwc_ep.xfer_len -
  86584. + ep->dwc_ep.xfer_count;
  86585. +
  86586. + ep->dwc_ep.xfer_buff += byte_count;
  86587. + ep->dwc_ep.dma_addr += byte_count;
  86588. + ep->dwc_ep.xfer_count += byte_count;
  86589. +
  86590. + DWC_DEBUGPL(DBG_PCDV,
  86591. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  86592. + ep->dwc_ep.num,
  86593. + (ep->dwc_ep.
  86594. + is_in ? "IN" : "OUT"),
  86595. + ep->dwc_ep.xfer_len,
  86596. + deptsiz.b.xfersize,
  86597. + deptsiz.b.pktcnt);
  86598. +
  86599. + if (ep->dwc_ep.xfer_len <
  86600. + ep->dwc_ep.total_len) {
  86601. + dwc_otg_ep_start_transfer
  86602. + (core_if, &ep->dwc_ep);
  86603. + } else if (ep->dwc_ep.sent_zlp) {
  86604. + /*
  86605. + * This fragment of code should initiate 0
  86606. + * length transfer in case if it is queued
  86607. + * a transfer with size divisible to EPs max
  86608. + * packet size and with usb_request zero field
  86609. + * is set, which means that after data is transfered,
  86610. + * it is also should be transfered
  86611. + * a 0 length packet at the end. For Slave and
  86612. + * Buffer DMA modes in this case SW has
  86613. + * to initiate 2 transfers one with transfer size,
  86614. + * and the second with 0 size. For Descriptor
  86615. + * DMA mode SW is able to initiate a transfer,
  86616. + * which will handle all the packets including
  86617. + * the last 0 length.
  86618. + */
  86619. + ep->dwc_ep.sent_zlp = 0;
  86620. + dwc_otg_ep_start_zl_transfer
  86621. + (core_if, &ep->dwc_ep);
  86622. + } else {
  86623. + is_last = 1;
  86624. + }
  86625. + } else {
  86626. + if (ep->dwc_ep.type ==
  86627. + DWC_OTG_EP_TYPE_ISOC) {
  86628. + req->actual = 0;
  86629. + dwc_otg_request_done(ep, req, 0);
  86630. +
  86631. + ep->dwc_ep.start_xfer_buff = 0;
  86632. + ep->dwc_ep.xfer_buff = 0;
  86633. + ep->dwc_ep.xfer_len = 0;
  86634. +
  86635. + /* If there is a request in the queue start it. */
  86636. + start_next_request(ep);
  86637. + } else
  86638. + DWC_WARN
  86639. + ("Incomplete transfer (%d - %s [siz=%d pkt=%d])\n",
  86640. + ep->dwc_ep.num,
  86641. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  86642. + deptsiz.b.xfersize,
  86643. + deptsiz.b.pktcnt);
  86644. + }
  86645. + } else {
  86646. + dma_desc = ep->dwc_ep.desc_addr;
  86647. + byte_count = 0;
  86648. + ep->dwc_ep.sent_zlp = 0;
  86649. +
  86650. +#ifdef DWC_UTE_CFI
  86651. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  86652. + ep->dwc_ep.buff_mode);
  86653. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86654. + int residue;
  86655. +
  86656. + residue = cfi_calc_desc_residue(ep);
  86657. + if (residue < 0)
  86658. + return;
  86659. +
  86660. + byte_count = residue;
  86661. + } else {
  86662. +#endif
  86663. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  86664. + ++i) {
  86665. + desc_sts = dma_desc->status;
  86666. + byte_count += desc_sts.b.bytes;
  86667. + dma_desc++;
  86668. + }
  86669. +#ifdef DWC_UTE_CFI
  86670. + }
  86671. +#endif
  86672. + if (byte_count == 0) {
  86673. + ep->dwc_ep.xfer_count =
  86674. + ep->dwc_ep.total_len;
  86675. + is_last = 1;
  86676. + } else {
  86677. + DWC_WARN("Incomplete transfer\n");
  86678. + }
  86679. + }
  86680. + } else {
  86681. + if (deptsiz.b.xfersize == 0 && deptsiz.b.pktcnt == 0) {
  86682. + DWC_DEBUGPL(DBG_PCDV,
  86683. + "%d-%s len=%d xfersize=%d pktcnt=%d\n",
  86684. + ep->dwc_ep.num,
  86685. + ep->dwc_ep.is_in ? "IN" : "OUT",
  86686. + ep->dwc_ep.xfer_len,
  86687. + deptsiz.b.xfersize,
  86688. + deptsiz.b.pktcnt);
  86689. +
  86690. + /* Check if the whole transfer was completed,
  86691. + * if no, setup transfer for next portion of data
  86692. + */
  86693. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86694. + dwc_otg_ep_start_transfer(core_if,
  86695. + &ep->dwc_ep);
  86696. + } else if (ep->dwc_ep.sent_zlp) {
  86697. + /*
  86698. + * This fragment of code should initiate 0
  86699. + * length trasfer in case if it is queued
  86700. + * a trasfer with size divisible to EPs max
  86701. + * packet size and with usb_request zero field
  86702. + * is set, which means that after data is transfered,
  86703. + * it is also should be transfered
  86704. + * a 0 length packet at the end. For Slave and
  86705. + * Buffer DMA modes in this case SW has
  86706. + * to initiate 2 transfers one with transfer size,
  86707. + * and the second with 0 size. For Desriptor
  86708. + * DMA mode SW is able to initiate a transfer,
  86709. + * which will handle all the packets including
  86710. + * the last 0 legth.
  86711. + */
  86712. + ep->dwc_ep.sent_zlp = 0;
  86713. + dwc_otg_ep_start_zl_transfer(core_if,
  86714. + &ep->dwc_ep);
  86715. + } else {
  86716. + is_last = 1;
  86717. + }
  86718. + } else {
  86719. + DWC_WARN
  86720. + ("Incomplete transfer (%d-%s [siz=%d pkt=%d])\n",
  86721. + ep->dwc_ep.num,
  86722. + (ep->dwc_ep.is_in ? "IN" : "OUT"),
  86723. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86724. + }
  86725. + }
  86726. + } else {
  86727. + dwc_otg_dev_out_ep_regs_t *out_ep_regs =
  86728. + dev_if->out_ep_regs[ep->dwc_ep.num];
  86729. + desc_sts.d32 = 0;
  86730. + if (core_if->dma_enable) {
  86731. + if (core_if->dma_desc_enable) {
  86732. + dma_desc = ep->dwc_ep.desc_addr;
  86733. + byte_count = 0;
  86734. + ep->dwc_ep.sent_zlp = 0;
  86735. +
  86736. +#ifdef DWC_UTE_CFI
  86737. + CFI_INFO("%s: BUFFER_MODE=%d\n", __func__,
  86738. + ep->dwc_ep.buff_mode);
  86739. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86740. + int residue;
  86741. + residue = cfi_calc_desc_residue(ep);
  86742. + if (residue < 0)
  86743. + return;
  86744. + byte_count = residue;
  86745. + } else {
  86746. +#endif
  86747. +
  86748. + for (i = 0; i < ep->dwc_ep.desc_cnt;
  86749. + ++i) {
  86750. + desc_sts = dma_desc->status;
  86751. + byte_count += desc_sts.b.bytes;
  86752. + dma_desc++;
  86753. + }
  86754. +
  86755. +#ifdef DWC_UTE_CFI
  86756. + }
  86757. +#endif
  86758. + /* Checking for interrupt Out transfers with not
  86759. + * dword aligned mps sizes
  86760. + */
  86761. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_INTR &&
  86762. + (ep->dwc_ep.maxpacket%4)) {
  86763. + ep->dwc_ep.xfer_count =
  86764. + ep->dwc_ep.total_len - byte_count;
  86765. + if ((ep->dwc_ep.xfer_len %
  86766. + ep->dwc_ep.maxpacket)
  86767. + && (ep->dwc_ep.xfer_len /
  86768. + ep->dwc_ep.maxpacket <
  86769. + MAX_DMA_DESC_CNT))
  86770. + ep->dwc_ep.xfer_len -=
  86771. + (ep->dwc_ep.desc_cnt -
  86772. + 1) * ep->dwc_ep.maxpacket +
  86773. + ep->dwc_ep.xfer_len %
  86774. + ep->dwc_ep.maxpacket;
  86775. + else
  86776. + ep->dwc_ep.xfer_len -=
  86777. + ep->dwc_ep.desc_cnt *
  86778. + ep->dwc_ep.maxpacket;
  86779. + if (ep->dwc_ep.xfer_len > 0) {
  86780. + dwc_otg_ep_start_transfer
  86781. + (core_if, &ep->dwc_ep);
  86782. + } else {
  86783. + is_last = 1;
  86784. + }
  86785. + } else {
  86786. + ep->dwc_ep.xfer_count =
  86787. + ep->dwc_ep.total_len - byte_count +
  86788. + ((4 -
  86789. + (ep->dwc_ep.
  86790. + total_len & 0x3)) & 0x3);
  86791. + is_last = 1;
  86792. + }
  86793. + } else {
  86794. + deptsiz.d32 = 0;
  86795. + deptsiz.d32 =
  86796. + DWC_READ_REG32(&out_ep_regs->doeptsiz);
  86797. +
  86798. + byte_count = (ep->dwc_ep.xfer_len -
  86799. + ep->dwc_ep.xfer_count -
  86800. + deptsiz.b.xfersize);
  86801. + ep->dwc_ep.xfer_buff += byte_count;
  86802. + ep->dwc_ep.dma_addr += byte_count;
  86803. + ep->dwc_ep.xfer_count += byte_count;
  86804. +
  86805. + /* Check if the whole transfer was completed,
  86806. + * if no, setup transfer for next portion of data
  86807. + */
  86808. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86809. + dwc_otg_ep_start_transfer(core_if,
  86810. + &ep->dwc_ep);
  86811. + } else if (ep->dwc_ep.sent_zlp) {
  86812. + /*
  86813. + * This fragment of code should initiate 0
  86814. + * length trasfer in case if it is queued
  86815. + * a trasfer with size divisible to EPs max
  86816. + * packet size and with usb_request zero field
  86817. + * is set, which means that after data is transfered,
  86818. + * it is also should be transfered
  86819. + * a 0 length packet at the end. For Slave and
  86820. + * Buffer DMA modes in this case SW has
  86821. + * to initiate 2 transfers one with transfer size,
  86822. + * and the second with 0 size. For Desriptor
  86823. + * DMA mode SW is able to initiate a transfer,
  86824. + * which will handle all the packets including
  86825. + * the last 0 legth.
  86826. + */
  86827. + ep->dwc_ep.sent_zlp = 0;
  86828. + dwc_otg_ep_start_zl_transfer(core_if,
  86829. + &ep->dwc_ep);
  86830. + } else {
  86831. + is_last = 1;
  86832. + }
  86833. + }
  86834. + } else {
  86835. + /* Check if the whole transfer was completed,
  86836. + * if no, setup transfer for next portion of data
  86837. + */
  86838. + if (ep->dwc_ep.xfer_len < ep->dwc_ep.total_len) {
  86839. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  86840. + } else if (ep->dwc_ep.sent_zlp) {
  86841. + /*
  86842. + * This fragment of code should initiate 0
  86843. + * length transfer in case if it is queued
  86844. + * a transfer with size divisible to EPs max
  86845. + * packet size and with usb_request zero field
  86846. + * is set, which means that after data is transfered,
  86847. + * it is also should be transfered
  86848. + * a 0 length packet at the end. For Slave and
  86849. + * Buffer DMA modes in this case SW has
  86850. + * to initiate 2 transfers one with transfer size,
  86851. + * and the second with 0 size. For Descriptor
  86852. + * DMA mode SW is able to initiate a transfer,
  86853. + * which will handle all the packets including
  86854. + * the last 0 length.
  86855. + */
  86856. + ep->dwc_ep.sent_zlp = 0;
  86857. + dwc_otg_ep_start_zl_transfer(core_if,
  86858. + &ep->dwc_ep);
  86859. + } else {
  86860. + is_last = 1;
  86861. + }
  86862. + }
  86863. +
  86864. + DWC_DEBUGPL(DBG_PCDV,
  86865. + "addr %p, %d-%s len=%d cnt=%d xsize=%d pktcnt=%d\n",
  86866. + &out_ep_regs->doeptsiz, ep->dwc_ep.num,
  86867. + ep->dwc_ep.is_in ? "IN" : "OUT",
  86868. + ep->dwc_ep.xfer_len, ep->dwc_ep.xfer_count,
  86869. + deptsiz.b.xfersize, deptsiz.b.pktcnt);
  86870. + }
  86871. +
  86872. + /* Complete the request */
  86873. + if (is_last) {
  86874. +#ifdef DWC_UTE_CFI
  86875. + if (ep->dwc_ep.buff_mode != BM_STANDARD) {
  86876. + req->actual = ep->dwc_ep.cfi_req_len - byte_count;
  86877. + } else {
  86878. +#endif
  86879. + req->actual = ep->dwc_ep.xfer_count;
  86880. +#ifdef DWC_UTE_CFI
  86881. + }
  86882. +#endif
  86883. + if (req->dw_align_buf) {
  86884. + if (!ep->dwc_ep.is_in) {
  86885. + dwc_memcpy(req->buf, req->dw_align_buf, req->length);
  86886. + }
  86887. + DWC_DMA_FREE(req->length, req->dw_align_buf,
  86888. + req->dw_align_buf_dma);
  86889. + }
  86890. +
  86891. + dwc_otg_request_done(ep, req, 0);
  86892. +
  86893. + ep->dwc_ep.start_xfer_buff = 0;
  86894. + ep->dwc_ep.xfer_buff = 0;
  86895. + ep->dwc_ep.xfer_len = 0;
  86896. +
  86897. + /* If there is a request in the queue start it. */
  86898. + start_next_request(ep);
  86899. + }
  86900. +}
  86901. +
  86902. +#ifdef DWC_EN_ISOC
  86903. +
  86904. +/**
  86905. + * This function BNA interrupt for Isochronous EPs
  86906. + *
  86907. + */
  86908. +static void dwc_otg_pcd_handle_iso_bna(dwc_otg_pcd_ep_t * ep)
  86909. +{
  86910. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  86911. + volatile uint32_t *addr;
  86912. + depctl_data_t depctl = {.d32 = 0 };
  86913. + dwc_otg_pcd_t *pcd = ep->pcd;
  86914. + dwc_otg_dev_dma_desc_t *dma_desc;
  86915. + int i;
  86916. +
  86917. + dma_desc =
  86918. + dwc_ep->iso_desc_addr + dwc_ep->desc_cnt * (dwc_ep->proc_buf_num);
  86919. +
  86920. + if (dwc_ep->is_in) {
  86921. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86922. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  86923. + sts.d32 = dma_desc->status.d32;
  86924. + sts.b_iso_in.bs = BS_HOST_READY;
  86925. + dma_desc->status.d32 = sts.d32;
  86926. + }
  86927. + } else {
  86928. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  86929. + for (i = 0; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  86930. + sts.d32 = dma_desc->status.d32;
  86931. + sts.b_iso_out.bs = BS_HOST_READY;
  86932. + dma_desc->status.d32 = sts.d32;
  86933. + }
  86934. + }
  86935. +
  86936. + if (dwc_ep->is_in == 0) {
  86937. + addr =
  86938. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->
  86939. + num]->doepctl;
  86940. + } else {
  86941. + addr =
  86942. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  86943. + }
  86944. + depctl.b.epena = 1;
  86945. + DWC_MODIFY_REG32(addr, depctl.d32, depctl.d32);
  86946. +}
  86947. +
  86948. +/**
  86949. + * This function sets latest iso packet information(non-PTI mode)
  86950. + *
  86951. + * @param core_if Programming view of DWC_otg controller.
  86952. + * @param ep The EP to start the transfer on.
  86953. + *
  86954. + */
  86955. +void set_current_pkt_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  86956. +{
  86957. + deptsiz_data_t deptsiz = {.d32 = 0 };
  86958. + dma_addr_t dma_addr;
  86959. + uint32_t offset;
  86960. +
  86961. + if (ep->proc_buf_num)
  86962. + dma_addr = ep->dma_addr1;
  86963. + else
  86964. + dma_addr = ep->dma_addr0;
  86965. +
  86966. + if (ep->is_in) {
  86967. + deptsiz.d32 =
  86968. + DWC_READ_REG32(&core_if->dev_if->
  86969. + in_ep_regs[ep->num]->dieptsiz);
  86970. + offset = ep->data_per_frame;
  86971. + } else {
  86972. + deptsiz.d32 =
  86973. + DWC_READ_REG32(&core_if->dev_if->
  86974. + out_ep_regs[ep->num]->doeptsiz);
  86975. + offset =
  86976. + ep->data_per_frame +
  86977. + (0x4 & (0x4 - (ep->data_per_frame & 0x3)));
  86978. + }
  86979. +
  86980. + if (!deptsiz.b.xfersize) {
  86981. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  86982. + ep->pkt_info[ep->cur_pkt].offset =
  86983. + ep->cur_pkt_dma_addr - dma_addr;
  86984. + ep->pkt_info[ep->cur_pkt].status = 0;
  86985. + } else {
  86986. + ep->pkt_info[ep->cur_pkt].length = ep->data_per_frame;
  86987. + ep->pkt_info[ep->cur_pkt].offset =
  86988. + ep->cur_pkt_dma_addr - dma_addr;
  86989. + ep->pkt_info[ep->cur_pkt].status = -DWC_E_NO_DATA;
  86990. + }
  86991. + ep->cur_pkt_addr += offset;
  86992. + ep->cur_pkt_dma_addr += offset;
  86993. + ep->cur_pkt++;
  86994. +}
  86995. +
  86996. +/**
  86997. + * This function sets latest iso packet information(DDMA mode)
  86998. + *
  86999. + * @param core_if Programming view of DWC_otg controller.
  87000. + * @param dwc_ep The EP to start the transfer on.
  87001. + *
  87002. + */
  87003. +static void set_ddma_iso_pkts_info(dwc_otg_core_if_t * core_if,
  87004. + dwc_ep_t * dwc_ep)
  87005. +{
  87006. + dwc_otg_dev_dma_desc_t *dma_desc;
  87007. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87008. + iso_pkt_info_t *iso_packet;
  87009. + uint32_t data_per_desc;
  87010. + uint32_t offset;
  87011. + int i, j;
  87012. +
  87013. + iso_packet = dwc_ep->pkt_info;
  87014. +
  87015. + /** Reinit closed DMA Descriptors*/
  87016. + /** ISO OUT EP */
  87017. + if (dwc_ep->is_in == 0) {
  87018. + dma_desc =
  87019. + dwc_ep->iso_desc_addr +
  87020. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87021. + offset = 0;
  87022. +
  87023. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  87024. + i += dwc_ep->pkt_per_frm) {
  87025. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  87026. + data_per_desc =
  87027. + ((j + 1) * dwc_ep->maxpacket >
  87028. + dwc_ep->
  87029. + data_per_frame) ? dwc_ep->data_per_frame -
  87030. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87031. + data_per_desc +=
  87032. + (data_per_desc % 4) ? (4 -
  87033. + data_per_desc %
  87034. + 4) : 0;
  87035. +
  87036. + sts.d32 = dma_desc->status.d32;
  87037. +
  87038. + /* Write status in iso_packet_decsriptor */
  87039. + iso_packet->status =
  87040. + sts.b_iso_out.rxsts +
  87041. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87042. + if (iso_packet->status) {
  87043. + iso_packet->status = -DWC_E_NO_DATA;
  87044. + }
  87045. +
  87046. + /* Received data length */
  87047. + if (!sts.b_iso_out.rxbytes) {
  87048. + iso_packet->length =
  87049. + data_per_desc -
  87050. + sts.b_iso_out.rxbytes;
  87051. + } else {
  87052. + iso_packet->length =
  87053. + data_per_desc -
  87054. + sts.b_iso_out.rxbytes + (4 -
  87055. + dwc_ep->data_per_frame
  87056. + % 4);
  87057. + }
  87058. +
  87059. + iso_packet->offset = offset;
  87060. +
  87061. + offset += data_per_desc;
  87062. + dma_desc++;
  87063. + iso_packet++;
  87064. + }
  87065. + }
  87066. +
  87067. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  87068. + data_per_desc =
  87069. + ((j + 1) * dwc_ep->maxpacket >
  87070. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87071. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87072. + data_per_desc +=
  87073. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87074. +
  87075. + sts.d32 = dma_desc->status.d32;
  87076. +
  87077. + /* Write status in iso_packet_decsriptor */
  87078. + iso_packet->status =
  87079. + sts.b_iso_out.rxsts +
  87080. + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87081. + if (iso_packet->status) {
  87082. + iso_packet->status = -DWC_E_NO_DATA;
  87083. + }
  87084. +
  87085. + /* Received data length */
  87086. + iso_packet->length =
  87087. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  87088. +
  87089. + iso_packet->offset = offset;
  87090. +
  87091. + offset += data_per_desc;
  87092. + iso_packet++;
  87093. + dma_desc++;
  87094. + }
  87095. +
  87096. + sts.d32 = dma_desc->status.d32;
  87097. +
  87098. + /* Write status in iso_packet_decsriptor */
  87099. + iso_packet->status =
  87100. + sts.b_iso_out.rxsts + (sts.b_iso_out.bs ^ BS_DMA_DONE);
  87101. + if (iso_packet->status) {
  87102. + iso_packet->status = -DWC_E_NO_DATA;
  87103. + }
  87104. + /* Received data length */
  87105. + if (!sts.b_iso_out.rxbytes) {
  87106. + iso_packet->length =
  87107. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes;
  87108. + } else {
  87109. + iso_packet->length =
  87110. + dwc_ep->data_per_frame - sts.b_iso_out.rxbytes +
  87111. + (4 - dwc_ep->data_per_frame % 4);
  87112. + }
  87113. +
  87114. + iso_packet->offset = offset;
  87115. + } else {
  87116. +/** ISO IN EP */
  87117. +
  87118. + dma_desc =
  87119. + dwc_ep->iso_desc_addr +
  87120. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87121. +
  87122. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  87123. + sts.d32 = dma_desc->status.d32;
  87124. +
  87125. + /* Write status in iso packet descriptor */
  87126. + iso_packet->status =
  87127. + sts.b_iso_in.txsts +
  87128. + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  87129. + if (iso_packet->status != 0) {
  87130. + iso_packet->status = -DWC_E_NO_DATA;
  87131. +
  87132. + }
  87133. + /* Bytes has been transfered */
  87134. + iso_packet->length =
  87135. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  87136. +
  87137. + dma_desc++;
  87138. + iso_packet++;
  87139. + }
  87140. +
  87141. + sts.d32 = dma_desc->status.d32;
  87142. + while (sts.b_iso_in.bs == BS_DMA_BUSY) {
  87143. + sts.d32 = dma_desc->status.d32;
  87144. + }
  87145. +
  87146. + /* Write status in iso packet descriptor ??? do be done with ERROR codes */
  87147. + iso_packet->status =
  87148. + sts.b_iso_in.txsts + (sts.b_iso_in.bs ^ BS_DMA_DONE);
  87149. + if (iso_packet->status != 0) {
  87150. + iso_packet->status = -DWC_E_NO_DATA;
  87151. + }
  87152. +
  87153. + /* Bytes has been transfered */
  87154. + iso_packet->length =
  87155. + dwc_ep->data_per_frame - sts.b_iso_in.txbytes;
  87156. + }
  87157. +}
  87158. +
  87159. +/**
  87160. + * This function reinitialize DMA Descriptors for Isochronous transfer
  87161. + *
  87162. + * @param core_if Programming view of DWC_otg controller.
  87163. + * @param dwc_ep The EP to start the transfer on.
  87164. + *
  87165. + */
  87166. +static void reinit_ddma_iso_xfer(dwc_otg_core_if_t * core_if, dwc_ep_t * dwc_ep)
  87167. +{
  87168. + int i, j;
  87169. + dwc_otg_dev_dma_desc_t *dma_desc;
  87170. + dma_addr_t dma_ad;
  87171. + volatile uint32_t *addr;
  87172. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87173. + uint32_t data_per_desc;
  87174. +
  87175. + if (dwc_ep->is_in == 0) {
  87176. + addr = &core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl;
  87177. + } else {
  87178. + addr = &core_if->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  87179. + }
  87180. +
  87181. + if (dwc_ep->proc_buf_num == 0) {
  87182. + /** Buffer 0 descriptors setup */
  87183. + dma_ad = dwc_ep->dma_addr0;
  87184. + } else {
  87185. + /** Buffer 1 descriptors setup */
  87186. + dma_ad = dwc_ep->dma_addr1;
  87187. + }
  87188. +
  87189. + /** Reinit closed DMA Descriptors*/
  87190. + /** ISO OUT EP */
  87191. + if (dwc_ep->is_in == 0) {
  87192. + dma_desc =
  87193. + dwc_ep->iso_desc_addr +
  87194. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87195. +
  87196. + sts.b_iso_out.bs = BS_HOST_READY;
  87197. + sts.b_iso_out.rxsts = 0;
  87198. + sts.b_iso_out.l = 0;
  87199. + sts.b_iso_out.sp = 0;
  87200. + sts.b_iso_out.ioc = 0;
  87201. + sts.b_iso_out.pid = 0;
  87202. + sts.b_iso_out.framenum = 0;
  87203. +
  87204. + for (i = 0; i < dwc_ep->desc_cnt - dwc_ep->pkt_per_frm;
  87205. + i += dwc_ep->pkt_per_frm) {
  87206. + for (j = 0; j < dwc_ep->pkt_per_frm; ++j) {
  87207. + data_per_desc =
  87208. + ((j + 1) * dwc_ep->maxpacket >
  87209. + dwc_ep->
  87210. + data_per_frame) ? dwc_ep->data_per_frame -
  87211. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87212. + data_per_desc +=
  87213. + (data_per_desc % 4) ? (4 -
  87214. + data_per_desc %
  87215. + 4) : 0;
  87216. + sts.b_iso_out.rxbytes = data_per_desc;
  87217. + dma_desc->buf = dma_ad;
  87218. + dma_desc->status.d32 = sts.d32;
  87219. +
  87220. + dma_ad += data_per_desc;
  87221. + dma_desc++;
  87222. + }
  87223. + }
  87224. +
  87225. + for (j = 0; j < dwc_ep->pkt_per_frm - 1; ++j) {
  87226. +
  87227. + data_per_desc =
  87228. + ((j + 1) * dwc_ep->maxpacket >
  87229. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87230. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87231. + data_per_desc +=
  87232. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87233. + sts.b_iso_out.rxbytes = data_per_desc;
  87234. +
  87235. + dma_desc->buf = dma_ad;
  87236. + dma_desc->status.d32 = sts.d32;
  87237. +
  87238. + dma_desc++;
  87239. + dma_ad += data_per_desc;
  87240. + }
  87241. +
  87242. + sts.b_iso_out.ioc = 1;
  87243. + sts.b_iso_out.l = dwc_ep->proc_buf_num;
  87244. +
  87245. + data_per_desc =
  87246. + ((j + 1) * dwc_ep->maxpacket >
  87247. + dwc_ep->data_per_frame) ? dwc_ep->data_per_frame -
  87248. + j * dwc_ep->maxpacket : dwc_ep->maxpacket;
  87249. + data_per_desc +=
  87250. + (data_per_desc % 4) ? (4 - data_per_desc % 4) : 0;
  87251. + sts.b_iso_out.rxbytes = data_per_desc;
  87252. +
  87253. + dma_desc->buf = dma_ad;
  87254. + dma_desc->status.d32 = sts.d32;
  87255. + } else {
  87256. +/** ISO IN EP */
  87257. +
  87258. + dma_desc =
  87259. + dwc_ep->iso_desc_addr +
  87260. + dwc_ep->desc_cnt * dwc_ep->proc_buf_num;
  87261. +
  87262. + sts.b_iso_in.bs = BS_HOST_READY;
  87263. + sts.b_iso_in.txsts = 0;
  87264. + sts.b_iso_in.sp = 0;
  87265. + sts.b_iso_in.ioc = 0;
  87266. + sts.b_iso_in.pid = dwc_ep->pkt_per_frm;
  87267. + sts.b_iso_in.framenum = dwc_ep->next_frame;
  87268. + sts.b_iso_in.txbytes = dwc_ep->data_per_frame;
  87269. + sts.b_iso_in.l = 0;
  87270. +
  87271. + for (i = 0; i < dwc_ep->desc_cnt - 1; i++) {
  87272. + dma_desc->buf = dma_ad;
  87273. + dma_desc->status.d32 = sts.d32;
  87274. +
  87275. + sts.b_iso_in.framenum += dwc_ep->bInterval;
  87276. + dma_ad += dwc_ep->data_per_frame;
  87277. + dma_desc++;
  87278. + }
  87279. +
  87280. + sts.b_iso_in.ioc = 1;
  87281. + sts.b_iso_in.l = dwc_ep->proc_buf_num;
  87282. +
  87283. + dma_desc->buf = dma_ad;
  87284. + dma_desc->status.d32 = sts.d32;
  87285. +
  87286. + dwc_ep->next_frame =
  87287. + sts.b_iso_in.framenum + dwc_ep->bInterval * 1;
  87288. + }
  87289. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87290. +}
  87291. +
  87292. +/**
  87293. + * This function is to handle Iso EP transfer complete interrupt
  87294. + * in case Iso out packet was dropped
  87295. + *
  87296. + * @param core_if Programming view of DWC_otg controller.
  87297. + * @param dwc_ep The EP for wihich transfer complete was asserted
  87298. + *
  87299. + */
  87300. +static uint32_t handle_iso_out_pkt_dropped(dwc_otg_core_if_t * core_if,
  87301. + dwc_ep_t * dwc_ep)
  87302. +{
  87303. + uint32_t dma_addr;
  87304. + uint32_t drp_pkt;
  87305. + uint32_t drp_pkt_cnt;
  87306. + deptsiz_data_t deptsiz = {.d32 = 0 };
  87307. + depctl_data_t depctl = {.d32 = 0 };
  87308. + int i;
  87309. +
  87310. + deptsiz.d32 =
  87311. + DWC_READ_REG32(&core_if->dev_if->
  87312. + out_ep_regs[dwc_ep->num]->doeptsiz);
  87313. +
  87314. + drp_pkt = dwc_ep->pkt_cnt - deptsiz.b.pktcnt;
  87315. + drp_pkt_cnt = dwc_ep->pkt_per_frm - (drp_pkt % dwc_ep->pkt_per_frm);
  87316. +
  87317. + /* Setting dropped packets status */
  87318. + for (i = 0; i < drp_pkt_cnt; ++i) {
  87319. + dwc_ep->pkt_info[drp_pkt].status = -DWC_E_NO_DATA;
  87320. + drp_pkt++;
  87321. + deptsiz.b.pktcnt--;
  87322. + }
  87323. +
  87324. + if (deptsiz.b.pktcnt > 0) {
  87325. + deptsiz.b.xfersize =
  87326. + dwc_ep->xfer_len - (dwc_ep->pkt_cnt -
  87327. + deptsiz.b.pktcnt) * dwc_ep->maxpacket;
  87328. + } else {
  87329. + deptsiz.b.xfersize = 0;
  87330. + deptsiz.b.pktcnt = 0;
  87331. + }
  87332. +
  87333. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz,
  87334. + deptsiz.d32);
  87335. +
  87336. + if (deptsiz.b.pktcnt > 0) {
  87337. + if (dwc_ep->proc_buf_num) {
  87338. + dma_addr =
  87339. + dwc_ep->dma_addr1 + dwc_ep->xfer_len -
  87340. + deptsiz.b.xfersize;
  87341. + } else {
  87342. + dma_addr =
  87343. + dwc_ep->dma_addr0 + dwc_ep->xfer_len -
  87344. + deptsiz.b.xfersize;;
  87345. + }
  87346. +
  87347. + DWC_WRITE_REG32(&core_if->dev_if->
  87348. + out_ep_regs[dwc_ep->num]->doepdma, dma_addr);
  87349. +
  87350. + /** Re-enable endpoint, clear nak */
  87351. + depctl.d32 = 0;
  87352. + depctl.b.epena = 1;
  87353. + depctl.b.cnak = 1;
  87354. +
  87355. + DWC_MODIFY_REG32(&core_if->dev_if->
  87356. + out_ep_regs[dwc_ep->num]->doepctl, depctl.d32,
  87357. + depctl.d32);
  87358. + return 0;
  87359. + } else {
  87360. + return 1;
  87361. + }
  87362. +}
  87363. +
  87364. +/**
  87365. + * This function sets iso packets information(PTI mode)
  87366. + *
  87367. + * @param core_if Programming view of DWC_otg controller.
  87368. + * @param ep The EP to start the transfer on.
  87369. + *
  87370. + */
  87371. +static uint32_t set_iso_pkts_info(dwc_otg_core_if_t * core_if, dwc_ep_t * ep)
  87372. +{
  87373. + int i, j;
  87374. + dma_addr_t dma_ad;
  87375. + iso_pkt_info_t *packet_info = ep->pkt_info;
  87376. + uint32_t offset;
  87377. + uint32_t frame_data;
  87378. + deptsiz_data_t deptsiz;
  87379. +
  87380. + if (ep->proc_buf_num == 0) {
  87381. + /** Buffer 0 descriptors setup */
  87382. + dma_ad = ep->dma_addr0;
  87383. + } else {
  87384. + /** Buffer 1 descriptors setup */
  87385. + dma_ad = ep->dma_addr1;
  87386. + }
  87387. +
  87388. + if (ep->is_in) {
  87389. + deptsiz.d32 =
  87390. + DWC_READ_REG32(&core_if->dev_if->in_ep_regs[ep->num]->
  87391. + dieptsiz);
  87392. + } else {
  87393. + deptsiz.d32 =
  87394. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[ep->num]->
  87395. + doeptsiz);
  87396. + }
  87397. +
  87398. + if (!deptsiz.b.xfersize) {
  87399. + offset = 0;
  87400. + for (i = 0; i < ep->pkt_cnt; i += ep->pkt_per_frm) {
  87401. + frame_data = ep->data_per_frame;
  87402. + for (j = 0; j < ep->pkt_per_frm; ++j) {
  87403. +
  87404. + /* Packet status - is not set as initially
  87405. + * it is set to 0 and if packet was sent
  87406. + successfully, status field will remain 0*/
  87407. +
  87408. + /* Bytes has been transfered */
  87409. + packet_info->length =
  87410. + (ep->maxpacket <
  87411. + frame_data) ? ep->maxpacket : frame_data;
  87412. +
  87413. + /* Received packet offset */
  87414. + packet_info->offset = offset;
  87415. + offset += packet_info->length;
  87416. + frame_data -= packet_info->length;
  87417. +
  87418. + packet_info++;
  87419. + }
  87420. + }
  87421. + return 1;
  87422. + } else {
  87423. + /* This is a workaround for in case of Transfer Complete with
  87424. + * PktDrpSts interrupts merging - in this case Transfer complete
  87425. + * interrupt for Isoc Out Endpoint is asserted without PktDrpSts
  87426. + * set and with DOEPTSIZ register non zero. Investigations showed,
  87427. + * that this happens when Out packet is dropped, but because of
  87428. + * interrupts merging during first interrupt handling PktDrpSts
  87429. + * bit is cleared and for next merged interrupts it is not reset.
  87430. + * In this case SW hadles the interrupt as if PktDrpSts bit is set.
  87431. + */
  87432. + if (ep->is_in) {
  87433. + return 1;
  87434. + } else {
  87435. + return handle_iso_out_pkt_dropped(core_if, ep);
  87436. + }
  87437. + }
  87438. +}
  87439. +
  87440. +/**
  87441. + * This function is to handle Iso EP transfer complete interrupt
  87442. + *
  87443. + * @param pcd The PCD
  87444. + * @param ep The EP for which transfer complete was asserted
  87445. + *
  87446. + */
  87447. +static void complete_iso_ep(dwc_otg_pcd_t * pcd, dwc_otg_pcd_ep_t * ep)
  87448. +{
  87449. + dwc_otg_core_if_t *core_if = GET_CORE_IF(ep->pcd);
  87450. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87451. + uint8_t is_last = 0;
  87452. +
  87453. + if (ep->dwc_ep.next_frame == 0xffffffff) {
  87454. + DWC_WARN("Next frame is not set!\n");
  87455. + return;
  87456. + }
  87457. +
  87458. + if (core_if->dma_enable) {
  87459. + if (core_if->dma_desc_enable) {
  87460. + set_ddma_iso_pkts_info(core_if, dwc_ep);
  87461. + reinit_ddma_iso_xfer(core_if, dwc_ep);
  87462. + is_last = 1;
  87463. + } else {
  87464. + if (core_if->pti_enh_enable) {
  87465. + if (set_iso_pkts_info(core_if, dwc_ep)) {
  87466. + dwc_ep->proc_buf_num =
  87467. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87468. + dwc_otg_iso_ep_start_buf_transfer
  87469. + (core_if, dwc_ep);
  87470. + is_last = 1;
  87471. + }
  87472. + } else {
  87473. + set_current_pkt_info(core_if, dwc_ep);
  87474. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87475. + is_last = 1;
  87476. + dwc_ep->cur_pkt = 0;
  87477. + dwc_ep->proc_buf_num =
  87478. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87479. + if (dwc_ep->proc_buf_num) {
  87480. + dwc_ep->cur_pkt_addr =
  87481. + dwc_ep->xfer_buff1;
  87482. + dwc_ep->cur_pkt_dma_addr =
  87483. + dwc_ep->dma_addr1;
  87484. + } else {
  87485. + dwc_ep->cur_pkt_addr =
  87486. + dwc_ep->xfer_buff0;
  87487. + dwc_ep->cur_pkt_dma_addr =
  87488. + dwc_ep->dma_addr0;
  87489. + }
  87490. +
  87491. + }
  87492. + dwc_otg_iso_ep_start_frm_transfer(core_if,
  87493. + dwc_ep);
  87494. + }
  87495. + }
  87496. + } else {
  87497. + set_current_pkt_info(core_if, dwc_ep);
  87498. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  87499. + is_last = 1;
  87500. + dwc_ep->cur_pkt = 0;
  87501. + dwc_ep->proc_buf_num = (dwc_ep->proc_buf_num ^ 1) & 0x1;
  87502. + if (dwc_ep->proc_buf_num) {
  87503. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff1;
  87504. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr1;
  87505. + } else {
  87506. + dwc_ep->cur_pkt_addr = dwc_ep->xfer_buff0;
  87507. + dwc_ep->cur_pkt_dma_addr = dwc_ep->dma_addr0;
  87508. + }
  87509. +
  87510. + }
  87511. + dwc_otg_iso_ep_start_frm_transfer(core_if, dwc_ep);
  87512. + }
  87513. + if (is_last)
  87514. + dwc_otg_iso_buffer_done(pcd, ep, ep->iso_req_handle);
  87515. +}
  87516. +#endif /* DWC_EN_ISOC */
  87517. +
  87518. +/**
  87519. + * This function handle BNA interrupt for Non Isochronous EPs
  87520. + *
  87521. + */
  87522. +static void dwc_otg_pcd_handle_noniso_bna(dwc_otg_pcd_ep_t * ep)
  87523. +{
  87524. + dwc_ep_t *dwc_ep = &ep->dwc_ep;
  87525. + volatile uint32_t *addr;
  87526. + depctl_data_t depctl = {.d32 = 0 };
  87527. + dwc_otg_pcd_t *pcd = ep->pcd;
  87528. + dwc_otg_dev_dma_desc_t *dma_desc;
  87529. + dev_dma_desc_sts_t sts = {.d32 = 0 };
  87530. + dwc_otg_core_if_t *core_if = ep->pcd->core_if;
  87531. + int i, start;
  87532. +
  87533. + if (!dwc_ep->desc_cnt)
  87534. + DWC_WARN("Ep%d %s Descriptor count = %d \n", dwc_ep->num,
  87535. + (dwc_ep->is_in ? "IN" : "OUT"), dwc_ep->desc_cnt);
  87536. +
  87537. + if (core_if->core_params->cont_on_bna && !dwc_ep->is_in
  87538. + && dwc_ep->type != DWC_OTG_EP_TYPE_CONTROL) {
  87539. + uint32_t doepdma;
  87540. + dwc_otg_dev_out_ep_regs_t *out_regs =
  87541. + core_if->dev_if->out_ep_regs[dwc_ep->num];
  87542. + doepdma = DWC_READ_REG32(&(out_regs->doepdma));
  87543. + start = (doepdma - dwc_ep->dma_desc_addr)/sizeof(dwc_otg_dev_dma_desc_t);
  87544. + dma_desc = &(dwc_ep->desc_addr[start]);
  87545. + } else {
  87546. + start = 0;
  87547. + dma_desc = dwc_ep->desc_addr;
  87548. + }
  87549. +
  87550. +
  87551. + for (i = start; i < dwc_ep->desc_cnt; ++i, ++dma_desc) {
  87552. + sts.d32 = dma_desc->status.d32;
  87553. + sts.b.bs = BS_HOST_READY;
  87554. + dma_desc->status.d32 = sts.d32;
  87555. + }
  87556. +
  87557. + if (dwc_ep->is_in == 0) {
  87558. + addr =
  87559. + &GET_CORE_IF(pcd)->dev_if->out_ep_regs[dwc_ep->num]->
  87560. + doepctl;
  87561. + } else {
  87562. + addr =
  87563. + &GET_CORE_IF(pcd)->dev_if->in_ep_regs[dwc_ep->num]->diepctl;
  87564. + }
  87565. + depctl.b.epena = 1;
  87566. + depctl.b.cnak = 1;
  87567. + DWC_MODIFY_REG32(addr, 0, depctl.d32);
  87568. +}
  87569. +
  87570. +/**
  87571. + * This function handles EP0 Control transfers.
  87572. + *
  87573. + * The state of the control transfers are tracked in
  87574. + * <code>ep0state</code>.
  87575. + */
  87576. +static void handle_ep0(dwc_otg_pcd_t * pcd)
  87577. +{
  87578. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87579. + dwc_otg_pcd_ep_t *ep0 = &pcd->ep0;
  87580. + dev_dma_desc_sts_t desc_sts;
  87581. + deptsiz0_data_t deptsiz;
  87582. + uint32_t byte_count;
  87583. +
  87584. +#ifdef DEBUG_EP0
  87585. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  87586. + print_ep0_state(pcd);
  87587. +#endif
  87588. +
  87589. +// DWC_PRINTF("HANDLE EP0\n");
  87590. +
  87591. + switch (pcd->ep0state) {
  87592. + case EP0_DISCONNECT:
  87593. + break;
  87594. +
  87595. + case EP0_IDLE:
  87596. + pcd->request_config = 0;
  87597. +
  87598. + pcd_setup(pcd);
  87599. + break;
  87600. +
  87601. + case EP0_IN_DATA_PHASE:
  87602. +#ifdef DEBUG_EP0
  87603. + DWC_DEBUGPL(DBG_PCD, "DATA_IN EP%d-%s: type=%d, mps=%d\n",
  87604. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  87605. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  87606. +#endif
  87607. +
  87608. + if (core_if->dma_enable != 0) {
  87609. + /*
  87610. + * For EP0 we can only program 1 packet at a time so we
  87611. + * need to do the make calculations after each complete.
  87612. + * Call write_packet to make the calculations, as in
  87613. + * slave mode, and use those values to determine if we
  87614. + * can complete.
  87615. + */
  87616. + if (core_if->dma_desc_enable == 0) {
  87617. + deptsiz.d32 =
  87618. + DWC_READ_REG32(&core_if->
  87619. + dev_if->in_ep_regs[0]->
  87620. + dieptsiz);
  87621. + byte_count =
  87622. + ep0->dwc_ep.xfer_len - deptsiz.b.xfersize;
  87623. + } else {
  87624. + desc_sts =
  87625. + core_if->dev_if->in_desc_addr->status;
  87626. + byte_count =
  87627. + ep0->dwc_ep.xfer_len - desc_sts.b.bytes;
  87628. + }
  87629. + ep0->dwc_ep.xfer_count += byte_count;
  87630. + ep0->dwc_ep.xfer_buff += byte_count;
  87631. + ep0->dwc_ep.dma_addr += byte_count;
  87632. + }
  87633. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  87634. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87635. + &ep0->dwc_ep);
  87636. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  87637. + } else if (ep0->dwc_ep.sent_zlp) {
  87638. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87639. + &ep0->dwc_ep);
  87640. + ep0->dwc_ep.sent_zlp = 0;
  87641. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  87642. + } else {
  87643. + ep0_complete_request(ep0);
  87644. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  87645. + }
  87646. + break;
  87647. + case EP0_OUT_DATA_PHASE:
  87648. +#ifdef DEBUG_EP0
  87649. + DWC_DEBUGPL(DBG_PCD, "DATA_OUT EP%d-%s: type=%d, mps=%d\n",
  87650. + ep0->dwc_ep.num, (ep0->dwc_ep.is_in ? "IN" : "OUT"),
  87651. + ep0->dwc_ep.type, ep0->dwc_ep.maxpacket);
  87652. +#endif
  87653. + if (core_if->dma_enable != 0) {
  87654. + if (core_if->dma_desc_enable == 0) {
  87655. + deptsiz.d32 =
  87656. + DWC_READ_REG32(&core_if->
  87657. + dev_if->out_ep_regs[0]->
  87658. + doeptsiz);
  87659. + byte_count =
  87660. + ep0->dwc_ep.maxpacket - deptsiz.b.xfersize;
  87661. + } else {
  87662. + desc_sts =
  87663. + core_if->dev_if->out_desc_addr->status;
  87664. + byte_count =
  87665. + ep0->dwc_ep.maxpacket - desc_sts.b.bytes;
  87666. + }
  87667. + ep0->dwc_ep.xfer_count += byte_count;
  87668. + ep0->dwc_ep.xfer_buff += byte_count;
  87669. + ep0->dwc_ep.dma_addr += byte_count;
  87670. + }
  87671. + if (ep0->dwc_ep.xfer_count < ep0->dwc_ep.total_len) {
  87672. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87673. + &ep0->dwc_ep);
  87674. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER\n");
  87675. + } else if (ep0->dwc_ep.sent_zlp) {
  87676. + dwc_otg_ep0_continue_transfer(GET_CORE_IF(pcd),
  87677. + &ep0->dwc_ep);
  87678. + ep0->dwc_ep.sent_zlp = 0;
  87679. + DWC_DEBUGPL(DBG_PCD, "CONTINUE TRANSFER sent zlp\n");
  87680. + } else {
  87681. + ep0_complete_request(ep0);
  87682. + DWC_DEBUGPL(DBG_PCD, "COMPLETE TRANSFER\n");
  87683. + }
  87684. + break;
  87685. +
  87686. + case EP0_IN_STATUS_PHASE:
  87687. + case EP0_OUT_STATUS_PHASE:
  87688. + DWC_DEBUGPL(DBG_PCD, "CASE: EP0_STATUS\n");
  87689. + ep0_complete_request(ep0);
  87690. + pcd->ep0state = EP0_IDLE;
  87691. + ep0->stopped = 1;
  87692. + ep0->dwc_ep.is_in = 0; /* OUT for next SETUP */
  87693. +
  87694. + /* Prepare for more SETUP Packets */
  87695. + if (core_if->dma_enable) {
  87696. + ep0_out_start(core_if, pcd);
  87697. + }
  87698. + break;
  87699. +
  87700. + case EP0_STALL:
  87701. + DWC_ERROR("EP0 STALLed, should not get here pcd_setup()\n");
  87702. + break;
  87703. + }
  87704. +#ifdef DEBUG_EP0
  87705. + print_ep0_state(pcd);
  87706. +#endif
  87707. +}
  87708. +
  87709. +/**
  87710. + * Restart transfer
  87711. + */
  87712. +static void restart_transfer(dwc_otg_pcd_t * pcd, const uint32_t epnum)
  87713. +{
  87714. + dwc_otg_core_if_t *core_if;
  87715. + dwc_otg_dev_if_t *dev_if;
  87716. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  87717. + dwc_otg_pcd_ep_t *ep;
  87718. +
  87719. + ep = get_in_ep(pcd, epnum);
  87720. +
  87721. +#ifdef DWC_EN_ISOC
  87722. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  87723. + return;
  87724. + }
  87725. +#endif /* DWC_EN_ISOC */
  87726. +
  87727. + core_if = GET_CORE_IF(pcd);
  87728. + dev_if = core_if->dev_if;
  87729. +
  87730. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  87731. +
  87732. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x xfer_len=%0x"
  87733. + " stopped=%d\n", ep->dwc_ep.xfer_buff,
  87734. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len, ep->stopped);
  87735. + /*
  87736. + * If xfersize is 0 and pktcnt in not 0, resend the last packet.
  87737. + */
  87738. + if (dieptsiz.b.pktcnt && dieptsiz.b.xfersize == 0 &&
  87739. + ep->dwc_ep.start_xfer_buff != 0) {
  87740. + if (ep->dwc_ep.total_len <= ep->dwc_ep.maxpacket) {
  87741. + ep->dwc_ep.xfer_count = 0;
  87742. + ep->dwc_ep.xfer_buff = ep->dwc_ep.start_xfer_buff;
  87743. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  87744. + } else {
  87745. + ep->dwc_ep.xfer_count -= ep->dwc_ep.maxpacket;
  87746. + /* convert packet size to dwords. */
  87747. + ep->dwc_ep.xfer_buff -= ep->dwc_ep.maxpacket;
  87748. + ep->dwc_ep.xfer_len = ep->dwc_ep.xfer_count;
  87749. + }
  87750. + ep->stopped = 0;
  87751. + DWC_DEBUGPL(DBG_PCD, "xfer_buff=%p xfer_count=%0x "
  87752. + "xfer_len=%0x stopped=%d\n",
  87753. + ep->dwc_ep.xfer_buff,
  87754. + ep->dwc_ep.xfer_count, ep->dwc_ep.xfer_len,
  87755. + ep->stopped);
  87756. + if (epnum == 0) {
  87757. + dwc_otg_ep0_start_transfer(core_if, &ep->dwc_ep);
  87758. + } else {
  87759. + dwc_otg_ep_start_transfer(core_if, &ep->dwc_ep);
  87760. + }
  87761. + }
  87762. +}
  87763. +
  87764. +/*
  87765. + * This function create new nextep sequnce based on Learn Queue.
  87766. + *
  87767. + * @param core_if Programming view of DWC_otg controller
  87768. + */
  87769. +void predict_nextep_seq( dwc_otg_core_if_t * core_if)
  87770. +{
  87771. + dwc_otg_device_global_regs_t *dev_global_regs =
  87772. + core_if->dev_if->dev_global_regs;
  87773. + const uint32_t TOKEN_Q_DEPTH = core_if->hwcfg2.b.dev_token_q_depth;
  87774. + /* Number of Token Queue Registers */
  87775. + const int DTKNQ_REG_CNT = (TOKEN_Q_DEPTH + 7) / 8;
  87776. + dtknq1_data_t dtknqr1;
  87777. + uint32_t in_tkn_epnums[4];
  87778. + uint8_t seqnum[MAX_EPS_CHANNELS];
  87779. + uint8_t intkn_seq[TOKEN_Q_DEPTH];
  87780. + grstctl_t resetctl = {.d32 = 0 };
  87781. + uint8_t temp;
  87782. + int ndx = 0;
  87783. + int start = 0;
  87784. + int end = 0;
  87785. + int sort_done = 0;
  87786. + int i = 0;
  87787. + volatile uint32_t *addr = &dev_global_regs->dtknqr1;
  87788. +
  87789. +
  87790. + DWC_DEBUGPL(DBG_PCD,"dev_token_q_depth=%d\n",TOKEN_Q_DEPTH);
  87791. +
  87792. + /* Read the DTKNQ Registers */
  87793. + for (i = 0; i < DTKNQ_REG_CNT; i++) {
  87794. + in_tkn_epnums[i] = DWC_READ_REG32(addr);
  87795. + DWC_DEBUGPL(DBG_PCDV, "DTKNQR%d=0x%08x\n", i + 1,
  87796. + in_tkn_epnums[i]);
  87797. + if (addr == &dev_global_regs->dvbusdis) {
  87798. + addr = &dev_global_regs->dtknqr3_dthrctl;
  87799. + } else {
  87800. + ++addr;
  87801. + }
  87802. +
  87803. + }
  87804. +
  87805. + /* Copy the DTKNQR1 data to the bit field. */
  87806. + dtknqr1.d32 = in_tkn_epnums[0];
  87807. + if (dtknqr1.b.wrap_bit) {
  87808. + ndx = dtknqr1.b.intknwptr;
  87809. + end = ndx -1;
  87810. + if (end < 0)
  87811. + end = TOKEN_Q_DEPTH -1;
  87812. + } else {
  87813. + ndx = 0;
  87814. + end = dtknqr1.b.intknwptr -1;
  87815. + if (end < 0)
  87816. + end = 0;
  87817. + }
  87818. + start = ndx;
  87819. +
  87820. + /* Fill seqnum[] by initial values: EP number + 31 */
  87821. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  87822. + seqnum[i] = i +31;
  87823. + }
  87824. +
  87825. + /* Fill intkn_seq[] from in_tkn_epnums[0] */
  87826. + for (i=0; i < 6; i++)
  87827. + intkn_seq[i] = (in_tkn_epnums[0] >> ((7-i) * 4)) & 0xf;
  87828. +
  87829. + if (TOKEN_Q_DEPTH > 6) {
  87830. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87831. + for (i=6; i < 14; i++)
  87832. + intkn_seq[i] =
  87833. + (in_tkn_epnums[1] >> ((7 - (i - 6)) * 4)) & 0xf;
  87834. + }
  87835. +
  87836. + if (TOKEN_Q_DEPTH > 14) {
  87837. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87838. + for (i=14; i < 22; i++)
  87839. + intkn_seq[i] =
  87840. + (in_tkn_epnums[2] >> ((7 - (i - 14)) * 4)) & 0xf;
  87841. + }
  87842. +
  87843. + if (TOKEN_Q_DEPTH > 22) {
  87844. + /* Fill intkn_seq[] from in_tkn_epnums[1] */
  87845. + for (i=22; i < 30; i++)
  87846. + intkn_seq[i] =
  87847. + (in_tkn_epnums[3] >> ((7 - (i - 22)) * 4)) & 0xf;
  87848. + }
  87849. +
  87850. + DWC_DEBUGPL(DBG_PCDV, "%s start=%d end=%d intkn_seq[]:\n", __func__,
  87851. + start, end);
  87852. + for (i=0; i<TOKEN_Q_DEPTH; i++)
  87853. + DWC_DEBUGPL(DBG_PCDV,"%d\n", intkn_seq[i]);
  87854. +
  87855. + /* Update seqnum based on intkn_seq[] */
  87856. + i = 0;
  87857. + do {
  87858. + seqnum[intkn_seq[ndx]] = i;
  87859. + ndx++;
  87860. + i++;
  87861. + if (ndx == TOKEN_Q_DEPTH)
  87862. + ndx = 0;
  87863. + } while ( i < TOKEN_Q_DEPTH );
  87864. +
  87865. + /* Mark non active EP's in seqnum[] by 0xff */
  87866. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  87867. + if (core_if->nextep_seq[i] == 0xff )
  87868. + seqnum[i] = 0xff;
  87869. + }
  87870. +
  87871. + /* Sort seqnum[] */
  87872. + sort_done = 0;
  87873. + while (!sort_done) {
  87874. + sort_done = 1;
  87875. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  87876. + if (seqnum[i] > seqnum[i+1]) {
  87877. + temp = seqnum[i];
  87878. + seqnum[i] = seqnum[i+1];
  87879. + seqnum[i+1] = temp;
  87880. + sort_done = 0;
  87881. + }
  87882. + }
  87883. + }
  87884. +
  87885. + ndx = start + seqnum[0];
  87886. + if (ndx >= TOKEN_Q_DEPTH)
  87887. + ndx = ndx % TOKEN_Q_DEPTH;
  87888. + core_if->first_in_nextep_seq = intkn_seq[ndx];
  87889. +
  87890. + /* Update seqnum[] by EP numbers */
  87891. + for (i=0; i<=core_if->dev_if->num_in_eps; i++) {
  87892. + ndx = start + i;
  87893. + if (seqnum[i] < 31) {
  87894. + ndx = start + seqnum[i];
  87895. + if (ndx >= TOKEN_Q_DEPTH)
  87896. + ndx = ndx % TOKEN_Q_DEPTH;
  87897. + seqnum[i] = intkn_seq[ndx];
  87898. + } else {
  87899. + if (seqnum[i] < 0xff) {
  87900. + seqnum[i] = seqnum[i] - 31;
  87901. + } else {
  87902. + break;
  87903. + }
  87904. + }
  87905. + }
  87906. +
  87907. + /* Update nextep_seq[] based on seqnum[] */
  87908. + for (i=0; i<core_if->dev_if->num_in_eps; i++) {
  87909. + if (seqnum[i] != 0xff) {
  87910. + if (seqnum[i+1] != 0xff) {
  87911. + core_if->nextep_seq[seqnum[i]] = seqnum[i+1];
  87912. + } else {
  87913. + core_if->nextep_seq[seqnum[i]] = core_if->first_in_nextep_seq;
  87914. + break;
  87915. + }
  87916. + } else {
  87917. + break;
  87918. + }
  87919. + }
  87920. +
  87921. + DWC_DEBUGPL(DBG_PCDV, "%s first_in_nextep_seq= %2d; nextep_seq[]:\n",
  87922. + __func__, core_if->first_in_nextep_seq);
  87923. + for (i=0; i <= core_if->dev_if->num_in_eps; i++) {
  87924. + DWC_DEBUGPL(DBG_PCDV,"%2d\n", core_if->nextep_seq[i]);
  87925. + }
  87926. +
  87927. + /* Flush the Learning Queue */
  87928. + resetctl.d32 = DWC_READ_REG32(&core_if->core_global_regs->grstctl);
  87929. + resetctl.b.intknqflsh = 1;
  87930. + DWC_WRITE_REG32(&core_if->core_global_regs->grstctl, resetctl.d32);
  87931. +
  87932. +
  87933. +}
  87934. +
  87935. +/**
  87936. + * handle the IN EP disable interrupt.
  87937. + */
  87938. +static inline void handle_in_ep_disable_intr(dwc_otg_pcd_t * pcd,
  87939. + const uint32_t epnum)
  87940. +{
  87941. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  87942. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  87943. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  87944. + dctl_data_t dctl = {.d32 = 0 };
  87945. + dwc_otg_pcd_ep_t *ep;
  87946. + dwc_ep_t *dwc_ep;
  87947. + gintmsk_data_t gintmsk_data;
  87948. + depctl_data_t depctl;
  87949. + uint32_t diepdma;
  87950. + uint32_t remain_to_transfer = 0;
  87951. + uint8_t i;
  87952. + uint32_t xfer_size;
  87953. +
  87954. + ep = get_in_ep(pcd, epnum);
  87955. + dwc_ep = &ep->dwc_ep;
  87956. +
  87957. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  87958. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  87959. + complete_ep(ep);
  87960. + return;
  87961. + }
  87962. +
  87963. + DWC_DEBUGPL(DBG_PCD, "diepctl%d=%0x\n", epnum,
  87964. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl));
  87965. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->dieptsiz);
  87966. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  87967. +
  87968. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  87969. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  87970. +
  87971. + if ((core_if->start_predict == 0) || (depctl.b.eptype & 1)) {
  87972. + if (ep->stopped) {
  87973. + if (core_if->en_multiple_tx_fifo)
  87974. + /* Flush the Tx FIFO */
  87975. + dwc_otg_flush_tx_fifo(core_if, dwc_ep->tx_fifo_num);
  87976. + /* Clear the Global IN NP NAK */
  87977. + dctl.d32 = 0;
  87978. + dctl.b.cgnpinnak = 1;
  87979. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  87980. + /* Restart the transaction */
  87981. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  87982. + restart_transfer(pcd, epnum);
  87983. + }
  87984. + } else {
  87985. + /* Restart the transaction */
  87986. + if (dieptsiz.b.pktcnt != 0 || dieptsiz.b.xfersize != 0) {
  87987. + restart_transfer(pcd, epnum);
  87988. + }
  87989. + DWC_DEBUGPL(DBG_ANY, "STOPPED!!!\n");
  87990. + }
  87991. + return;
  87992. + }
  87993. +
  87994. + if (core_if->start_predict > 2) { // NP IN EP
  87995. + core_if->start_predict--;
  87996. + return;
  87997. + }
  87998. +
  87999. + core_if->start_predict--;
  88000. +
  88001. + if (core_if->start_predict == 1) { // All NP IN Ep's disabled now
  88002. +
  88003. + predict_nextep_seq(core_if);
  88004. +
  88005. + /* Update all active IN EP's NextEP field based of nextep_seq[] */
  88006. + for ( i = 0; i <= core_if->dev_if->num_in_eps; i++) {
  88007. + depctl.d32 =
  88008. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88009. + if (core_if->nextep_seq[i] != 0xff) { // Active NP IN EP
  88010. + depctl.b.nextep = core_if->nextep_seq[i];
  88011. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  88012. + }
  88013. + }
  88014. + /* Flush Shared NP TxFIFO */
  88015. + dwc_otg_flush_tx_fifo(core_if, 0);
  88016. + /* Rewind buffers */
  88017. + if (!core_if->dma_desc_enable) {
  88018. + i = core_if->first_in_nextep_seq;
  88019. + do {
  88020. + ep = get_in_ep(pcd, i);
  88021. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  88022. + xfer_size = ep->dwc_ep.total_len - ep->dwc_ep.xfer_count;
  88023. + if (xfer_size > ep->dwc_ep.maxxfer)
  88024. + xfer_size = ep->dwc_ep.maxxfer;
  88025. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88026. + if (dieptsiz.b.pktcnt != 0) {
  88027. + if (xfer_size == 0) {
  88028. + remain_to_transfer = 0;
  88029. + } else {
  88030. + if ((xfer_size % ep->dwc_ep.maxpacket) == 0) {
  88031. + remain_to_transfer =
  88032. + dieptsiz.b.pktcnt * ep->dwc_ep.maxpacket;
  88033. + } else {
  88034. + remain_to_transfer = ((dieptsiz.b.pktcnt -1) * ep->dwc_ep.maxpacket)
  88035. + + (xfer_size % ep->dwc_ep.maxpacket);
  88036. + }
  88037. + }
  88038. + diepdma = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepdma);
  88039. + dieptsiz.b.xfersize = remain_to_transfer;
  88040. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->dieptsiz, dieptsiz.d32);
  88041. + diepdma = ep->dwc_ep.dma_addr + (xfer_size - remain_to_transfer);
  88042. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepdma, diepdma);
  88043. + }
  88044. + i = core_if->nextep_seq[i];
  88045. + } while (i != core_if->first_in_nextep_seq);
  88046. + } else { // dma_desc_enable
  88047. + DWC_PRINTF("%s Learning Queue not supported in DDMA\n", __func__);
  88048. + }
  88049. +
  88050. + /* Restart transfers in predicted sequences */
  88051. + i = core_if->first_in_nextep_seq;
  88052. + do {
  88053. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  88054. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88055. + if (dieptsiz.b.pktcnt != 0) {
  88056. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  88057. + depctl.b.epena = 1;
  88058. + depctl.b.cnak = 1;
  88059. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32);
  88060. + }
  88061. + i = core_if->nextep_seq[i];
  88062. + } while (i != core_if->first_in_nextep_seq);
  88063. +
  88064. + /* Clear the global non-periodic IN NAK handshake */
  88065. + dctl.d32 = 0;
  88066. + dctl.b.cgnpinnak = 1;
  88067. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  88068. +
  88069. + /* Unmask EP Mismatch interrupt */
  88070. + gintmsk_data.d32 = 0;
  88071. + gintmsk_data.b.epmismatch = 1;
  88072. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, gintmsk_data.d32);
  88073. +
  88074. + core_if->start_predict = 0;
  88075. +
  88076. + }
  88077. +}
  88078. +
  88079. +/**
  88080. + * Handler for the IN EP timeout handshake interrupt.
  88081. + */
  88082. +static inline void handle_in_ep_timeout_intr(dwc_otg_pcd_t * pcd,
  88083. + const uint32_t epnum)
  88084. +{
  88085. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88086. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88087. +
  88088. +#ifdef DEBUG
  88089. + deptsiz_data_t dieptsiz = {.d32 = 0 };
  88090. + uint32_t num = 0;
  88091. +#endif
  88092. + dctl_data_t dctl = {.d32 = 0 };
  88093. + dwc_otg_pcd_ep_t *ep;
  88094. +
  88095. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88096. +
  88097. + ep = get_in_ep(pcd, epnum);
  88098. +
  88099. + /* Disable the NP Tx Fifo Empty Interrrupt */
  88100. + if (!core_if->dma_enable) {
  88101. + intr_mask.b.nptxfempty = 1;
  88102. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  88103. + intr_mask.d32, 0);
  88104. + }
  88105. + /** @todo NGS Check EP type.
  88106. + * Implement for Periodic EPs */
  88107. + /*
  88108. + * Non-periodic EP
  88109. + */
  88110. + /* Enable the Global IN NAK Effective Interrupt */
  88111. + intr_mask.b.ginnakeff = 1;
  88112. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk, 0, intr_mask.d32);
  88113. +
  88114. + /* Set Global IN NAK */
  88115. + dctl.b.sgnpinnak = 1;
  88116. + DWC_MODIFY_REG32(&dev_if->dev_global_regs->dctl, dctl.d32, dctl.d32);
  88117. +
  88118. + ep->stopped = 1;
  88119. +
  88120. +#ifdef DEBUG
  88121. + dieptsiz.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[num]->dieptsiz);
  88122. + DWC_DEBUGPL(DBG_ANY, "pktcnt=%d size=%d\n",
  88123. + dieptsiz.b.pktcnt, dieptsiz.b.xfersize);
  88124. +#endif
  88125. +
  88126. +#ifdef DISABLE_PERIODIC_EP
  88127. + /*
  88128. + * Set the NAK bit for this EP to
  88129. + * start the disable process.
  88130. + */
  88131. + diepctl.d32 = 0;
  88132. + diepctl.b.snak = 1;
  88133. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[num]->diepctl, diepctl.d32,
  88134. + diepctl.d32);
  88135. + ep->disabling = 1;
  88136. + ep->stopped = 1;
  88137. +#endif
  88138. +}
  88139. +
  88140. +/**
  88141. + * Handler for the IN EP NAK interrupt.
  88142. + */
  88143. +static inline int32_t handle_in_ep_nak_intr(dwc_otg_pcd_t * pcd,
  88144. + const uint32_t epnum)
  88145. +{
  88146. + /** @todo implement ISR */
  88147. + dwc_otg_core_if_t *core_if;
  88148. + diepmsk_data_t intr_mask = {.d32 = 0 };
  88149. +
  88150. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "IN EP NAK");
  88151. + core_if = GET_CORE_IF(pcd);
  88152. + intr_mask.b.nak = 1;
  88153. +
  88154. + if (core_if->multiproc_int_enable) {
  88155. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88156. + diepeachintmsk[epnum], intr_mask.d32, 0);
  88157. + } else {
  88158. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->diepmsk,
  88159. + intr_mask.d32, 0);
  88160. + }
  88161. +
  88162. + return 1;
  88163. +}
  88164. +
  88165. +/**
  88166. + * Handler for the OUT EP Babble interrupt.
  88167. + */
  88168. +static inline int32_t handle_out_ep_babble_intr(dwc_otg_pcd_t * pcd,
  88169. + const uint32_t epnum)
  88170. +{
  88171. + /** @todo implement ISR */
  88172. + dwc_otg_core_if_t *core_if;
  88173. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88174. +
  88175. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  88176. + "OUT EP Babble");
  88177. + core_if = GET_CORE_IF(pcd);
  88178. + intr_mask.b.babble = 1;
  88179. +
  88180. + if (core_if->multiproc_int_enable) {
  88181. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88182. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88183. + } else {
  88184. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88185. + intr_mask.d32, 0);
  88186. + }
  88187. +
  88188. + return 1;
  88189. +}
  88190. +
  88191. +/**
  88192. + * Handler for the OUT EP NAK interrupt.
  88193. + */
  88194. +static inline int32_t handle_out_ep_nak_intr(dwc_otg_pcd_t * pcd,
  88195. + const uint32_t epnum)
  88196. +{
  88197. + /** @todo implement ISR */
  88198. + dwc_otg_core_if_t *core_if;
  88199. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88200. +
  88201. + DWC_DEBUGPL(DBG_ANY, "INTERRUPT Handler not implemented for %s\n", "OUT EP NAK");
  88202. + core_if = GET_CORE_IF(pcd);
  88203. + intr_mask.b.nak = 1;
  88204. +
  88205. + if (core_if->multiproc_int_enable) {
  88206. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88207. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88208. + } else {
  88209. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88210. + intr_mask.d32, 0);
  88211. + }
  88212. +
  88213. + return 1;
  88214. +}
  88215. +
  88216. +/**
  88217. + * Handler for the OUT EP NYET interrupt.
  88218. + */
  88219. +static inline int32_t handle_out_ep_nyet_intr(dwc_otg_pcd_t * pcd,
  88220. + const uint32_t epnum)
  88221. +{
  88222. + /** @todo implement ISR */
  88223. + dwc_otg_core_if_t *core_if;
  88224. + doepmsk_data_t intr_mask = {.d32 = 0 };
  88225. +
  88226. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n", "OUT EP NYET");
  88227. + core_if = GET_CORE_IF(pcd);
  88228. + intr_mask.b.nyet = 1;
  88229. +
  88230. + if (core_if->multiproc_int_enable) {
  88231. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->
  88232. + doepeachintmsk[epnum], intr_mask.d32, 0);
  88233. + } else {
  88234. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  88235. + intr_mask.d32, 0);
  88236. + }
  88237. +
  88238. + return 1;
  88239. +}
  88240. +
  88241. +/**
  88242. + * This interrupt indicates that an IN EP has a pending Interrupt.
  88243. + * The sequence for handling the IN EP interrupt is shown below:
  88244. + * -# Read the Device All Endpoint Interrupt register
  88245. + * -# Repeat the following for each IN EP interrupt bit set (from
  88246. + * LSB to MSB).
  88247. + * -# Read the Device Endpoint Interrupt (DIEPINTn) register
  88248. + * -# If "Transfer Complete" call the request complete function
  88249. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  88250. + * -# If "AHB Error Interrupt" log error
  88251. + * -# If "Time-out Handshake" log error
  88252. + * -# If "IN Token Received when TxFIFO Empty" write packet to Tx
  88253. + * FIFO.
  88254. + * -# If "IN Token EP Mismatch" (disable, this is handled by EP
  88255. + * Mismatch Interrupt)
  88256. + */
  88257. +static int32_t dwc_otg_pcd_handle_in_ep_intr(dwc_otg_pcd_t * pcd)
  88258. +{
  88259. +#define CLEAR_IN_EP_INTR(__core_if,__epnum,__intr) \
  88260. +do { \
  88261. + diepint_data_t diepint = {.d32=0}; \
  88262. + diepint.b.__intr = 1; \
  88263. + DWC_WRITE_REG32(&__core_if->dev_if->in_ep_regs[__epnum]->diepint, \
  88264. + diepint.d32); \
  88265. +} while (0)
  88266. +
  88267. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88268. + dwc_otg_dev_if_t *dev_if = core_if->dev_if;
  88269. + diepint_data_t diepint = {.d32 = 0 };
  88270. + depctl_data_t depctl = {.d32 = 0 };
  88271. + uint32_t ep_intr;
  88272. + uint32_t epnum = 0;
  88273. + dwc_otg_pcd_ep_t *ep;
  88274. + dwc_ep_t *dwc_ep;
  88275. + gintmsk_data_t intr_mask = {.d32 = 0 };
  88276. +
  88277. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, pcd);
  88278. +
  88279. + /* Read in the device interrupt bits */
  88280. + ep_intr = dwc_otg_read_dev_all_in_ep_intr(core_if);
  88281. +
  88282. + /* Service the Device IN interrupts for each endpoint */
  88283. + while (ep_intr) {
  88284. + if (ep_intr & 0x1) {
  88285. + uint32_t empty_msk;
  88286. + /* Get EP pointer */
  88287. + ep = get_in_ep(pcd, epnum);
  88288. + dwc_ep = &ep->dwc_ep;
  88289. +
  88290. + depctl.d32 =
  88291. + DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  88292. + empty_msk =
  88293. + DWC_READ_REG32(&dev_if->
  88294. + dev_global_regs->dtknqr4_fifoemptymsk);
  88295. +
  88296. + DWC_DEBUGPL(DBG_PCDV,
  88297. + "IN EP INTERRUPT - %d\nepmty_msk - %8x diepctl - %8x\n",
  88298. + epnum, empty_msk, depctl.d32);
  88299. +
  88300. + DWC_DEBUGPL(DBG_PCD,
  88301. + "EP%d-%s: type=%d, mps=%d\n",
  88302. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  88303. + dwc_ep->type, dwc_ep->maxpacket);
  88304. +
  88305. + diepint.d32 =
  88306. + dwc_otg_read_dev_in_ep_intr(core_if, dwc_ep);
  88307. +
  88308. + DWC_DEBUGPL(DBG_PCDV,
  88309. + "EP %d Interrupt Register - 0x%x\n", epnum,
  88310. + diepint.d32);
  88311. + /* Transfer complete */
  88312. + if (diepint.b.xfercompl) {
  88313. + /* Disable the NP Tx FIFO Empty
  88314. + * Interrupt */
  88315. + if (core_if->en_multiple_tx_fifo == 0) {
  88316. + intr_mask.b.nptxfempty = 1;
  88317. + DWC_MODIFY_REG32
  88318. + (&core_if->core_global_regs->gintmsk,
  88319. + intr_mask.d32, 0);
  88320. + } else {
  88321. + /* Disable the Tx FIFO Empty Interrupt for this EP */
  88322. + uint32_t fifoemptymsk =
  88323. + 0x1 << dwc_ep->num;
  88324. + DWC_MODIFY_REG32(&core_if->
  88325. + dev_if->dev_global_regs->dtknqr4_fifoemptymsk,
  88326. + fifoemptymsk, 0);
  88327. + }
  88328. + /* Clear the bit in DIEPINTn for this interrupt */
  88329. + CLEAR_IN_EP_INTR(core_if, epnum, xfercompl);
  88330. +
  88331. + /* Complete the transfer */
  88332. + if (epnum == 0) {
  88333. + handle_ep0(pcd);
  88334. + }
  88335. +#ifdef DWC_EN_ISOC
  88336. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88337. + if (!ep->stopped)
  88338. + complete_iso_ep(pcd, ep);
  88339. + }
  88340. +#endif /* DWC_EN_ISOC */
  88341. +#ifdef DWC_UTE_PER_IO
  88342. + else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88343. + if (!ep->stopped)
  88344. + complete_xiso_ep(ep);
  88345. + }
  88346. +#endif /* DWC_UTE_PER_IO */
  88347. + else {
  88348. + if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC &&
  88349. + dwc_ep->bInterval > 1) {
  88350. + dwc_ep->frame_num += dwc_ep->bInterval;
  88351. + if (dwc_ep->frame_num > 0x3FFF)
  88352. + {
  88353. + dwc_ep->frm_overrun = 1;
  88354. + dwc_ep->frame_num &= 0x3FFF;
  88355. + } else
  88356. + dwc_ep->frm_overrun = 0;
  88357. + }
  88358. + complete_ep(ep);
  88359. + if(diepint.b.nak)
  88360. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  88361. + }
  88362. + }
  88363. + /* Endpoint disable */
  88364. + if (diepint.b.epdisabled) {
  88365. + DWC_DEBUGPL(DBG_ANY, "EP%d IN disabled\n",
  88366. + epnum);
  88367. + handle_in_ep_disable_intr(pcd, epnum);
  88368. +
  88369. + /* Clear the bit in DIEPINTn for this interrupt */
  88370. + CLEAR_IN_EP_INTR(core_if, epnum, epdisabled);
  88371. + }
  88372. + /* AHB Error */
  88373. + if (diepint.b.ahberr) {
  88374. + DWC_ERROR("EP%d IN AHB Error\n", epnum);
  88375. + /* Clear the bit in DIEPINTn for this interrupt */
  88376. + CLEAR_IN_EP_INTR(core_if, epnum, ahberr);
  88377. + }
  88378. + /* TimeOUT Handshake (non-ISOC IN EPs) */
  88379. + if (diepint.b.timeout) {
  88380. + DWC_ERROR("EP%d IN Time-out\n", epnum);
  88381. + handle_in_ep_timeout_intr(pcd, epnum);
  88382. +
  88383. + CLEAR_IN_EP_INTR(core_if, epnum, timeout);
  88384. + }
  88385. + /** IN Token received with TxF Empty */
  88386. + if (diepint.b.intktxfemp) {
  88387. + DWC_DEBUGPL(DBG_ANY,
  88388. + "EP%d IN TKN TxFifo Empty\n",
  88389. + epnum);
  88390. + if (!ep->stopped && epnum != 0) {
  88391. +
  88392. + diepmsk_data_t diepmsk = {.d32 = 0 };
  88393. + diepmsk.b.intktxfemp = 1;
  88394. +
  88395. + if (core_if->multiproc_int_enable) {
  88396. + DWC_MODIFY_REG32
  88397. + (&dev_if->dev_global_regs->diepeachintmsk
  88398. + [epnum], diepmsk.d32, 0);
  88399. + } else {
  88400. + DWC_MODIFY_REG32
  88401. + (&dev_if->dev_global_regs->diepmsk,
  88402. + diepmsk.d32, 0);
  88403. + }
  88404. + } else if (core_if->dma_desc_enable
  88405. + && epnum == 0
  88406. + && pcd->ep0state ==
  88407. + EP0_OUT_STATUS_PHASE) {
  88408. + // EP0 IN set STALL
  88409. + depctl.d32 =
  88410. + DWC_READ_REG32(&dev_if->in_ep_regs
  88411. + [epnum]->diepctl);
  88412. +
  88413. + /* set the disable and stall bits */
  88414. + if (depctl.b.epena) {
  88415. + depctl.b.epdis = 1;
  88416. + }
  88417. + depctl.b.stall = 1;
  88418. + DWC_WRITE_REG32(&dev_if->in_ep_regs
  88419. + [epnum]->diepctl,
  88420. + depctl.d32);
  88421. + }
  88422. + CLEAR_IN_EP_INTR(core_if, epnum, intktxfemp);
  88423. + }
  88424. + /** IN Token Received with EP mismatch */
  88425. + if (diepint.b.intknepmis) {
  88426. + DWC_DEBUGPL(DBG_ANY,
  88427. + "EP%d IN TKN EP Mismatch\n", epnum);
  88428. + CLEAR_IN_EP_INTR(core_if, epnum, intknepmis);
  88429. + }
  88430. + /** IN Endpoint NAK Effective */
  88431. + if (diepint.b.inepnakeff) {
  88432. + DWC_DEBUGPL(DBG_ANY,
  88433. + "EP%d IN EP NAK Effective\n",
  88434. + epnum);
  88435. + /* Periodic EP */
  88436. + if (ep->disabling) {
  88437. + depctl.d32 = 0;
  88438. + depctl.b.snak = 1;
  88439. + depctl.b.epdis = 1;
  88440. + DWC_MODIFY_REG32(&dev_if->in_ep_regs
  88441. + [epnum]->diepctl,
  88442. + depctl.d32,
  88443. + depctl.d32);
  88444. + }
  88445. + CLEAR_IN_EP_INTR(core_if, epnum, inepnakeff);
  88446. +
  88447. + }
  88448. +
  88449. + /** IN EP Tx FIFO Empty Intr */
  88450. + if (diepint.b.emptyintr) {
  88451. + DWC_DEBUGPL(DBG_ANY,
  88452. + "EP%d Tx FIFO Empty Intr \n",
  88453. + epnum);
  88454. + write_empty_tx_fifo(pcd, epnum);
  88455. +
  88456. + CLEAR_IN_EP_INTR(core_if, epnum, emptyintr);
  88457. +
  88458. + }
  88459. +
  88460. + /** IN EP BNA Intr */
  88461. + if (diepint.b.bna) {
  88462. + CLEAR_IN_EP_INTR(core_if, epnum, bna);
  88463. + if (core_if->dma_desc_enable) {
  88464. +#ifdef DWC_EN_ISOC
  88465. + if (dwc_ep->type ==
  88466. + DWC_OTG_EP_TYPE_ISOC) {
  88467. + /*
  88468. + * This checking is performed to prevent first "false" BNA
  88469. + * handling occuring right after reconnect
  88470. + */
  88471. + if (dwc_ep->next_frame !=
  88472. + 0xffffffff)
  88473. + dwc_otg_pcd_handle_iso_bna(ep);
  88474. + } else
  88475. +#endif /* DWC_EN_ISOC */
  88476. + {
  88477. + dwc_otg_pcd_handle_noniso_bna(ep);
  88478. + }
  88479. + }
  88480. + }
  88481. + /* NAK Interrutp */
  88482. + if (diepint.b.nak) {
  88483. + DWC_DEBUGPL(DBG_ANY, "EP%d IN NAK Interrupt\n",
  88484. + epnum);
  88485. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  88486. + depctl_data_t depctl;
  88487. + if (ep->dwc_ep.frame_num == 0xFFFFFFFF) {
  88488. + ep->dwc_ep.frame_num = core_if->frame_num;
  88489. + if (ep->dwc_ep.bInterval > 1) {
  88490. + depctl.d32 = 0;
  88491. + depctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[epnum]->diepctl);
  88492. + if (ep->dwc_ep.frame_num & 0x1) {
  88493. + depctl.b.setd1pid = 1;
  88494. + depctl.b.setd0pid = 0;
  88495. + } else {
  88496. + depctl.b.setd0pid = 1;
  88497. + depctl.b.setd1pid = 0;
  88498. + }
  88499. + DWC_WRITE_REG32(&dev_if->in_ep_regs[epnum]->diepctl, depctl.d32);
  88500. + }
  88501. + start_next_request(ep);
  88502. + }
  88503. + ep->dwc_ep.frame_num += ep->dwc_ep.bInterval;
  88504. + if (dwc_ep->frame_num > 0x3FFF) {
  88505. + dwc_ep->frm_overrun = 1;
  88506. + dwc_ep->frame_num &= 0x3FFF;
  88507. + } else
  88508. + dwc_ep->frm_overrun = 0;
  88509. + }
  88510. +
  88511. + CLEAR_IN_EP_INTR(core_if, epnum, nak);
  88512. + }
  88513. + }
  88514. + epnum++;
  88515. + ep_intr >>= 1;
  88516. + }
  88517. +
  88518. + return 1;
  88519. +#undef CLEAR_IN_EP_INTR
  88520. +}
  88521. +
  88522. +/**
  88523. + * This interrupt indicates that an OUT EP has a pending Interrupt.
  88524. + * The sequence for handling the OUT EP interrupt is shown below:
  88525. + * -# Read the Device All Endpoint Interrupt register
  88526. + * -# Repeat the following for each OUT EP interrupt bit set (from
  88527. + * LSB to MSB).
  88528. + * -# Read the Device Endpoint Interrupt (DOEPINTn) register
  88529. + * -# If "Transfer Complete" call the request complete function
  88530. + * -# If "Endpoint Disabled" complete the EP disable procedure.
  88531. + * -# If "AHB Error Interrupt" log error
  88532. + * -# If "Setup Phase Done" process Setup Packet (See Standard USB
  88533. + * Command Processing)
  88534. + */
  88535. +static int32_t dwc_otg_pcd_handle_out_ep_intr(dwc_otg_pcd_t * pcd)
  88536. +{
  88537. +#define CLEAR_OUT_EP_INTR(__core_if,__epnum,__intr) \
  88538. +do { \
  88539. + doepint_data_t doepint = {.d32=0}; \
  88540. + doepint.b.__intr = 1; \
  88541. + DWC_WRITE_REG32(&__core_if->dev_if->out_ep_regs[__epnum]->doepint, \
  88542. + doepint.d32); \
  88543. +} while (0)
  88544. +
  88545. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  88546. + uint32_t ep_intr;
  88547. + doepint_data_t doepint = {.d32 = 0 };
  88548. + uint32_t epnum = 0;
  88549. + dwc_otg_pcd_ep_t *ep;
  88550. + dwc_ep_t *dwc_ep;
  88551. + dctl_data_t dctl = {.d32 = 0 };
  88552. + gintmsk_data_t gintmsk = {.d32 = 0 };
  88553. +
  88554. +
  88555. + DWC_DEBUGPL(DBG_PCDV, "%s()\n", __func__);
  88556. +
  88557. + /* Read in the device interrupt bits */
  88558. + ep_intr = dwc_otg_read_dev_all_out_ep_intr(core_if);
  88559. +
  88560. + while (ep_intr) {
  88561. + if (ep_intr & 0x1) {
  88562. + /* Get EP pointer */
  88563. + ep = get_out_ep(pcd, epnum);
  88564. + dwc_ep = &ep->dwc_ep;
  88565. +
  88566. +#ifdef VERBOSE
  88567. + DWC_DEBUGPL(DBG_PCDV,
  88568. + "EP%d-%s: type=%d, mps=%d\n",
  88569. + dwc_ep->num, (dwc_ep->is_in ? "IN" : "OUT"),
  88570. + dwc_ep->type, dwc_ep->maxpacket);
  88571. +#endif
  88572. + doepint.d32 =
  88573. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep);
  88574. + /* Moved this interrupt upper due to core deffect of asserting
  88575. + * OUT EP 0 xfercompl along with stsphsrcvd in BDMA */
  88576. + if (doepint.b.stsphsercvd) {
  88577. + deptsiz0_data_t deptsiz;
  88578. + CLEAR_OUT_EP_INTR(core_if, epnum, stsphsercvd);
  88579. + deptsiz.d32 =
  88580. + DWC_READ_REG32(&core_if->dev_if->
  88581. + out_ep_regs[0]->doeptsiz);
  88582. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  88583. + && core_if->dma_enable
  88584. + && core_if->dma_desc_enable == 0
  88585. + && doepint.b.xfercompl
  88586. + && deptsiz.b.xfersize == 24) {
  88587. + CLEAR_OUT_EP_INTR(core_if, epnum,
  88588. + xfercompl);
  88589. + doepint.b.xfercompl = 0;
  88590. + ep0_out_start(core_if, pcd);
  88591. + }
  88592. + if ((core_if->dma_desc_enable) ||
  88593. + (core_if->dma_enable
  88594. + && core_if->snpsid >=
  88595. + OTG_CORE_REV_3_00a)) {
  88596. + do_setup_in_status_phase(pcd);
  88597. + }
  88598. + }
  88599. + /* Transfer complete */
  88600. + if (doepint.b.xfercompl) {
  88601. +
  88602. + if (epnum == 0) {
  88603. + /* Clear the bit in DOEPINTn for this interrupt */
  88604. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  88605. + if (core_if->snpsid >= OTG_CORE_REV_3_00a) {
  88606. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  88607. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepint),
  88608. + doepint.d32);
  88609. + DWC_DEBUGPL(DBG_PCDV, "DOEPCTL=%x \n",
  88610. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[0]->doepctl));
  88611. +
  88612. + if (core_if->snpsid >= OTG_CORE_REV_3_00a
  88613. + && core_if->dma_enable == 0) {
  88614. + doepint_data_t doepint;
  88615. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88616. + out_ep_regs[0]->doepint);
  88617. + if (pcd->ep0state == EP0_IDLE && doepint.b.sr) {
  88618. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88619. + goto exit_xfercompl;
  88620. + }
  88621. + }
  88622. + /* In case of DDMA look at SR bit to go to the Data Stage */
  88623. + if (core_if->dma_desc_enable) {
  88624. + dev_dma_desc_sts_t status = {.d32 = 0};
  88625. + if (pcd->ep0state == EP0_IDLE) {
  88626. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  88627. + dev_if->setup_desc_index]->status.d32;
  88628. + if(pcd->data_terminated) {
  88629. + pcd->data_terminated = 0;
  88630. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  88631. + dwc_memcpy(&pcd->setup_pkt->req, pcd->backup_buf, 8);
  88632. + }
  88633. + if (status.b.sr) {
  88634. + if (doepint.b.setup) {
  88635. + DWC_DEBUGPL(DBG_PCDV, "DMA DESC EP0_IDLE SR=1 setup=1\n");
  88636. + /* Already started data stage, clear setup */
  88637. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88638. + doepint.b.setup = 0;
  88639. + handle_ep0(pcd);
  88640. + /* Prepare for more setup packets */
  88641. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  88642. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  88643. + ep0_out_start(core_if, pcd);
  88644. + }
  88645. +
  88646. + goto exit_xfercompl;
  88647. + } else {
  88648. + /* Prepare for more setup packets */
  88649. + DWC_DEBUGPL(DBG_PCDV,
  88650. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  88651. + ep0_out_start(core_if, pcd);
  88652. + }
  88653. + }
  88654. + } else {
  88655. + dwc_otg_pcd_request_t *req;
  88656. + dev_dma_desc_sts_t status = {.d32 = 0};
  88657. + diepint_data_t diepint0;
  88658. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88659. + in_ep_regs[0]->diepint);
  88660. +
  88661. + if (pcd->ep0state == EP0_STALL || pcd->ep0state == EP0_DISCONNECT) {
  88662. + DWC_ERROR("EP0 is stalled/disconnected\n");
  88663. + }
  88664. +
  88665. + /* Clear IN xfercompl if set */
  88666. + if (diepint0.b.xfercompl && (pcd->ep0state == EP0_IN_STATUS_PHASE
  88667. + || pcd->ep0state == EP0_IN_DATA_PHASE)) {
  88668. + DWC_WRITE_REG32(&core_if->dev_if->
  88669. + in_ep_regs[0]->diepint, diepint0.d32);
  88670. + }
  88671. +
  88672. + status.d32 = core_if->dev_if->setup_desc_addr[core_if->
  88673. + dev_if->setup_desc_index]->status.d32;
  88674. +
  88675. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len
  88676. + && (pcd->ep0state == EP0_OUT_DATA_PHASE))
  88677. + status.d32 = core_if->dev_if->out_desc_addr->status.d32;
  88678. + if (pcd->ep0state == EP0_OUT_STATUS_PHASE)
  88679. + status.d32 = core_if->dev_if->
  88680. + out_desc_addr->status.d32;
  88681. +
  88682. + if (status.b.sr) {
  88683. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88684. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  88685. + } else {
  88686. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  88687. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88688. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  88689. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  88690. + /* Read arrived setup packet from req->buf */
  88691. + dwc_memcpy(&pcd->setup_pkt->req,
  88692. + req->buf + ep->dwc_ep.xfer_count, 8);
  88693. + }
  88694. + req->actual = ep->dwc_ep.xfer_count;
  88695. + dwc_otg_request_done(ep, req, -ECONNRESET);
  88696. + ep->dwc_ep.start_xfer_buff = 0;
  88697. + ep->dwc_ep.xfer_buff = 0;
  88698. + ep->dwc_ep.xfer_len = 0;
  88699. + }
  88700. + pcd->ep0state = EP0_IDLE;
  88701. + if (doepint.b.setup) {
  88702. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  88703. + /* Data stage started, clear setup */
  88704. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88705. + doepint.b.setup = 0;
  88706. + handle_ep0(pcd);
  88707. + /* Prepare for setup packets if ep0in was enabled*/
  88708. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88709. + ep0_out_start(core_if, pcd);
  88710. + }
  88711. +
  88712. + goto exit_xfercompl;
  88713. + } else {
  88714. + /* Prepare for more setup packets */
  88715. + DWC_DEBUGPL(DBG_PCDV,
  88716. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  88717. + ep0_out_start(core_if, pcd);
  88718. + }
  88719. + }
  88720. + }
  88721. + }
  88722. + if (core_if->snpsid >= OTG_CORE_REV_2_94a && core_if->dma_enable
  88723. + && core_if->dma_desc_enable == 0) {
  88724. + doepint_data_t doepint_temp = {.d32 = 0};
  88725. + deptsiz0_data_t doeptsize0 = {.d32 = 0 };
  88726. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  88727. + out_ep_regs[ep->dwc_ep.num]->doepint);
  88728. + doeptsize0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88729. + out_ep_regs[ep->dwc_ep.num]->doeptsiz);
  88730. + if (pcd->ep0state == EP0_IDLE) {
  88731. + if (doepint_temp.b.sr) {
  88732. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88733. + }
  88734. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88735. + out_ep_regs[0]->doepint);
  88736. + if (doeptsize0.b.supcnt == 3) {
  88737. + DWC_DEBUGPL(DBG_ANY, "Rolling over!!!!!!!\n");
  88738. + ep->dwc_ep.stp_rollover = 1;
  88739. + }
  88740. + if (doepint.b.setup) {
  88741. +retry:
  88742. + /* Already started data stage, clear setup */
  88743. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88744. + doepint.b.setup = 0;
  88745. + handle_ep0(pcd);
  88746. + ep->dwc_ep.stp_rollover = 0;
  88747. + /* Prepare for more setup packets */
  88748. + if (pcd->ep0state == EP0_IN_STATUS_PHASE ||
  88749. + pcd->ep0state == EP0_IN_DATA_PHASE) {
  88750. + ep0_out_start(core_if, pcd);
  88751. + }
  88752. + goto exit_xfercompl;
  88753. + } else {
  88754. + /* Prepare for more setup packets */
  88755. + DWC_DEBUGPL(DBG_ANY,
  88756. + "EP0_IDLE SR=1 setup=0 new setup comes\n");
  88757. + doepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88758. + out_ep_regs[0]->doepint);
  88759. + if(doepint.b.setup)
  88760. + goto retry;
  88761. + ep0_out_start(core_if, pcd);
  88762. + }
  88763. + } else {
  88764. + dwc_otg_pcd_request_t *req;
  88765. + diepint_data_t diepint0 = {.d32 = 0};
  88766. + doepint_data_t doepint_temp = {.d32 = 0};
  88767. + depctl_data_t diepctl0;
  88768. + diepint0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88769. + in_ep_regs[0]->diepint);
  88770. + diepctl0.d32 = DWC_READ_REG32(&core_if->dev_if->
  88771. + in_ep_regs[0]->diepctl);
  88772. +
  88773. + if (pcd->ep0state == EP0_IN_DATA_PHASE
  88774. + || pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88775. + if (diepint0.b.xfercompl) {
  88776. + DWC_WRITE_REG32(&core_if->dev_if->
  88777. + in_ep_regs[0]->diepint, diepint0.d32);
  88778. + }
  88779. + if (diepctl0.b.epena) {
  88780. + diepint_data_t diepint = {.d32 = 0};
  88781. + diepctl0.b.snak = 1;
  88782. + DWC_WRITE_REG32(&core_if->dev_if->
  88783. + in_ep_regs[0]->diepctl, diepctl0.d32);
  88784. + do {
  88785. + dwc_udelay(10);
  88786. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88787. + in_ep_regs[0]->diepint);
  88788. + } while (!diepint.b.inepnakeff);
  88789. + diepint.b.inepnakeff = 1;
  88790. + DWC_WRITE_REG32(&core_if->dev_if->
  88791. + in_ep_regs[0]->diepint, diepint.d32);
  88792. + diepctl0.d32 = 0;
  88793. + diepctl0.b.epdis = 1;
  88794. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepctl,
  88795. + diepctl0.d32);
  88796. + do {
  88797. + dwc_udelay(10);
  88798. + diepint.d32 = DWC_READ_REG32(&core_if->dev_if->
  88799. + in_ep_regs[0]->diepint);
  88800. + } while (!diepint.b.epdisabled);
  88801. + diepint.b.epdisabled = 1;
  88802. + DWC_WRITE_REG32(&core_if->dev_if->in_ep_regs[0]->diepint,
  88803. + diepint.d32);
  88804. + }
  88805. + }
  88806. + doepint_temp.d32 = DWC_READ_REG32(&core_if->dev_if->
  88807. + out_ep_regs[ep->dwc_ep.num]->doepint);
  88808. + if (doepint_temp.b.sr) {
  88809. + CLEAR_OUT_EP_INTR(core_if, epnum, sr);
  88810. + if (DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88811. + DWC_DEBUGPL(DBG_PCDV, "Request queue empty!!\n");
  88812. + } else {
  88813. + DWC_DEBUGPL(DBG_PCDV, "complete req!!\n");
  88814. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88815. + if (ep->dwc_ep.xfer_count != ep->dwc_ep.total_len &&
  88816. + pcd->ep0state == EP0_OUT_DATA_PHASE) {
  88817. + /* Read arrived setup packet from req->buf */
  88818. + dwc_memcpy(&pcd->setup_pkt->req,
  88819. + req->buf + ep->dwc_ep.xfer_count, 8);
  88820. + }
  88821. + req->actual = ep->dwc_ep.xfer_count;
  88822. + dwc_otg_request_done(ep, req, -ECONNRESET);
  88823. + ep->dwc_ep.start_xfer_buff = 0;
  88824. + ep->dwc_ep.xfer_buff = 0;
  88825. + ep->dwc_ep.xfer_len = 0;
  88826. + }
  88827. + pcd->ep0state = EP0_IDLE;
  88828. + if (doepint.b.setup) {
  88829. + DWC_DEBUGPL(DBG_PCDV, "EP0_IDLE SR=1 setup=1\n");
  88830. + /* Data stage started, clear setup */
  88831. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88832. + doepint.b.setup = 0;
  88833. + handle_ep0(pcd);
  88834. + /* Prepare for setup packets if ep0in was enabled*/
  88835. + if (pcd->ep0state == EP0_IN_STATUS_PHASE) {
  88836. + ep0_out_start(core_if, pcd);
  88837. + }
  88838. + goto exit_xfercompl;
  88839. + } else {
  88840. + /* Prepare for more setup packets */
  88841. + DWC_DEBUGPL(DBG_PCDV,
  88842. + "EP0_IDLE SR=1 setup=0 new setup comes 2\n");
  88843. + ep0_out_start(core_if, pcd);
  88844. + }
  88845. + }
  88846. + }
  88847. + }
  88848. + if (core_if->dma_enable == 0 || pcd->ep0state != EP0_IDLE)
  88849. + handle_ep0(pcd);
  88850. +exit_xfercompl:
  88851. + DWC_DEBUGPL(DBG_PCDV, "DOEPINT=%x doepint=%x\n",
  88852. + dwc_otg_read_dev_out_ep_intr(core_if, dwc_ep), doepint.d32);
  88853. + } else {
  88854. + if (core_if->dma_desc_enable == 0
  88855. + || pcd->ep0state != EP0_IDLE)
  88856. + handle_ep0(pcd);
  88857. + }
  88858. +#ifdef DWC_EN_ISOC
  88859. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88860. + if (doepint.b.pktdrpsts == 0) {
  88861. + /* Clear the bit in DOEPINTn for this interrupt */
  88862. + CLEAR_OUT_EP_INTR(core_if,
  88863. + epnum,
  88864. + xfercompl);
  88865. + complete_iso_ep(pcd, ep);
  88866. + } else {
  88867. +
  88868. + doepint_data_t doepint = {.d32 = 0 };
  88869. + doepint.b.xfercompl = 1;
  88870. + doepint.b.pktdrpsts = 1;
  88871. + DWC_WRITE_REG32
  88872. + (&core_if->dev_if->out_ep_regs
  88873. + [epnum]->doepint,
  88874. + doepint.d32);
  88875. + if (handle_iso_out_pkt_dropped
  88876. + (core_if, dwc_ep)) {
  88877. + complete_iso_ep(pcd,
  88878. + ep);
  88879. + }
  88880. + }
  88881. +#endif /* DWC_EN_ISOC */
  88882. +#ifdef DWC_UTE_PER_IO
  88883. + } else if (dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  88884. + CLEAR_OUT_EP_INTR(core_if, epnum, xfercompl);
  88885. + if (!ep->stopped)
  88886. + complete_xiso_ep(ep);
  88887. +#endif /* DWC_UTE_PER_IO */
  88888. + } else {
  88889. + /* Clear the bit in DOEPINTn for this interrupt */
  88890. + CLEAR_OUT_EP_INTR(core_if, epnum,
  88891. + xfercompl);
  88892. +
  88893. + if (core_if->core_params->dev_out_nak) {
  88894. + DWC_TIMER_CANCEL(pcd->core_if->ep_xfer_timer[epnum]);
  88895. + pcd->core_if->ep_xfer_info[epnum].state = 0;
  88896. +#ifdef DEBUG
  88897. + print_memory_payload(pcd, dwc_ep);
  88898. +#endif
  88899. + }
  88900. + complete_ep(ep);
  88901. + }
  88902. +
  88903. + }
  88904. +
  88905. + /* Endpoint disable */
  88906. + if (doepint.b.epdisabled) {
  88907. +
  88908. + /* Clear the bit in DOEPINTn for this interrupt */
  88909. + CLEAR_OUT_EP_INTR(core_if, epnum, epdisabled);
  88910. + if (core_if->core_params->dev_out_nak) {
  88911. +#ifdef DEBUG
  88912. + print_memory_payload(pcd, dwc_ep);
  88913. +#endif
  88914. + /* In case of timeout condition */
  88915. + if (core_if->ep_xfer_info[epnum].state == 2) {
  88916. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  88917. + dev_global_regs->dctl);
  88918. + dctl.b.cgoutnak = 1;
  88919. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  88920. + dctl.d32);
  88921. + /* Unmask goutnakeff interrupt which was masked
  88922. + * during handle nak out interrupt */
  88923. + gintmsk.b.goutnakeff = 1;
  88924. + DWC_MODIFY_REG32(&core_if->core_global_regs->gintmsk,
  88925. + 0, gintmsk.d32);
  88926. +
  88927. + complete_ep(ep);
  88928. + }
  88929. + }
  88930. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC)
  88931. + {
  88932. + dctl_data_t dctl;
  88933. + gintmsk_data_t intr_mask = {.d32 = 0};
  88934. + dwc_otg_pcd_request_t *req = 0;
  88935. +
  88936. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  88937. + dev_global_regs->dctl);
  88938. + dctl.b.cgoutnak = 1;
  88939. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl,
  88940. + dctl.d32);
  88941. +
  88942. + intr_mask.d32 = 0;
  88943. + intr_mask.b.incomplisoout = 1;
  88944. +
  88945. + /* Get any pending requests */
  88946. + if (!DWC_CIRCLEQ_EMPTY(&ep->queue)) {
  88947. + req = DWC_CIRCLEQ_FIRST(&ep->queue);
  88948. + if (!req) {
  88949. + DWC_PRINTF("complete_ep 0x%p, req = NULL!\n", ep);
  88950. + } else {
  88951. + dwc_otg_request_done(ep, req, 0);
  88952. + start_next_request(ep);
  88953. + }
  88954. + } else {
  88955. + DWC_PRINTF("complete_ep 0x%p, ep->queue empty!\n", ep);
  88956. + }
  88957. + }
  88958. + }
  88959. + /* AHB Error */
  88960. + if (doepint.b.ahberr) {
  88961. + DWC_ERROR("EP%d OUT AHB Error\n", epnum);
  88962. + DWC_ERROR("EP%d DEPDMA=0x%08x \n",
  88963. + epnum, core_if->dev_if->out_ep_regs[epnum]->doepdma);
  88964. + CLEAR_OUT_EP_INTR(core_if, epnum, ahberr);
  88965. + }
  88966. + /* Setup Phase Done (contorl EPs) */
  88967. + if (doepint.b.setup) {
  88968. +#ifdef DEBUG_EP0
  88969. + DWC_DEBUGPL(DBG_PCD, "EP%d SETUP Done\n", epnum);
  88970. +#endif
  88971. + CLEAR_OUT_EP_INTR(core_if, epnum, setup);
  88972. +
  88973. + handle_ep0(pcd);
  88974. + }
  88975. +
  88976. + /** OUT EP BNA Intr */
  88977. + if (doepint.b.bna) {
  88978. + CLEAR_OUT_EP_INTR(core_if, epnum, bna);
  88979. + if (core_if->dma_desc_enable) {
  88980. +#ifdef DWC_EN_ISOC
  88981. + if (dwc_ep->type ==
  88982. + DWC_OTG_EP_TYPE_ISOC) {
  88983. + /*
  88984. + * This checking is performed to prevent first "false" BNA
  88985. + * handling occuring right after reconnect
  88986. + */
  88987. + if (dwc_ep->next_frame !=
  88988. + 0xffffffff)
  88989. + dwc_otg_pcd_handle_iso_bna(ep);
  88990. + } else
  88991. +#endif /* DWC_EN_ISOC */
  88992. + {
  88993. + dwc_otg_pcd_handle_noniso_bna(ep);
  88994. + }
  88995. + }
  88996. + }
  88997. + /* Babble Interrupt */
  88998. + if (doepint.b.babble) {
  88999. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Babble\n",
  89000. + epnum);
  89001. + handle_out_ep_babble_intr(pcd, epnum);
  89002. +
  89003. + CLEAR_OUT_EP_INTR(core_if, epnum, babble);
  89004. + }
  89005. + if (doepint.b.outtknepdis) {
  89006. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT Token received when EP is \
  89007. + disabled\n",epnum);
  89008. + if (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89009. + doepmsk_data_t doepmsk = {.d32 = 0};
  89010. + ep->dwc_ep.frame_num = core_if->frame_num;
  89011. + if (ep->dwc_ep.bInterval > 1) {
  89012. + depctl_data_t depctl;
  89013. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->
  89014. + out_ep_regs[epnum]->doepctl);
  89015. + if (ep->dwc_ep.frame_num & 0x1) {
  89016. + depctl.b.setd1pid = 1;
  89017. + depctl.b.setd0pid = 0;
  89018. + } else {
  89019. + depctl.b.setd0pid = 1;
  89020. + depctl.b.setd1pid = 0;
  89021. + }
  89022. + DWC_WRITE_REG32(&core_if->dev_if->
  89023. + out_ep_regs[epnum]->doepctl, depctl.d32);
  89024. + }
  89025. + start_next_request(ep);
  89026. + doepmsk.b.outtknepdis = 1;
  89027. + DWC_MODIFY_REG32(&core_if->dev_if->dev_global_regs->doepmsk,
  89028. + doepmsk.d32, 0);
  89029. + }
  89030. + CLEAR_OUT_EP_INTR(core_if, epnum, outtknepdis);
  89031. + }
  89032. +
  89033. + /* NAK Interrutp */
  89034. + if (doepint.b.nak) {
  89035. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NAK\n", epnum);
  89036. + handle_out_ep_nak_intr(pcd, epnum);
  89037. +
  89038. + CLEAR_OUT_EP_INTR(core_if, epnum, nak);
  89039. + }
  89040. + /* NYET Interrutp */
  89041. + if (doepint.b.nyet) {
  89042. + DWC_DEBUGPL(DBG_ANY, "EP%d OUT NYET\n", epnum);
  89043. + handle_out_ep_nyet_intr(pcd, epnum);
  89044. +
  89045. + CLEAR_OUT_EP_INTR(core_if, epnum, nyet);
  89046. + }
  89047. + }
  89048. +
  89049. + epnum++;
  89050. + ep_intr >>= 1;
  89051. + }
  89052. +
  89053. + return 1;
  89054. +
  89055. +#undef CLEAR_OUT_EP_INTR
  89056. +}
  89057. +static int drop_transfer(uint32_t trgt_fr, uint32_t curr_fr, uint8_t frm_overrun)
  89058. +{
  89059. + int retval = 0;
  89060. + if(!frm_overrun && curr_fr >= trgt_fr)
  89061. + retval = 1;
  89062. + else if (frm_overrun
  89063. + && (curr_fr >= trgt_fr && ((curr_fr - trgt_fr) < 0x3FFF / 2)))
  89064. + retval = 1;
  89065. + return retval;
  89066. +}
  89067. +/**
  89068. + * Incomplete ISO IN Transfer Interrupt.
  89069. + * This interrupt indicates one of the following conditions occurred
  89070. + * while transmitting an ISOC transaction.
  89071. + * - Corrupted IN Token for ISOC EP.
  89072. + * - Packet not complete in FIFO.
  89073. + * The follow actions will be taken:
  89074. + * -# Determine the EP
  89075. + * -# Set incomplete flag in dwc_ep structure
  89076. + * -# Disable EP; when "Endpoint Disabled" interrupt is received
  89077. + * Flush FIFO
  89078. + */
  89079. +int32_t dwc_otg_pcd_handle_incomplete_isoc_in_intr(dwc_otg_pcd_t * pcd)
  89080. +{
  89081. + gintsts_data_t gintsts;
  89082. +
  89083. +#ifdef DWC_EN_ISOC
  89084. + dwc_otg_dev_if_t *dev_if;
  89085. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89086. + depctl_data_t depctl = {.d32 = 0 };
  89087. + dsts_data_t dsts = {.d32 = 0 };
  89088. + dwc_ep_t *dwc_ep;
  89089. + int i;
  89090. +
  89091. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89092. +
  89093. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  89094. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  89095. + if (dwc_ep->active && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89096. + deptsiz.d32 =
  89097. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->dieptsiz);
  89098. + depctl.d32 =
  89099. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89100. +
  89101. + if (depctl.b.epdis && deptsiz.d32) {
  89102. + set_current_pkt_info(GET_CORE_IF(pcd), dwc_ep);
  89103. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89104. + dwc_ep->cur_pkt = 0;
  89105. + dwc_ep->proc_buf_num =
  89106. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89107. +
  89108. + if (dwc_ep->proc_buf_num) {
  89109. + dwc_ep->cur_pkt_addr =
  89110. + dwc_ep->xfer_buff1;
  89111. + dwc_ep->cur_pkt_dma_addr =
  89112. + dwc_ep->dma_addr1;
  89113. + } else {
  89114. + dwc_ep->cur_pkt_addr =
  89115. + dwc_ep->xfer_buff0;
  89116. + dwc_ep->cur_pkt_dma_addr =
  89117. + dwc_ep->dma_addr0;
  89118. + }
  89119. +
  89120. + }
  89121. +
  89122. + dsts.d32 =
  89123. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  89124. + dev_global_regs->dsts);
  89125. + dwc_ep->next_frame = dsts.b.soffn;
  89126. +
  89127. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  89128. + (pcd),
  89129. + dwc_ep);
  89130. + }
  89131. + }
  89132. + }
  89133. +
  89134. +#else
  89135. + depctl_data_t depctl = {.d32 = 0 };
  89136. + dwc_ep_t *dwc_ep;
  89137. + dwc_otg_dev_if_t *dev_if;
  89138. + int i;
  89139. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89140. +
  89141. + DWC_DEBUGPL(DBG_PCD,"Incomplete ISO IN \n");
  89142. +
  89143. + for (i = 1; i <= dev_if->num_in_eps; ++i) {
  89144. + dwc_ep = &pcd->in_ep[i-1].dwc_ep;
  89145. + depctl.d32 =
  89146. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89147. + if (depctl.b.epena && dwc_ep->type == DWC_OTG_EP_TYPE_ISOC) {
  89148. + if (drop_transfer(dwc_ep->frame_num, GET_CORE_IF(pcd)->frame_num,
  89149. + dwc_ep->frm_overrun))
  89150. + {
  89151. + depctl.d32 =
  89152. + DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89153. + depctl.b.snak = 1;
  89154. + depctl.b.epdis = 1;
  89155. + DWC_MODIFY_REG32(&dev_if->in_ep_regs[i]->diepctl, depctl.d32, depctl.d32);
  89156. + }
  89157. + }
  89158. + }
  89159. +
  89160. + /*intr_mask.b.incomplisoin = 1;
  89161. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89162. + intr_mask.d32, 0); */
  89163. +#endif //DWC_EN_ISOC
  89164. +
  89165. + /* Clear interrupt */
  89166. + gintsts.d32 = 0;
  89167. + gintsts.b.incomplisoin = 1;
  89168. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89169. + gintsts.d32);
  89170. +
  89171. + return 1;
  89172. +}
  89173. +
  89174. +/**
  89175. + * Incomplete ISO OUT Transfer Interrupt.
  89176. + *
  89177. + * This interrupt indicates that the core has dropped an ISO OUT
  89178. + * packet. The following conditions can be the cause:
  89179. + * - FIFO Full, the entire packet would not fit in the FIFO.
  89180. + * - CRC Error
  89181. + * - Corrupted Token
  89182. + * The follow actions will be taken:
  89183. + * -# Determine the EP
  89184. + * -# Set incomplete flag in dwc_ep structure
  89185. + * -# Read any data from the FIFO
  89186. + * -# Disable EP. When "Endpoint Disabled" interrupt is received
  89187. + * re-enable EP.
  89188. + */
  89189. +int32_t dwc_otg_pcd_handle_incomplete_isoc_out_intr(dwc_otg_pcd_t * pcd)
  89190. +{
  89191. +
  89192. + gintsts_data_t gintsts;
  89193. +
  89194. +#ifdef DWC_EN_ISOC
  89195. + dwc_otg_dev_if_t *dev_if;
  89196. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89197. + depctl_data_t depctl = {.d32 = 0 };
  89198. + dsts_data_t dsts = {.d32 = 0 };
  89199. + dwc_ep_t *dwc_ep;
  89200. + int i;
  89201. +
  89202. + dev_if = GET_CORE_IF(pcd)->dev_if;
  89203. +
  89204. + for (i = 1; i <= dev_if->num_out_eps; ++i) {
  89205. + dwc_ep = &pcd->in_ep[i].dwc_ep;
  89206. + if (pcd->out_ep[i].dwc_ep.active &&
  89207. + pcd->out_ep[i].dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) {
  89208. + deptsiz.d32 =
  89209. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doeptsiz);
  89210. + depctl.d32 =
  89211. + DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  89212. +
  89213. + if (depctl.b.epdis && deptsiz.d32) {
  89214. + set_current_pkt_info(GET_CORE_IF(pcd),
  89215. + &pcd->out_ep[i].dwc_ep);
  89216. + if (dwc_ep->cur_pkt >= dwc_ep->pkt_cnt) {
  89217. + dwc_ep->cur_pkt = 0;
  89218. + dwc_ep->proc_buf_num =
  89219. + (dwc_ep->proc_buf_num ^ 1) & 0x1;
  89220. +
  89221. + if (dwc_ep->proc_buf_num) {
  89222. + dwc_ep->cur_pkt_addr =
  89223. + dwc_ep->xfer_buff1;
  89224. + dwc_ep->cur_pkt_dma_addr =
  89225. + dwc_ep->dma_addr1;
  89226. + } else {
  89227. + dwc_ep->cur_pkt_addr =
  89228. + dwc_ep->xfer_buff0;
  89229. + dwc_ep->cur_pkt_dma_addr =
  89230. + dwc_ep->dma_addr0;
  89231. + }
  89232. +
  89233. + }
  89234. +
  89235. + dsts.d32 =
  89236. + DWC_READ_REG32(&GET_CORE_IF(pcd)->dev_if->
  89237. + dev_global_regs->dsts);
  89238. + dwc_ep->next_frame = dsts.b.soffn;
  89239. +
  89240. + dwc_otg_iso_ep_start_frm_transfer(GET_CORE_IF
  89241. + (pcd),
  89242. + dwc_ep);
  89243. + }
  89244. + }
  89245. + }
  89246. +#else
  89247. + /** @todo implement ISR */
  89248. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89249. + dwc_otg_core_if_t *core_if;
  89250. + deptsiz_data_t deptsiz = {.d32 = 0 };
  89251. + depctl_data_t depctl = {.d32 = 0 };
  89252. + dctl_data_t dctl = {.d32 = 0 };
  89253. + dwc_ep_t *dwc_ep = NULL;
  89254. + int i;
  89255. + core_if = GET_CORE_IF(pcd);
  89256. +
  89257. + for (i = 0; i < core_if->dev_if->num_out_eps; ++i) {
  89258. + dwc_ep = &pcd->out_ep[i].dwc_ep;
  89259. + depctl.d32 =
  89260. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  89261. + if (depctl.b.epena && depctl.b.dpid == (core_if->frame_num & 0x1)) {
  89262. + core_if->dev_if->isoc_ep = dwc_ep;
  89263. + deptsiz.d32 =
  89264. + DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doeptsiz);
  89265. + break;
  89266. + }
  89267. + }
  89268. + dctl.d32 = DWC_READ_REG32(&core_if->dev_if->dev_global_regs->dctl);
  89269. + gintsts.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintsts);
  89270. + intr_mask.d32 = DWC_READ_REG32(&core_if->core_global_regs->gintmsk);
  89271. +
  89272. + if (!intr_mask.b.goutnakeff) {
  89273. + /* Unmask it */
  89274. + intr_mask.b.goutnakeff = 1;
  89275. + DWC_WRITE_REG32(&core_if->core_global_regs->gintmsk, intr_mask.d32);
  89276. + }
  89277. + if (!gintsts.b.goutnakeff) {
  89278. + dctl.b.sgoutnak = 1;
  89279. + }
  89280. + DWC_WRITE_REG32(&core_if->dev_if->dev_global_regs->dctl, dctl.d32);
  89281. +
  89282. + depctl.d32 = DWC_READ_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl);
  89283. + if (depctl.b.epena) {
  89284. + depctl.b.epdis = 1;
  89285. + depctl.b.snak = 1;
  89286. + }
  89287. + DWC_WRITE_REG32(&core_if->dev_if->out_ep_regs[dwc_ep->num]->doepctl, depctl.d32);
  89288. +
  89289. + intr_mask.d32 = 0;
  89290. + intr_mask.b.incomplisoout = 1;
  89291. +
  89292. +#endif /* DWC_EN_ISOC */
  89293. +
  89294. + /* Clear interrupt */
  89295. + gintsts.d32 = 0;
  89296. + gintsts.b.incomplisoout = 1;
  89297. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89298. + gintsts.d32);
  89299. +
  89300. + return 1;
  89301. +}
  89302. +
  89303. +/**
  89304. + * This function handles the Global IN NAK Effective interrupt.
  89305. + *
  89306. + */
  89307. +int32_t dwc_otg_pcd_handle_in_nak_effective(dwc_otg_pcd_t * pcd)
  89308. +{
  89309. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  89310. + depctl_data_t diepctl = {.d32 = 0 };
  89311. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89312. + gintsts_data_t gintsts;
  89313. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89314. + int i;
  89315. +
  89316. + DWC_DEBUGPL(DBG_PCD, "Global IN NAK Effective\n");
  89317. +
  89318. + /* Disable all active IN EPs */
  89319. + for (i = 0; i <= dev_if->num_in_eps; i++) {
  89320. + diepctl.d32 = DWC_READ_REG32(&dev_if->in_ep_regs[i]->diepctl);
  89321. + if (!(diepctl.b.eptype & 1) && diepctl.b.epena) {
  89322. + if (core_if->start_predict > 0)
  89323. + core_if->start_predict++;
  89324. + diepctl.b.epdis = 1;
  89325. + diepctl.b.snak = 1;
  89326. + DWC_WRITE_REG32(&dev_if->in_ep_regs[i]->diepctl, diepctl.d32);
  89327. + }
  89328. + }
  89329. +
  89330. +
  89331. + /* Disable the Global IN NAK Effective Interrupt */
  89332. + intr_mask.b.ginnakeff = 1;
  89333. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89334. + intr_mask.d32, 0);
  89335. +
  89336. + /* Clear interrupt */
  89337. + gintsts.d32 = 0;
  89338. + gintsts.b.ginnakeff = 1;
  89339. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89340. + gintsts.d32);
  89341. +
  89342. + return 1;
  89343. +}
  89344. +
  89345. +/**
  89346. + * OUT NAK Effective.
  89347. + *
  89348. + */
  89349. +int32_t dwc_otg_pcd_handle_out_nak_effective(dwc_otg_pcd_t * pcd)
  89350. +{
  89351. + dwc_otg_dev_if_t *dev_if = GET_CORE_IF(pcd)->dev_if;
  89352. + gintmsk_data_t intr_mask = {.d32 = 0 };
  89353. + gintsts_data_t gintsts;
  89354. + depctl_data_t doepctl;
  89355. + int i;
  89356. +
  89357. + /* Disable the Global OUT NAK Effective Interrupt */
  89358. + intr_mask.b.goutnakeff = 1;
  89359. + DWC_MODIFY_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintmsk,
  89360. + intr_mask.d32, 0);
  89361. +
  89362. + /* If DEV OUT NAK enabled*/
  89363. + if (pcd->core_if->core_params->dev_out_nak) {
  89364. + /* Run over all out endpoints to determine the ep number on
  89365. + * which the timeout has happened
  89366. + */
  89367. + for (i = 0; i <= dev_if->num_out_eps; i++) {
  89368. + if ( pcd->core_if->ep_xfer_info[i].state == 2 )
  89369. + break;
  89370. + }
  89371. + if (i > dev_if->num_out_eps) {
  89372. + dctl_data_t dctl;
  89373. + dctl.d32 =
  89374. + DWC_READ_REG32(&dev_if->dev_global_regs->dctl);
  89375. + dctl.b.cgoutnak = 1;
  89376. + DWC_WRITE_REG32(&dev_if->dev_global_regs->dctl,
  89377. + dctl.d32);
  89378. + goto out;
  89379. + }
  89380. +
  89381. + /* Disable the endpoint */
  89382. + doepctl.d32 = DWC_READ_REG32(&dev_if->out_ep_regs[i]->doepctl);
  89383. + if (doepctl.b.epena) {
  89384. + doepctl.b.epdis = 1;
  89385. + doepctl.b.snak = 1;
  89386. + }
  89387. + DWC_WRITE_REG32(&dev_if->out_ep_regs[i]->doepctl, doepctl.d32);
  89388. + return 1;
  89389. + }
  89390. + /* We come here from Incomplete ISO OUT handler */
  89391. + if (dev_if->isoc_ep) {
  89392. + dwc_ep_t *dwc_ep = (dwc_ep_t *)dev_if->isoc_ep;
  89393. + uint32_t epnum = dwc_ep->num;
  89394. + doepint_data_t doepint;
  89395. + doepint.d32 =
  89396. + DWC_READ_REG32(&dev_if->out_ep_regs[dwc_ep->num]->doepint);
  89397. + dev_if->isoc_ep = NULL;
  89398. + doepctl.d32 =
  89399. + DWC_READ_REG32(&dev_if->out_ep_regs[epnum]->doepctl);
  89400. + DWC_PRINTF("Before disable DOEPCTL = %08x\n", doepctl.d32);
  89401. + if (doepctl.b.epena) {
  89402. + doepctl.b.epdis = 1;
  89403. + doepctl.b.snak = 1;
  89404. + }
  89405. + DWC_WRITE_REG32(&dev_if->out_ep_regs[epnum]->doepctl,
  89406. + doepctl.d32);
  89407. + return 1;
  89408. + } else
  89409. + DWC_PRINTF("INTERRUPT Handler not implemented for %s\n",
  89410. + "Global OUT NAK Effective\n");
  89411. +
  89412. +out:
  89413. + /* Clear interrupt */
  89414. + gintsts.d32 = 0;
  89415. + gintsts.b.goutnakeff = 1;
  89416. + DWC_WRITE_REG32(&GET_CORE_IF(pcd)->core_global_regs->gintsts,
  89417. + gintsts.d32);
  89418. +
  89419. + return 1;
  89420. +}
  89421. +
  89422. +/**
  89423. + * PCD interrupt handler.
  89424. + *
  89425. + * The PCD handles the device interrupts. Many conditions can cause a
  89426. + * device interrupt. When an interrupt occurs, the device interrupt
  89427. + * service routine determines the cause of the interrupt and
  89428. + * dispatches handling to the appropriate function. These interrupt
  89429. + * handling functions are described below.
  89430. + *
  89431. + * All interrupt registers are processed from LSB to MSB.
  89432. + *
  89433. + */
  89434. +int32_t dwc_otg_pcd_handle_intr(dwc_otg_pcd_t * pcd)
  89435. +{
  89436. + dwc_otg_core_if_t *core_if = GET_CORE_IF(pcd);
  89437. +#ifdef VERBOSE
  89438. + dwc_otg_core_global_regs_t *global_regs = core_if->core_global_regs;
  89439. +#endif
  89440. + gintsts_data_t gintr_status;
  89441. + int32_t retval = 0;
  89442. +
  89443. + /* Exit from ISR if core is hibernated */
  89444. + if (core_if->hibernation_suspend == 1) {
  89445. + return retval;
  89446. + }
  89447. +#ifdef VERBOSE
  89448. + DWC_DEBUGPL(DBG_ANY, "%s() gintsts=%08x gintmsk=%08x\n",
  89449. + __func__,
  89450. + DWC_READ_REG32(&global_regs->gintsts),
  89451. + DWC_READ_REG32(&global_regs->gintmsk));
  89452. +#endif
  89453. +
  89454. + if (dwc_otg_is_device_mode(core_if)) {
  89455. + DWC_SPINLOCK(pcd->lock);
  89456. +#ifdef VERBOSE
  89457. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%08x gintmsk=%08x\n",
  89458. + __func__,
  89459. + DWC_READ_REG32(&global_regs->gintsts),
  89460. + DWC_READ_REG32(&global_regs->gintmsk));
  89461. +#endif
  89462. +
  89463. + gintr_status.d32 = dwc_otg_read_core_intr(core_if);
  89464. +
  89465. + DWC_DEBUGPL(DBG_PCDV, "%s: gintsts&gintmsk=%08x\n",
  89466. + __func__, gintr_status.d32);
  89467. +
  89468. + if (gintr_status.b.sofintr) {
  89469. + retval |= dwc_otg_pcd_handle_sof_intr(pcd);
  89470. + }
  89471. + if (gintr_status.b.rxstsqlvl) {
  89472. + retval |=
  89473. + dwc_otg_pcd_handle_rx_status_q_level_intr(pcd);
  89474. + }
  89475. + if (gintr_status.b.nptxfempty) {
  89476. + retval |= dwc_otg_pcd_handle_np_tx_fifo_empty_intr(pcd);
  89477. + }
  89478. + if (gintr_status.b.goutnakeff) {
  89479. + retval |= dwc_otg_pcd_handle_out_nak_effective(pcd);
  89480. + }
  89481. + if (gintr_status.b.i2cintr) {
  89482. + retval |= dwc_otg_pcd_handle_i2c_intr(pcd);
  89483. + }
  89484. + if (gintr_status.b.erlysuspend) {
  89485. + retval |= dwc_otg_pcd_handle_early_suspend_intr(pcd);
  89486. + }
  89487. + if (gintr_status.b.usbreset) {
  89488. + retval |= dwc_otg_pcd_handle_usb_reset_intr(pcd);
  89489. + }
  89490. + if (gintr_status.b.enumdone) {
  89491. + retval |= dwc_otg_pcd_handle_enum_done_intr(pcd);
  89492. + }
  89493. + if (gintr_status.b.isooutdrop) {
  89494. + retval |=
  89495. + dwc_otg_pcd_handle_isoc_out_packet_dropped_intr
  89496. + (pcd);
  89497. + }
  89498. + if (gintr_status.b.eopframe) {
  89499. + retval |=
  89500. + dwc_otg_pcd_handle_end_periodic_frame_intr(pcd);
  89501. + }
  89502. + if (gintr_status.b.inepint) {
  89503. + if (!core_if->multiproc_int_enable) {
  89504. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  89505. + }
  89506. + }
  89507. + if (gintr_status.b.outepintr) {
  89508. + if (!core_if->multiproc_int_enable) {
  89509. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  89510. + }
  89511. + }
  89512. + if (gintr_status.b.epmismatch) {
  89513. + retval |= dwc_otg_pcd_handle_ep_mismatch_intr(pcd);
  89514. + }
  89515. + if (gintr_status.b.fetsusp) {
  89516. + retval |= dwc_otg_pcd_handle_ep_fetsusp_intr(pcd);
  89517. + }
  89518. + if (gintr_status.b.ginnakeff) {
  89519. + retval |= dwc_otg_pcd_handle_in_nak_effective(pcd);
  89520. + }
  89521. + if (gintr_status.b.incomplisoin) {
  89522. + retval |=
  89523. + dwc_otg_pcd_handle_incomplete_isoc_in_intr(pcd);
  89524. + }
  89525. + if (gintr_status.b.incomplisoout) {
  89526. + retval |=
  89527. + dwc_otg_pcd_handle_incomplete_isoc_out_intr(pcd);
  89528. + }
  89529. +
  89530. + /* In MPI mode Device Endpoints interrupts are asserted
  89531. + * without setting outepintr and inepint bits set, so these
  89532. + * Interrupt handlers are called without checking these bit-fields
  89533. + */
  89534. + if (core_if->multiproc_int_enable) {
  89535. + retval |= dwc_otg_pcd_handle_in_ep_intr(pcd);
  89536. + retval |= dwc_otg_pcd_handle_out_ep_intr(pcd);
  89537. + }
  89538. +#ifdef VERBOSE
  89539. + DWC_DEBUGPL(DBG_PCDV, "%s() gintsts=%0x\n", __func__,
  89540. + DWC_READ_REG32(&global_regs->gintsts));
  89541. +#endif
  89542. + DWC_SPINUNLOCK(pcd->lock);
  89543. + }
  89544. + return retval;
  89545. +}
  89546. +
  89547. +#endif /* DWC_HOST_ONLY */
  89548. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c
  89549. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 1970-01-01 01:00:00.000000000 +0100
  89550. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_pcd_linux.c 2014-06-11 21:03:43.000000000 +0200
  89551. @@ -0,0 +1,1360 @@
  89552. + /* ==========================================================================
  89553. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_pcd_linux.c $
  89554. + * $Revision: #21 $
  89555. + * $Date: 2012/08/10 $
  89556. + * $Change: 2047372 $
  89557. + *
  89558. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  89559. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  89560. + * otherwise expressly agreed to in writing between Synopsys and you.
  89561. + *
  89562. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  89563. + * any End User Software License Agreement or Agreement for Licensed Product
  89564. + * with Synopsys or any supplement thereto. You are permitted to use and
  89565. + * redistribute this Software in source and binary forms, with or without
  89566. + * modification, provided that redistributions of source code must retain this
  89567. + * notice. You may not view, use, disclose, copy or distribute this file or
  89568. + * any information contained herein except pursuant to this license grant from
  89569. + * Synopsys. If you do not agree with this notice, including the disclaimer
  89570. + * below, then you are not authorized to use the Software.
  89571. + *
  89572. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  89573. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  89574. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  89575. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  89576. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89577. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  89578. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  89579. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  89580. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  89581. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  89582. + * DAMAGE.
  89583. + * ========================================================================== */
  89584. +#ifndef DWC_HOST_ONLY
  89585. +
  89586. +/** @file
  89587. + * This file implements the Peripheral Controller Driver.
  89588. + *
  89589. + * The Peripheral Controller Driver (PCD) is responsible for
  89590. + * translating requests from the Function Driver into the appropriate
  89591. + * actions on the DWC_otg controller. It isolates the Function Driver
  89592. + * from the specifics of the controller by providing an API to the
  89593. + * Function Driver.
  89594. + *
  89595. + * The Peripheral Controller Driver for Linux will implement the
  89596. + * Gadget API, so that the existing Gadget drivers can be used.
  89597. + * (Gadget Driver is the Linux terminology for a Function Driver.)
  89598. + *
  89599. + * The Linux Gadget API is defined in the header file
  89600. + * <code><linux/usb_gadget.h></code>. The USB EP operations API is
  89601. + * defined in the structure <code>usb_ep_ops</code> and the USB
  89602. + * Controller API is defined in the structure
  89603. + * <code>usb_gadget_ops</code>.
  89604. + *
  89605. + */
  89606. +
  89607. +#include "dwc_otg_os_dep.h"
  89608. +#include "dwc_otg_pcd_if.h"
  89609. +#include "dwc_otg_pcd.h"
  89610. +#include "dwc_otg_driver.h"
  89611. +#include "dwc_otg_dbg.h"
  89612. +
  89613. +extern bool fiq_enable;
  89614. +
  89615. +static struct gadget_wrapper {
  89616. + dwc_otg_pcd_t *pcd;
  89617. +
  89618. + struct usb_gadget gadget;
  89619. + struct usb_gadget_driver *driver;
  89620. +
  89621. + struct usb_ep ep0;
  89622. + struct usb_ep in_ep[16];
  89623. + struct usb_ep out_ep[16];
  89624. +
  89625. +} *gadget_wrapper;
  89626. +
  89627. +/* Display the contents of the buffer */
  89628. +extern void dump_msg(const u8 * buf, unsigned int length);
  89629. +/**
  89630. + * Get the dwc_otg_pcd_ep_t* from usb_ep* pointer - NULL in case
  89631. + * if the endpoint is not found
  89632. + */
  89633. +static struct dwc_otg_pcd_ep *ep_from_handle(dwc_otg_pcd_t * pcd, void *handle)
  89634. +{
  89635. + int i;
  89636. + if (pcd->ep0.priv == handle) {
  89637. + return &pcd->ep0;
  89638. + }
  89639. +
  89640. + for (i = 0; i < MAX_EPS_CHANNELS - 1; i++) {
  89641. + if (pcd->in_ep[i].priv == handle)
  89642. + return &pcd->in_ep[i];
  89643. + if (pcd->out_ep[i].priv == handle)
  89644. + return &pcd->out_ep[i];
  89645. + }
  89646. +
  89647. + return NULL;
  89648. +}
  89649. +
  89650. +/* USB Endpoint Operations */
  89651. +/*
  89652. + * The following sections briefly describe the behavior of the Gadget
  89653. + * API endpoint operations implemented in the DWC_otg driver
  89654. + * software. Detailed descriptions of the generic behavior of each of
  89655. + * these functions can be found in the Linux header file
  89656. + * include/linux/usb_gadget.h.
  89657. + *
  89658. + * The Gadget API provides wrapper functions for each of the function
  89659. + * pointers defined in usb_ep_ops. The Gadget Driver calls the wrapper
  89660. + * function, which then calls the underlying PCD function. The
  89661. + * following sections are named according to the wrapper
  89662. + * functions. Within each section, the corresponding DWC_otg PCD
  89663. + * function name is specified.
  89664. + *
  89665. + */
  89666. +
  89667. +/**
  89668. + * This function is called by the Gadget Driver for each EP to be
  89669. + * configured for the current configuration (SET_CONFIGURATION).
  89670. + *
  89671. + * This function initializes the dwc_otg_ep_t data structure, and then
  89672. + * calls dwc_otg_ep_activate.
  89673. + */
  89674. +static int ep_enable(struct usb_ep *usb_ep,
  89675. + const struct usb_endpoint_descriptor *ep_desc)
  89676. +{
  89677. + int retval;
  89678. +
  89679. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, ep_desc);
  89680. +
  89681. + if (!usb_ep || !ep_desc || ep_desc->bDescriptorType != USB_DT_ENDPOINT) {
  89682. + DWC_WARN("%s, bad ep or descriptor\n", __func__);
  89683. + return -EINVAL;
  89684. + }
  89685. + if (usb_ep == &gadget_wrapper->ep0) {
  89686. + DWC_WARN("%s, bad ep(0)\n", __func__);
  89687. + return -EINVAL;
  89688. + }
  89689. +
  89690. + /* Check FIFO size? */
  89691. + if (!ep_desc->wMaxPacketSize) {
  89692. + DWC_WARN("%s, bad %s maxpacket\n", __func__, usb_ep->name);
  89693. + return -ERANGE;
  89694. + }
  89695. +
  89696. + if (!gadget_wrapper->driver ||
  89697. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89698. + DWC_WARN("%s, bogus device state\n", __func__);
  89699. + return -ESHUTDOWN;
  89700. + }
  89701. +
  89702. + /* Delete after check - MAS */
  89703. +#if 0
  89704. + nat = (uint32_t) ep_desc->wMaxPacketSize;
  89705. + printk(KERN_ALERT "%s: nat (before) =%d\n", __func__, nat);
  89706. + nat = (nat >> 11) & 0x03;
  89707. + printk(KERN_ALERT "%s: nat (after) =%d\n", __func__, nat);
  89708. +#endif
  89709. + retval = dwc_otg_pcd_ep_enable(gadget_wrapper->pcd,
  89710. + (const uint8_t *)ep_desc,
  89711. + (void *)usb_ep);
  89712. + if (retval) {
  89713. + DWC_WARN("dwc_otg_pcd_ep_enable failed\n");
  89714. + return -EINVAL;
  89715. + }
  89716. +
  89717. + usb_ep->maxpacket = le16_to_cpu(ep_desc->wMaxPacketSize);
  89718. +
  89719. + return 0;
  89720. +}
  89721. +
  89722. +/**
  89723. + * This function is called when an EP is disabled due to disconnect or
  89724. + * change in configuration. Any pending requests will terminate with a
  89725. + * status of -ESHUTDOWN.
  89726. + *
  89727. + * This function modifies the dwc_otg_ep_t data structure for this EP,
  89728. + * and then calls dwc_otg_ep_deactivate.
  89729. + */
  89730. +static int ep_disable(struct usb_ep *usb_ep)
  89731. +{
  89732. + int retval;
  89733. +
  89734. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, usb_ep);
  89735. + if (!usb_ep) {
  89736. + DWC_DEBUGPL(DBG_PCD, "%s, %s not enabled\n", __func__,
  89737. + usb_ep ? usb_ep->name : NULL);
  89738. + return -EINVAL;
  89739. + }
  89740. +
  89741. + retval = dwc_otg_pcd_ep_disable(gadget_wrapper->pcd, usb_ep);
  89742. + if (retval) {
  89743. + retval = -EINVAL;
  89744. + }
  89745. +
  89746. + return retval;
  89747. +}
  89748. +
  89749. +/**
  89750. + * This function allocates a request object to use with the specified
  89751. + * endpoint.
  89752. + *
  89753. + * @param ep The endpoint to be used with with the request
  89754. + * @param gfp_flags the GFP_* flags to use.
  89755. + */
  89756. +static struct usb_request *dwc_otg_pcd_alloc_request(struct usb_ep *ep,
  89757. + gfp_t gfp_flags)
  89758. +{
  89759. + struct usb_request *usb_req;
  89760. +
  89761. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d)\n", __func__, ep, gfp_flags);
  89762. + if (0 == ep) {
  89763. + DWC_WARN("%s() %s\n", __func__, "Invalid EP!\n");
  89764. + return 0;
  89765. + }
  89766. + usb_req = kmalloc(sizeof(*usb_req), gfp_flags);
  89767. + if (0 == usb_req) {
  89768. + DWC_WARN("%s() %s\n", __func__, "request allocation failed!\n");
  89769. + return 0;
  89770. + }
  89771. + memset(usb_req, 0, sizeof(*usb_req));
  89772. + usb_req->dma = DWC_DMA_ADDR_INVALID;
  89773. +
  89774. + return usb_req;
  89775. +}
  89776. +
  89777. +/**
  89778. + * This function frees a request object.
  89779. + *
  89780. + * @param ep The endpoint associated with the request
  89781. + * @param req The request being freed
  89782. + */
  89783. +static void dwc_otg_pcd_free_request(struct usb_ep *ep, struct usb_request *req)
  89784. +{
  89785. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, ep, req);
  89786. +
  89787. + if (0 == ep || 0 == req) {
  89788. + DWC_WARN("%s() %s\n", __func__,
  89789. + "Invalid ep or req argument!\n");
  89790. + return;
  89791. + }
  89792. +
  89793. + kfree(req);
  89794. +}
  89795. +
  89796. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89797. +/**
  89798. + * This function allocates an I/O buffer to be used for a transfer
  89799. + * to/from the specified endpoint.
  89800. + *
  89801. + * @param usb_ep The endpoint to be used with with the request
  89802. + * @param bytes The desired number of bytes for the buffer
  89803. + * @param dma Pointer to the buffer's DMA address; must be valid
  89804. + * @param gfp_flags the GFP_* flags to use.
  89805. + * @return address of a new buffer or null is buffer could not be allocated.
  89806. + */
  89807. +static void *dwc_otg_pcd_alloc_buffer(struct usb_ep *usb_ep, unsigned bytes,
  89808. + dma_addr_t * dma, gfp_t gfp_flags)
  89809. +{
  89810. + void *buf;
  89811. + dwc_otg_pcd_t *pcd = 0;
  89812. +
  89813. + pcd = gadget_wrapper->pcd;
  89814. +
  89815. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%d,%p,%0x)\n", __func__, usb_ep, bytes,
  89816. + dma, gfp_flags);
  89817. +
  89818. + /* Check dword alignment */
  89819. + if ((bytes & 0x3UL) != 0) {
  89820. + DWC_WARN("%s() Buffer size is not a multiple of"
  89821. + "DWORD size (%d)", __func__, bytes);
  89822. + }
  89823. +
  89824. + buf = dma_alloc_coherent(NULL, bytes, dma, gfp_flags);
  89825. +
  89826. + /* Check dword alignment */
  89827. + if (((int)buf & 0x3UL) != 0) {
  89828. + DWC_WARN("%s() Buffer is not DWORD aligned (%p)",
  89829. + __func__, buf);
  89830. + }
  89831. +
  89832. + return buf;
  89833. +}
  89834. +
  89835. +/**
  89836. + * This function frees an I/O buffer that was allocated by alloc_buffer.
  89837. + *
  89838. + * @param usb_ep the endpoint associated with the buffer
  89839. + * @param buf address of the buffer
  89840. + * @param dma The buffer's DMA address
  89841. + * @param bytes The number of bytes of the buffer
  89842. + */
  89843. +static void dwc_otg_pcd_free_buffer(struct usb_ep *usb_ep, void *buf,
  89844. + dma_addr_t dma, unsigned bytes)
  89845. +{
  89846. + dwc_otg_pcd_t *pcd = 0;
  89847. +
  89848. + pcd = gadget_wrapper->pcd;
  89849. +
  89850. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%0x,%d)\n", __func__, buf, dma, bytes);
  89851. +
  89852. + dma_free_coherent(NULL, bytes, buf, dma);
  89853. +}
  89854. +#endif
  89855. +
  89856. +/**
  89857. + * This function is used to submit an I/O Request to an EP.
  89858. + *
  89859. + * - When the request completes the request's completion callback
  89860. + * is called to return the request to the driver.
  89861. + * - An EP, except control EPs, may have multiple requests
  89862. + * pending.
  89863. + * - Once submitted the request cannot be examined or modified.
  89864. + * - Each request is turned into one or more packets.
  89865. + * - A BULK EP can queue any amount of data; the transfer is
  89866. + * packetized.
  89867. + * - Zero length Packets are specified with the request 'zero'
  89868. + * flag.
  89869. + */
  89870. +static int ep_queue(struct usb_ep *usb_ep, struct usb_request *usb_req,
  89871. + gfp_t gfp_flags)
  89872. +{
  89873. + dwc_otg_pcd_t *pcd;
  89874. + struct dwc_otg_pcd_ep *ep = NULL;
  89875. + int retval = 0, is_isoc_ep = 0;
  89876. + dma_addr_t dma_addr = DWC_DMA_ADDR_INVALID;
  89877. +
  89878. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p,%d)\n",
  89879. + __func__, usb_ep, usb_req, gfp_flags);
  89880. +
  89881. + if (!usb_req || !usb_req->complete || !usb_req->buf) {
  89882. + DWC_WARN("bad params\n");
  89883. + return -EINVAL;
  89884. + }
  89885. +
  89886. + if (!usb_ep) {
  89887. + DWC_WARN("bad ep\n");
  89888. + return -EINVAL;
  89889. + }
  89890. +
  89891. + pcd = gadget_wrapper->pcd;
  89892. + if (!gadget_wrapper->driver ||
  89893. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89894. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  89895. + gadget_wrapper->gadget.speed);
  89896. + DWC_WARN("bogus device state\n");
  89897. + return -ESHUTDOWN;
  89898. + }
  89899. +
  89900. + DWC_DEBUGPL(DBG_PCD, "%s queue req %p, len %d buf %p\n",
  89901. + usb_ep->name, usb_req, usb_req->length, usb_req->buf);
  89902. +
  89903. + usb_req->status = -EINPROGRESS;
  89904. + usb_req->actual = 0;
  89905. +
  89906. + ep = ep_from_handle(pcd, usb_ep);
  89907. + if (ep == NULL)
  89908. + is_isoc_ep = 0;
  89909. + else
  89910. + is_isoc_ep = (ep->dwc_ep.type == DWC_OTG_EP_TYPE_ISOC) ? 1 : 0;
  89911. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  89912. + dma_addr = usb_req->dma;
  89913. +#else
  89914. + if (GET_CORE_IF(pcd)->dma_enable) {
  89915. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  89916. + struct device *dev = NULL;
  89917. +
  89918. + if (otg_dev != NULL)
  89919. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  89920. +
  89921. + if (usb_req->length != 0 &&
  89922. + usb_req->dma == DWC_DMA_ADDR_INVALID) {
  89923. + dma_addr = dma_map_single(dev, usb_req->buf,
  89924. + usb_req->length,
  89925. + ep->dwc_ep.is_in ?
  89926. + DMA_TO_DEVICE:
  89927. + DMA_FROM_DEVICE);
  89928. + }
  89929. + }
  89930. +#endif
  89931. +
  89932. +#ifdef DWC_UTE_PER_IO
  89933. + if (is_isoc_ep == 1) {
  89934. + retval = dwc_otg_pcd_xiso_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  89935. + usb_req->length, usb_req->zero, usb_req,
  89936. + gfp_flags == GFP_ATOMIC ? 1 : 0, &usb_req->ext_req);
  89937. + if (retval)
  89938. + return -EINVAL;
  89939. +
  89940. + return 0;
  89941. + }
  89942. +#endif
  89943. + retval = dwc_otg_pcd_ep_queue(pcd, usb_ep, usb_req->buf, dma_addr,
  89944. + usb_req->length, usb_req->zero, usb_req,
  89945. + gfp_flags == GFP_ATOMIC ? 1 : 0);
  89946. + if (retval) {
  89947. + return -EINVAL;
  89948. + }
  89949. +
  89950. + return 0;
  89951. +}
  89952. +
  89953. +/**
  89954. + * This function cancels an I/O request from an EP.
  89955. + */
  89956. +static int ep_dequeue(struct usb_ep *usb_ep, struct usb_request *usb_req)
  89957. +{
  89958. + DWC_DEBUGPL(DBG_PCDV, "%s(%p,%p)\n", __func__, usb_ep, usb_req);
  89959. +
  89960. + if (!usb_ep || !usb_req) {
  89961. + DWC_WARN("bad argument\n");
  89962. + return -EINVAL;
  89963. + }
  89964. + if (!gadget_wrapper->driver ||
  89965. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  89966. + DWC_WARN("bogus device state\n");
  89967. + return -ESHUTDOWN;
  89968. + }
  89969. + if (dwc_otg_pcd_ep_dequeue(gadget_wrapper->pcd, usb_ep, usb_req)) {
  89970. + return -EINVAL;
  89971. + }
  89972. +
  89973. + return 0;
  89974. +}
  89975. +
  89976. +/**
  89977. + * usb_ep_set_halt stalls an endpoint.
  89978. + *
  89979. + * usb_ep_clear_halt clears an endpoint halt and resets its data
  89980. + * toggle.
  89981. + *
  89982. + * Both of these functions are implemented with the same underlying
  89983. + * function. The behavior depends on the value argument.
  89984. + *
  89985. + * @param[in] usb_ep the Endpoint to halt or clear halt.
  89986. + * @param[in] value
  89987. + * - 0 means clear_halt.
  89988. + * - 1 means set_halt,
  89989. + * - 2 means clear stall lock flag.
  89990. + * - 3 means set stall lock flag.
  89991. + */
  89992. +static int ep_halt(struct usb_ep *usb_ep, int value)
  89993. +{
  89994. + int retval = 0;
  89995. +
  89996. + DWC_DEBUGPL(DBG_PCD, "HALT %s %d\n", usb_ep->name, value);
  89997. +
  89998. + if (!usb_ep) {
  89999. + DWC_WARN("bad ep\n");
  90000. + return -EINVAL;
  90001. + }
  90002. +
  90003. + retval = dwc_otg_pcd_ep_halt(gadget_wrapper->pcd, usb_ep, value);
  90004. + if (retval == -DWC_E_AGAIN) {
  90005. + return -EAGAIN;
  90006. + } else if (retval) {
  90007. + retval = -EINVAL;
  90008. + }
  90009. +
  90010. + return retval;
  90011. +}
  90012. +
  90013. +//#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30))
  90014. +#if 0
  90015. +/**
  90016. + * ep_wedge: sets the halt feature and ignores clear requests
  90017. + *
  90018. + * @usb_ep: the endpoint being wedged
  90019. + *
  90020. + * Use this to stall an endpoint and ignore CLEAR_FEATURE(HALT_ENDPOINT)
  90021. + * requests. If the gadget driver clears the halt status, it will
  90022. + * automatically unwedge the endpoint.
  90023. + *
  90024. + * Returns zero on success, else negative errno. *
  90025. + * Check usb_ep_set_wedge() at "usb_gadget.h" for details
  90026. + */
  90027. +static int ep_wedge(struct usb_ep *usb_ep)
  90028. +{
  90029. + int retval = 0;
  90030. +
  90031. + DWC_DEBUGPL(DBG_PCD, "WEDGE %s\n", usb_ep->name);
  90032. +
  90033. + if (!usb_ep) {
  90034. + DWC_WARN("bad ep\n");
  90035. + return -EINVAL;
  90036. + }
  90037. +
  90038. + retval = dwc_otg_pcd_ep_wedge(gadget_wrapper->pcd, usb_ep);
  90039. + if (retval == -DWC_E_AGAIN) {
  90040. + retval = -EAGAIN;
  90041. + } else if (retval) {
  90042. + retval = -EINVAL;
  90043. + }
  90044. +
  90045. + return retval;
  90046. +}
  90047. +#endif
  90048. +
  90049. +#ifdef DWC_EN_ISOC
  90050. +/**
  90051. + * This function is used to submit an ISOC Transfer Request to an EP.
  90052. + *
  90053. + * - Every time a sync period completes the request's completion callback
  90054. + * is called to provide data to the gadget driver.
  90055. + * - Once submitted the request cannot be modified.
  90056. + * - Each request is turned into periodic data packets untill ISO
  90057. + * Transfer is stopped..
  90058. + */
  90059. +static int iso_ep_start(struct usb_ep *usb_ep, struct usb_iso_request *req,
  90060. + gfp_t gfp_flags)
  90061. +{
  90062. + int retval = 0;
  90063. +
  90064. + if (!req || !req->process_buffer || !req->buf0 || !req->buf1) {
  90065. + DWC_WARN("bad params\n");
  90066. + return -EINVAL;
  90067. + }
  90068. +
  90069. + if (!usb_ep) {
  90070. + DWC_PRINTF("bad params\n");
  90071. + return -EINVAL;
  90072. + }
  90073. +
  90074. + req->status = -EINPROGRESS;
  90075. +
  90076. + retval =
  90077. + dwc_otg_pcd_iso_ep_start(gadget_wrapper->pcd, usb_ep, req->buf0,
  90078. + req->buf1, req->dma0, req->dma1,
  90079. + req->sync_frame, req->data_pattern_frame,
  90080. + req->data_per_frame,
  90081. + req->
  90082. + flags & USB_REQ_ISO_ASAP ? -1 :
  90083. + req->start_frame, req->buf_proc_intrvl,
  90084. + req, gfp_flags == GFP_ATOMIC ? 1 : 0);
  90085. +
  90086. + if (retval) {
  90087. + return -EINVAL;
  90088. + }
  90089. +
  90090. + return retval;
  90091. +}
  90092. +
  90093. +/**
  90094. + * This function stops ISO EP Periodic Data Transfer.
  90095. + */
  90096. +static int iso_ep_stop(struct usb_ep *usb_ep, struct usb_iso_request *req)
  90097. +{
  90098. + int retval = 0;
  90099. + if (!usb_ep) {
  90100. + DWC_WARN("bad ep\n");
  90101. + }
  90102. +
  90103. + if (!gadget_wrapper->driver ||
  90104. + gadget_wrapper->gadget.speed == USB_SPEED_UNKNOWN) {
  90105. + DWC_DEBUGPL(DBG_PCDV, "gadget.speed=%d\n",
  90106. + gadget_wrapper->gadget.speed);
  90107. + DWC_WARN("bogus device state\n");
  90108. + }
  90109. +
  90110. + dwc_otg_pcd_iso_ep_stop(gadget_wrapper->pcd, usb_ep, req);
  90111. + if (retval) {
  90112. + retval = -EINVAL;
  90113. + }
  90114. +
  90115. + return retval;
  90116. +}
  90117. +
  90118. +static struct usb_iso_request *alloc_iso_request(struct usb_ep *ep,
  90119. + int packets, gfp_t gfp_flags)
  90120. +{
  90121. + struct usb_iso_request *pReq = NULL;
  90122. + uint32_t req_size;
  90123. +
  90124. + req_size = sizeof(struct usb_iso_request);
  90125. + req_size +=
  90126. + (2 * packets * (sizeof(struct usb_gadget_iso_packet_descriptor)));
  90127. +
  90128. + pReq = kmalloc(req_size, gfp_flags);
  90129. + if (!pReq) {
  90130. + DWC_WARN("Can't allocate Iso Request\n");
  90131. + return 0;
  90132. + }
  90133. + pReq->iso_packet_desc0 = (void *)(pReq + 1);
  90134. +
  90135. + pReq->iso_packet_desc1 = pReq->iso_packet_desc0 + packets;
  90136. +
  90137. + return pReq;
  90138. +}
  90139. +
  90140. +static void free_iso_request(struct usb_ep *ep, struct usb_iso_request *req)
  90141. +{
  90142. + kfree(req);
  90143. +}
  90144. +
  90145. +static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops = {
  90146. + .ep_ops = {
  90147. + .enable = ep_enable,
  90148. + .disable = ep_disable,
  90149. +
  90150. + .alloc_request = dwc_otg_pcd_alloc_request,
  90151. + .free_request = dwc_otg_pcd_free_request,
  90152. +
  90153. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90154. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  90155. + .free_buffer = dwc_otg_pcd_free_buffer,
  90156. +#endif
  90157. +
  90158. + .queue = ep_queue,
  90159. + .dequeue = ep_dequeue,
  90160. +
  90161. + .set_halt = ep_halt,
  90162. + .fifo_status = 0,
  90163. + .fifo_flush = 0,
  90164. + },
  90165. + .iso_ep_start = iso_ep_start,
  90166. + .iso_ep_stop = iso_ep_stop,
  90167. + .alloc_iso_request = alloc_iso_request,
  90168. + .free_iso_request = free_iso_request,
  90169. +};
  90170. +
  90171. +#else
  90172. +
  90173. + int (*enable) (struct usb_ep *ep,
  90174. + const struct usb_endpoint_descriptor *desc);
  90175. + int (*disable) (struct usb_ep *ep);
  90176. +
  90177. + struct usb_request *(*alloc_request) (struct usb_ep *ep,
  90178. + gfp_t gfp_flags);
  90179. + void (*free_request) (struct usb_ep *ep, struct usb_request *req);
  90180. +
  90181. + int (*queue) (struct usb_ep *ep, struct usb_request *req,
  90182. + gfp_t gfp_flags);
  90183. + int (*dequeue) (struct usb_ep *ep, struct usb_request *req);
  90184. +
  90185. + int (*set_halt) (struct usb_ep *ep, int value);
  90186. + int (*set_wedge) (struct usb_ep *ep);
  90187. +
  90188. + int (*fifo_status) (struct usb_ep *ep);
  90189. + void (*fifo_flush) (struct usb_ep *ep);
  90190. +static struct usb_ep_ops dwc_otg_pcd_ep_ops = {
  90191. + .enable = ep_enable,
  90192. + .disable = ep_disable,
  90193. +
  90194. + .alloc_request = dwc_otg_pcd_alloc_request,
  90195. + .free_request = dwc_otg_pcd_free_request,
  90196. +
  90197. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
  90198. + .alloc_buffer = dwc_otg_pcd_alloc_buffer,
  90199. + .free_buffer = dwc_otg_pcd_free_buffer,
  90200. +#else
  90201. + /* .set_wedge = ep_wedge, */
  90202. + .set_wedge = NULL, /* uses set_halt instead */
  90203. +#endif
  90204. +
  90205. + .queue = ep_queue,
  90206. + .dequeue = ep_dequeue,
  90207. +
  90208. + .set_halt = ep_halt,
  90209. + .fifo_status = 0,
  90210. + .fifo_flush = 0,
  90211. +
  90212. +};
  90213. +
  90214. +#endif /* _EN_ISOC_ */
  90215. +/* Gadget Operations */
  90216. +/**
  90217. + * The following gadget operations will be implemented in the DWC_otg
  90218. + * PCD. Functions in the API that are not described below are not
  90219. + * implemented.
  90220. + *
  90221. + * The Gadget API provides wrapper functions for each of the function
  90222. + * pointers defined in usb_gadget_ops. The Gadget Driver calls the
  90223. + * wrapper function, which then calls the underlying PCD function. The
  90224. + * following sections are named according to the wrapper functions
  90225. + * (except for ioctl, which doesn't have a wrapper function). Within
  90226. + * each section, the corresponding DWC_otg PCD function name is
  90227. + * specified.
  90228. + *
  90229. + */
  90230. +
  90231. +/**
  90232. + *Gets the USB Frame number of the last SOF.
  90233. + */
  90234. +static int get_frame_number(struct usb_gadget *gadget)
  90235. +{
  90236. + struct gadget_wrapper *d;
  90237. +
  90238. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  90239. +
  90240. + if (gadget == 0) {
  90241. + return -ENODEV;
  90242. + }
  90243. +
  90244. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90245. + return dwc_otg_pcd_get_frame_number(d->pcd);
  90246. +}
  90247. +
  90248. +#ifdef CONFIG_USB_DWC_OTG_LPM
  90249. +static int test_lpm_enabled(struct usb_gadget *gadget)
  90250. +{
  90251. + struct gadget_wrapper *d;
  90252. +
  90253. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90254. +
  90255. + return dwc_otg_pcd_is_lpm_enabled(d->pcd);
  90256. +}
  90257. +#endif
  90258. +
  90259. +/**
  90260. + * Initiates Session Request Protocol (SRP) to wakeup the host if no
  90261. + * session is in progress. If a session is already in progress, but
  90262. + * the device is suspended, remote wakeup signaling is started.
  90263. + *
  90264. + */
  90265. +static int wakeup(struct usb_gadget *gadget)
  90266. +{
  90267. + struct gadget_wrapper *d;
  90268. +
  90269. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, gadget);
  90270. +
  90271. + if (gadget == 0) {
  90272. + return -ENODEV;
  90273. + } else {
  90274. + d = container_of(gadget, struct gadget_wrapper, gadget);
  90275. + }
  90276. + dwc_otg_pcd_wakeup(d->pcd);
  90277. + return 0;
  90278. +}
  90279. +
  90280. +static const struct usb_gadget_ops dwc_otg_pcd_ops = {
  90281. + .get_frame = get_frame_number,
  90282. + .wakeup = wakeup,
  90283. +#ifdef CONFIG_USB_DWC_OTG_LPM
  90284. + .lpm_support = test_lpm_enabled,
  90285. +#endif
  90286. + // current versions must always be self-powered
  90287. +};
  90288. +
  90289. +static int _setup(dwc_otg_pcd_t * pcd, uint8_t * bytes)
  90290. +{
  90291. + int retval = -DWC_E_NOT_SUPPORTED;
  90292. + if (gadget_wrapper->driver && gadget_wrapper->driver->setup) {
  90293. + retval = gadget_wrapper->driver->setup(&gadget_wrapper->gadget,
  90294. + (struct usb_ctrlrequest
  90295. + *)bytes);
  90296. + }
  90297. +
  90298. + if (retval == -ENOTSUPP) {
  90299. + retval = -DWC_E_NOT_SUPPORTED;
  90300. + } else if (retval < 0) {
  90301. + retval = -DWC_E_INVALID;
  90302. + }
  90303. +
  90304. + return retval;
  90305. +}
  90306. +
  90307. +#ifdef DWC_EN_ISOC
  90308. +static int _isoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90309. + void *req_handle, int proc_buf_num)
  90310. +{
  90311. + int i, packet_count;
  90312. + struct usb_gadget_iso_packet_descriptor *iso_packet = 0;
  90313. + struct usb_iso_request *iso_req = req_handle;
  90314. +
  90315. + if (proc_buf_num) {
  90316. + iso_packet = iso_req->iso_packet_desc1;
  90317. + } else {
  90318. + iso_packet = iso_req->iso_packet_desc0;
  90319. + }
  90320. + packet_count =
  90321. + dwc_otg_pcd_get_iso_packet_count(pcd, ep_handle, req_handle);
  90322. + for (i = 0; i < packet_count; ++i) {
  90323. + int status;
  90324. + int actual;
  90325. + int offset;
  90326. + dwc_otg_pcd_get_iso_packet_params(pcd, ep_handle, req_handle,
  90327. + i, &status, &actual, &offset);
  90328. + switch (status) {
  90329. + case -DWC_E_NO_DATA:
  90330. + status = -ENODATA;
  90331. + break;
  90332. + default:
  90333. + if (status) {
  90334. + DWC_PRINTF("unknown status in isoc packet\n");
  90335. + }
  90336. +
  90337. + }
  90338. + iso_packet[i].status = status;
  90339. + iso_packet[i].offset = offset;
  90340. + iso_packet[i].actual_length = actual;
  90341. + }
  90342. +
  90343. + iso_req->status = 0;
  90344. + iso_req->process_buffer(ep_handle, iso_req);
  90345. +
  90346. + return 0;
  90347. +}
  90348. +#endif /* DWC_EN_ISOC */
  90349. +
  90350. +#ifdef DWC_UTE_PER_IO
  90351. +/**
  90352. + * Copy the contents of the extended request to the Linux usb_request's
  90353. + * extended part and call the gadget's completion.
  90354. + *
  90355. + * @param pcd Pointer to the pcd structure
  90356. + * @param ep_handle Void pointer to the usb_ep structure
  90357. + * @param req_handle Void pointer to the usb_request structure
  90358. + * @param status Request status returned from the portable logic
  90359. + * @param ereq_port Void pointer to the extended request structure
  90360. + * created in the the portable part that contains the
  90361. + * results of the processed iso packets.
  90362. + */
  90363. +static int _xisoc_complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90364. + void *req_handle, int32_t status, void *ereq_port)
  90365. +{
  90366. + struct dwc_ute_iso_req_ext *ereqorg = NULL;
  90367. + struct dwc_iso_xreq_port *ereqport = NULL;
  90368. + struct dwc_ute_iso_packet_descriptor *desc_org = NULL;
  90369. + int i;
  90370. + struct usb_request *req;
  90371. + //struct dwc_ute_iso_packet_descriptor *
  90372. + //int status = 0;
  90373. +
  90374. + req = (struct usb_request *)req_handle;
  90375. + ereqorg = &req->ext_req;
  90376. + ereqport = (struct dwc_iso_xreq_port *)ereq_port;
  90377. + desc_org = ereqorg->per_io_frame_descs;
  90378. +
  90379. + if (req && req->complete) {
  90380. + /* Copy the request data from the portable logic to our request */
  90381. + for (i = 0; i < ereqport->pio_pkt_count; i++) {
  90382. + desc_org[i].actual_length =
  90383. + ereqport->per_io_frame_descs[i].actual_length;
  90384. + desc_org[i].status =
  90385. + ereqport->per_io_frame_descs[i].status;
  90386. + }
  90387. +
  90388. + switch (status) {
  90389. + case -DWC_E_SHUTDOWN:
  90390. + req->status = -ESHUTDOWN;
  90391. + break;
  90392. + case -DWC_E_RESTART:
  90393. + req->status = -ECONNRESET;
  90394. + break;
  90395. + case -DWC_E_INVALID:
  90396. + req->status = -EINVAL;
  90397. + break;
  90398. + case -DWC_E_TIMEOUT:
  90399. + req->status = -ETIMEDOUT;
  90400. + break;
  90401. + default:
  90402. + req->status = status;
  90403. + }
  90404. +
  90405. + /* And call the gadget's completion */
  90406. + req->complete(ep_handle, req);
  90407. + }
  90408. +
  90409. + return 0;
  90410. +}
  90411. +#endif /* DWC_UTE_PER_IO */
  90412. +
  90413. +static int _complete(dwc_otg_pcd_t * pcd, void *ep_handle,
  90414. + void *req_handle, int32_t status, uint32_t actual)
  90415. +{
  90416. + struct usb_request *req = (struct usb_request *)req_handle;
  90417. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  90418. + struct dwc_otg_pcd_ep *ep = NULL;
  90419. +#endif
  90420. +
  90421. + if (req && req->complete) {
  90422. + switch (status) {
  90423. + case -DWC_E_SHUTDOWN:
  90424. + req->status = -ESHUTDOWN;
  90425. + break;
  90426. + case -DWC_E_RESTART:
  90427. + req->status = -ECONNRESET;
  90428. + break;
  90429. + case -DWC_E_INVALID:
  90430. + req->status = -EINVAL;
  90431. + break;
  90432. + case -DWC_E_TIMEOUT:
  90433. + req->status = -ETIMEDOUT;
  90434. + break;
  90435. + default:
  90436. + req->status = status;
  90437. +
  90438. + }
  90439. +
  90440. + req->actual = actual;
  90441. + DWC_SPINUNLOCK(pcd->lock);
  90442. + req->complete(ep_handle, req);
  90443. + DWC_SPINLOCK(pcd->lock);
  90444. + }
  90445. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27)
  90446. + ep = ep_from_handle(pcd, ep_handle);
  90447. + if (GET_CORE_IF(pcd)->dma_enable) {
  90448. + if (req->length != 0) {
  90449. + dwc_otg_device_t *otg_dev = gadget_wrapper->pcd->otg_dev;
  90450. + struct device *dev = NULL;
  90451. +
  90452. + if (otg_dev != NULL)
  90453. + dev = DWC_OTG_OS_GETDEV(otg_dev->os_dep);
  90454. +
  90455. + dma_unmap_single(dev, req->dma, req->length,
  90456. + ep->dwc_ep.is_in ?
  90457. + DMA_TO_DEVICE: DMA_FROM_DEVICE);
  90458. + }
  90459. + }
  90460. +#endif
  90461. +
  90462. + return 0;
  90463. +}
  90464. +
  90465. +static int _connect(dwc_otg_pcd_t * pcd, int speed)
  90466. +{
  90467. + gadget_wrapper->gadget.speed = speed;
  90468. + return 0;
  90469. +}
  90470. +
  90471. +static int _disconnect(dwc_otg_pcd_t * pcd)
  90472. +{
  90473. + if (gadget_wrapper->driver && gadget_wrapper->driver->disconnect) {
  90474. + gadget_wrapper->driver->disconnect(&gadget_wrapper->gadget);
  90475. + }
  90476. + return 0;
  90477. +}
  90478. +
  90479. +static int _resume(dwc_otg_pcd_t * pcd)
  90480. +{
  90481. + if (gadget_wrapper->driver && gadget_wrapper->driver->resume) {
  90482. + gadget_wrapper->driver->resume(&gadget_wrapper->gadget);
  90483. + }
  90484. +
  90485. + return 0;
  90486. +}
  90487. +
  90488. +static int _suspend(dwc_otg_pcd_t * pcd)
  90489. +{
  90490. + if (gadget_wrapper->driver && gadget_wrapper->driver->suspend) {
  90491. + gadget_wrapper->driver->suspend(&gadget_wrapper->gadget);
  90492. + }
  90493. + return 0;
  90494. +}
  90495. +
  90496. +/**
  90497. + * This function updates the otg values in the gadget structure.
  90498. + */
  90499. +static int _hnp_changed(dwc_otg_pcd_t * pcd)
  90500. +{
  90501. +
  90502. + if (!gadget_wrapper->gadget.is_otg)
  90503. + return 0;
  90504. +
  90505. + gadget_wrapper->gadget.b_hnp_enable = get_b_hnp_enable(pcd);
  90506. + gadget_wrapper->gadget.a_hnp_support = get_a_hnp_support(pcd);
  90507. + gadget_wrapper->gadget.a_alt_hnp_support = get_a_alt_hnp_support(pcd);
  90508. + return 0;
  90509. +}
  90510. +
  90511. +static int _reset(dwc_otg_pcd_t * pcd)
  90512. +{
  90513. + return 0;
  90514. +}
  90515. +
  90516. +#ifdef DWC_UTE_CFI
  90517. +static int _cfi_setup(dwc_otg_pcd_t * pcd, void *cfi_req)
  90518. +{
  90519. + int retval = -DWC_E_INVALID;
  90520. + if (gadget_wrapper->driver->cfi_feature_setup) {
  90521. + retval =
  90522. + gadget_wrapper->driver->
  90523. + cfi_feature_setup(&gadget_wrapper->gadget,
  90524. + (struct cfi_usb_ctrlrequest *)cfi_req);
  90525. + }
  90526. +
  90527. + return retval;
  90528. +}
  90529. +#endif
  90530. +
  90531. +static const struct dwc_otg_pcd_function_ops fops = {
  90532. + .complete = _complete,
  90533. +#ifdef DWC_EN_ISOC
  90534. + .isoc_complete = _isoc_complete,
  90535. +#endif
  90536. + .setup = _setup,
  90537. + .disconnect = _disconnect,
  90538. + .connect = _connect,
  90539. + .resume = _resume,
  90540. + .suspend = _suspend,
  90541. + .hnp_changed = _hnp_changed,
  90542. + .reset = _reset,
  90543. +#ifdef DWC_UTE_CFI
  90544. + .cfi_setup = _cfi_setup,
  90545. +#endif
  90546. +#ifdef DWC_UTE_PER_IO
  90547. + .xisoc_complete = _xisoc_complete,
  90548. +#endif
  90549. +};
  90550. +
  90551. +/**
  90552. + * This function is the top level PCD interrupt handler.
  90553. + */
  90554. +static irqreturn_t dwc_otg_pcd_irq(int irq, void *dev)
  90555. +{
  90556. + dwc_otg_pcd_t *pcd = dev;
  90557. + int32_t retval = IRQ_NONE;
  90558. +
  90559. + retval = dwc_otg_pcd_handle_intr(pcd);
  90560. + if (retval != 0) {
  90561. + S3C2410X_CLEAR_EINTPEND();
  90562. + }
  90563. + return IRQ_RETVAL(retval);
  90564. +}
  90565. +
  90566. +/**
  90567. + * This function initialized the usb_ep structures to there default
  90568. + * state.
  90569. + *
  90570. + * @param d Pointer on gadget_wrapper.
  90571. + */
  90572. +void gadget_add_eps(struct gadget_wrapper *d)
  90573. +{
  90574. + static const char *names[] = {
  90575. +
  90576. + "ep0",
  90577. + "ep1in",
  90578. + "ep2in",
  90579. + "ep3in",
  90580. + "ep4in",
  90581. + "ep5in",
  90582. + "ep6in",
  90583. + "ep7in",
  90584. + "ep8in",
  90585. + "ep9in",
  90586. + "ep10in",
  90587. + "ep11in",
  90588. + "ep12in",
  90589. + "ep13in",
  90590. + "ep14in",
  90591. + "ep15in",
  90592. + "ep1out",
  90593. + "ep2out",
  90594. + "ep3out",
  90595. + "ep4out",
  90596. + "ep5out",
  90597. + "ep6out",
  90598. + "ep7out",
  90599. + "ep8out",
  90600. + "ep9out",
  90601. + "ep10out",
  90602. + "ep11out",
  90603. + "ep12out",
  90604. + "ep13out",
  90605. + "ep14out",
  90606. + "ep15out"
  90607. + };
  90608. +
  90609. + int i;
  90610. + struct usb_ep *ep;
  90611. + int8_t dev_endpoints;
  90612. +
  90613. + DWC_DEBUGPL(DBG_PCDV, "%s\n", __func__);
  90614. +
  90615. + INIT_LIST_HEAD(&d->gadget.ep_list);
  90616. + d->gadget.ep0 = &d->ep0;
  90617. + d->gadget.speed = USB_SPEED_UNKNOWN;
  90618. +
  90619. + INIT_LIST_HEAD(&d->gadget.ep0->ep_list);
  90620. +
  90621. + /**
  90622. + * Initialize the EP0 structure.
  90623. + */
  90624. + ep = &d->ep0;
  90625. +
  90626. + /* Init the usb_ep structure. */
  90627. + ep->name = names[0];
  90628. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90629. +
  90630. + /**
  90631. + * @todo NGS: What should the max packet size be set to
  90632. + * here? Before EP type is set?
  90633. + */
  90634. + ep->maxpacket = MAX_PACKET_SIZE;
  90635. + dwc_otg_pcd_ep_enable(d->pcd, NULL, ep);
  90636. +
  90637. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90638. +
  90639. + /**
  90640. + * Initialize the EP structures.
  90641. + */
  90642. + dev_endpoints = d->pcd->core_if->dev_if->num_in_eps;
  90643. +
  90644. + for (i = 0; i < dev_endpoints; i++) {
  90645. + ep = &d->in_ep[i];
  90646. +
  90647. + /* Init the usb_ep structure. */
  90648. + ep->name = names[d->pcd->in_ep[i].dwc_ep.num];
  90649. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90650. +
  90651. + /**
  90652. + * @todo NGS: What should the max packet size be set to
  90653. + * here? Before EP type is set?
  90654. + */
  90655. + ep->maxpacket = MAX_PACKET_SIZE;
  90656. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90657. + }
  90658. +
  90659. + dev_endpoints = d->pcd->core_if->dev_if->num_out_eps;
  90660. +
  90661. + for (i = 0; i < dev_endpoints; i++) {
  90662. + ep = &d->out_ep[i];
  90663. +
  90664. + /* Init the usb_ep structure. */
  90665. + ep->name = names[15 + d->pcd->out_ep[i].dwc_ep.num];
  90666. + ep->ops = (struct usb_ep_ops *)&dwc_otg_pcd_ep_ops;
  90667. +
  90668. + /**
  90669. + * @todo NGS: What should the max packet size be set to
  90670. + * here? Before EP type is set?
  90671. + */
  90672. + ep->maxpacket = MAX_PACKET_SIZE;
  90673. +
  90674. + list_add_tail(&ep->ep_list, &d->gadget.ep_list);
  90675. + }
  90676. +
  90677. + /* remove ep0 from the list. There is a ep0 pointer. */
  90678. + list_del_init(&d->ep0.ep_list);
  90679. +
  90680. + d->ep0.maxpacket = MAX_EP0_SIZE;
  90681. +}
  90682. +
  90683. +/**
  90684. + * This function releases the Gadget device.
  90685. + * required by device_unregister().
  90686. + *
  90687. + * @todo Should this do something? Should it free the PCD?
  90688. + */
  90689. +static void dwc_otg_pcd_gadget_release(struct device *dev)
  90690. +{
  90691. + DWC_DEBUGPL(DBG_PCDV, "%s(%p)\n", __func__, dev);
  90692. +}
  90693. +
  90694. +static struct gadget_wrapper *alloc_wrapper(dwc_bus_dev_t *_dev)
  90695. +{
  90696. + static char pcd_name[] = "dwc_otg_pcd";
  90697. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90698. + struct gadget_wrapper *d;
  90699. + int retval;
  90700. +
  90701. + d = DWC_ALLOC(sizeof(*d));
  90702. + if (d == NULL) {
  90703. + return NULL;
  90704. + }
  90705. +
  90706. + memset(d, 0, sizeof(*d));
  90707. +
  90708. + d->gadget.name = pcd_name;
  90709. + d->pcd = otg_dev->pcd;
  90710. +
  90711. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
  90712. + strcpy(d->gadget.dev.bus_id, "gadget");
  90713. +#else
  90714. + dev_set_name(&d->gadget.dev, "%s", "gadget");
  90715. +#endif
  90716. +
  90717. + d->gadget.dev.parent = &_dev->dev;
  90718. + d->gadget.dev.release = dwc_otg_pcd_gadget_release;
  90719. + d->gadget.ops = &dwc_otg_pcd_ops;
  90720. + d->gadget.max_speed = dwc_otg_pcd_is_dualspeed(otg_dev->pcd) ? USB_SPEED_HIGH:USB_SPEED_FULL;
  90721. + d->gadget.is_otg = dwc_otg_pcd_is_otg(otg_dev->pcd);
  90722. +
  90723. + d->driver = 0;
  90724. + /* Register the gadget device */
  90725. + retval = device_register(&d->gadget.dev);
  90726. + if (retval != 0) {
  90727. + DWC_ERROR("device_register failed\n");
  90728. + DWC_FREE(d);
  90729. + return NULL;
  90730. + }
  90731. +
  90732. + return d;
  90733. +}
  90734. +
  90735. +static void free_wrapper(struct gadget_wrapper *d)
  90736. +{
  90737. + if (d->driver) {
  90738. + /* should have been done already by driver model core */
  90739. + DWC_WARN("driver '%s' is still registered\n",
  90740. + d->driver->driver.name);
  90741. + usb_gadget_unregister_driver(d->driver);
  90742. + }
  90743. +
  90744. + device_unregister(&d->gadget.dev);
  90745. + DWC_FREE(d);
  90746. +}
  90747. +
  90748. +/**
  90749. + * This function initialized the PCD portion of the driver.
  90750. + *
  90751. + */
  90752. +int pcd_init(dwc_bus_dev_t *_dev)
  90753. +{
  90754. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90755. + int retval = 0;
  90756. +
  90757. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev=%p\n", __func__, _dev, otg_dev);
  90758. +
  90759. + otg_dev->pcd = dwc_otg_pcd_init(otg_dev->core_if);
  90760. +
  90761. + if (!otg_dev->pcd) {
  90762. + DWC_ERROR("dwc_otg_pcd_init failed\n");
  90763. + return -ENOMEM;
  90764. + }
  90765. +
  90766. + otg_dev->pcd->otg_dev = otg_dev;
  90767. + gadget_wrapper = alloc_wrapper(_dev);
  90768. +
  90769. + /*
  90770. + * Initialize EP structures
  90771. + */
  90772. + gadget_add_eps(gadget_wrapper);
  90773. + /*
  90774. + * Setup interupt handler
  90775. + */
  90776. +#ifdef PLATFORM_INTERFACE
  90777. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  90778. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  90779. + retval = request_irq(platform_get_irq(_dev, fiq_enable ? 0 : 1), dwc_otg_pcd_irq,
  90780. + IRQF_SHARED, gadget_wrapper->gadget.name,
  90781. + otg_dev->pcd);
  90782. + if (retval != 0) {
  90783. + DWC_ERROR("request of irq%d failed\n",
  90784. + platform_get_irq(_dev, fiq_enable ? 0 : 1));
  90785. + free_wrapper(gadget_wrapper);
  90786. + return -EBUSY;
  90787. + }
  90788. +#else
  90789. + DWC_DEBUGPL(DBG_ANY, "registering handler for irq%d\n",
  90790. + _dev->irq);
  90791. + retval = request_irq(_dev->irq, dwc_otg_pcd_irq,
  90792. + IRQF_SHARED | IRQF_DISABLED,
  90793. + gadget_wrapper->gadget.name, otg_dev->pcd);
  90794. + if (retval != 0) {
  90795. + DWC_ERROR("request of irq%d failed\n", _dev->irq);
  90796. + free_wrapper(gadget_wrapper);
  90797. + return -EBUSY;
  90798. + }
  90799. +#endif
  90800. +
  90801. + dwc_otg_pcd_start(gadget_wrapper->pcd, &fops);
  90802. +
  90803. + return retval;
  90804. +}
  90805. +
  90806. +/**
  90807. + * Cleanup the PCD.
  90808. + */
  90809. +void pcd_remove(dwc_bus_dev_t *_dev)
  90810. +{
  90811. + dwc_otg_device_t *otg_dev = DWC_OTG_BUSDRVDATA(_dev);
  90812. + dwc_otg_pcd_t *pcd = otg_dev->pcd;
  90813. +
  90814. + DWC_DEBUGPL(DBG_PCDV, "%s(%p) otg_dev %p\n", __func__, _dev, otg_dev);
  90815. +
  90816. + /*
  90817. + * Free the IRQ
  90818. + */
  90819. +#ifdef PLATFORM_INTERFACE
  90820. + free_irq(platform_get_irq(_dev, 0), pcd);
  90821. +#else
  90822. + free_irq(_dev->irq, pcd);
  90823. +#endif
  90824. + dwc_otg_pcd_remove(otg_dev->pcd);
  90825. + free_wrapper(gadget_wrapper);
  90826. + otg_dev->pcd = 0;
  90827. +}
  90828. +
  90829. +/**
  90830. + * This function registers a gadget driver with the PCD.
  90831. + *
  90832. + * When a driver is successfully registered, it will receive control
  90833. + * requests including set_configuration(), which enables non-control
  90834. + * requests. then usb traffic follows until a disconnect is reported.
  90835. + * then a host may connect again, or the driver might get unbound.
  90836. + *
  90837. + * @param driver The driver being registered
  90838. + * @param bind The bind function of gadget driver
  90839. + */
  90840. +
  90841. +int usb_gadget_probe_driver(struct usb_gadget_driver *driver)
  90842. +{
  90843. + int retval;
  90844. +
  90845. + DWC_DEBUGPL(DBG_PCD, "registering gadget driver '%s'\n",
  90846. + driver->driver.name);
  90847. +
  90848. + if (!driver || driver->max_speed == USB_SPEED_UNKNOWN ||
  90849. + !driver->bind ||
  90850. + !driver->unbind || !driver->disconnect || !driver->setup) {
  90851. + DWC_DEBUGPL(DBG_PCDV, "EINVAL\n");
  90852. + return -EINVAL;
  90853. + }
  90854. + if (gadget_wrapper == 0) {
  90855. + DWC_DEBUGPL(DBG_PCDV, "ENODEV\n");
  90856. + return -ENODEV;
  90857. + }
  90858. + if (gadget_wrapper->driver != 0) {
  90859. + DWC_DEBUGPL(DBG_PCDV, "EBUSY (%p)\n", gadget_wrapper->driver);
  90860. + return -EBUSY;
  90861. + }
  90862. +
  90863. + /* hook up the driver */
  90864. + gadget_wrapper->driver = driver;
  90865. + gadget_wrapper->gadget.dev.driver = &driver->driver;
  90866. +
  90867. + DWC_DEBUGPL(DBG_PCD, "bind to driver %s\n", driver->driver.name);
  90868. + retval = driver->bind(&gadget_wrapper->gadget, gadget_wrapper->driver);
  90869. + if (retval) {
  90870. + DWC_ERROR("bind to driver %s --> error %d\n",
  90871. + driver->driver.name, retval);
  90872. + gadget_wrapper->driver = 0;
  90873. + gadget_wrapper->gadget.dev.driver = 0;
  90874. + return retval;
  90875. + }
  90876. + DWC_DEBUGPL(DBG_ANY, "registered gadget driver '%s'\n",
  90877. + driver->driver.name);
  90878. + return 0;
  90879. +}
  90880. +EXPORT_SYMBOL(usb_gadget_probe_driver);
  90881. +
  90882. +/**
  90883. + * This function unregisters a gadget driver
  90884. + *
  90885. + * @param driver The driver being unregistered
  90886. + */
  90887. +int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
  90888. +{
  90889. + //DWC_DEBUGPL(DBG_PCDV,"%s(%p)\n", __func__, _driver);
  90890. +
  90891. + if (gadget_wrapper == 0) {
  90892. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): s_pcd==0\n", __func__,
  90893. + -ENODEV);
  90894. + return -ENODEV;
  90895. + }
  90896. + if (driver == 0 || driver != gadget_wrapper->driver) {
  90897. + DWC_DEBUGPL(DBG_ANY, "%s Return(%d): driver?\n", __func__,
  90898. + -EINVAL);
  90899. + return -EINVAL;
  90900. + }
  90901. +
  90902. + driver->unbind(&gadget_wrapper->gadget);
  90903. + gadget_wrapper->driver = 0;
  90904. +
  90905. + DWC_DEBUGPL(DBG_ANY, "unregistered driver '%s'\n", driver->driver.name);
  90906. + return 0;
  90907. +}
  90908. +
  90909. +EXPORT_SYMBOL(usb_gadget_unregister_driver);
  90910. +
  90911. +#endif /* DWC_HOST_ONLY */
  90912. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_regs.h linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h
  90913. --- linux-3.15/drivers/usb/host/dwc_otg/dwc_otg_regs.h 1970-01-01 01:00:00.000000000 +0100
  90914. +++ linux-rpi/drivers/usb/host/dwc_otg/dwc_otg_regs.h 2014-06-11 21:03:43.000000000 +0200
  90915. @@ -0,0 +1,2550 @@
  90916. +/* ==========================================================================
  90917. + * $File: //dwh/usb_iip/dev/software/otg/linux/drivers/dwc_otg_regs.h $
  90918. + * $Revision: #98 $
  90919. + * $Date: 2012/08/10 $
  90920. + * $Change: 2047372 $
  90921. + *
  90922. + * Synopsys HS OTG Linux Software Driver and documentation (hereinafter,
  90923. + * "Software") is an Unsupported proprietary work of Synopsys, Inc. unless
  90924. + * otherwise expressly agreed to in writing between Synopsys and you.
  90925. + *
  90926. + * The Software IS NOT an item of Licensed Software or Licensed Product under
  90927. + * any End User Software License Agreement or Agreement for Licensed Product
  90928. + * with Synopsys or any supplement thereto. You are permitted to use and
  90929. + * redistribute this Software in source and binary forms, with or without
  90930. + * modification, provided that redistributions of source code must retain this
  90931. + * notice. You may not view, use, disclose, copy or distribute this file or
  90932. + * any information contained herein except pursuant to this license grant from
  90933. + * Synopsys. If you do not agree with this notice, including the disclaimer
  90934. + * below, then you are not authorized to use the Software.
  90935. + *
  90936. + * THIS SOFTWARE IS BEING DISTRIBUTED BY SYNOPSYS SOLELY ON AN "AS IS" BASIS
  90937. + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  90938. + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  90939. + * ARE HEREBY DISCLAIMED. IN NO EVENT SHALL SYNOPSYS BE LIABLE FOR ANY DIRECT,
  90940. + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  90941. + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  90942. + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  90943. + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  90944. + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  90945. + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  90946. + * DAMAGE.
  90947. + * ========================================================================== */
  90948. +
  90949. +#ifndef __DWC_OTG_REGS_H__
  90950. +#define __DWC_OTG_REGS_H__
  90951. +
  90952. +#include "dwc_otg_core_if.h"
  90953. +
  90954. +/**
  90955. + * @file
  90956. + *
  90957. + * This file contains the data structures for accessing the DWC_otg core registers.
  90958. + *
  90959. + * The application interfaces with the HS OTG core by reading from and
  90960. + * writing to the Control and Status Register (CSR) space through the
  90961. + * AHB Slave interface. These registers are 32 bits wide, and the
  90962. + * addresses are 32-bit-block aligned.
  90963. + * CSRs are classified as follows:
  90964. + * - Core Global Registers
  90965. + * - Device Mode Registers
  90966. + * - Device Global Registers
  90967. + * - Device Endpoint Specific Registers
  90968. + * - Host Mode Registers
  90969. + * - Host Global Registers
  90970. + * - Host Port CSRs
  90971. + * - Host Channel Specific Registers
  90972. + *
  90973. + * Only the Core Global registers can be accessed in both Device and
  90974. + * Host modes. When the HS OTG core is operating in one mode, either
  90975. + * Device or Host, the application must not access registers from the
  90976. + * other mode. When the core switches from one mode to another, the
  90977. + * registers in the new mode of operation must be reprogrammed as they
  90978. + * would be after a power-on reset.
  90979. + */
  90980. +
  90981. +/****************************************************************************/
  90982. +/** DWC_otg Core registers .
  90983. + * The dwc_otg_core_global_regs structure defines the size
  90984. + * and relative field offsets for the Core Global registers.
  90985. + */
  90986. +typedef struct dwc_otg_core_global_regs {
  90987. + /** OTG Control and Status Register. <i>Offset: 000h</i> */
  90988. + volatile uint32_t gotgctl;
  90989. + /** OTG Interrupt Register. <i>Offset: 004h</i> */
  90990. + volatile uint32_t gotgint;
  90991. + /**Core AHB Configuration Register. <i>Offset: 008h</i> */
  90992. + volatile uint32_t gahbcfg;
  90993. +
  90994. +#define DWC_GLBINTRMASK 0x0001
  90995. +#define DWC_DMAENABLE 0x0020
  90996. +#define DWC_NPTXEMPTYLVL_EMPTY 0x0080
  90997. +#define DWC_NPTXEMPTYLVL_HALFEMPTY 0x0000
  90998. +#define DWC_PTXEMPTYLVL_EMPTY 0x0100
  90999. +#define DWC_PTXEMPTYLVL_HALFEMPTY 0x0000
  91000. +
  91001. + /**Core USB Configuration Register. <i>Offset: 00Ch</i> */
  91002. + volatile uint32_t gusbcfg;
  91003. + /**Core Reset Register. <i>Offset: 010h</i> */
  91004. + volatile uint32_t grstctl;
  91005. + /**Core Interrupt Register. <i>Offset: 014h</i> */
  91006. + volatile uint32_t gintsts;
  91007. + /**Core Interrupt Mask Register. <i>Offset: 018h</i> */
  91008. + volatile uint32_t gintmsk;
  91009. + /**Receive Status Queue Read Register (Read Only). <i>Offset: 01Ch</i> */
  91010. + volatile uint32_t grxstsr;
  91011. + /**Receive Status Queue Read & POP Register (Read Only). <i>Offset: 020h</i>*/
  91012. + volatile uint32_t grxstsp;
  91013. + /**Receive FIFO Size Register. <i>Offset: 024h</i> */
  91014. + volatile uint32_t grxfsiz;
  91015. + /**Non Periodic Transmit FIFO Size Register. <i>Offset: 028h</i> */
  91016. + volatile uint32_t gnptxfsiz;
  91017. + /**Non Periodic Transmit FIFO/Queue Status Register (Read
  91018. + * Only). <i>Offset: 02Ch</i> */
  91019. + volatile uint32_t gnptxsts;
  91020. + /**I2C Access Register. <i>Offset: 030h</i> */
  91021. + volatile uint32_t gi2cctl;
  91022. + /**PHY Vendor Control Register. <i>Offset: 034h</i> */
  91023. + volatile uint32_t gpvndctl;
  91024. + /**General Purpose Input/Output Register. <i>Offset: 038h</i> */
  91025. + volatile uint32_t ggpio;
  91026. + /**User ID Register. <i>Offset: 03Ch</i> */
  91027. + volatile uint32_t guid;
  91028. + /**Synopsys ID Register (Read Only). <i>Offset: 040h</i> */
  91029. + volatile uint32_t gsnpsid;
  91030. + /**User HW Config1 Register (Read Only). <i>Offset: 044h</i> */
  91031. + volatile uint32_t ghwcfg1;
  91032. + /**User HW Config2 Register (Read Only). <i>Offset: 048h</i> */
  91033. + volatile uint32_t ghwcfg2;
  91034. +#define DWC_SLAVE_ONLY_ARCH 0
  91035. +#define DWC_EXT_DMA_ARCH 1
  91036. +#define DWC_INT_DMA_ARCH 2
  91037. +
  91038. +#define DWC_MODE_HNP_SRP_CAPABLE 0
  91039. +#define DWC_MODE_SRP_ONLY_CAPABLE 1
  91040. +#define DWC_MODE_NO_HNP_SRP_CAPABLE 2
  91041. +#define DWC_MODE_SRP_CAPABLE_DEVICE 3
  91042. +#define DWC_MODE_NO_SRP_CAPABLE_DEVICE 4
  91043. +#define DWC_MODE_SRP_CAPABLE_HOST 5
  91044. +#define DWC_MODE_NO_SRP_CAPABLE_HOST 6
  91045. +
  91046. + /**User HW Config3 Register (Read Only). <i>Offset: 04Ch</i> */
  91047. + volatile uint32_t ghwcfg3;
  91048. + /**User HW Config4 Register (Read Only). <i>Offset: 050h</i>*/
  91049. + volatile uint32_t ghwcfg4;
  91050. + /** Core LPM Configuration register <i>Offset: 054h</i>*/
  91051. + volatile uint32_t glpmcfg;
  91052. + /** Global PowerDn Register <i>Offset: 058h</i> */
  91053. + volatile uint32_t gpwrdn;
  91054. + /** Global DFIFO SW Config Register <i>Offset: 05Ch</i> */
  91055. + volatile uint32_t gdfifocfg;
  91056. + /** ADP Control Register <i>Offset: 060h</i> */
  91057. + volatile uint32_t adpctl;
  91058. + /** Reserved <i>Offset: 064h-0FFh</i> */
  91059. + volatile uint32_t reserved39[39];
  91060. + /** Host Periodic Transmit FIFO Size Register. <i>Offset: 100h</i> */
  91061. + volatile uint32_t hptxfsiz;
  91062. + /** Device Periodic Transmit FIFO#n Register if dedicated fifos are disabled,
  91063. + otherwise Device Transmit FIFO#n Register.
  91064. + * <i>Offset: 104h + (FIFO_Number-1)*04h, 1 <= FIFO Number <= 15 (1<=n<=15).</i> */
  91065. + volatile uint32_t dtxfsiz[15];
  91066. +} dwc_otg_core_global_regs_t;
  91067. +
  91068. +/**
  91069. + * This union represents the bit fields of the Core OTG Control
  91070. + * and Status Register (GOTGCTL). Set the bits using the bit
  91071. + * fields then write the <i>d32</i> value to the register.
  91072. + */
  91073. +typedef union gotgctl_data {
  91074. + /** raw register data */
  91075. + uint32_t d32;
  91076. + /** register bits */
  91077. + struct {
  91078. + unsigned sesreqscs:1;
  91079. + unsigned sesreq:1;
  91080. + unsigned vbvalidoven:1;
  91081. + unsigned vbvalidovval:1;
  91082. + unsigned avalidoven:1;
  91083. + unsigned avalidovval:1;
  91084. + unsigned bvalidoven:1;
  91085. + unsigned bvalidovval:1;
  91086. + unsigned hstnegscs:1;
  91087. + unsigned hnpreq:1;
  91088. + unsigned hstsethnpen:1;
  91089. + unsigned devhnpen:1;
  91090. + unsigned reserved12_15:4;
  91091. + unsigned conidsts:1;
  91092. + unsigned dbnctime:1;
  91093. + unsigned asesvld:1;
  91094. + unsigned bsesvld:1;
  91095. + unsigned otgver:1;
  91096. + unsigned reserved1:1;
  91097. + unsigned multvalidbc:5;
  91098. + unsigned chirpen:1;
  91099. + unsigned reserved28_31:4;
  91100. + } b;
  91101. +} gotgctl_data_t;
  91102. +
  91103. +/**
  91104. + * This union represents the bit fields of the Core OTG Interrupt Register
  91105. + * (GOTGINT). Set/clear the bits using the bit fields then write the <i>d32</i>
  91106. + * value to the register.
  91107. + */
  91108. +typedef union gotgint_data {
  91109. + /** raw register data */
  91110. + uint32_t d32;
  91111. + /** register bits */
  91112. + struct {
  91113. + /** Current Mode */
  91114. + unsigned reserved0_1:2;
  91115. +
  91116. + /** Session End Detected */
  91117. + unsigned sesenddet:1;
  91118. +
  91119. + unsigned reserved3_7:5;
  91120. +
  91121. + /** Session Request Success Status Change */
  91122. + unsigned sesreqsucstschng:1;
  91123. + /** Host Negotiation Success Status Change */
  91124. + unsigned hstnegsucstschng:1;
  91125. +
  91126. + unsigned reserved10_16:7;
  91127. +
  91128. + /** Host Negotiation Detected */
  91129. + unsigned hstnegdet:1;
  91130. + /** A-Device Timeout Change */
  91131. + unsigned adevtoutchng:1;
  91132. + /** Debounce Done */
  91133. + unsigned debdone:1;
  91134. + /** Multi-Valued input changed */
  91135. + unsigned mvic:1;
  91136. +
  91137. + unsigned reserved31_21:11;
  91138. +
  91139. + } b;
  91140. +} gotgint_data_t;
  91141. +
  91142. +/**
  91143. + * This union represents the bit fields of the Core AHB Configuration
  91144. + * Register (GAHBCFG). Set/clear the bits using the bit fields then
  91145. + * write the <i>d32</i> value to the register.
  91146. + */
  91147. +typedef union gahbcfg_data {
  91148. + /** raw register data */
  91149. + uint32_t d32;
  91150. + /** register bits */
  91151. + struct {
  91152. + unsigned glblintrmsk:1;
  91153. +#define DWC_GAHBCFG_GLBINT_ENABLE 1
  91154. +
  91155. + unsigned hburstlen:4;
  91156. +#define DWC_GAHBCFG_INT_DMA_BURST_SINGLE 0
  91157. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR 1
  91158. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR4 3
  91159. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR8 5
  91160. +#define DWC_GAHBCFG_INT_DMA_BURST_INCR16 7
  91161. +
  91162. + unsigned dmaenable:1;
  91163. +#define DWC_GAHBCFG_DMAENABLE 1
  91164. + unsigned reserved:1;
  91165. + unsigned nptxfemplvl_txfemplvl:1;
  91166. + unsigned ptxfemplvl:1;
  91167. +#define DWC_GAHBCFG_TXFEMPTYLVL_EMPTY 1
  91168. +#define DWC_GAHBCFG_TXFEMPTYLVL_HALFEMPTY 0
  91169. + unsigned reserved9_20:12;
  91170. + unsigned remmemsupp:1;
  91171. + unsigned notialldmawrit:1;
  91172. + unsigned ahbsingle:1;
  91173. + unsigned reserved24_31:8;
  91174. + } b;
  91175. +} gahbcfg_data_t;
  91176. +
  91177. +/**
  91178. + * This union represents the bit fields of the Core USB Configuration
  91179. + * Register (GUSBCFG). Set the bits using the bit fields then write
  91180. + * the <i>d32</i> value to the register.
  91181. + */
  91182. +typedef union gusbcfg_data {
  91183. + /** raw register data */
  91184. + uint32_t d32;
  91185. + /** register bits */
  91186. + struct {
  91187. + unsigned toutcal:3;
  91188. + unsigned phyif:1;
  91189. + unsigned ulpi_utmi_sel:1;
  91190. + unsigned fsintf:1;
  91191. + unsigned physel:1;
  91192. + unsigned ddrsel:1;
  91193. + unsigned srpcap:1;
  91194. + unsigned hnpcap:1;
  91195. + unsigned usbtrdtim:4;
  91196. + unsigned reserved1:1;
  91197. + unsigned phylpwrclksel:1;
  91198. + unsigned otgutmifssel:1;
  91199. + unsigned ulpi_fsls:1;
  91200. + unsigned ulpi_auto_res:1;
  91201. + unsigned ulpi_clk_sus_m:1;
  91202. + unsigned ulpi_ext_vbus_drv:1;
  91203. + unsigned ulpi_int_vbus_indicator:1;
  91204. + unsigned term_sel_dl_pulse:1;
  91205. + unsigned indicator_complement:1;
  91206. + unsigned indicator_pass_through:1;
  91207. + unsigned ulpi_int_prot_dis:1;
  91208. + unsigned ic_usb_cap:1;
  91209. + unsigned ic_traffic_pull_remove:1;
  91210. + unsigned tx_end_delay:1;
  91211. + unsigned force_host_mode:1;
  91212. + unsigned force_dev_mode:1;
  91213. + unsigned reserved31:1;
  91214. + } b;
  91215. +} gusbcfg_data_t;
  91216. +
  91217. +/**
  91218. + * This union represents the bit fields of the Core Reset Register
  91219. + * (GRSTCTL). Set/clear the bits using the bit fields then write the
  91220. + * <i>d32</i> value to the register.
  91221. + */
  91222. +typedef union grstctl_data {
  91223. + /** raw register data */
  91224. + uint32_t d32;
  91225. + /** register bits */
  91226. + struct {
  91227. + /** Core Soft Reset (CSftRst) (Device and Host)
  91228. + *
  91229. + * The application can flush the control logic in the
  91230. + * entire core using this bit. This bit resets the
  91231. + * pipelines in the AHB Clock domain as well as the
  91232. + * PHY Clock domain.
  91233. + *
  91234. + * The state machines are reset to an IDLE state, the
  91235. + * control bits in the CSRs are cleared, all the
  91236. + * transmit FIFOs and the receive FIFO are flushed.
  91237. + *
  91238. + * The status mask bits that control the generation of
  91239. + * the interrupt, are cleared, to clear the
  91240. + * interrupt. The interrupt status bits are not
  91241. + * cleared, so the application can get the status of
  91242. + * any events that occurred in the core after it has
  91243. + * set this bit.
  91244. + *
  91245. + * Any transactions on the AHB are terminated as soon
  91246. + * as possible following the protocol. Any
  91247. + * transactions on the USB are terminated immediately.
  91248. + *
  91249. + * The configuration settings in the CSRs are
  91250. + * unchanged, so the software doesn't have to
  91251. + * reprogram these registers (Device
  91252. + * Configuration/Host Configuration/Core System
  91253. + * Configuration/Core PHY Configuration).
  91254. + *
  91255. + * The application can write to this bit, any time it
  91256. + * wants to reset the core. This is a self clearing
  91257. + * bit and the core clears this bit after all the
  91258. + * necessary logic is reset in the core, which may
  91259. + * take several clocks, depending on the current state
  91260. + * of the core.
  91261. + */
  91262. + unsigned csftrst:1;
  91263. + /** Hclk Soft Reset
  91264. + *
  91265. + * The application uses this bit to reset the control logic in
  91266. + * the AHB clock domain. Only AHB clock domain pipelines are
  91267. + * reset.
  91268. + */
  91269. + unsigned hsftrst:1;
  91270. + /** Host Frame Counter Reset (Host Only)<br>
  91271. + *
  91272. + * The application can reset the (micro)frame number
  91273. + * counter inside the core, using this bit. When the
  91274. + * (micro)frame counter is reset, the subsequent SOF
  91275. + * sent out by the core, will have a (micro)frame
  91276. + * number of 0.
  91277. + */
  91278. + unsigned hstfrm:1;
  91279. + /** In Token Sequence Learning Queue Flush
  91280. + * (INTknQFlsh) (Device Only)
  91281. + */
  91282. + unsigned intknqflsh:1;
  91283. + /** RxFIFO Flush (RxFFlsh) (Device and Host)
  91284. + *
  91285. + * The application can flush the entire Receive FIFO
  91286. + * using this bit. The application must first
  91287. + * ensure that the core is not in the middle of a
  91288. + * transaction. The application should write into
  91289. + * this bit, only after making sure that neither the
  91290. + * DMA engine is reading from the RxFIFO nor the MAC
  91291. + * is writing the data in to the FIFO. The
  91292. + * application should wait until the bit is cleared
  91293. + * before performing any other operations. This bit
  91294. + * will takes 8 clocks (slowest of PHY or AHB clock)
  91295. + * to clear.
  91296. + */
  91297. + unsigned rxfflsh:1;
  91298. + /** TxFIFO Flush (TxFFlsh) (Device and Host).
  91299. + *
  91300. + * This bit is used to selectively flush a single or
  91301. + * all transmit FIFOs. The application must first
  91302. + * ensure that the core is not in the middle of a
  91303. + * transaction. The application should write into
  91304. + * this bit, only after making sure that neither the
  91305. + * DMA engine is writing into the TxFIFO nor the MAC
  91306. + * is reading the data out of the FIFO. The
  91307. + * application should wait until the core clears this
  91308. + * bit, before performing any operations. This bit
  91309. + * will takes 8 clocks (slowest of PHY or AHB clock)
  91310. + * to clear.
  91311. + */
  91312. + unsigned txfflsh:1;
  91313. +
  91314. + /** TxFIFO Number (TxFNum) (Device and Host).
  91315. + *
  91316. + * This is the FIFO number which needs to be flushed,
  91317. + * using the TxFIFO Flush bit. This field should not
  91318. + * be changed until the TxFIFO Flush bit is cleared by
  91319. + * the core.
  91320. + * - 0x0 : Non Periodic TxFIFO Flush
  91321. + * - 0x1 : Periodic TxFIFO #1 Flush in device mode
  91322. + * or Periodic TxFIFO in host mode
  91323. + * - 0x2 : Periodic TxFIFO #2 Flush in device mode.
  91324. + * - ...
  91325. + * - 0xF : Periodic TxFIFO #15 Flush in device mode
  91326. + * - 0x10: Flush all the Transmit NonPeriodic and
  91327. + * Transmit Periodic FIFOs in the core
  91328. + */
  91329. + unsigned txfnum:5;
  91330. + /** Reserved */
  91331. + unsigned reserved11_29:19;
  91332. + /** DMA Request Signal. Indicated DMA request is in
  91333. + * probress. Used for debug purpose. */
  91334. + unsigned dmareq:1;
  91335. + /** AHB Master Idle. Indicates the AHB Master State
  91336. + * Machine is in IDLE condition. */
  91337. + unsigned ahbidle:1;
  91338. + } b;
  91339. +} grstctl_t;
  91340. +
  91341. +/**
  91342. + * This union represents the bit fields of the Core Interrupt Mask
  91343. + * Register (GINTMSK). Set/clear the bits using the bit fields then
  91344. + * write the <i>d32</i> value to the register.
  91345. + */
  91346. +typedef union gintmsk_data {
  91347. + /** raw register data */
  91348. + uint32_t d32;
  91349. + /** register bits */
  91350. + struct {
  91351. + unsigned reserved0:1;
  91352. + unsigned modemismatch:1;
  91353. + unsigned otgintr:1;
  91354. + unsigned sofintr:1;
  91355. + unsigned rxstsqlvl:1;
  91356. + unsigned nptxfempty:1;
  91357. + unsigned ginnakeff:1;
  91358. + unsigned goutnakeff:1;
  91359. + unsigned ulpickint:1;
  91360. + unsigned i2cintr:1;
  91361. + unsigned erlysuspend:1;
  91362. + unsigned usbsuspend:1;
  91363. + unsigned usbreset:1;
  91364. + unsigned enumdone:1;
  91365. + unsigned isooutdrop:1;
  91366. + unsigned eopframe:1;
  91367. + unsigned restoredone:1;
  91368. + unsigned epmismatch:1;
  91369. + unsigned inepintr:1;
  91370. + unsigned outepintr:1;
  91371. + unsigned incomplisoin:1;
  91372. + unsigned incomplisoout:1;
  91373. + unsigned fetsusp:1;
  91374. + unsigned resetdet:1;
  91375. + unsigned portintr:1;
  91376. + unsigned hcintr:1;
  91377. + unsigned ptxfempty:1;
  91378. + unsigned lpmtranrcvd:1;
  91379. + unsigned conidstschng:1;
  91380. + unsigned disconnect:1;
  91381. + unsigned sessreqintr:1;
  91382. + unsigned wkupintr:1;
  91383. + } b;
  91384. +} gintmsk_data_t;
  91385. +/**
  91386. + * This union represents the bit fields of the Core Interrupt Register
  91387. + * (GINTSTS). Set/clear the bits using the bit fields then write the
  91388. + * <i>d32</i> value to the register.
  91389. + */
  91390. +typedef union gintsts_data {
  91391. + /** raw register data */
  91392. + uint32_t d32;
  91393. +#define DWC_SOF_INTR_MASK 0x0008
  91394. + /** register bits */
  91395. + struct {
  91396. +#define DWC_HOST_MODE 1
  91397. + unsigned curmode:1;
  91398. + unsigned modemismatch:1;
  91399. + unsigned otgintr:1;
  91400. + unsigned sofintr:1;
  91401. + unsigned rxstsqlvl:1;
  91402. + unsigned nptxfempty:1;
  91403. + unsigned ginnakeff:1;
  91404. + unsigned goutnakeff:1;
  91405. + unsigned ulpickint:1;
  91406. + unsigned i2cintr:1;
  91407. + unsigned erlysuspend:1;
  91408. + unsigned usbsuspend:1;
  91409. + unsigned usbreset:1;
  91410. + unsigned enumdone:1;
  91411. + unsigned isooutdrop:1;
  91412. + unsigned eopframe:1;
  91413. + unsigned restoredone:1;
  91414. + unsigned epmismatch:1;
  91415. + unsigned inepint:1;
  91416. + unsigned outepintr:1;
  91417. + unsigned incomplisoin:1;
  91418. + unsigned incomplisoout:1;
  91419. + unsigned fetsusp:1;
  91420. + unsigned resetdet:1;
  91421. + unsigned portintr:1;
  91422. + unsigned hcintr:1;
  91423. + unsigned ptxfempty:1;
  91424. + unsigned lpmtranrcvd:1;
  91425. + unsigned conidstschng:1;
  91426. + unsigned disconnect:1;
  91427. + unsigned sessreqintr:1;
  91428. + unsigned wkupintr:1;
  91429. + } b;
  91430. +} gintsts_data_t;
  91431. +
  91432. +/**
  91433. + * This union represents the bit fields in the Device Receive Status Read and
  91434. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  91435. + * element then read out the bits using the <i>b</i>it elements.
  91436. + */
  91437. +typedef union device_grxsts_data {
  91438. + /** raw register data */
  91439. + uint32_t d32;
  91440. + /** register bits */
  91441. + struct {
  91442. + unsigned epnum:4;
  91443. + unsigned bcnt:11;
  91444. + unsigned dpid:2;
  91445. +
  91446. +#define DWC_STS_DATA_UPDT 0x2 // OUT Data Packet
  91447. +#define DWC_STS_XFER_COMP 0x3 // OUT Data Transfer Complete
  91448. +
  91449. +#define DWC_DSTS_GOUT_NAK 0x1 // Global OUT NAK
  91450. +#define DWC_DSTS_SETUP_COMP 0x4 // Setup Phase Complete
  91451. +#define DWC_DSTS_SETUP_UPDT 0x6 // SETUP Packet
  91452. + unsigned pktsts:4;
  91453. + unsigned fn:4;
  91454. + unsigned reserved25_31:7;
  91455. + } b;
  91456. +} device_grxsts_data_t;
  91457. +
  91458. +/**
  91459. + * This union represents the bit fields in the Host Receive Status Read and
  91460. + * Pop Registers (GRXSTSR, GRXSTSP) Read the register into the <i>d32</i>
  91461. + * element then read out the bits using the <i>b</i>it elements.
  91462. + */
  91463. +typedef union host_grxsts_data {
  91464. + /** raw register data */
  91465. + uint32_t d32;
  91466. + /** register bits */
  91467. + struct {
  91468. + unsigned chnum:4;
  91469. + unsigned bcnt:11;
  91470. + unsigned dpid:2;
  91471. +
  91472. + unsigned pktsts:4;
  91473. +#define DWC_GRXSTS_PKTSTS_IN 0x2
  91474. +#define DWC_GRXSTS_PKTSTS_IN_XFER_COMP 0x3
  91475. +#define DWC_GRXSTS_PKTSTS_DATA_TOGGLE_ERR 0x5
  91476. +#define DWC_GRXSTS_PKTSTS_CH_HALTED 0x7
  91477. +
  91478. + unsigned reserved21_31:11;
  91479. + } b;
  91480. +} host_grxsts_data_t;
  91481. +
  91482. +/**
  91483. + * This union represents the bit fields in the FIFO Size Registers (HPTXFSIZ,
  91484. + * GNPTXFSIZ, DPTXFSIZn, DIEPTXFn). Read the register into the <i>d32</i> element
  91485. + * then read out the bits using the <i>b</i>it elements.
  91486. + */
  91487. +typedef union fifosize_data {
  91488. + /** raw register data */
  91489. + uint32_t d32;
  91490. + /** register bits */
  91491. + struct {
  91492. + unsigned startaddr:16;
  91493. + unsigned depth:16;
  91494. + } b;
  91495. +} fifosize_data_t;
  91496. +
  91497. +/**
  91498. + * This union represents the bit fields in the Non-Periodic Transmit
  91499. + * FIFO/Queue Status Register (GNPTXSTS). Read the register into the
  91500. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  91501. + * elements.
  91502. + */
  91503. +typedef union gnptxsts_data {
  91504. + /** raw register data */
  91505. + uint32_t d32;
  91506. + /** register bits */
  91507. + struct {
  91508. + unsigned nptxfspcavail:16;
  91509. + unsigned nptxqspcavail:8;
  91510. + /** Top of the Non-Periodic Transmit Request Queue
  91511. + * - bit 24 - Terminate (Last entry for the selected
  91512. + * channel/EP)
  91513. + * - bits 26:25 - Token Type
  91514. + * - 2'b00 - IN/OUT
  91515. + * - 2'b01 - Zero Length OUT
  91516. + * - 2'b10 - PING/Complete Split
  91517. + * - 2'b11 - Channel Halt
  91518. + * - bits 30:27 - Channel/EP Number
  91519. + */
  91520. + unsigned nptxqtop_terminate:1;
  91521. + unsigned nptxqtop_token:2;
  91522. + unsigned nptxqtop_chnep:4;
  91523. + unsigned reserved:1;
  91524. + } b;
  91525. +} gnptxsts_data_t;
  91526. +
  91527. +/**
  91528. + * This union represents the bit fields in the Transmit
  91529. + * FIFO Status Register (DTXFSTS). Read the register into the
  91530. + * <i>d32</i> element then read out the bits using the <i>b</i>it
  91531. + * elements.
  91532. + */
  91533. +typedef union dtxfsts_data {
  91534. + /** raw register data */
  91535. + uint32_t d32;
  91536. + /** register bits */
  91537. + struct {
  91538. + unsigned txfspcavail:16;
  91539. + unsigned reserved:16;
  91540. + } b;
  91541. +} dtxfsts_data_t;
  91542. +
  91543. +/**
  91544. + * This union represents the bit fields in the I2C Control Register
  91545. + * (I2CCTL). Read the register into the <i>d32</i> element then read out the
  91546. + * bits using the <i>b</i>it elements.
  91547. + */
  91548. +typedef union gi2cctl_data {
  91549. + /** raw register data */
  91550. + uint32_t d32;
  91551. + /** register bits */
  91552. + struct {
  91553. + unsigned rwdata:8;
  91554. + unsigned regaddr:8;
  91555. + unsigned addr:7;
  91556. + unsigned i2cen:1;
  91557. + unsigned ack:1;
  91558. + unsigned i2csuspctl:1;
  91559. + unsigned i2cdevaddr:2;
  91560. + unsigned i2cdatse0:1;
  91561. + unsigned reserved:1;
  91562. + unsigned rw:1;
  91563. + unsigned bsydne:1;
  91564. + } b;
  91565. +} gi2cctl_data_t;
  91566. +
  91567. +/**
  91568. + * This union represents the bit fields in the PHY Vendor Control Register
  91569. + * (GPVNDCTL). Read the register into the <i>d32</i> element then read out the
  91570. + * bits using the <i>b</i>it elements.
  91571. + */
  91572. +typedef union gpvndctl_data {
  91573. + /** raw register data */
  91574. + uint32_t d32;
  91575. + /** register bits */
  91576. + struct {
  91577. + unsigned regdata:8;
  91578. + unsigned vctrl:8;
  91579. + unsigned regaddr16_21:6;
  91580. + unsigned regwr:1;
  91581. + unsigned reserved23_24:2;
  91582. + unsigned newregreq:1;
  91583. + unsigned vstsbsy:1;
  91584. + unsigned vstsdone:1;
  91585. + unsigned reserved28_30:3;
  91586. + unsigned disulpidrvr:1;
  91587. + } b;
  91588. +} gpvndctl_data_t;
  91589. +
  91590. +/**
  91591. + * This union represents the bit fields in the General Purpose
  91592. + * Input/Output Register (GGPIO).
  91593. + * Read the register into the <i>d32</i> element then read out the
  91594. + * bits using the <i>b</i>it elements.
  91595. + */
  91596. +typedef union ggpio_data {
  91597. + /** raw register data */
  91598. + uint32_t d32;
  91599. + /** register bits */
  91600. + struct {
  91601. + unsigned gpi:16;
  91602. + unsigned gpo:16;
  91603. + } b;
  91604. +} ggpio_data_t;
  91605. +
  91606. +/**
  91607. + * This union represents the bit fields in the User ID Register
  91608. + * (GUID). Read the register into the <i>d32</i> element then read out the
  91609. + * bits using the <i>b</i>it elements.
  91610. + */
  91611. +typedef union guid_data {
  91612. + /** raw register data */
  91613. + uint32_t d32;
  91614. + /** register bits */
  91615. + struct {
  91616. + unsigned rwdata:32;
  91617. + } b;
  91618. +} guid_data_t;
  91619. +
  91620. +/**
  91621. + * This union represents the bit fields in the Synopsys ID Register
  91622. + * (GSNPSID). Read the register into the <i>d32</i> element then read out the
  91623. + * bits using the <i>b</i>it elements.
  91624. + */
  91625. +typedef union gsnpsid_data {
  91626. + /** raw register data */
  91627. + uint32_t d32;
  91628. + /** register bits */
  91629. + struct {
  91630. + unsigned rwdata:32;
  91631. + } b;
  91632. +} gsnpsid_data_t;
  91633. +
  91634. +/**
  91635. + * This union represents the bit fields in the User HW Config1
  91636. + * Register. Read the register into the <i>d32</i> element then read
  91637. + * out the bits using the <i>b</i>it elements.
  91638. + */
  91639. +typedef union hwcfg1_data {
  91640. + /** raw register data */
  91641. + uint32_t d32;
  91642. + /** register bits */
  91643. + struct {
  91644. + unsigned ep_dir0:2;
  91645. + unsigned ep_dir1:2;
  91646. + unsigned ep_dir2:2;
  91647. + unsigned ep_dir3:2;
  91648. + unsigned ep_dir4:2;
  91649. + unsigned ep_dir5:2;
  91650. + unsigned ep_dir6:2;
  91651. + unsigned ep_dir7:2;
  91652. + unsigned ep_dir8:2;
  91653. + unsigned ep_dir9:2;
  91654. + unsigned ep_dir10:2;
  91655. + unsigned ep_dir11:2;
  91656. + unsigned ep_dir12:2;
  91657. + unsigned ep_dir13:2;
  91658. + unsigned ep_dir14:2;
  91659. + unsigned ep_dir15:2;
  91660. + } b;
  91661. +} hwcfg1_data_t;
  91662. +
  91663. +/**
  91664. + * This union represents the bit fields in the User HW Config2
  91665. + * Register. Read the register into the <i>d32</i> element then read
  91666. + * out the bits using the <i>b</i>it elements.
  91667. + */
  91668. +typedef union hwcfg2_data {
  91669. + /** raw register data */
  91670. + uint32_t d32;
  91671. + /** register bits */
  91672. + struct {
  91673. + /* GHWCFG2 */
  91674. + unsigned op_mode:3;
  91675. +#define DWC_HWCFG2_OP_MODE_HNP_SRP_CAPABLE_OTG 0
  91676. +#define DWC_HWCFG2_OP_MODE_SRP_ONLY_CAPABLE_OTG 1
  91677. +#define DWC_HWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE_OTG 2
  91678. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3
  91679. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4
  91680. +#define DWC_HWCFG2_OP_MODE_SRP_CAPABLE_HOST 5
  91681. +#define DWC_HWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6
  91682. +
  91683. + unsigned architecture:2;
  91684. + unsigned point2point:1;
  91685. + unsigned hs_phy_type:2;
  91686. +#define DWC_HWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0
  91687. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI 1
  91688. +#define DWC_HWCFG2_HS_PHY_TYPE_ULPI 2
  91689. +#define DWC_HWCFG2_HS_PHY_TYPE_UTMI_ULPI 3
  91690. +
  91691. + unsigned fs_phy_type:2;
  91692. + unsigned num_dev_ep:4;
  91693. + unsigned num_host_chan:4;
  91694. + unsigned perio_ep_supported:1;
  91695. + unsigned dynamic_fifo:1;
  91696. + unsigned multi_proc_int:1;
  91697. + unsigned reserved21:1;
  91698. + unsigned nonperio_tx_q_depth:2;
  91699. + unsigned host_perio_tx_q_depth:2;
  91700. + unsigned dev_token_q_depth:5;
  91701. + unsigned otg_enable_ic_usb:1;
  91702. + } b;
  91703. +} hwcfg2_data_t;
  91704. +
  91705. +/**
  91706. + * This union represents the bit fields in the User HW Config3
  91707. + * Register. Read the register into the <i>d32</i> element then read
  91708. + * out the bits using the <i>b</i>it elements.
  91709. + */
  91710. +typedef union hwcfg3_data {
  91711. + /** raw register data */
  91712. + uint32_t d32;
  91713. + /** register bits */
  91714. + struct {
  91715. + /* GHWCFG3 */
  91716. + unsigned xfer_size_cntr_width:4;
  91717. + unsigned packet_size_cntr_width:3;
  91718. + unsigned otg_func:1;
  91719. + unsigned i2c:1;
  91720. + unsigned vendor_ctrl_if:1;
  91721. + unsigned optional_features:1;
  91722. + unsigned synch_reset_type:1;
  91723. + unsigned adp_supp:1;
  91724. + unsigned otg_enable_hsic:1;
  91725. + unsigned bc_support:1;
  91726. + unsigned otg_lpm_en:1;
  91727. + unsigned dfifo_depth:16;
  91728. + } b;
  91729. +} hwcfg3_data_t;
  91730. +
  91731. +/**
  91732. + * This union represents the bit fields in the User HW Config4
  91733. + * Register. Read the register into the <i>d32</i> element then read
  91734. + * out the bits using the <i>b</i>it elements.
  91735. + */
  91736. +typedef union hwcfg4_data {
  91737. + /** raw register data */
  91738. + uint32_t d32;
  91739. + /** register bits */
  91740. + struct {
  91741. + unsigned num_dev_perio_in_ep:4;
  91742. + unsigned power_optimiz:1;
  91743. + unsigned min_ahb_freq:1;
  91744. + unsigned hiber:1;
  91745. + unsigned xhiber:1;
  91746. + unsigned reserved:6;
  91747. + unsigned utmi_phy_data_width:2;
  91748. + unsigned num_dev_mode_ctrl_ep:4;
  91749. + unsigned iddig_filt_en:1;
  91750. + unsigned vbus_valid_filt_en:1;
  91751. + unsigned a_valid_filt_en:1;
  91752. + unsigned b_valid_filt_en:1;
  91753. + unsigned session_end_filt_en:1;
  91754. + unsigned ded_fifo_en:1;
  91755. + unsigned num_in_eps:4;
  91756. + unsigned desc_dma:1;
  91757. + unsigned desc_dma_dyn:1;
  91758. + } b;
  91759. +} hwcfg4_data_t;
  91760. +
  91761. +/**
  91762. + * This union represents the bit fields of the Core LPM Configuration
  91763. + * Register (GLPMCFG). Set the bits using bit fields then write
  91764. + * the <i>d32</i> value to the register.
  91765. + */
  91766. +typedef union glpmctl_data {
  91767. + /** raw register data */
  91768. + uint32_t d32;
  91769. + /** register bits */
  91770. + struct {
  91771. + /** LPM-Capable (LPMCap) (Device and Host)
  91772. + * The application uses this bit to control
  91773. + * the DWC_otg core LPM capabilities.
  91774. + */
  91775. + unsigned lpm_cap_en:1;
  91776. + /** LPM response programmed by application (AppL1Res) (Device)
  91777. + * Handshake response to LPM token pre-programmed
  91778. + * by device application software.
  91779. + */
  91780. + unsigned appl_resp:1;
  91781. + /** Host Initiated Resume Duration (HIRD) (Device and Host)
  91782. + * In Host mode this field indicates the value of HIRD
  91783. + * to be sent in an LPM transaction.
  91784. + * In Device mode this field is updated with the
  91785. + * Received LPM Token HIRD bmAttribute
  91786. + * when an ACK/NYET/STALL response is sent
  91787. + * to an LPM transaction.
  91788. + */
  91789. + unsigned hird:4;
  91790. + /** RemoteWakeEnable (bRemoteWake) (Device and Host)
  91791. + * In Host mode this bit indicates the value of remote
  91792. + * wake up to be sent in wIndex field of LPM transaction.
  91793. + * In Device mode this field is updated with the
  91794. + * Received LPM Token bRemoteWake bmAttribute
  91795. + * when an ACK/NYET/STALL response is sent
  91796. + * to an LPM transaction.
  91797. + */
  91798. + unsigned rem_wkup_en:1;
  91799. + /** Enable utmi_sleep_n (EnblSlpM) (Device and Host)
  91800. + * The application uses this bit to control
  91801. + * the utmi_sleep_n assertion to the PHY when in L1 state.
  91802. + */
  91803. + unsigned en_utmi_sleep:1;
  91804. + /** HIRD Threshold (HIRD_Thres) (Device and Host)
  91805. + */
  91806. + unsigned hird_thres:5;
  91807. + /** LPM Response (CoreL1Res) (Device and Host)
  91808. + * In Host mode this bit contains handsake response to
  91809. + * LPM transaction.
  91810. + * In Device mode the response of the core to
  91811. + * LPM transaction received is reflected in these two bits.
  91812. + - 0x0 : ERROR (No handshake response)
  91813. + - 0x1 : STALL
  91814. + - 0x2 : NYET
  91815. + - 0x3 : ACK
  91816. + */
  91817. + unsigned lpm_resp:2;
  91818. + /** Port Sleep Status (SlpSts) (Device and Host)
  91819. + * This bit is set as long as a Sleep condition
  91820. + * is present on the USB bus.
  91821. + */
  91822. + unsigned prt_sleep_sts:1;
  91823. + /** Sleep State Resume OK (L1ResumeOK) (Device and Host)
  91824. + * Indicates that the application or host
  91825. + * can start resume from Sleep state.
  91826. + */
  91827. + unsigned sleep_state_resumeok:1;
  91828. + /** LPM channel Index (LPM_Chnl_Indx) (Host)
  91829. + * The channel number on which the LPM transaction
  91830. + * has to be applied while sending
  91831. + * an LPM transaction to the local device.
  91832. + */
  91833. + unsigned lpm_chan_index:4;
  91834. + /** LPM Retry Count (LPM_Retry_Cnt) (Host)
  91835. + * Number host retries that would be performed
  91836. + * if the device response was not valid response.
  91837. + */
  91838. + unsigned retry_count:3;
  91839. + /** Send LPM Transaction (SndLPM) (Host)
  91840. + * When set by application software,
  91841. + * an LPM transaction containing two tokens
  91842. + * is sent.
  91843. + */
  91844. + unsigned send_lpm:1;
  91845. + /** LPM Retry status (LPM_RetryCnt_Sts) (Host)
  91846. + * Number of LPM Host Retries still remaining
  91847. + * to be transmitted for the current LPM sequence
  91848. + */
  91849. + unsigned retry_count_sts:3;
  91850. + unsigned reserved28_29:2;
  91851. + /** In host mode once this bit is set, the host
  91852. + * configures to drive the HSIC Idle state on the bus.
  91853. + * It then waits for the device to initiate the Connect sequence.
  91854. + * In device mode once this bit is set, the device waits for
  91855. + * the HSIC Idle line state on the bus. Upon receving the Idle
  91856. + * line state, it initiates the HSIC Connect sequence.
  91857. + */
  91858. + unsigned hsic_connect:1;
  91859. + /** This bit overrides and functionally inverts
  91860. + * the if_select_hsic input port signal.
  91861. + */
  91862. + unsigned inv_sel_hsic:1;
  91863. + } b;
  91864. +} glpmcfg_data_t;
  91865. +
  91866. +/**
  91867. + * This union represents the bit fields of the Core ADP Timer, Control and
  91868. + * Status Register (ADPTIMCTLSTS). Set the bits using bit fields then write
  91869. + * the <i>d32</i> value to the register.
  91870. + */
  91871. +typedef union adpctl_data {
  91872. + /** raw register data */
  91873. + uint32_t d32;
  91874. + /** register bits */
  91875. + struct {
  91876. + /** Probe Discharge (PRB_DSCHG)
  91877. + * These bits set the times for TADP_DSCHG.
  91878. + * These bits are defined as follows:
  91879. + * 2'b00 - 4 msec
  91880. + * 2'b01 - 8 msec
  91881. + * 2'b10 - 16 msec
  91882. + * 2'b11 - 32 msec
  91883. + */
  91884. + unsigned prb_dschg:2;
  91885. + /** Probe Delta (PRB_DELTA)
  91886. + * These bits set the resolution for RTIM value.
  91887. + * The bits are defined in units of 32 kHz clock cycles as follows:
  91888. + * 2'b00 - 1 cycles
  91889. + * 2'b01 - 2 cycles
  91890. + * 2'b10 - 3 cycles
  91891. + * 2'b11 - 4 cycles
  91892. + * For example if this value is chosen to 2'b01, it means that RTIM
  91893. + * increments for every 3(three) 32Khz clock cycles.
  91894. + */
  91895. + unsigned prb_delta:2;
  91896. + /** Probe Period (PRB_PER)
  91897. + * These bits sets the TADP_PRD as shown in Figure 4 as follows:
  91898. + * 2'b00 - 0.625 to 0.925 sec (typical 0.775 sec)
  91899. + * 2'b01 - 1.25 to 1.85 sec (typical 1.55 sec)
  91900. + * 2'b10 - 1.9 to 2.6 sec (typical 2.275 sec)
  91901. + * 2'b11 - Reserved
  91902. + */
  91903. + unsigned prb_per:2;
  91904. + /** These bits capture the latest time it took for VBUS to ramp from
  91905. + * VADP_SINK to VADP_PRB.
  91906. + * 0x000 - 1 cycles
  91907. + * 0x001 - 2 cycles
  91908. + * 0x002 - 3 cycles
  91909. + * etc
  91910. + * 0x7FF - 2048 cycles
  91911. + * A time of 1024 cycles at 32 kHz corresponds to a time of 32 msec.
  91912. + */
  91913. + unsigned rtim:11;
  91914. + /** Enable Probe (EnaPrb)
  91915. + * When programmed to 1'b1, the core performs a probe operation.
  91916. + * This bit is valid only if OTG_Ver = 1'b1.
  91917. + */
  91918. + unsigned enaprb:1;
  91919. + /** Enable Sense (EnaSns)
  91920. + * When programmed to 1'b1, the core performs a Sense operation.
  91921. + * This bit is valid only if OTG_Ver = 1'b1.
  91922. + */
  91923. + unsigned enasns:1;
  91924. + /** ADP Reset (ADPRes)
  91925. + * When set, ADP controller is reset.
  91926. + * This bit is valid only if OTG_Ver = 1'b1.
  91927. + */
  91928. + unsigned adpres:1;
  91929. + /** ADP Enable (ADPEn)
  91930. + * When set, the core performs either ADP probing or sensing
  91931. + * based on EnaPrb or EnaSns.
  91932. + * This bit is valid only if OTG_Ver = 1'b1.
  91933. + */
  91934. + unsigned adpen:1;
  91935. + /** ADP Probe Interrupt (ADP_PRB_INT)
  91936. + * When this bit is set, it means that the VBUS
  91937. + * voltage is greater than VADP_PRB or VADP_PRB is reached.
  91938. + * This bit is valid only if OTG_Ver = 1'b1.
  91939. + */
  91940. + unsigned adp_prb_int:1;
  91941. + /**
  91942. + * ADP Sense Interrupt (ADP_SNS_INT)
  91943. + * When this bit is set, it means that the VBUS voltage is greater than
  91944. + * VADP_SNS value or VADP_SNS is reached.
  91945. + * This bit is valid only if OTG_Ver = 1'b1.
  91946. + */
  91947. + unsigned adp_sns_int:1;
  91948. + /** ADP Tomeout Interrupt (ADP_TMOUT_INT)
  91949. + * This bit is relevant only for an ADP probe.
  91950. + * When this bit is set, it means that the ramp time has
  91951. + * completed ie ADPCTL.RTIM has reached its terminal value
  91952. + * of 0x7FF. This is a debug feature that allows software
  91953. + * to read the ramp time after each cycle.
  91954. + * This bit is valid only if OTG_Ver = 1'b1.
  91955. + */
  91956. + unsigned adp_tmout_int:1;
  91957. + /** ADP Probe Interrupt Mask (ADP_PRB_INT_MSK)
  91958. + * When this bit is set, it unmasks the interrupt due to ADP_PRB_INT.
  91959. + * This bit is valid only if OTG_Ver = 1'b1.
  91960. + */
  91961. + unsigned adp_prb_int_msk:1;
  91962. + /** ADP Sense Interrupt Mask (ADP_SNS_INT_MSK)
  91963. + * When this bit is set, it unmasks the interrupt due to ADP_SNS_INT.
  91964. + * This bit is valid only if OTG_Ver = 1'b1.
  91965. + */
  91966. + unsigned adp_sns_int_msk:1;
  91967. + /** ADP Timoeout Interrupt Mask (ADP_TMOUT_MSK)
  91968. + * When this bit is set, it unmasks the interrupt due to ADP_TMOUT_INT.
  91969. + * This bit is valid only if OTG_Ver = 1'b1.
  91970. + */
  91971. + unsigned adp_tmout_int_msk:1;
  91972. + /** Access Request
  91973. + * 2'b00 - Read/Write Valid (updated by the core)
  91974. + * 2'b01 - Read
  91975. + * 2'b00 - Write
  91976. + * 2'b00 - Reserved
  91977. + */
  91978. + unsigned ar:2;
  91979. + /** Reserved */
  91980. + unsigned reserved29_31:3;
  91981. + } b;
  91982. +} adpctl_data_t;
  91983. +
  91984. +////////////////////////////////////////////
  91985. +// Device Registers
  91986. +/**
  91987. + * Device Global Registers. <i>Offsets 800h-BFFh</i>
  91988. + *
  91989. + * The following structures define the size and relative field offsets
  91990. + * for the Device Mode Registers.
  91991. + *
  91992. + * <i>These registers are visible only in Device mode and must not be
  91993. + * accessed in Host mode, as the results are unknown.</i>
  91994. + */
  91995. +typedef struct dwc_otg_dev_global_regs {
  91996. + /** Device Configuration Register. <i>Offset 800h</i> */
  91997. + volatile uint32_t dcfg;
  91998. + /** Device Control Register. <i>Offset: 804h</i> */
  91999. + volatile uint32_t dctl;
  92000. + /** Device Status Register (Read Only). <i>Offset: 808h</i> */
  92001. + volatile uint32_t dsts;
  92002. + /** Reserved. <i>Offset: 80Ch</i> */
  92003. + uint32_t unused;
  92004. + /** Device IN Endpoint Common Interrupt Mask
  92005. + * Register. <i>Offset: 810h</i> */
  92006. + volatile uint32_t diepmsk;
  92007. + /** Device OUT Endpoint Common Interrupt Mask
  92008. + * Register. <i>Offset: 814h</i> */
  92009. + volatile uint32_t doepmsk;
  92010. + /** Device All Endpoints Interrupt Register. <i>Offset: 818h</i> */
  92011. + volatile uint32_t daint;
  92012. + /** Device All Endpoints Interrupt Mask Register. <i>Offset:
  92013. + * 81Ch</i> */
  92014. + volatile uint32_t daintmsk;
  92015. + /** Device IN Token Queue Read Register-1 (Read Only).
  92016. + * <i>Offset: 820h</i> */
  92017. + volatile uint32_t dtknqr1;
  92018. + /** Device IN Token Queue Read Register-2 (Read Only).
  92019. + * <i>Offset: 824h</i> */
  92020. + volatile uint32_t dtknqr2;
  92021. + /** Device VBUS discharge Register. <i>Offset: 828h</i> */
  92022. + volatile uint32_t dvbusdis;
  92023. + /** Device VBUS Pulse Register. <i>Offset: 82Ch</i> */
  92024. + volatile uint32_t dvbuspulse;
  92025. + /** Device IN Token Queue Read Register-3 (Read Only). /
  92026. + * Device Thresholding control register (Read/Write)
  92027. + * <i>Offset: 830h</i> */
  92028. + volatile uint32_t dtknqr3_dthrctl;
  92029. + /** Device IN Token Queue Read Register-4 (Read Only). /
  92030. + * Device IN EPs empty Inr. Mask Register (Read/Write)
  92031. + * <i>Offset: 834h</i> */
  92032. + volatile uint32_t dtknqr4_fifoemptymsk;
  92033. + /** Device Each Endpoint Interrupt Register (Read Only). /
  92034. + * <i>Offset: 838h</i> */
  92035. + volatile uint32_t deachint;
  92036. + /** Device Each Endpoint Interrupt mask Register (Read/Write). /
  92037. + * <i>Offset: 83Ch</i> */
  92038. + volatile uint32_t deachintmsk;
  92039. + /** Device Each In Endpoint Interrupt mask Register (Read/Write). /
  92040. + * <i>Offset: 840h</i> */
  92041. + volatile uint32_t diepeachintmsk[MAX_EPS_CHANNELS];
  92042. + /** Device Each Out Endpoint Interrupt mask Register (Read/Write). /
  92043. + * <i>Offset: 880h</i> */
  92044. + volatile uint32_t doepeachintmsk[MAX_EPS_CHANNELS];
  92045. +} dwc_otg_device_global_regs_t;
  92046. +
  92047. +/**
  92048. + * This union represents the bit fields in the Device Configuration
  92049. + * Register. Read the register into the <i>d32</i> member then
  92050. + * set/clear the bits using the <i>b</i>it elements. Write the
  92051. + * <i>d32</i> member to the dcfg register.
  92052. + */
  92053. +typedef union dcfg_data {
  92054. + /** raw register data */
  92055. + uint32_t d32;
  92056. + /** register bits */
  92057. + struct {
  92058. + /** Device Speed */
  92059. + unsigned devspd:2;
  92060. + /** Non Zero Length Status OUT Handshake */
  92061. + unsigned nzstsouthshk:1;
  92062. +#define DWC_DCFG_SEND_STALL 1
  92063. +
  92064. + unsigned ena32khzs:1;
  92065. + /** Device Addresses */
  92066. + unsigned devaddr:7;
  92067. + /** Periodic Frame Interval */
  92068. + unsigned perfrint:2;
  92069. +#define DWC_DCFG_FRAME_INTERVAL_80 0
  92070. +#define DWC_DCFG_FRAME_INTERVAL_85 1
  92071. +#define DWC_DCFG_FRAME_INTERVAL_90 2
  92072. +#define DWC_DCFG_FRAME_INTERVAL_95 3
  92073. +
  92074. + /** Enable Device OUT NAK for bulk in DDMA mode */
  92075. + unsigned endevoutnak:1;
  92076. +
  92077. + unsigned reserved14_17:4;
  92078. + /** In Endpoint Mis-match count */
  92079. + unsigned epmscnt:5;
  92080. + /** Enable Descriptor DMA in Device mode */
  92081. + unsigned descdma:1;
  92082. + unsigned perschintvl:2;
  92083. + unsigned resvalid:6;
  92084. + } b;
  92085. +} dcfg_data_t;
  92086. +
  92087. +/**
  92088. + * This union represents the bit fields in the Device Control
  92089. + * Register. Read the register into the <i>d32</i> member then
  92090. + * set/clear the bits using the <i>b</i>it elements.
  92091. + */
  92092. +typedef union dctl_data {
  92093. + /** raw register data */
  92094. + uint32_t d32;
  92095. + /** register bits */
  92096. + struct {
  92097. + /** Remote Wakeup */
  92098. + unsigned rmtwkupsig:1;
  92099. + /** Soft Disconnect */
  92100. + unsigned sftdiscon:1;
  92101. + /** Global Non-Periodic IN NAK Status */
  92102. + unsigned gnpinnaksts:1;
  92103. + /** Global OUT NAK Status */
  92104. + unsigned goutnaksts:1;
  92105. + /** Test Control */
  92106. + unsigned tstctl:3;
  92107. + /** Set Global Non-Periodic IN NAK */
  92108. + unsigned sgnpinnak:1;
  92109. + /** Clear Global Non-Periodic IN NAK */
  92110. + unsigned cgnpinnak:1;
  92111. + /** Set Global OUT NAK */
  92112. + unsigned sgoutnak:1;
  92113. + /** Clear Global OUT NAK */
  92114. + unsigned cgoutnak:1;
  92115. + /** Power-On Programming Done */
  92116. + unsigned pwronprgdone:1;
  92117. + /** Reserved */
  92118. + unsigned reserved:1;
  92119. + /** Global Multi Count */
  92120. + unsigned gmc:2;
  92121. + /** Ignore Frame Number for ISOC EPs */
  92122. + unsigned ifrmnum:1;
  92123. + /** NAK on Babble */
  92124. + unsigned nakonbble:1;
  92125. + /** Enable Continue on BNA */
  92126. + unsigned encontonbna:1;
  92127. +
  92128. + unsigned reserved18_31:14;
  92129. + } b;
  92130. +} dctl_data_t;
  92131. +
  92132. +/**
  92133. + * This union represents the bit fields in the Device Status
  92134. + * Register. Read the register into the <i>d32</i> member then
  92135. + * set/clear the bits using the <i>b</i>it elements.
  92136. + */
  92137. +typedef union dsts_data {
  92138. + /** raw register data */
  92139. + uint32_t d32;
  92140. + /** register bits */
  92141. + struct {
  92142. + /** Suspend Status */
  92143. + unsigned suspsts:1;
  92144. + /** Enumerated Speed */
  92145. + unsigned enumspd:2;
  92146. +#define DWC_DSTS_ENUMSPD_HS_PHY_30MHZ_OR_60MHZ 0
  92147. +#define DWC_DSTS_ENUMSPD_FS_PHY_30MHZ_OR_60MHZ 1
  92148. +#define DWC_DSTS_ENUMSPD_LS_PHY_6MHZ 2
  92149. +#define DWC_DSTS_ENUMSPD_FS_PHY_48MHZ 3
  92150. + /** Erratic Error */
  92151. + unsigned errticerr:1;
  92152. + unsigned reserved4_7:4;
  92153. + /** Frame or Microframe Number of the received SOF */
  92154. + unsigned soffn:14;
  92155. + unsigned reserved22_31:10;
  92156. + } b;
  92157. +} dsts_data_t;
  92158. +
  92159. +/**
  92160. + * This union represents the bit fields in the Device IN EP Interrupt
  92161. + * Register and the Device IN EP Common Mask Register.
  92162. + *
  92163. + * - Read the register into the <i>d32</i> member then set/clear the
  92164. + * bits using the <i>b</i>it elements.
  92165. + */
  92166. +typedef union diepint_data {
  92167. + /** raw register data */
  92168. + uint32_t d32;
  92169. + /** register bits */
  92170. + struct {
  92171. + /** Transfer complete mask */
  92172. + unsigned xfercompl:1;
  92173. + /** Endpoint disable mask */
  92174. + unsigned epdisabled:1;
  92175. + /** AHB Error mask */
  92176. + unsigned ahberr:1;
  92177. + /** TimeOUT Handshake mask (non-ISOC EPs) */
  92178. + unsigned timeout:1;
  92179. + /** IN Token received with TxF Empty mask */
  92180. + unsigned intktxfemp:1;
  92181. + /** IN Token Received with EP mismatch mask */
  92182. + unsigned intknepmis:1;
  92183. + /** IN Endpoint NAK Effective mask */
  92184. + unsigned inepnakeff:1;
  92185. + /** Reserved */
  92186. + unsigned emptyintr:1;
  92187. +
  92188. + unsigned txfifoundrn:1;
  92189. +
  92190. + /** BNA Interrupt mask */
  92191. + unsigned bna:1;
  92192. +
  92193. + unsigned reserved10_12:3;
  92194. + /** BNA Interrupt mask */
  92195. + unsigned nak:1;
  92196. +
  92197. + unsigned reserved14_31:18;
  92198. + } b;
  92199. +} diepint_data_t;
  92200. +
  92201. +/**
  92202. + * This union represents the bit fields in the Device IN EP
  92203. + * Common/Dedicated Interrupt Mask Register.
  92204. + */
  92205. +typedef union diepint_data diepmsk_data_t;
  92206. +
  92207. +/**
  92208. + * This union represents the bit fields in the Device OUT EP Interrupt
  92209. + * Registerand Device OUT EP Common Interrupt Mask Register.
  92210. + *
  92211. + * - Read the register into the <i>d32</i> member then set/clear the
  92212. + * bits using the <i>b</i>it elements.
  92213. + */
  92214. +typedef union doepint_data {
  92215. + /** raw register data */
  92216. + uint32_t d32;
  92217. + /** register bits */
  92218. + struct {
  92219. + /** Transfer complete */
  92220. + unsigned xfercompl:1;
  92221. + /** Endpoint disable */
  92222. + unsigned epdisabled:1;
  92223. + /** AHB Error */
  92224. + unsigned ahberr:1;
  92225. + /** Setup Phase Done (contorl EPs) */
  92226. + unsigned setup:1;
  92227. + /** OUT Token Received when Endpoint Disabled */
  92228. + unsigned outtknepdis:1;
  92229. +
  92230. + unsigned stsphsercvd:1;
  92231. + /** Back-to-Back SETUP Packets Received */
  92232. + unsigned back2backsetup:1;
  92233. +
  92234. + unsigned reserved7:1;
  92235. + /** OUT packet Error */
  92236. + unsigned outpkterr:1;
  92237. + /** BNA Interrupt */
  92238. + unsigned bna:1;
  92239. +
  92240. + unsigned reserved10:1;
  92241. + /** Packet Drop Status */
  92242. + unsigned pktdrpsts:1;
  92243. + /** Babble Interrupt */
  92244. + unsigned babble:1;
  92245. + /** NAK Interrupt */
  92246. + unsigned nak:1;
  92247. + /** NYET Interrupt */
  92248. + unsigned nyet:1;
  92249. + /** Bit indicating setup packet received */
  92250. + unsigned sr:1;
  92251. +
  92252. + unsigned reserved16_31:16;
  92253. + } b;
  92254. +} doepint_data_t;
  92255. +
  92256. +/**
  92257. + * This union represents the bit fields in the Device OUT EP
  92258. + * Common/Dedicated Interrupt Mask Register.
  92259. + */
  92260. +typedef union doepint_data doepmsk_data_t;
  92261. +
  92262. +/**
  92263. + * This union represents the bit fields in the Device All EP Interrupt
  92264. + * and Mask Registers.
  92265. + * - Read the register into the <i>d32</i> member then set/clear the
  92266. + * bits using the <i>b</i>it elements.
  92267. + */
  92268. +typedef union daint_data {
  92269. + /** raw register data */
  92270. + uint32_t d32;
  92271. + /** register bits */
  92272. + struct {
  92273. + /** IN Endpoint bits */
  92274. + unsigned in:16;
  92275. + /** OUT Endpoint bits */
  92276. + unsigned out:16;
  92277. + } ep;
  92278. + struct {
  92279. + /** IN Endpoint bits */
  92280. + unsigned inep0:1;
  92281. + unsigned inep1:1;
  92282. + unsigned inep2:1;
  92283. + unsigned inep3:1;
  92284. + unsigned inep4:1;
  92285. + unsigned inep5:1;
  92286. + unsigned inep6:1;
  92287. + unsigned inep7:1;
  92288. + unsigned inep8:1;
  92289. + unsigned inep9:1;
  92290. + unsigned inep10:1;
  92291. + unsigned inep11:1;
  92292. + unsigned inep12:1;
  92293. + unsigned inep13:1;
  92294. + unsigned inep14:1;
  92295. + unsigned inep15:1;
  92296. + /** OUT Endpoint bits */
  92297. + unsigned outep0:1;
  92298. + unsigned outep1:1;
  92299. + unsigned outep2:1;
  92300. + unsigned outep3:1;
  92301. + unsigned outep4:1;
  92302. + unsigned outep5:1;
  92303. + unsigned outep6:1;
  92304. + unsigned outep7:1;
  92305. + unsigned outep8:1;
  92306. + unsigned outep9:1;
  92307. + unsigned outep10:1;
  92308. + unsigned outep11:1;
  92309. + unsigned outep12:1;
  92310. + unsigned outep13:1;
  92311. + unsigned outep14:1;
  92312. + unsigned outep15:1;
  92313. + } b;
  92314. +} daint_data_t;
  92315. +
  92316. +/**
  92317. + * This union represents the bit fields in the Device IN Token Queue
  92318. + * Read Registers.
  92319. + * - Read the register into the <i>d32</i> member.
  92320. + * - READ-ONLY Register
  92321. + */
  92322. +typedef union dtknq1_data {
  92323. + /** raw register data */
  92324. + uint32_t d32;
  92325. + /** register bits */
  92326. + struct {
  92327. + /** In Token Queue Write Pointer */
  92328. + unsigned intknwptr:5;
  92329. + /** Reserved */
  92330. + unsigned reserved05_06:2;
  92331. + /** write pointer has wrapped. */
  92332. + unsigned wrap_bit:1;
  92333. + /** EP Numbers of IN Tokens 0 ... 4 */
  92334. + unsigned epnums0_5:24;
  92335. + } b;
  92336. +} dtknq1_data_t;
  92337. +
  92338. +/**
  92339. + * This union represents Threshold control Register
  92340. + * - Read and write the register into the <i>d32</i> member.
  92341. + * - READ-WRITABLE Register
  92342. + */
  92343. +typedef union dthrctl_data {
  92344. + /** raw register data */
  92345. + uint32_t d32;
  92346. + /** register bits */
  92347. + struct {
  92348. + /** non ISO Tx Thr. Enable */
  92349. + unsigned non_iso_thr_en:1;
  92350. + /** ISO Tx Thr. Enable */
  92351. + unsigned iso_thr_en:1;
  92352. + /** Tx Thr. Length */
  92353. + unsigned tx_thr_len:9;
  92354. + /** AHB Threshold ratio */
  92355. + unsigned ahb_thr_ratio:2;
  92356. + /** Reserved */
  92357. + unsigned reserved13_15:3;
  92358. + /** Rx Thr. Enable */
  92359. + unsigned rx_thr_en:1;
  92360. + /** Rx Thr. Length */
  92361. + unsigned rx_thr_len:9;
  92362. + unsigned reserved26:1;
  92363. + /** Arbiter Parking Enable*/
  92364. + unsigned arbprken:1;
  92365. + /** Reserved */
  92366. + unsigned reserved28_31:4;
  92367. + } b;
  92368. +} dthrctl_data_t;
  92369. +
  92370. +/**
  92371. + * Device Logical IN Endpoint-Specific Registers. <i>Offsets
  92372. + * 900h-AFCh</i>
  92373. + *
  92374. + * There will be one set of endpoint registers per logical endpoint
  92375. + * implemented.
  92376. + *
  92377. + * <i>These registers are visible only in Device mode and must not be
  92378. + * accessed in Host mode, as the results are unknown.</i>
  92379. + */
  92380. +typedef struct dwc_otg_dev_in_ep_regs {
  92381. + /** Device IN Endpoint Control Register. <i>Offset:900h +
  92382. + * (ep_num * 20h) + 00h</i> */
  92383. + volatile uint32_t diepctl;
  92384. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 04h</i> */
  92385. + uint32_t reserved04;
  92386. + /** Device IN Endpoint Interrupt Register. <i>Offset:900h +
  92387. + * (ep_num * 20h) + 08h</i> */
  92388. + volatile uint32_t diepint;
  92389. + /** Reserved. <i>Offset:900h + (ep_num * 20h) + 0Ch</i> */
  92390. + uint32_t reserved0C;
  92391. + /** Device IN Endpoint Transfer Size
  92392. + * Register. <i>Offset:900h + (ep_num * 20h) + 10h</i> */
  92393. + volatile uint32_t dieptsiz;
  92394. + /** Device IN Endpoint DMA Address Register. <i>Offset:900h +
  92395. + * (ep_num * 20h) + 14h</i> */
  92396. + volatile uint32_t diepdma;
  92397. + /** Device IN Endpoint Transmit FIFO Status Register. <i>Offset:900h +
  92398. + * (ep_num * 20h) + 18h</i> */
  92399. + volatile uint32_t dtxfsts;
  92400. + /** Device IN Endpoint DMA Buffer Register. <i>Offset:900h +
  92401. + * (ep_num * 20h) + 1Ch</i> */
  92402. + volatile uint32_t diepdmab;
  92403. +} dwc_otg_dev_in_ep_regs_t;
  92404. +
  92405. +/**
  92406. + * Device Logical OUT Endpoint-Specific Registers. <i>Offsets:
  92407. + * B00h-CFCh</i>
  92408. + *
  92409. + * There will be one set of endpoint registers per logical endpoint
  92410. + * implemented.
  92411. + *
  92412. + * <i>These registers are visible only in Device mode and must not be
  92413. + * accessed in Host mode, as the results are unknown.</i>
  92414. + */
  92415. +typedef struct dwc_otg_dev_out_ep_regs {
  92416. + /** Device OUT Endpoint Control Register. <i>Offset:B00h +
  92417. + * (ep_num * 20h) + 00h</i> */
  92418. + volatile uint32_t doepctl;
  92419. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 04h</i> */
  92420. + uint32_t reserved04;
  92421. + /** Device OUT Endpoint Interrupt Register. <i>Offset:B00h +
  92422. + * (ep_num * 20h) + 08h</i> */
  92423. + volatile uint32_t doepint;
  92424. + /** Reserved. <i>Offset:B00h + (ep_num * 20h) + 0Ch</i> */
  92425. + uint32_t reserved0C;
  92426. + /** Device OUT Endpoint Transfer Size Register. <i>Offset:
  92427. + * B00h + (ep_num * 20h) + 10h</i> */
  92428. + volatile uint32_t doeptsiz;
  92429. + /** Device OUT Endpoint DMA Address Register. <i>Offset:B00h
  92430. + * + (ep_num * 20h) + 14h</i> */
  92431. + volatile uint32_t doepdma;
  92432. + /** Reserved. <i>Offset:B00h + * (ep_num * 20h) + 18h</i> */
  92433. + uint32_t unused;
  92434. + /** Device OUT Endpoint DMA Buffer Register. <i>Offset:B00h
  92435. + * + (ep_num * 20h) + 1Ch</i> */
  92436. + uint32_t doepdmab;
  92437. +} dwc_otg_dev_out_ep_regs_t;
  92438. +
  92439. +/**
  92440. + * This union represents the bit fields in the Device EP Control
  92441. + * Register. Read the register into the <i>d32</i> member then
  92442. + * set/clear the bits using the <i>b</i>it elements.
  92443. + */
  92444. +typedef union depctl_data {
  92445. + /** raw register data */
  92446. + uint32_t d32;
  92447. + /** register bits */
  92448. + struct {
  92449. + /** Maximum Packet Size
  92450. + * IN/OUT EPn
  92451. + * IN/OUT EP0 - 2 bits
  92452. + * 2'b00: 64 Bytes
  92453. + * 2'b01: 32
  92454. + * 2'b10: 16
  92455. + * 2'b11: 8 */
  92456. + unsigned mps:11;
  92457. +#define DWC_DEP0CTL_MPS_64 0
  92458. +#define DWC_DEP0CTL_MPS_32 1
  92459. +#define DWC_DEP0CTL_MPS_16 2
  92460. +#define DWC_DEP0CTL_MPS_8 3
  92461. +
  92462. + /** Next Endpoint
  92463. + * IN EPn/IN EP0
  92464. + * OUT EPn/OUT EP0 - reserved */
  92465. + unsigned nextep:4;
  92466. +
  92467. + /** USB Active Endpoint */
  92468. + unsigned usbactep:1;
  92469. +
  92470. + /** Endpoint DPID (INTR/Bulk IN and OUT endpoints)
  92471. + * This field contains the PID of the packet going to
  92472. + * be received or transmitted on this endpoint. The
  92473. + * application should program the PID of the first
  92474. + * packet going to be received or transmitted on this
  92475. + * endpoint , after the endpoint is
  92476. + * activated. Application use the SetD1PID and
  92477. + * SetD0PID fields of this register to program either
  92478. + * D0 or D1 PID.
  92479. + *
  92480. + * The encoding for this field is
  92481. + * - 0: D0
  92482. + * - 1: D1
  92483. + */
  92484. + unsigned dpid:1;
  92485. +
  92486. + /** NAK Status */
  92487. + unsigned naksts:1;
  92488. +
  92489. + /** Endpoint Type
  92490. + * 2'b00: Control
  92491. + * 2'b01: Isochronous
  92492. + * 2'b10: Bulk
  92493. + * 2'b11: Interrupt */
  92494. + unsigned eptype:2;
  92495. +
  92496. + /** Snoop Mode
  92497. + * OUT EPn/OUT EP0
  92498. + * IN EPn/IN EP0 - reserved */
  92499. + unsigned snp:1;
  92500. +
  92501. + /** Stall Handshake */
  92502. + unsigned stall:1;
  92503. +
  92504. + /** Tx Fifo Number
  92505. + * IN EPn/IN EP0
  92506. + * OUT EPn/OUT EP0 - reserved */
  92507. + unsigned txfnum:4;
  92508. +
  92509. + /** Clear NAK */
  92510. + unsigned cnak:1;
  92511. + /** Set NAK */
  92512. + unsigned snak:1;
  92513. + /** Set DATA0 PID (INTR/Bulk IN and OUT endpoints)
  92514. + * Writing to this field sets the Endpoint DPID (DPID)
  92515. + * field in this register to DATA0. Set Even
  92516. + * (micro)frame (SetEvenFr) (ISO IN and OUT Endpoints)
  92517. + * Writing to this field sets the Even/Odd
  92518. + * (micro)frame (EO_FrNum) field to even (micro)
  92519. + * frame.
  92520. + */
  92521. + unsigned setd0pid:1;
  92522. + /** Set DATA1 PID (INTR/Bulk IN and OUT endpoints)
  92523. + * Writing to this field sets the Endpoint DPID (DPID)
  92524. + * field in this register to DATA1 Set Odd
  92525. + * (micro)frame (SetOddFr) (ISO IN and OUT Endpoints)
  92526. + * Writing to this field sets the Even/Odd
  92527. + * (micro)frame (EO_FrNum) field to odd (micro) frame.
  92528. + */
  92529. + unsigned setd1pid:1;
  92530. +
  92531. + /** Endpoint Disable */
  92532. + unsigned epdis:1;
  92533. + /** Endpoint Enable */
  92534. + unsigned epena:1;
  92535. + } b;
  92536. +} depctl_data_t;
  92537. +
  92538. +/**
  92539. + * This union represents the bit fields in the Device EP Transfer
  92540. + * Size Register. Read the register into the <i>d32</i> member then
  92541. + * set/clear the bits using the <i>b</i>it elements.
  92542. + */
  92543. +typedef union deptsiz_data {
  92544. + /** raw register data */
  92545. + uint32_t d32;
  92546. + /** register bits */
  92547. + struct {
  92548. + /** Transfer size */
  92549. + unsigned xfersize:19;
  92550. +/** Max packet count for EP (pow(2,10)-1) */
  92551. +#define MAX_PKT_CNT 1023
  92552. + /** Packet Count */
  92553. + unsigned pktcnt:10;
  92554. + /** Multi Count - Periodic IN endpoints */
  92555. + unsigned mc:2;
  92556. + unsigned reserved:1;
  92557. + } b;
  92558. +} deptsiz_data_t;
  92559. +
  92560. +/**
  92561. + * This union represents the bit fields in the Device EP 0 Transfer
  92562. + * Size Register. Read the register into the <i>d32</i> member then
  92563. + * set/clear the bits using the <i>b</i>it elements.
  92564. + */
  92565. +typedef union deptsiz0_data {
  92566. + /** raw register data */
  92567. + uint32_t d32;
  92568. + /** register bits */
  92569. + struct {
  92570. + /** Transfer size */
  92571. + unsigned xfersize:7;
  92572. + /** Reserved */
  92573. + unsigned reserved7_18:12;
  92574. + /** Packet Count */
  92575. + unsigned pktcnt:2;
  92576. + /** Reserved */
  92577. + unsigned reserved21_28:8;
  92578. + /**Setup Packet Count (DOEPTSIZ0 Only) */
  92579. + unsigned supcnt:2;
  92580. + unsigned reserved31;
  92581. + } b;
  92582. +} deptsiz0_data_t;
  92583. +
  92584. +/////////////////////////////////////////////////
  92585. +// DMA Descriptor Specific Structures
  92586. +//
  92587. +
  92588. +/** Buffer status definitions */
  92589. +
  92590. +#define BS_HOST_READY 0x0
  92591. +#define BS_DMA_BUSY 0x1
  92592. +#define BS_DMA_DONE 0x2
  92593. +#define BS_HOST_BUSY 0x3
  92594. +
  92595. +/** Receive/Transmit status definitions */
  92596. +
  92597. +#define RTS_SUCCESS 0x0
  92598. +#define RTS_BUFFLUSH 0x1
  92599. +#define RTS_RESERVED 0x2
  92600. +#define RTS_BUFERR 0x3
  92601. +
  92602. +/**
  92603. + * This union represents the bit fields in the DMA Descriptor
  92604. + * status quadlet. Read the quadlet into the <i>d32</i> member then
  92605. + * set/clear the bits using the <i>b</i>it, <i>b_iso_out</i> and
  92606. + * <i>b_iso_in</i> elements.
  92607. + */
  92608. +typedef union dev_dma_desc_sts {
  92609. + /** raw register data */
  92610. + uint32_t d32;
  92611. + /** quadlet bits */
  92612. + struct {
  92613. + /** Received number of bytes */
  92614. + unsigned bytes:16;
  92615. + /** NAK bit - only for OUT EPs */
  92616. + unsigned nak:1;
  92617. + unsigned reserved17_22:6;
  92618. + /** Multiple Transfer - only for OUT EPs */
  92619. + unsigned mtrf:1;
  92620. + /** Setup Packet received - only for OUT EPs */
  92621. + unsigned sr:1;
  92622. + /** Interrupt On Complete */
  92623. + unsigned ioc:1;
  92624. + /** Short Packet */
  92625. + unsigned sp:1;
  92626. + /** Last */
  92627. + unsigned l:1;
  92628. + /** Receive Status */
  92629. + unsigned sts:2;
  92630. + /** Buffer Status */
  92631. + unsigned bs:2;
  92632. + } b;
  92633. +
  92634. +//#ifdef DWC_EN_ISOC
  92635. + /** iso out quadlet bits */
  92636. + struct {
  92637. + /** Received number of bytes */
  92638. + unsigned rxbytes:11;
  92639. +
  92640. + unsigned reserved11:1;
  92641. + /** Frame Number */
  92642. + unsigned framenum:11;
  92643. + /** Received ISO Data PID */
  92644. + unsigned pid:2;
  92645. + /** Interrupt On Complete */
  92646. + unsigned ioc:1;
  92647. + /** Short Packet */
  92648. + unsigned sp:1;
  92649. + /** Last */
  92650. + unsigned l:1;
  92651. + /** Receive Status */
  92652. + unsigned rxsts:2;
  92653. + /** Buffer Status */
  92654. + unsigned bs:2;
  92655. + } b_iso_out;
  92656. +
  92657. + /** iso in quadlet bits */
  92658. + struct {
  92659. + /** Transmited number of bytes */
  92660. + unsigned txbytes:12;
  92661. + /** Frame Number */
  92662. + unsigned framenum:11;
  92663. + /** Transmited ISO Data PID */
  92664. + unsigned pid:2;
  92665. + /** Interrupt On Complete */
  92666. + unsigned ioc:1;
  92667. + /** Short Packet */
  92668. + unsigned sp:1;
  92669. + /** Last */
  92670. + unsigned l:1;
  92671. + /** Transmit Status */
  92672. + unsigned txsts:2;
  92673. + /** Buffer Status */
  92674. + unsigned bs:2;
  92675. + } b_iso_in;
  92676. +//#endif /* DWC_EN_ISOC */
  92677. +} dev_dma_desc_sts_t;
  92678. +
  92679. +/**
  92680. + * DMA Descriptor structure
  92681. + *
  92682. + * DMA Descriptor structure contains two quadlets:
  92683. + * Status quadlet and Data buffer pointer.
  92684. + */
  92685. +typedef struct dwc_otg_dev_dma_desc {
  92686. + /** DMA Descriptor status quadlet */
  92687. + dev_dma_desc_sts_t status;
  92688. + /** DMA Descriptor data buffer pointer */
  92689. + uint32_t buf;
  92690. +} dwc_otg_dev_dma_desc_t;
  92691. +
  92692. +/**
  92693. + * The dwc_otg_dev_if structure contains information needed to manage
  92694. + * the DWC_otg controller acting in device mode. It represents the
  92695. + * programming view of the device-specific aspects of the controller.
  92696. + */
  92697. +typedef struct dwc_otg_dev_if {
  92698. + /** Pointer to device Global registers.
  92699. + * Device Global Registers starting at offset 800h
  92700. + */
  92701. + dwc_otg_device_global_regs_t *dev_global_regs;
  92702. +#define DWC_DEV_GLOBAL_REG_OFFSET 0x800
  92703. +
  92704. + /**
  92705. + * Device Logical IN Endpoint-Specific Registers 900h-AFCh
  92706. + */
  92707. + dwc_otg_dev_in_ep_regs_t *in_ep_regs[MAX_EPS_CHANNELS];
  92708. +#define DWC_DEV_IN_EP_REG_OFFSET 0x900
  92709. +#define DWC_EP_REG_OFFSET 0x20
  92710. +
  92711. + /** Device Logical OUT Endpoint-Specific Registers B00h-CFCh */
  92712. + dwc_otg_dev_out_ep_regs_t *out_ep_regs[MAX_EPS_CHANNELS];
  92713. +#define DWC_DEV_OUT_EP_REG_OFFSET 0xB00
  92714. +
  92715. + /* Device configuration information */
  92716. + uint8_t speed; /**< Device Speed 0: Unknown, 1: LS, 2:FS, 3: HS */
  92717. + uint8_t num_in_eps; /**< Number # of Tx EP range: 0-15 exept ep0 */
  92718. + uint8_t num_out_eps; /**< Number # of Rx EP range: 0-15 exept ep 0*/
  92719. +
  92720. + /** Size of periodic FIFOs (Bytes) */
  92721. + uint16_t perio_tx_fifo_size[MAX_PERIO_FIFOS];
  92722. +
  92723. + /** Size of Tx FIFOs (Bytes) */
  92724. + uint16_t tx_fifo_size[MAX_TX_FIFOS];
  92725. +
  92726. + /** Thresholding enable flags and length varaiables **/
  92727. + uint16_t rx_thr_en;
  92728. + uint16_t iso_tx_thr_en;
  92729. + uint16_t non_iso_tx_thr_en;
  92730. +
  92731. + uint16_t rx_thr_length;
  92732. + uint16_t tx_thr_length;
  92733. +
  92734. + /**
  92735. + * Pointers to the DMA Descriptors for EP0 Control
  92736. + * transfers (virtual and physical)
  92737. + */
  92738. +
  92739. + /** 2 descriptors for SETUP packets */
  92740. + dwc_dma_t dma_setup_desc_addr[2];
  92741. + dwc_otg_dev_dma_desc_t *setup_desc_addr[2];
  92742. +
  92743. + /** Pointer to Descriptor with latest SETUP packet */
  92744. + dwc_otg_dev_dma_desc_t *psetup;
  92745. +
  92746. + /** Index of current SETUP handler descriptor */
  92747. + uint32_t setup_desc_index;
  92748. +
  92749. + /** Descriptor for Data In or Status In phases */
  92750. + dwc_dma_t dma_in_desc_addr;
  92751. + dwc_otg_dev_dma_desc_t *in_desc_addr;
  92752. +
  92753. + /** Descriptor for Data Out or Status Out phases */
  92754. + dwc_dma_t dma_out_desc_addr;
  92755. + dwc_otg_dev_dma_desc_t *out_desc_addr;
  92756. +
  92757. + /** Setup Packet Detected - if set clear NAK when queueing */
  92758. + uint32_t spd;
  92759. + /** Isoc ep pointer on which incomplete happens */
  92760. + void *isoc_ep;
  92761. +
  92762. +} dwc_otg_dev_if_t;
  92763. +
  92764. +/////////////////////////////////////////////////
  92765. +// Host Mode Register Structures
  92766. +//
  92767. +/**
  92768. + * The Host Global Registers structure defines the size and relative
  92769. + * field offsets for the Host Mode Global Registers. Host Global
  92770. + * Registers offsets 400h-7FFh.
  92771. +*/
  92772. +typedef struct dwc_otg_host_global_regs {
  92773. + /** Host Configuration Register. <i>Offset: 400h</i> */
  92774. + volatile uint32_t hcfg;
  92775. + /** Host Frame Interval Register. <i>Offset: 404h</i> */
  92776. + volatile uint32_t hfir;
  92777. + /** Host Frame Number / Frame Remaining Register. <i>Offset: 408h</i> */
  92778. + volatile uint32_t hfnum;
  92779. + /** Reserved. <i>Offset: 40Ch</i> */
  92780. + uint32_t reserved40C;
  92781. + /** Host Periodic Transmit FIFO/ Queue Status Register. <i>Offset: 410h</i> */
  92782. + volatile uint32_t hptxsts;
  92783. + /** Host All Channels Interrupt Register. <i>Offset: 414h</i> */
  92784. + volatile uint32_t haint;
  92785. + /** Host All Channels Interrupt Mask Register. <i>Offset: 418h</i> */
  92786. + volatile uint32_t haintmsk;
  92787. + /** Host Frame List Base Address Register . <i>Offset: 41Ch</i> */
  92788. + volatile uint32_t hflbaddr;
  92789. +} dwc_otg_host_global_regs_t;
  92790. +
  92791. +/**
  92792. + * This union represents the bit fields in the Host Configuration Register.
  92793. + * Read the register into the <i>d32</i> member then set/clear the bits using
  92794. + * the <i>b</i>it elements. Write the <i>d32</i> member to the hcfg register.
  92795. + */
  92796. +typedef union hcfg_data {
  92797. + /** raw register data */
  92798. + uint32_t d32;
  92799. +
  92800. + /** register bits */
  92801. + struct {
  92802. + /** FS/LS Phy Clock Select */
  92803. + unsigned fslspclksel:2;
  92804. +#define DWC_HCFG_30_60_MHZ 0
  92805. +#define DWC_HCFG_48_MHZ 1
  92806. +#define DWC_HCFG_6_MHZ 2
  92807. +
  92808. + /** FS/LS Only Support */
  92809. + unsigned fslssupp:1;
  92810. + unsigned reserved3_6:4;
  92811. + /** Enable 32-KHz Suspend Mode */
  92812. + unsigned ena32khzs:1;
  92813. + /** Resume Validation Periiod */
  92814. + unsigned resvalid:8;
  92815. + unsigned reserved16_22:7;
  92816. + /** Enable Scatter/gather DMA in Host mode */
  92817. + unsigned descdma:1;
  92818. + /** Frame List Entries */
  92819. + unsigned frlisten:2;
  92820. + /** Enable Periodic Scheduling */
  92821. + unsigned perschedena:1;
  92822. + unsigned reserved27_30:4;
  92823. + unsigned modechtimen:1;
  92824. + } b;
  92825. +} hcfg_data_t;
  92826. +
  92827. +/**
  92828. + * This union represents the bit fields in the Host Frame Remaing/Number
  92829. + * Register.
  92830. + */
  92831. +typedef union hfir_data {
  92832. + /** raw register data */
  92833. + uint32_t d32;
  92834. +
  92835. + /** register bits */
  92836. + struct {
  92837. + unsigned frint:16;
  92838. + unsigned hfirrldctrl:1;
  92839. + unsigned reserved:15;
  92840. + } b;
  92841. +} hfir_data_t;
  92842. +
  92843. +/**
  92844. + * This union represents the bit fields in the Host Frame Remaing/Number
  92845. + * Register.
  92846. + */
  92847. +typedef union hfnum_data {
  92848. + /** raw register data */
  92849. + uint32_t d32;
  92850. +
  92851. + /** register bits */
  92852. + struct {
  92853. + unsigned frnum:16;
  92854. +#define DWC_HFNUM_MAX_FRNUM 0x3FFF
  92855. + unsigned frrem:16;
  92856. + } b;
  92857. +} hfnum_data_t;
  92858. +
  92859. +typedef union hptxsts_data {
  92860. + /** raw register data */
  92861. + uint32_t d32;
  92862. +
  92863. + /** register bits */
  92864. + struct {
  92865. + unsigned ptxfspcavail:16;
  92866. + unsigned ptxqspcavail:8;
  92867. + /** Top of the Periodic Transmit Request Queue
  92868. + * - bit 24 - Terminate (last entry for the selected channel)
  92869. + * - bits 26:25 - Token Type
  92870. + * - 2'b00 - Zero length
  92871. + * - 2'b01 - Ping
  92872. + * - 2'b10 - Disable
  92873. + * - bits 30:27 - Channel Number
  92874. + * - bit 31 - Odd/even microframe
  92875. + */
  92876. + unsigned ptxqtop_terminate:1;
  92877. + unsigned ptxqtop_token:2;
  92878. + unsigned ptxqtop_chnum:4;
  92879. + unsigned ptxqtop_odd:1;
  92880. + } b;
  92881. +} hptxsts_data_t;
  92882. +
  92883. +/**
  92884. + * This union represents the bit fields in the Host Port Control and Status
  92885. + * Register. Read the register into the <i>d32</i> member then set/clear the
  92886. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  92887. + * hprt0 register.
  92888. + */
  92889. +typedef union hprt0_data {
  92890. + /** raw register data */
  92891. + uint32_t d32;
  92892. + /** register bits */
  92893. + struct {
  92894. + unsigned prtconnsts:1;
  92895. + unsigned prtconndet:1;
  92896. + unsigned prtena:1;
  92897. + unsigned prtenchng:1;
  92898. + unsigned prtovrcurract:1;
  92899. + unsigned prtovrcurrchng:1;
  92900. + unsigned prtres:1;
  92901. + unsigned prtsusp:1;
  92902. + unsigned prtrst:1;
  92903. + unsigned reserved9:1;
  92904. + unsigned prtlnsts:2;
  92905. + unsigned prtpwr:1;
  92906. + unsigned prttstctl:4;
  92907. + unsigned prtspd:2;
  92908. +#define DWC_HPRT0_PRTSPD_HIGH_SPEED 0
  92909. +#define DWC_HPRT0_PRTSPD_FULL_SPEED 1
  92910. +#define DWC_HPRT0_PRTSPD_LOW_SPEED 2
  92911. + unsigned reserved19_31:13;
  92912. + } b;
  92913. +} hprt0_data_t;
  92914. +
  92915. +/**
  92916. + * This union represents the bit fields in the Host All Interrupt
  92917. + * Register.
  92918. + */
  92919. +typedef union haint_data {
  92920. + /** raw register data */
  92921. + uint32_t d32;
  92922. + /** register bits */
  92923. + struct {
  92924. + unsigned ch0:1;
  92925. + unsigned ch1:1;
  92926. + unsigned ch2:1;
  92927. + unsigned ch3:1;
  92928. + unsigned ch4:1;
  92929. + unsigned ch5:1;
  92930. + unsigned ch6:1;
  92931. + unsigned ch7:1;
  92932. + unsigned ch8:1;
  92933. + unsigned ch9:1;
  92934. + unsigned ch10:1;
  92935. + unsigned ch11:1;
  92936. + unsigned ch12:1;
  92937. + unsigned ch13:1;
  92938. + unsigned ch14:1;
  92939. + unsigned ch15:1;
  92940. + unsigned reserved:16;
  92941. + } b;
  92942. +
  92943. + struct {
  92944. + unsigned chint:16;
  92945. + unsigned reserved:16;
  92946. + } b2;
  92947. +} haint_data_t;
  92948. +
  92949. +/**
  92950. + * This union represents the bit fields in the Host All Interrupt
  92951. + * Register.
  92952. + */
  92953. +typedef union haintmsk_data {
  92954. + /** raw register data */
  92955. + uint32_t d32;
  92956. + /** register bits */
  92957. + struct {
  92958. + unsigned ch0:1;
  92959. + unsigned ch1:1;
  92960. + unsigned ch2:1;
  92961. + unsigned ch3:1;
  92962. + unsigned ch4:1;
  92963. + unsigned ch5:1;
  92964. + unsigned ch6:1;
  92965. + unsigned ch7:1;
  92966. + unsigned ch8:1;
  92967. + unsigned ch9:1;
  92968. + unsigned ch10:1;
  92969. + unsigned ch11:1;
  92970. + unsigned ch12:1;
  92971. + unsigned ch13:1;
  92972. + unsigned ch14:1;
  92973. + unsigned ch15:1;
  92974. + unsigned reserved:16;
  92975. + } b;
  92976. +
  92977. + struct {
  92978. + unsigned chint:16;
  92979. + unsigned reserved:16;
  92980. + } b2;
  92981. +} haintmsk_data_t;
  92982. +
  92983. +/**
  92984. + * Host Channel Specific Registers. <i>500h-5FCh</i>
  92985. + */
  92986. +typedef struct dwc_otg_hc_regs {
  92987. + /** Host Channel 0 Characteristic Register. <i>Offset: 500h + (chan_num * 20h) + 00h</i> */
  92988. + volatile uint32_t hcchar;
  92989. + /** Host Channel 0 Split Control Register. <i>Offset: 500h + (chan_num * 20h) + 04h</i> */
  92990. + volatile uint32_t hcsplt;
  92991. + /** Host Channel 0 Interrupt Register. <i>Offset: 500h + (chan_num * 20h) + 08h</i> */
  92992. + volatile uint32_t hcint;
  92993. + /** Host Channel 0 Interrupt Mask Register. <i>Offset: 500h + (chan_num * 20h) + 0Ch</i> */
  92994. + volatile uint32_t hcintmsk;
  92995. + /** Host Channel 0 Transfer Size Register. <i>Offset: 500h + (chan_num * 20h) + 10h</i> */
  92996. + volatile uint32_t hctsiz;
  92997. + /** Host Channel 0 DMA Address Register. <i>Offset: 500h + (chan_num * 20h) + 14h</i> */
  92998. + volatile uint32_t hcdma;
  92999. + volatile uint32_t reserved;
  93000. + /** Host Channel 0 DMA Buffer Address Register. <i>Offset: 500h + (chan_num * 20h) + 1Ch</i> */
  93001. + volatile uint32_t hcdmab;
  93002. +} dwc_otg_hc_regs_t;
  93003. +
  93004. +/**
  93005. + * This union represents the bit fields in the Host Channel Characteristics
  93006. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93007. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93008. + * hcchar register.
  93009. + */
  93010. +typedef union hcchar_data {
  93011. + /** raw register data */
  93012. + uint32_t d32;
  93013. +
  93014. + /** register bits */
  93015. + struct {
  93016. + /** Maximum packet size in bytes */
  93017. + unsigned mps:11;
  93018. +
  93019. + /** Endpoint number */
  93020. + unsigned epnum:4;
  93021. +
  93022. + /** 0: OUT, 1: IN */
  93023. + unsigned epdir:1;
  93024. +
  93025. + unsigned reserved:1;
  93026. +
  93027. + /** 0: Full/high speed device, 1: Low speed device */
  93028. + unsigned lspddev:1;
  93029. +
  93030. + /** 0: Control, 1: Isoc, 2: Bulk, 3: Intr */
  93031. + unsigned eptype:2;
  93032. +
  93033. + /** Packets per frame for periodic transfers. 0 is reserved. */
  93034. + unsigned multicnt:2;
  93035. +
  93036. + /** Device address */
  93037. + unsigned devaddr:7;
  93038. +
  93039. + /**
  93040. + * Frame to transmit periodic transaction.
  93041. + * 0: even, 1: odd
  93042. + */
  93043. + unsigned oddfrm:1;
  93044. +
  93045. + /** Channel disable */
  93046. + unsigned chdis:1;
  93047. +
  93048. + /** Channel enable */
  93049. + unsigned chen:1;
  93050. + } b;
  93051. +} hcchar_data_t;
  93052. +
  93053. +typedef union hcsplt_data {
  93054. + /** raw register data */
  93055. + uint32_t d32;
  93056. +
  93057. + /** register bits */
  93058. + struct {
  93059. + /** Port Address */
  93060. + unsigned prtaddr:7;
  93061. +
  93062. + /** Hub Address */
  93063. + unsigned hubaddr:7;
  93064. +
  93065. + /** Transaction Position */
  93066. + unsigned xactpos:2;
  93067. +#define DWC_HCSPLIT_XACTPOS_MID 0
  93068. +#define DWC_HCSPLIT_XACTPOS_END 1
  93069. +#define DWC_HCSPLIT_XACTPOS_BEGIN 2
  93070. +#define DWC_HCSPLIT_XACTPOS_ALL 3
  93071. +
  93072. + /** Do Complete Split */
  93073. + unsigned compsplt:1;
  93074. +
  93075. + /** Reserved */
  93076. + unsigned reserved:14;
  93077. +
  93078. + /** Split Enble */
  93079. + unsigned spltena:1;
  93080. + } b;
  93081. +} hcsplt_data_t;
  93082. +
  93083. +/**
  93084. + * This union represents the bit fields in the Host All Interrupt
  93085. + * Register.
  93086. + */
  93087. +typedef union hcint_data {
  93088. + /** raw register data */
  93089. + uint32_t d32;
  93090. + /** register bits */
  93091. + struct {
  93092. + /** Transfer Complete */
  93093. + unsigned xfercomp:1;
  93094. + /** Channel Halted */
  93095. + unsigned chhltd:1;
  93096. + /** AHB Error */
  93097. + unsigned ahberr:1;
  93098. + /** STALL Response Received */
  93099. + unsigned stall:1;
  93100. + /** NAK Response Received */
  93101. + unsigned nak:1;
  93102. + /** ACK Response Received */
  93103. + unsigned ack:1;
  93104. + /** NYET Response Received */
  93105. + unsigned nyet:1;
  93106. + /** Transaction Err */
  93107. + unsigned xacterr:1;
  93108. + /** Babble Error */
  93109. + unsigned bblerr:1;
  93110. + /** Frame Overrun */
  93111. + unsigned frmovrun:1;
  93112. + /** Data Toggle Error */
  93113. + unsigned datatglerr:1;
  93114. + /** Buffer Not Available (only for DDMA mode) */
  93115. + unsigned bna:1;
  93116. + /** Exessive transaction error (only for DDMA mode) */
  93117. + unsigned xcs_xact:1;
  93118. + /** Frame List Rollover interrupt */
  93119. + unsigned frm_list_roll:1;
  93120. + /** Reserved */
  93121. + unsigned reserved14_31:18;
  93122. + } b;
  93123. +} hcint_data_t;
  93124. +
  93125. +/**
  93126. + * This union represents the bit fields in the Host Channel Interrupt Mask
  93127. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93128. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93129. + * hcintmsk register.
  93130. + */
  93131. +typedef union hcintmsk_data {
  93132. + /** raw register data */
  93133. + uint32_t d32;
  93134. +
  93135. + /** register bits */
  93136. + struct {
  93137. + unsigned xfercompl:1;
  93138. + unsigned chhltd:1;
  93139. + unsigned ahberr:1;
  93140. + unsigned stall:1;
  93141. + unsigned nak:1;
  93142. + unsigned ack:1;
  93143. + unsigned nyet:1;
  93144. + unsigned xacterr:1;
  93145. + unsigned bblerr:1;
  93146. + unsigned frmovrun:1;
  93147. + unsigned datatglerr:1;
  93148. + unsigned bna:1;
  93149. + unsigned xcs_xact:1;
  93150. + unsigned frm_list_roll:1;
  93151. + unsigned reserved14_31:18;
  93152. + } b;
  93153. +} hcintmsk_data_t;
  93154. +
  93155. +/**
  93156. + * This union represents the bit fields in the Host Channel Transfer Size
  93157. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93158. + * bits using the <i>b</i>it elements. Write the <i>d32</i> member to the
  93159. + * hcchar register.
  93160. + */
  93161. +
  93162. +typedef union hctsiz_data {
  93163. + /** raw register data */
  93164. + uint32_t d32;
  93165. +
  93166. + /** register bits */
  93167. + struct {
  93168. + /** Total transfer size in bytes */
  93169. + unsigned xfersize:19;
  93170. +
  93171. + /** Data packets to transfer */
  93172. + unsigned pktcnt:10;
  93173. +
  93174. + /**
  93175. + * Packet ID for next data packet
  93176. + * 0: DATA0
  93177. + * 1: DATA2
  93178. + * 2: DATA1
  93179. + * 3: MDATA (non-Control), SETUP (Control)
  93180. + */
  93181. + unsigned pid:2;
  93182. +#define DWC_HCTSIZ_DATA0 0
  93183. +#define DWC_HCTSIZ_DATA1 2
  93184. +#define DWC_HCTSIZ_DATA2 1
  93185. +#define DWC_HCTSIZ_MDATA 3
  93186. +#define DWC_HCTSIZ_SETUP 3
  93187. +
  93188. + /** Do PING protocol when 1 */
  93189. + unsigned dopng:1;
  93190. + } b;
  93191. +
  93192. + /** register bits */
  93193. + struct {
  93194. + /** Scheduling information */
  93195. + unsigned schinfo:8;
  93196. +
  93197. + /** Number of transfer descriptors.
  93198. + * Max value:
  93199. + * 64 in general,
  93200. + * 256 only for HS isochronous endpoint.
  93201. + */
  93202. + unsigned ntd:8;
  93203. +
  93204. + /** Data packets to transfer */
  93205. + unsigned reserved16_28:13;
  93206. +
  93207. + /**
  93208. + * Packet ID for next data packet
  93209. + * 0: DATA0
  93210. + * 1: DATA2
  93211. + * 2: DATA1
  93212. + * 3: MDATA (non-Control)
  93213. + */
  93214. + unsigned pid:2;
  93215. +
  93216. + /** Do PING protocol when 1 */
  93217. + unsigned dopng:1;
  93218. + } b_ddma;
  93219. +} hctsiz_data_t;
  93220. +
  93221. +/**
  93222. + * This union represents the bit fields in the Host DMA Address
  93223. + * Register used in Descriptor DMA mode.
  93224. + */
  93225. +typedef union hcdma_data {
  93226. + /** raw register data */
  93227. + uint32_t d32;
  93228. + /** register bits */
  93229. + struct {
  93230. + unsigned reserved0_2:3;
  93231. + /** Current Transfer Descriptor. Not used for ISOC */
  93232. + unsigned ctd:8;
  93233. + /** Start Address of Descriptor List */
  93234. + unsigned dma_addr:21;
  93235. + } b;
  93236. +} hcdma_data_t;
  93237. +
  93238. +/**
  93239. + * This union represents the bit fields in the DMA Descriptor
  93240. + * status quadlet for host mode. Read the quadlet into the <i>d32</i> member then
  93241. + * set/clear the bits using the <i>b</i>it elements.
  93242. + */
  93243. +typedef union host_dma_desc_sts {
  93244. + /** raw register data */
  93245. + uint32_t d32;
  93246. + /** quadlet bits */
  93247. +
  93248. + /* for non-isochronous */
  93249. + struct {
  93250. + /** Number of bytes */
  93251. + unsigned n_bytes:17;
  93252. + /** QTD offset to jump when Short Packet received - only for IN EPs */
  93253. + unsigned qtd_offset:6;
  93254. + /**
  93255. + * Set to request the core to jump to alternate QTD if
  93256. + * Short Packet received - only for IN EPs
  93257. + */
  93258. + unsigned a_qtd:1;
  93259. + /**
  93260. + * Setup Packet bit. When set indicates that buffer contains
  93261. + * setup packet.
  93262. + */
  93263. + unsigned sup:1;
  93264. + /** Interrupt On Complete */
  93265. + unsigned ioc:1;
  93266. + /** End of List */
  93267. + unsigned eol:1;
  93268. + unsigned reserved27:1;
  93269. + /** Rx/Tx Status */
  93270. + unsigned sts:2;
  93271. +#define DMA_DESC_STS_PKTERR 1
  93272. + unsigned reserved30:1;
  93273. + /** Active Bit */
  93274. + unsigned a:1;
  93275. + } b;
  93276. + /* for isochronous */
  93277. + struct {
  93278. + /** Number of bytes */
  93279. + unsigned n_bytes:12;
  93280. + unsigned reserved12_24:13;
  93281. + /** Interrupt On Complete */
  93282. + unsigned ioc:1;
  93283. + unsigned reserved26_27:2;
  93284. + /** Rx/Tx Status */
  93285. + unsigned sts:2;
  93286. + unsigned reserved30:1;
  93287. + /** Active Bit */
  93288. + unsigned a:1;
  93289. + } b_isoc;
  93290. +} host_dma_desc_sts_t;
  93291. +
  93292. +#define MAX_DMA_DESC_SIZE 131071
  93293. +#define MAX_DMA_DESC_NUM_GENERIC 64
  93294. +#define MAX_DMA_DESC_NUM_HS_ISOC 256
  93295. +#define MAX_FRLIST_EN_NUM 64
  93296. +/**
  93297. + * Host-mode DMA Descriptor structure
  93298. + *
  93299. + * DMA Descriptor structure contains two quadlets:
  93300. + * Status quadlet and Data buffer pointer.
  93301. + */
  93302. +typedef struct dwc_otg_host_dma_desc {
  93303. + /** DMA Descriptor status quadlet */
  93304. + host_dma_desc_sts_t status;
  93305. + /** DMA Descriptor data buffer pointer */
  93306. + uint32_t buf;
  93307. +} dwc_otg_host_dma_desc_t;
  93308. +
  93309. +/** OTG Host Interface Structure.
  93310. + *
  93311. + * The OTG Host Interface Structure structure contains information
  93312. + * needed to manage the DWC_otg controller acting in host mode. It
  93313. + * represents the programming view of the host-specific aspects of the
  93314. + * controller.
  93315. + */
  93316. +typedef struct dwc_otg_host_if {
  93317. + /** Host Global Registers starting at offset 400h.*/
  93318. + dwc_otg_host_global_regs_t *host_global_regs;
  93319. +#define DWC_OTG_HOST_GLOBAL_REG_OFFSET 0x400
  93320. +
  93321. + /** Host Port 0 Control and Status Register */
  93322. + volatile uint32_t *hprt0;
  93323. +#define DWC_OTG_HOST_PORT_REGS_OFFSET 0x440
  93324. +
  93325. + /** Host Channel Specific Registers at offsets 500h-5FCh. */
  93326. + dwc_otg_hc_regs_t *hc_regs[MAX_EPS_CHANNELS];
  93327. +#define DWC_OTG_HOST_CHAN_REGS_OFFSET 0x500
  93328. +#define DWC_OTG_CHAN_REGS_OFFSET 0x20
  93329. +
  93330. + /* Host configuration information */
  93331. + /** Number of Host Channels (range: 1-16) */
  93332. + uint8_t num_host_channels;
  93333. + /** Periodic EPs supported (0: no, 1: yes) */
  93334. + uint8_t perio_eps_supported;
  93335. + /** Periodic Tx FIFO Size (Only 1 host periodic Tx FIFO) */
  93336. + uint16_t perio_tx_fifo_size;
  93337. +
  93338. +} dwc_otg_host_if_t;
  93339. +
  93340. +/**
  93341. + * This union represents the bit fields in the Power and Clock Gating Control
  93342. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93343. + * bits using the <i>b</i>it elements.
  93344. + */
  93345. +typedef union pcgcctl_data {
  93346. + /** raw register data */
  93347. + uint32_t d32;
  93348. +
  93349. + /** register bits */
  93350. + struct {
  93351. + /** Stop Pclk */
  93352. + unsigned stoppclk:1;
  93353. + /** Gate Hclk */
  93354. + unsigned gatehclk:1;
  93355. + /** Power Clamp */
  93356. + unsigned pwrclmp:1;
  93357. + /** Reset Power Down Modules */
  93358. + unsigned rstpdwnmodule:1;
  93359. + /** Reserved */
  93360. + unsigned reserved:1;
  93361. + /** Enable Sleep Clock Gating (Enbl_L1Gating) */
  93362. + unsigned enbl_sleep_gating:1;
  93363. + /** PHY In Sleep (PhySleep) */
  93364. + unsigned phy_in_sleep:1;
  93365. + /** Deep Sleep*/
  93366. + unsigned deep_sleep:1;
  93367. + unsigned resetaftsusp:1;
  93368. + unsigned restoremode:1;
  93369. + unsigned enbl_extnd_hiber:1;
  93370. + unsigned extnd_hiber_pwrclmp:1;
  93371. + unsigned extnd_hiber_switch:1;
  93372. + unsigned ess_reg_restored:1;
  93373. + unsigned prt_clk_sel:2;
  93374. + unsigned port_power:1;
  93375. + unsigned max_xcvrselect:2;
  93376. + unsigned max_termsel:1;
  93377. + unsigned mac_dev_addr:7;
  93378. + unsigned p2hd_dev_enum_spd:2;
  93379. + unsigned p2hd_prt_spd:2;
  93380. + unsigned if_dev_mode:1;
  93381. + } b;
  93382. +} pcgcctl_data_t;
  93383. +
  93384. +/**
  93385. + * This union represents the bit fields in the Global Data FIFO Software
  93386. + * Configuration Register. Read the register into the <i>d32</i> member then
  93387. + * set/clear the bits using the <i>b</i>it elements.
  93388. + */
  93389. +typedef union gdfifocfg_data {
  93390. + /* raw register data */
  93391. + uint32_t d32;
  93392. + /** register bits */
  93393. + struct {
  93394. + /** OTG Data FIFO depth */
  93395. + unsigned gdfifocfg:16;
  93396. + /** Start address of EP info controller */
  93397. + unsigned epinfobase:16;
  93398. + } b;
  93399. +} gdfifocfg_data_t;
  93400. +
  93401. +/**
  93402. + * This union represents the bit fields in the Global Power Down Register
  93403. + * Register. Read the register into the <i>d32</i> member then set/clear the
  93404. + * bits using the <i>b</i>it elements.
  93405. + */
  93406. +typedef union gpwrdn_data {
  93407. + /* raw register data */
  93408. + uint32_t d32;
  93409. +
  93410. + /** register bits */
  93411. + struct {
  93412. + /** PMU Interrupt Select */
  93413. + unsigned pmuintsel:1;
  93414. + /** PMU Active */
  93415. + unsigned pmuactv:1;
  93416. + /** Restore */
  93417. + unsigned restore:1;
  93418. + /** Power Down Clamp */
  93419. + unsigned pwrdnclmp:1;
  93420. + /** Power Down Reset */
  93421. + unsigned pwrdnrstn:1;
  93422. + /** Power Down Switch */
  93423. + unsigned pwrdnswtch:1;
  93424. + /** Disable VBUS */
  93425. + unsigned dis_vbus:1;
  93426. + /** Line State Change */
  93427. + unsigned lnstschng:1;
  93428. + /** Line state change mask */
  93429. + unsigned lnstchng_msk:1;
  93430. + /** Reset Detected */
  93431. + unsigned rst_det:1;
  93432. + /** Reset Detect mask */
  93433. + unsigned rst_det_msk:1;
  93434. + /** Disconnect Detected */
  93435. + unsigned disconn_det:1;
  93436. + /** Disconnect Detect mask */
  93437. + unsigned disconn_det_msk:1;
  93438. + /** Connect Detected*/
  93439. + unsigned connect_det:1;
  93440. + /** Connect Detected Mask*/
  93441. + unsigned connect_det_msk:1;
  93442. + /** SRP Detected */
  93443. + unsigned srp_det:1;
  93444. + /** SRP Detect mask */
  93445. + unsigned srp_det_msk:1;
  93446. + /** Status Change Interrupt */
  93447. + unsigned sts_chngint:1;
  93448. + /** Status Change Interrupt Mask */
  93449. + unsigned sts_chngint_msk:1;
  93450. + /** Line State */
  93451. + unsigned linestate:2;
  93452. + /** Indicates current mode(status of IDDIG signal) */
  93453. + unsigned idsts:1;
  93454. + /** B Session Valid signal status*/
  93455. + unsigned bsessvld:1;
  93456. + /** ADP Event Detected */
  93457. + unsigned adp_int:1;
  93458. + /** Multi Valued ID pin */
  93459. + unsigned mult_val_id_bc:5;
  93460. + /** Reserved 24_31 */
  93461. + unsigned reserved29_31:3;
  93462. + } b;
  93463. +} gpwrdn_data_t;
  93464. +
  93465. +#endif
  93466. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/Makefile linux-rpi/drivers/usb/host/dwc_otg/Makefile
  93467. --- linux-3.15/drivers/usb/host/dwc_otg/Makefile 1970-01-01 01:00:00.000000000 +0100
  93468. +++ linux-rpi/drivers/usb/host/dwc_otg/Makefile 2014-06-11 21:03:43.000000000 +0200
  93469. @@ -0,0 +1,82 @@
  93470. +#
  93471. +# Makefile for DWC_otg Highspeed USB controller driver
  93472. +#
  93473. +
  93474. +ifneq ($(KERNELRELEASE),)
  93475. +
  93476. +# Use the BUS_INTERFACE variable to compile the software for either
  93477. +# PCI(PCI_INTERFACE) or LM(LM_INTERFACE) bus.
  93478. +ifeq ($(BUS_INTERFACE),)
  93479. +# BUS_INTERFACE = -DPCI_INTERFACE
  93480. +# BUS_INTERFACE = -DLM_INTERFACE
  93481. + BUS_INTERFACE = -DPLATFORM_INTERFACE
  93482. +endif
  93483. +
  93484. +#ccflags-y += -DDEBUG
  93485. +#ccflags-y += -DDWC_OTG_DEBUGLEV=1 # reduce common debug msgs
  93486. +
  93487. +# Use one of the following flags to compile the software in host-only or
  93488. +# device-only mode.
  93489. +#ccflags-y += -DDWC_HOST_ONLY
  93490. +#ccflags-y += -DDWC_DEVICE_ONLY
  93491. +
  93492. +ccflags-y += -Dlinux -DDWC_HS_ELECT_TST
  93493. +#ccflags-y += -DDWC_EN_ISOC
  93494. +ccflags-y += -I$(obj)/../dwc_common_port
  93495. +#ccflags-y += -I$(PORTLIB)
  93496. +ccflags-y += -DDWC_LINUX
  93497. +ccflags-y += $(CFI)
  93498. +ccflags-y += $(BUS_INTERFACE)
  93499. +#ccflags-y += -DDWC_DEV_SRPCAP
  93500. +
  93501. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg.o
  93502. +
  93503. +dwc_otg-objs := dwc_otg_driver.o dwc_otg_attr.o
  93504. +dwc_otg-objs += dwc_otg_cil.o dwc_otg_cil_intr.o
  93505. +dwc_otg-objs += dwc_otg_pcd_linux.o dwc_otg_pcd.o dwc_otg_pcd_intr.o
  93506. +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
  93507. +dwc_otg-objs += dwc_otg_adp.o
  93508. +dwc_otg-objs += dwc_otg_fiq_fsm.o
  93509. +dwc_otg-objs += dwc_otg_fiq_stub.o
  93510. +ifneq ($(CFI),)
  93511. +dwc_otg-objs += dwc_otg_cfi.o
  93512. +endif
  93513. +
  93514. +kernrelwd := $(subst ., ,$(KERNELRELEASE))
  93515. +kernrel3 := $(word 1,$(kernrelwd)).$(word 2,$(kernrelwd)).$(word 3,$(kernrelwd))
  93516. +
  93517. +ifneq ($(kernrel3),2.6.20)
  93518. +ccflags-y += $(CPPFLAGS)
  93519. +endif
  93520. +
  93521. +else
  93522. +
  93523. +PWD := $(shell pwd)
  93524. +PORTLIB := $(PWD)/../dwc_common_port
  93525. +
  93526. +# Command paths
  93527. +CTAGS := $(CTAGS)
  93528. +DOXYGEN := $(DOXYGEN)
  93529. +
  93530. +default: portlib
  93531. + $(MAKE) -C$(KDIR) M=$(PWD) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  93532. +
  93533. +install: default
  93534. + $(MAKE) -C$(KDIR) M=$(PORTLIB) modules_install
  93535. + $(MAKE) -C$(KDIR) M=$(PWD) modules_install
  93536. +
  93537. +portlib:
  93538. + $(MAKE) -C$(KDIR) M=$(PORTLIB) ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) modules
  93539. + cp $(PORTLIB)/Module.symvers $(PWD)/
  93540. +
  93541. +docs: $(wildcard *.[hc]) doc/doxygen.cfg
  93542. + $(DOXYGEN) doc/doxygen.cfg
  93543. +
  93544. +tags: $(wildcard *.[hc])
  93545. + $(CTAGS) -e $(wildcard *.[hc]) $(wildcard linux/*.[hc]) $(wildcard $(KDIR)/include/linux/usb*.h)
  93546. +
  93547. +
  93548. +clean:
  93549. + rm -rf *.o *.ko .*cmd *.mod.c .tmp_versions Module.symvers
  93550. +
  93551. +endif
  93552. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm
  93553. --- linux-3.15/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 1970-01-01 01:00:00.000000000 +0100
  93554. +++ linux-rpi/drivers/usb/host/dwc_otg/test/dwc_otg_test.pm 2014-06-11 21:03:43.000000000 +0200
  93555. @@ -0,0 +1,337 @@
  93556. +package dwc_otg_test;
  93557. +
  93558. +use strict;
  93559. +use Exporter ();
  93560. +
  93561. +use vars qw(@ISA @EXPORT
  93562. +$sysfsdir $paramdir $errors $params
  93563. +);
  93564. +
  93565. +@ISA = qw(Exporter);
  93566. +
  93567. +#
  93568. +# Globals
  93569. +#
  93570. +$sysfsdir = "/sys/devices/lm0";
  93571. +$paramdir = "/sys/module/dwc_otg";
  93572. +$errors = 0;
  93573. +
  93574. +$params = [
  93575. + {
  93576. + NAME => "otg_cap",
  93577. + DEFAULT => 0,
  93578. + ENUM => [],
  93579. + LOW => 0,
  93580. + HIGH => 2
  93581. + },
  93582. + {
  93583. + NAME => "dma_enable",
  93584. + DEFAULT => 0,
  93585. + ENUM => [],
  93586. + LOW => 0,
  93587. + HIGH => 1
  93588. + },
  93589. + {
  93590. + NAME => "dma_burst_size",
  93591. + DEFAULT => 32,
  93592. + ENUM => [1, 4, 8, 16, 32, 64, 128, 256],
  93593. + LOW => 1,
  93594. + HIGH => 256
  93595. + },
  93596. + {
  93597. + NAME => "host_speed",
  93598. + DEFAULT => 0,
  93599. + ENUM => [],
  93600. + LOW => 0,
  93601. + HIGH => 1
  93602. + },
  93603. + {
  93604. + NAME => "host_support_fs_ls_low_power",
  93605. + DEFAULT => 0,
  93606. + ENUM => [],
  93607. + LOW => 0,
  93608. + HIGH => 1
  93609. + },
  93610. + {
  93611. + NAME => "host_ls_low_power_phy_clk",
  93612. + DEFAULT => 0,
  93613. + ENUM => [],
  93614. + LOW => 0,
  93615. + HIGH => 1
  93616. + },
  93617. + {
  93618. + NAME => "dev_speed",
  93619. + DEFAULT => 0,
  93620. + ENUM => [],
  93621. + LOW => 0,
  93622. + HIGH => 1
  93623. + },
  93624. + {
  93625. + NAME => "enable_dynamic_fifo",
  93626. + DEFAULT => 1,
  93627. + ENUM => [],
  93628. + LOW => 0,
  93629. + HIGH => 1
  93630. + },
  93631. + {
  93632. + NAME => "data_fifo_size",
  93633. + DEFAULT => 8192,
  93634. + ENUM => [],
  93635. + LOW => 32,
  93636. + HIGH => 32768
  93637. + },
  93638. + {
  93639. + NAME => "dev_rx_fifo_size",
  93640. + DEFAULT => 1064,
  93641. + ENUM => [],
  93642. + LOW => 16,
  93643. + HIGH => 32768
  93644. + },
  93645. + {
  93646. + NAME => "dev_nperio_tx_fifo_size",
  93647. + DEFAULT => 1024,
  93648. + ENUM => [],
  93649. + LOW => 16,
  93650. + HIGH => 32768
  93651. + },
  93652. + {
  93653. + NAME => "dev_perio_tx_fifo_size_1",
  93654. + DEFAULT => 256,
  93655. + ENUM => [],
  93656. + LOW => 4,
  93657. + HIGH => 768
  93658. + },
  93659. + {
  93660. + NAME => "dev_perio_tx_fifo_size_2",
  93661. + DEFAULT => 256,
  93662. + ENUM => [],
  93663. + LOW => 4,
  93664. + HIGH => 768
  93665. + },
  93666. + {
  93667. + NAME => "dev_perio_tx_fifo_size_3",
  93668. + DEFAULT => 256,
  93669. + ENUM => [],
  93670. + LOW => 4,
  93671. + HIGH => 768
  93672. + },
  93673. + {
  93674. + NAME => "dev_perio_tx_fifo_size_4",
  93675. + DEFAULT => 256,
  93676. + ENUM => [],
  93677. + LOW => 4,
  93678. + HIGH => 768
  93679. + },
  93680. + {
  93681. + NAME => "dev_perio_tx_fifo_size_5",
  93682. + DEFAULT => 256,
  93683. + ENUM => [],
  93684. + LOW => 4,
  93685. + HIGH => 768
  93686. + },
  93687. + {
  93688. + NAME => "dev_perio_tx_fifo_size_6",
  93689. + DEFAULT => 256,
  93690. + ENUM => [],
  93691. + LOW => 4,
  93692. + HIGH => 768
  93693. + },
  93694. + {
  93695. + NAME => "dev_perio_tx_fifo_size_7",
  93696. + DEFAULT => 256,
  93697. + ENUM => [],
  93698. + LOW => 4,
  93699. + HIGH => 768
  93700. + },
  93701. + {
  93702. + NAME => "dev_perio_tx_fifo_size_8",
  93703. + DEFAULT => 256,
  93704. + ENUM => [],
  93705. + LOW => 4,
  93706. + HIGH => 768
  93707. + },
  93708. + {
  93709. + NAME => "dev_perio_tx_fifo_size_9",
  93710. + DEFAULT => 256,
  93711. + ENUM => [],
  93712. + LOW => 4,
  93713. + HIGH => 768
  93714. + },
  93715. + {
  93716. + NAME => "dev_perio_tx_fifo_size_10",
  93717. + DEFAULT => 256,
  93718. + ENUM => [],
  93719. + LOW => 4,
  93720. + HIGH => 768
  93721. + },
  93722. + {
  93723. + NAME => "dev_perio_tx_fifo_size_11",
  93724. + DEFAULT => 256,
  93725. + ENUM => [],
  93726. + LOW => 4,
  93727. + HIGH => 768
  93728. + },
  93729. + {
  93730. + NAME => "dev_perio_tx_fifo_size_12",
  93731. + DEFAULT => 256,
  93732. + ENUM => [],
  93733. + LOW => 4,
  93734. + HIGH => 768
  93735. + },
  93736. + {
  93737. + NAME => "dev_perio_tx_fifo_size_13",
  93738. + DEFAULT => 256,
  93739. + ENUM => [],
  93740. + LOW => 4,
  93741. + HIGH => 768
  93742. + },
  93743. + {
  93744. + NAME => "dev_perio_tx_fifo_size_14",
  93745. + DEFAULT => 256,
  93746. + ENUM => [],
  93747. + LOW => 4,
  93748. + HIGH => 768
  93749. + },
  93750. + {
  93751. + NAME => "dev_perio_tx_fifo_size_15",
  93752. + DEFAULT => 256,
  93753. + ENUM => [],
  93754. + LOW => 4,
  93755. + HIGH => 768
  93756. + },
  93757. + {
  93758. + NAME => "host_rx_fifo_size",
  93759. + DEFAULT => 1024,
  93760. + ENUM => [],
  93761. + LOW => 16,
  93762. + HIGH => 32768
  93763. + },
  93764. + {
  93765. + NAME => "host_nperio_tx_fifo_size",
  93766. + DEFAULT => 1024,
  93767. + ENUM => [],
  93768. + LOW => 16,
  93769. + HIGH => 32768
  93770. + },
  93771. + {
  93772. + NAME => "host_perio_tx_fifo_size",
  93773. + DEFAULT => 1024,
  93774. + ENUM => [],
  93775. + LOW => 16,
  93776. + HIGH => 32768
  93777. + },
  93778. + {
  93779. + NAME => "max_transfer_size",
  93780. + DEFAULT => 65535,
  93781. + ENUM => [],
  93782. + LOW => 2047,
  93783. + HIGH => 65535
  93784. + },
  93785. + {
  93786. + NAME => "max_packet_count",
  93787. + DEFAULT => 511,
  93788. + ENUM => [],
  93789. + LOW => 15,
  93790. + HIGH => 511
  93791. + },
  93792. + {
  93793. + NAME => "host_channels",
  93794. + DEFAULT => 12,
  93795. + ENUM => [],
  93796. + LOW => 1,
  93797. + HIGH => 16
  93798. + },
  93799. + {
  93800. + NAME => "dev_endpoints",
  93801. + DEFAULT => 6,
  93802. + ENUM => [],
  93803. + LOW => 1,
  93804. + HIGH => 15
  93805. + },
  93806. + {
  93807. + NAME => "phy_type",
  93808. + DEFAULT => 1,
  93809. + ENUM => [],
  93810. + LOW => 0,
  93811. + HIGH => 2
  93812. + },
  93813. + {
  93814. + NAME => "phy_utmi_width",
  93815. + DEFAULT => 16,
  93816. + ENUM => [8, 16],
  93817. + LOW => 8,
  93818. + HIGH => 16
  93819. + },
  93820. + {
  93821. + NAME => "phy_ulpi_ddr",
  93822. + DEFAULT => 0,
  93823. + ENUM => [],
  93824. + LOW => 0,
  93825. + HIGH => 1
  93826. + },
  93827. + ];
  93828. +
  93829. +
  93830. +#
  93831. +#
  93832. +sub check_arch {
  93833. + $_ = `uname -m`;
  93834. + chomp;
  93835. + unless (m/armv4tl/) {
  93836. + warn "# \n# Can't execute on $_. Run on integrator platform.\n# \n";
  93837. + return 0;
  93838. + }
  93839. + return 1;
  93840. +}
  93841. +
  93842. +#
  93843. +#
  93844. +sub load_module {
  93845. + my $params = shift;
  93846. + print "\nRemoving Module\n";
  93847. + system "rmmod dwc_otg";
  93848. + print "Loading Module\n";
  93849. + if ($params ne "") {
  93850. + print "Module Parameters: $params\n";
  93851. + }
  93852. + if (system("modprobe dwc_otg $params")) {
  93853. + warn "Unable to load module\n";
  93854. + return 0;
  93855. + }
  93856. + return 1;
  93857. +}
  93858. +
  93859. +#
  93860. +#
  93861. +sub test_status {
  93862. + my $arg = shift;
  93863. +
  93864. + print "\n";
  93865. +
  93866. + if (defined $arg) {
  93867. + warn "WARNING: $arg\n";
  93868. + }
  93869. +
  93870. + if ($errors > 0) {
  93871. + warn "TEST FAILED with $errors errors\n";
  93872. + return 0;
  93873. + } else {
  93874. + print "TEST PASSED\n";
  93875. + return 0 if (defined $arg);
  93876. + }
  93877. + return 1;
  93878. +}
  93879. +
  93880. +#
  93881. +#
  93882. +@EXPORT = qw(
  93883. +$sysfsdir
  93884. +$paramdir
  93885. +$params
  93886. +$errors
  93887. +check_arch
  93888. +load_module
  93889. +test_status
  93890. +);
  93891. +
  93892. +1;
  93893. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/test/Makefile linux-rpi/drivers/usb/host/dwc_otg/test/Makefile
  93894. --- linux-3.15/drivers/usb/host/dwc_otg/test/Makefile 1970-01-01 01:00:00.000000000 +0100
  93895. +++ linux-rpi/drivers/usb/host/dwc_otg/test/Makefile 2014-06-11 21:03:43.000000000 +0200
  93896. @@ -0,0 +1,16 @@
  93897. +
  93898. +PERL=/usr/bin/perl
  93899. +PL_TESTS=test_sysfs.pl test_mod_param.pl
  93900. +
  93901. +.PHONY : test
  93902. +test : perl_tests
  93903. +
  93904. +perl_tests :
  93905. + @echo
  93906. + @echo Running perl tests
  93907. + @for test in $(PL_TESTS); do \
  93908. + if $(PERL) ./$$test ; then \
  93909. + echo "=======> $$test, PASSED" ; \
  93910. + else echo "=======> $$test, FAILED" ; \
  93911. + fi \
  93912. + done
  93913. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/test/test_mod_param.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl
  93914. --- linux-3.15/drivers/usb/host/dwc_otg/test/test_mod_param.pl 1970-01-01 01:00:00.000000000 +0100
  93915. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_mod_param.pl 2014-06-11 21:03:43.000000000 +0200
  93916. @@ -0,0 +1,133 @@
  93917. +#!/usr/bin/perl -w
  93918. +#
  93919. +# Run this program on the integrator.
  93920. +#
  93921. +# - Tests module parameter default values.
  93922. +# - Tests setting of valid module parameter values via modprobe.
  93923. +# - Tests invalid module parameter values.
  93924. +# -----------------------------------------------------------------------------
  93925. +use strict;
  93926. +use dwc_otg_test;
  93927. +
  93928. +check_arch() or die;
  93929. +
  93930. +#
  93931. +#
  93932. +sub test {
  93933. + my ($param,$expected) = @_;
  93934. + my $value = get($param);
  93935. +
  93936. + if ($value == $expected) {
  93937. + print "$param = $value, okay\n";
  93938. + }
  93939. +
  93940. + else {
  93941. + warn "ERROR: value of $param != $expected, $value\n";
  93942. + $errors ++;
  93943. + }
  93944. +}
  93945. +
  93946. +#
  93947. +#
  93948. +sub get {
  93949. + my $param = shift;
  93950. + my $tmp = `cat $paramdir/$param`;
  93951. + chomp $tmp;
  93952. + return $tmp;
  93953. +}
  93954. +
  93955. +#
  93956. +#
  93957. +sub test_main {
  93958. +
  93959. + print "\nTesting Module Parameters\n";
  93960. +
  93961. + load_module("") or die;
  93962. +
  93963. + # Test initial values
  93964. + print "\nTesting Default Values\n";
  93965. + foreach (@{$params}) {
  93966. + test ($_->{NAME}, $_->{DEFAULT});
  93967. + }
  93968. +
  93969. + # Test low value
  93970. + print "\nTesting Low Value\n";
  93971. + my $cmd_params = "";
  93972. + foreach (@{$params}) {
  93973. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{LOW} ";
  93974. + }
  93975. + load_module($cmd_params) or die;
  93976. +
  93977. + foreach (@{$params}) {
  93978. + test ($_->{NAME}, $_->{LOW});
  93979. + }
  93980. +
  93981. + # Test high value
  93982. + print "\nTesting High Value\n";
  93983. + $cmd_params = "";
  93984. + foreach (@{$params}) {
  93985. + $cmd_params = $cmd_params . "$_->{NAME}=$_->{HIGH} ";
  93986. + }
  93987. + load_module($cmd_params) or die;
  93988. +
  93989. + foreach (@{$params}) {
  93990. + test ($_->{NAME}, $_->{HIGH});
  93991. + }
  93992. +
  93993. + # Test Enum
  93994. + print "\nTesting Enumerated\n";
  93995. + foreach (@{$params}) {
  93996. + if (defined $_->{ENUM}) {
  93997. + my $value;
  93998. + foreach $value (@{$_->{ENUM}}) {
  93999. + $cmd_params = "$_->{NAME}=$value";
  94000. + load_module($cmd_params) or die;
  94001. + test ($_->{NAME}, $value);
  94002. + }
  94003. + }
  94004. + }
  94005. +
  94006. + # Test Invalid Values
  94007. + print "\nTesting Invalid Values\n";
  94008. + $cmd_params = "";
  94009. + foreach (@{$params}) {
  94010. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{LOW}-1;
  94011. + }
  94012. + load_module($cmd_params) or die;
  94013. +
  94014. + foreach (@{$params}) {
  94015. + test ($_->{NAME}, $_->{DEFAULT});
  94016. + }
  94017. +
  94018. + $cmd_params = "";
  94019. + foreach (@{$params}) {
  94020. + $cmd_params = $cmd_params . sprintf "$_->{NAME}=%d ", $_->{HIGH}+1;
  94021. + }
  94022. + load_module($cmd_params) or die;
  94023. +
  94024. + foreach (@{$params}) {
  94025. + test ($_->{NAME}, $_->{DEFAULT});
  94026. + }
  94027. +
  94028. + print "\nTesting Enumerated\n";
  94029. + foreach (@{$params}) {
  94030. + if (defined $_->{ENUM}) {
  94031. + my $value;
  94032. + foreach $value (@{$_->{ENUM}}) {
  94033. + $value = $value + 1;
  94034. + $cmd_params = "$_->{NAME}=$value";
  94035. + load_module($cmd_params) or die;
  94036. + test ($_->{NAME}, $_->{DEFAULT});
  94037. + $value = $value - 2;
  94038. + $cmd_params = "$_->{NAME}=$value";
  94039. + load_module($cmd_params) or die;
  94040. + test ($_->{NAME}, $_->{DEFAULT});
  94041. + }
  94042. + }
  94043. + }
  94044. +
  94045. + test_status() or die;
  94046. +}
  94047. +
  94048. +test_main();
  94049. +0;
  94050. diff -Nur linux-3.15/drivers/usb/host/dwc_otg/test/test_sysfs.pl linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl
  94051. --- linux-3.15/drivers/usb/host/dwc_otg/test/test_sysfs.pl 1970-01-01 01:00:00.000000000 +0100
  94052. +++ linux-rpi/drivers/usb/host/dwc_otg/test/test_sysfs.pl 2014-06-11 21:03:43.000000000 +0200
  94053. @@ -0,0 +1,193 @@
  94054. +#!/usr/bin/perl -w
  94055. +#
  94056. +# Run this program on the integrator
  94057. +# - Tests select sysfs attributes.
  94058. +# - Todo ... test more attributes, hnp/srp, buspower/bussuspend, etc.
  94059. +# -----------------------------------------------------------------------------
  94060. +use strict;
  94061. +use dwc_otg_test;
  94062. +
  94063. +check_arch() or die;
  94064. +
  94065. +#
  94066. +#
  94067. +sub test {
  94068. + my ($attr,$expected) = @_;
  94069. + my $string = get($attr);
  94070. +
  94071. + if ($string eq $expected) {
  94072. + printf("$attr = $string, okay\n");
  94073. + }
  94074. + else {
  94075. + warn "ERROR: value of $attr != $expected, $string\n";
  94076. + $errors ++;
  94077. + }
  94078. +}
  94079. +
  94080. +#
  94081. +#
  94082. +sub set {
  94083. + my ($reg, $value) = @_;
  94084. + system "echo $value > $sysfsdir/$reg";
  94085. +}
  94086. +
  94087. +#
  94088. +#
  94089. +sub get {
  94090. + my $attr = shift;
  94091. + my $string = `cat $sysfsdir/$attr`;
  94092. + chomp $string;
  94093. + if ($string =~ m/\s\=\s/) {
  94094. + my $tmp;
  94095. + ($tmp, $string) = split /\s=\s/, $string;
  94096. + }
  94097. + return $string;
  94098. +}
  94099. +
  94100. +#
  94101. +#
  94102. +sub test_main {
  94103. + print("\nTesting Sysfs Attributes\n");
  94104. +
  94105. + load_module("") or die;
  94106. +
  94107. + # Test initial values of regoffset/regvalue/guid/gsnpsid
  94108. + print("\nTesting Default Values\n");
  94109. +
  94110. + test("regoffset", "0xffffffff");
  94111. + test("regvalue", "invalid offset");
  94112. + test("guid", "0x12345678"); # this will fail if it has been changed
  94113. + test("gsnpsid", "0x4f54200a");
  94114. +
  94115. + # Test operation of regoffset/regvalue
  94116. + print("\nTesting regoffset\n");
  94117. + set('regoffset', '5a5a5a5a');
  94118. + test("regoffset", "0xffffffff");
  94119. +
  94120. + set('regoffset', '0');
  94121. + test("regoffset", "0x00000000");
  94122. +
  94123. + set('regoffset', '40000');
  94124. + test("regoffset", "0x00000000");
  94125. +
  94126. + set('regoffset', '3ffff');
  94127. + test("regoffset", "0x0003ffff");
  94128. +
  94129. + set('regoffset', '1');
  94130. + test("regoffset", "0x00000001");
  94131. +
  94132. + print("\nTesting regvalue\n");
  94133. + set('regoffset', '3c');
  94134. + test("regvalue", "0x12345678");
  94135. + set('regvalue', '5a5a5a5a');
  94136. + test("regvalue", "0x5a5a5a5a");
  94137. + set('regvalue','a5a5a5a5');
  94138. + test("regvalue", "0xa5a5a5a5");
  94139. + set('guid','12345678');
  94140. +
  94141. + # Test HNP Capable
  94142. + print("\nTesting HNP Capable bit\n");
  94143. + set('hnpcapable', '1');
  94144. + test("hnpcapable", "0x1");
  94145. + set('hnpcapable','0');
  94146. + test("hnpcapable", "0x0");
  94147. +
  94148. + set('regoffset','0c');
  94149. +
  94150. + my $old = get('gusbcfg');
  94151. + print("setting hnpcapable\n");
  94152. + set('hnpcapable', '1');
  94153. + test("hnpcapable", "0x1");
  94154. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<9)));
  94155. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<9)));
  94156. +
  94157. + $old = get('gusbcfg');
  94158. + print("clearing hnpcapable\n");
  94159. + set('hnpcapable', '0');
  94160. + test("hnpcapable", "0x0");
  94161. + test ('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  94162. + test ('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<9)));
  94163. +
  94164. + # Test SRP Capable
  94165. + print("\nTesting SRP Capable bit\n");
  94166. + set('srpcapable', '1');
  94167. + test("srpcapable", "0x1");
  94168. + set('srpcapable','0');
  94169. + test("srpcapable", "0x0");
  94170. +
  94171. + set('regoffset','0c');
  94172. +
  94173. + $old = get('gusbcfg');
  94174. + print("setting srpcapable\n");
  94175. + set('srpcapable', '1');
  94176. + test("srpcapable", "0x1");
  94177. + test('gusbcfg', sprintf "0x%08x", (oct ($old) | (1<<8)));
  94178. + test('regvalue', sprintf "0x%08x", (oct ($old) | (1<<8)));
  94179. +
  94180. + $old = get('gusbcfg');
  94181. + print("clearing srpcapable\n");
  94182. + set('srpcapable', '0');
  94183. + test("srpcapable", "0x0");
  94184. + test('gusbcfg', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  94185. + test('regvalue', sprintf "0x%08x", oct ($old) & (~(1<<8)));
  94186. +
  94187. + # Test GGPIO
  94188. + print("\nTesting GGPIO\n");
  94189. + set('ggpio','5a5a5a5a');
  94190. + test('ggpio','0x5a5a0000');
  94191. + set('ggpio','a5a5a5a5');
  94192. + test('ggpio','0xa5a50000');
  94193. + set('ggpio','11110000');
  94194. + test('ggpio','0x11110000');
  94195. + set('ggpio','00001111');
  94196. + test('ggpio','0x00000000');
  94197. +
  94198. + # Test DEVSPEED
  94199. + print("\nTesting DEVSPEED\n");
  94200. + set('regoffset','800');
  94201. + $old = get('regvalue');
  94202. + set('devspeed','0');
  94203. + test('devspeed','0x0');
  94204. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  94205. + set('devspeed','1');
  94206. + test('devspeed','0x1');
  94207. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  94208. + set('devspeed','2');
  94209. + test('devspeed','0x2');
  94210. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 2));
  94211. + set('devspeed','3');
  94212. + test('devspeed','0x3');
  94213. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 3));
  94214. + set('devspeed','4');
  94215. + test('devspeed','0x0');
  94216. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3)));
  94217. + set('devspeed','5');
  94218. + test('devspeed','0x1');
  94219. + test('regvalue',sprintf("0x%08x", oct($old) & ~(0x3) | 1));
  94220. +
  94221. +
  94222. + # mode Returns the current mode:0 for device mode1 for host mode Read
  94223. + # hnp Initiate the Host Negotiation Protocol. Read returns the status. Read/Write
  94224. + # srp Initiate the Session Request Protocol. Read returns the status. Read/Write
  94225. + # buspower Get or Set the Power State of the bus (0 - Off or 1 - On) Read/Write
  94226. + # bussuspend Suspend the USB bus. Read/Write
  94227. + # busconnected Get the connection status of the bus Read
  94228. +
  94229. + # gotgctl Get or set the Core Control Status Register. Read/Write
  94230. + ## gusbcfg Get or set the Core USB Configuration Register Read/Write
  94231. + # grxfsiz Get or set the Receive FIFO Size Register Read/Write
  94232. + # gnptxfsiz Get or set the non-periodic Transmit Size Register Read/Write
  94233. + # gpvndctl Get or set the PHY Vendor Control Register Read/Write
  94234. + ## ggpio Get the value in the lower 16-bits of the General Purpose IO Register or Set the upper 16 bits. Read/Write
  94235. + ## guid Get or set the value of the User ID Register Read/Write
  94236. + ## gsnpsid Get the value of the Synopsys ID Regester Read
  94237. + ## devspeed Get or set the device speed setting in the DCFG register Read/Write
  94238. + # enumspeed Gets the device enumeration Speed. Read
  94239. + # hptxfsiz Get the value of the Host Periodic Transmit FIFO Read
  94240. + # hprt0 Get or Set the value in the Host Port Control and Status Register Read/Write
  94241. +
  94242. + test_status("TEST NYI") or die;
  94243. +}
  94244. +
  94245. +test_main();
  94246. +0;
  94247. diff -Nur linux-3.15/drivers/usb/host/Kconfig linux-rpi/drivers/usb/host/Kconfig
  94248. --- linux-3.15/drivers/usb/host/Kconfig 2014-06-08 20:19:54.000000000 +0200
  94249. +++ linux-rpi/drivers/usb/host/Kconfig 2014-06-11 21:05:32.000000000 +0200
  94250. @@ -685,6 +685,19 @@
  94251. To compile this driver a module, choose M here: the module
  94252. will be called "hwa-hc".
  94253. +config USB_DWCOTG
  94254. + tristate "Synopsis DWC host support"
  94255. + depends on USB
  94256. + help
  94257. + The Synopsis DWC controller is a dual-role
  94258. + host/peripheral/OTG ("On The Go") USB controllers.
  94259. +
  94260. + Enable this option to support this IP in host controller mode.
  94261. + If unsure, say N.
  94262. +
  94263. + To compile this driver as a module, choose M here: the
  94264. + modules built will be called dwc_otg and dwc_common_port.
  94265. +
  94266. config USB_IMX21_HCD
  94267. tristate "i.MX21 HCD support"
  94268. depends on ARM && ARCH_MXC
  94269. diff -Nur linux-3.15/drivers/usb/host/Makefile linux-rpi/drivers/usb/host/Makefile
  94270. --- linux-3.15/drivers/usb/host/Makefile 2014-06-08 20:19:54.000000000 +0200
  94271. +++ linux-rpi/drivers/usb/host/Makefile 2014-06-11 21:05:32.000000000 +0200
  94272. @@ -63,6 +63,8 @@
  94273. obj-$(CONFIG_USB_R8A66597_HCD) += r8a66597-hcd.o
  94274. obj-$(CONFIG_USB_ISP1760_HCD) += isp1760.o
  94275. obj-$(CONFIG_USB_HWA_HCD) += hwa-hc.o
  94276. +
  94277. +obj-$(CONFIG_USB_DWCOTG) += dwc_otg/ dwc_common_port/
  94278. obj-$(CONFIG_USB_IMX21_HCD) += imx21-hcd.o
  94279. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += fsl-mph-dr-of.o
  94280. obj-$(CONFIG_USB_OCTEON2_COMMON) += octeon2-common.o
  94281. diff -Nur linux-3.15/drivers/usb/Makefile linux-rpi/drivers/usb/Makefile
  94282. --- linux-3.15/drivers/usb/Makefile 2014-06-08 20:19:54.000000000 +0200
  94283. +++ linux-rpi/drivers/usb/Makefile 2014-06-11 21:05:32.000000000 +0200
  94284. @@ -24,6 +24,7 @@
  94285. obj-$(CONFIG_USB_R8A66597_HCD) += host/
  94286. obj-$(CONFIG_USB_HWA_HCD) += host/
  94287. obj-$(CONFIG_USB_ISP1760_HCD) += host/
  94288. +obj-$(CONFIG_USB_DWCOTG) += host/
  94289. obj-$(CONFIG_USB_IMX21_HCD) += host/
  94290. obj-$(CONFIG_USB_FSL_MPH_DR_OF) += host/
  94291. obj-$(CONFIG_USB_FUSBH200_HCD) += host/
  94292. diff -Nur linux-3.15/drivers/video/fbdev/bcm2708_fb.c linux-rpi/drivers/video/fbdev/bcm2708_fb.c
  94293. --- linux-3.15/drivers/video/fbdev/bcm2708_fb.c 1970-01-01 01:00:00.000000000 +0100
  94294. +++ linux-rpi/drivers/video/fbdev/bcm2708_fb.c 2014-06-11 21:05:32.000000000 +0200
  94295. @@ -0,0 +1,765 @@
  94296. +/*
  94297. + * linux/drivers/video/bcm2708_fb.c
  94298. + *
  94299. + * Copyright (C) 2010 Broadcom
  94300. + *
  94301. + * This file is subject to the terms and conditions of the GNU General Public
  94302. + * License. See the file COPYING in the main directory of this archive
  94303. + * for more details.
  94304. + *
  94305. + * Broadcom simple framebuffer driver
  94306. + *
  94307. + * This file is derived from cirrusfb.c
  94308. + * Copyright 1999-2001 Jeff Garzik <jgarzik@pobox.com>
  94309. + *
  94310. + */
  94311. +#include <linux/module.h>
  94312. +#include <linux/kernel.h>
  94313. +#include <linux/errno.h>
  94314. +#include <linux/string.h>
  94315. +#include <linux/slab.h>
  94316. +#include <linux/mm.h>
  94317. +#include <linux/fb.h>
  94318. +#include <linux/init.h>
  94319. +#include <linux/interrupt.h>
  94320. +#include <linux/ioport.h>
  94321. +#include <linux/list.h>
  94322. +#include <linux/platform_device.h>
  94323. +#include <linux/clk.h>
  94324. +#include <linux/printk.h>
  94325. +#include <linux/console.h>
  94326. +#include <linux/debugfs.h>
  94327. +
  94328. +#include <mach/dma.h>
  94329. +#include <mach/platform.h>
  94330. +#include <mach/vcio.h>
  94331. +
  94332. +#include <asm/sizes.h>
  94333. +#include <linux/io.h>
  94334. +#include <linux/dma-mapping.h>
  94335. +
  94336. +#ifdef BCM2708_FB_DEBUG
  94337. +#define print_debug(fmt,...) pr_debug("%s:%s:%d: "fmt, MODULE_NAME, __func__, __LINE__, ##__VA_ARGS__)
  94338. +#else
  94339. +#define print_debug(fmt,...)
  94340. +#endif
  94341. +
  94342. +/* This is limited to 16 characters when displayed by X startup */
  94343. +static const char *bcm2708_name = "BCM2708 FB";
  94344. +
  94345. +#define DRIVER_NAME "bcm2708_fb"
  94346. +
  94347. +static int fbwidth = 800; /* module parameter */
  94348. +static int fbheight = 480; /* module parameter */
  94349. +static int fbdepth = 16; /* module parameter */
  94350. +static int fbswap = 0; /* module parameter */
  94351. +
  94352. +static u32 dma_busy_wait_threshold = 1<<15;
  94353. +module_param(dma_busy_wait_threshold, int, 0644);
  94354. +MODULE_PARM_DESC(dma_busy_wait_threshold, "Busy-wait for DMA completion below this area");
  94355. +
  94356. +/* this data structure describes each frame buffer device we find */
  94357. +
  94358. +struct fbinfo_s {
  94359. + u32 xres, yres, xres_virtual, yres_virtual;
  94360. + u32 pitch, bpp;
  94361. + u32 xoffset, yoffset;
  94362. + u32 base;
  94363. + u32 screen_size;
  94364. + u16 cmap[256];
  94365. +};
  94366. +
  94367. +struct bcm2708_fb_stats {
  94368. + struct debugfs_regset32 regset;
  94369. + u32 dma_copies;
  94370. + u32 dma_irqs;
  94371. +};
  94372. +
  94373. +struct bcm2708_fb {
  94374. + struct fb_info fb;
  94375. + struct platform_device *dev;
  94376. + struct fbinfo_s *info;
  94377. + dma_addr_t dma;
  94378. + u32 cmap[16];
  94379. + int dma_chan;
  94380. + int dma_irq;
  94381. + void __iomem *dma_chan_base;
  94382. + void *cb_base; /* DMA control blocks */
  94383. + dma_addr_t cb_handle;
  94384. + struct dentry *debugfs_dir;
  94385. + wait_queue_head_t dma_waitq;
  94386. + struct bcm2708_fb_stats stats;
  94387. + unsigned long fb_bus_address;
  94388. +};
  94389. +
  94390. +#define to_bcm2708(info) container_of(info, struct bcm2708_fb, fb)
  94391. +
  94392. +static void bcm2708_fb_debugfs_deinit(struct bcm2708_fb *fb)
  94393. +{
  94394. + debugfs_remove_recursive(fb->debugfs_dir);
  94395. + fb->debugfs_dir = NULL;
  94396. +}
  94397. +
  94398. +static int bcm2708_fb_debugfs_init(struct bcm2708_fb *fb)
  94399. +{
  94400. + static struct debugfs_reg32 stats_registers[] = {
  94401. + {
  94402. + "dma_copies",
  94403. + offsetof(struct bcm2708_fb_stats, dma_copies)
  94404. + },
  94405. + {
  94406. + "dma_irqs",
  94407. + offsetof(struct bcm2708_fb_stats, dma_irqs)
  94408. + },
  94409. + };
  94410. +
  94411. + fb->debugfs_dir = debugfs_create_dir(DRIVER_NAME, NULL);
  94412. + if (!fb->debugfs_dir) {
  94413. + pr_warn("%s: could not create debugfs entry\n",
  94414. + __func__);
  94415. + return -EFAULT;
  94416. + }
  94417. +
  94418. + fb->stats.regset.regs = stats_registers;
  94419. + fb->stats.regset.nregs = ARRAY_SIZE(stats_registers);
  94420. + fb->stats.regset.base = &fb->stats;
  94421. +
  94422. + if (!debugfs_create_regset32(
  94423. + "stats", 0444, fb->debugfs_dir, &fb->stats.regset)) {
  94424. + pr_warn("%s: could not create statistics registers\n",
  94425. + __func__);
  94426. + goto fail;
  94427. + }
  94428. + return 0;
  94429. +
  94430. +fail:
  94431. + bcm2708_fb_debugfs_deinit(fb);
  94432. + return -EFAULT;
  94433. +}
  94434. +
  94435. +static int bcm2708_fb_set_bitfields(struct fb_var_screeninfo *var)
  94436. +{
  94437. + int ret = 0;
  94438. +
  94439. + memset(&var->transp, 0, sizeof(var->transp));
  94440. +
  94441. + var->red.msb_right = 0;
  94442. + var->green.msb_right = 0;
  94443. + var->blue.msb_right = 0;
  94444. +
  94445. + switch (var->bits_per_pixel) {
  94446. + case 1:
  94447. + case 2:
  94448. + case 4:
  94449. + case 8:
  94450. + var->red.length = var->bits_per_pixel;
  94451. + var->red.offset = 0;
  94452. + var->green.length = var->bits_per_pixel;
  94453. + var->green.offset = 0;
  94454. + var->blue.length = var->bits_per_pixel;
  94455. + var->blue.offset = 0;
  94456. + break;
  94457. + case 16:
  94458. + var->red.length = 5;
  94459. + var->blue.length = 5;
  94460. + /*
  94461. + * Green length can be 5 or 6 depending whether
  94462. + * we're operating in RGB555 or RGB565 mode.
  94463. + */
  94464. + if (var->green.length != 5 && var->green.length != 6)
  94465. + var->green.length = 6;
  94466. + break;
  94467. + case 24:
  94468. + var->red.length = 8;
  94469. + var->blue.length = 8;
  94470. + var->green.length = 8;
  94471. + break;
  94472. + case 32:
  94473. + var->red.length = 8;
  94474. + var->green.length = 8;
  94475. + var->blue.length = 8;
  94476. + var->transp.length = 8;
  94477. + break;
  94478. + default:
  94479. + ret = -EINVAL;
  94480. + break;
  94481. + }
  94482. +
  94483. + /*
  94484. + * >= 16bpp displays have separate colour component bitfields
  94485. + * encoded in the pixel data. Calculate their position from
  94486. + * the bitfield length defined above.
  94487. + */
  94488. + if (ret == 0 && var->bits_per_pixel >= 24 && fbswap) {
  94489. + var->blue.offset = 0;
  94490. + var->green.offset = var->blue.offset + var->blue.length;
  94491. + var->red.offset = var->green.offset + var->green.length;
  94492. + var->transp.offset = var->red.offset + var->red.length;
  94493. + } else if (ret == 0 && var->bits_per_pixel >= 24) {
  94494. + var->red.offset = 0;
  94495. + var->green.offset = var->red.offset + var->red.length;
  94496. + var->blue.offset = var->green.offset + var->green.length;
  94497. + var->transp.offset = var->blue.offset + var->blue.length;
  94498. + } else if (ret == 0 && var->bits_per_pixel >= 16) {
  94499. + var->blue.offset = 0;
  94500. + var->green.offset = var->blue.offset + var->blue.length;
  94501. + var->red.offset = var->green.offset + var->green.length;
  94502. + var->transp.offset = var->red.offset + var->red.length;
  94503. + }
  94504. +
  94505. + return ret;
  94506. +}
  94507. +
  94508. +static int bcm2708_fb_check_var(struct fb_var_screeninfo *var,
  94509. + struct fb_info *info)
  94510. +{
  94511. + /* info input, var output */
  94512. + int yres;
  94513. +
  94514. + /* info input, var output */
  94515. + print_debug("bcm2708_fb_check_var info(%p) %dx%d (%dx%d), %d, %d\n", info,
  94516. + info->var.xres, info->var.yres, info->var.xres_virtual,
  94517. + info->var.yres_virtual, (int)info->screen_size,
  94518. + info->var.bits_per_pixel);
  94519. + print_debug("bcm2708_fb_check_var var(%p) %dx%d (%dx%d), %d\n", var,
  94520. + var->xres, var->yres, var->xres_virtual, var->yres_virtual,
  94521. + var->bits_per_pixel);
  94522. +
  94523. + if (!var->bits_per_pixel)
  94524. + var->bits_per_pixel = 16;
  94525. +
  94526. + if (bcm2708_fb_set_bitfields(var) != 0) {
  94527. + pr_err("bcm2708_fb_check_var: invalid bits_per_pixel %d\n",
  94528. + var->bits_per_pixel);
  94529. + return -EINVAL;
  94530. + }
  94531. +
  94532. +
  94533. + if (var->xres_virtual < var->xres)
  94534. + var->xres_virtual = var->xres;
  94535. + /* use highest possible virtual resolution */
  94536. + if (var->yres_virtual == -1) {
  94537. + var->yres_virtual = 480;
  94538. +
  94539. + pr_err
  94540. + ("bcm2708_fb_check_var: virtual resolution set to maximum of %dx%d\n",
  94541. + var->xres_virtual, var->yres_virtual);
  94542. + }
  94543. + if (var->yres_virtual < var->yres)
  94544. + var->yres_virtual = var->yres;
  94545. +
  94546. + if (var->xoffset < 0)
  94547. + var->xoffset = 0;
  94548. + if (var->yoffset < 0)
  94549. + var->yoffset = 0;
  94550. +
  94551. + /* truncate xoffset and yoffset to maximum if too high */
  94552. + if (var->xoffset > var->xres_virtual - var->xres)
  94553. + var->xoffset = var->xres_virtual - var->xres - 1;
  94554. + if (var->yoffset > var->yres_virtual - var->yres)
  94555. + var->yoffset = var->yres_virtual - var->yres - 1;
  94556. +
  94557. + yres = var->yres;
  94558. + if (var->vmode & FB_VMODE_DOUBLE)
  94559. + yres *= 2;
  94560. + else if (var->vmode & FB_VMODE_INTERLACED)
  94561. + yres = (yres + 1) / 2;
  94562. +
  94563. + if (var->xres * yres > 1920 * 1200) {
  94564. + pr_err("bcm2708_fb_check_var: ERROR: Pixel size >= 1920x1200; "
  94565. + "special treatment required! (TODO)\n");
  94566. + return -EINVAL;
  94567. + }
  94568. +
  94569. + return 0;
  94570. +}
  94571. +
  94572. +static int bcm2708_fb_set_par(struct fb_info *info)
  94573. +{
  94574. + uint32_t val = 0;
  94575. + struct bcm2708_fb *fb = to_bcm2708(info);
  94576. + volatile struct fbinfo_s *fbinfo = fb->info;
  94577. + fbinfo->xres = info->var.xres;
  94578. + fbinfo->yres = info->var.yres;
  94579. + fbinfo->xres_virtual = info->var.xres_virtual;
  94580. + fbinfo->yres_virtual = info->var.yres_virtual;
  94581. + fbinfo->bpp = info->var.bits_per_pixel;
  94582. + fbinfo->xoffset = info->var.xoffset;
  94583. + fbinfo->yoffset = info->var.yoffset;
  94584. + fbinfo->base = 0; /* filled in by VC */
  94585. + fbinfo->pitch = 0; /* filled in by VC */
  94586. +
  94587. + print_debug("bcm2708_fb_set_par info(%p) %dx%d (%dx%d), %d, %d\n", info,
  94588. + info->var.xres, info->var.yres, info->var.xres_virtual,
  94589. + info->var.yres_virtual, (int)info->screen_size,
  94590. + info->var.bits_per_pixel);
  94591. +
  94592. + /* ensure last write to fbinfo is visible to GPU */
  94593. + wmb();
  94594. +
  94595. + /* inform vc about new framebuffer */
  94596. + bcm_mailbox_write(MBOX_CHAN_FB, fb->dma);
  94597. +
  94598. + /* TODO: replace fb driver with vchiq version */
  94599. + /* wait for response */
  94600. + bcm_mailbox_read(MBOX_CHAN_FB, &val);
  94601. +
  94602. + /* ensure GPU writes are visible to us */
  94603. + rmb();
  94604. +
  94605. + if (val == 0) {
  94606. + fb->fb.fix.line_length = fbinfo->pitch;
  94607. +
  94608. + if (info->var.bits_per_pixel <= 8)
  94609. + fb->fb.fix.visual = FB_VISUAL_PSEUDOCOLOR;
  94610. + else
  94611. + fb->fb.fix.visual = FB_VISUAL_TRUECOLOR;
  94612. +
  94613. + fb->fb_bus_address = fbinfo->base;
  94614. + fbinfo->base &= ~0xc0000000;
  94615. + fb->fb.fix.smem_start = fbinfo->base;
  94616. + fb->fb.fix.smem_len = fbinfo->pitch * fbinfo->yres_virtual;
  94617. + fb->fb.screen_size = fbinfo->screen_size;
  94618. + if (fb->fb.screen_base)
  94619. + iounmap(fb->fb.screen_base);
  94620. + fb->fb.screen_base =
  94621. + (void *)ioremap_wc(fbinfo->base, fb->fb.screen_size);
  94622. + if (!fb->fb.screen_base) {
  94623. + /* the console may currently be locked */
  94624. + console_trylock();
  94625. + console_unlock();
  94626. +
  94627. + BUG(); /* what can we do here */
  94628. + }
  94629. + }
  94630. + print_debug
  94631. + ("BCM2708FB: start = %p,%p width=%d, height=%d, bpp=%d, pitch=%d size=%d success=%d\n",
  94632. + (void *)fb->fb.screen_base, (void *)fb->fb_bus_address,
  94633. + fbinfo->xres, fbinfo->yres, fbinfo->bpp,
  94634. + fbinfo->pitch, (int)fb->fb.screen_size, val);
  94635. +
  94636. + return val;
  94637. +}
  94638. +
  94639. +static inline u32 convert_bitfield(int val, struct fb_bitfield *bf)
  94640. +{
  94641. + unsigned int mask = (1 << bf->length) - 1;
  94642. +
  94643. + return (val >> (16 - bf->length) & mask) << bf->offset;
  94644. +}
  94645. +
  94646. +
  94647. +static int bcm2708_fb_setcolreg(unsigned int regno, unsigned int red,
  94648. + unsigned int green, unsigned int blue,
  94649. + unsigned int transp, struct fb_info *info)
  94650. +{
  94651. + struct bcm2708_fb *fb = to_bcm2708(info);
  94652. +
  94653. + /*print_debug("BCM2708FB: setcolreg %d:(%02x,%02x,%02x,%02x) %x\n", regno, red, green, blue, transp, fb->fb.fix.visual);*/
  94654. + if (fb->fb.var.bits_per_pixel <= 8) {
  94655. + if (regno < 256) {
  94656. + /* blue [0:4], green [5:10], red [11:15] */
  94657. + fb->info->cmap[regno] = ((red >> (16-5)) & 0x1f) << 11 |
  94658. + ((green >> (16-6)) & 0x3f) << 5 |
  94659. + ((blue >> (16-5)) & 0x1f) << 0;
  94660. + }
  94661. + /* 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 */
  94662. + /* So just call it for what looks like the last colour in a list for now. */
  94663. + if (regno == 15 || regno == 255)
  94664. + bcm2708_fb_set_par(info);
  94665. + } else if (regno < 16) {
  94666. + fb->cmap[regno] = convert_bitfield(transp, &fb->fb.var.transp) |
  94667. + convert_bitfield(blue, &fb->fb.var.blue) |
  94668. + convert_bitfield(green, &fb->fb.var.green) |
  94669. + convert_bitfield(red, &fb->fb.var.red);
  94670. + }
  94671. + return regno > 255;
  94672. +}
  94673. +
  94674. +static int bcm2708_fb_blank(int blank_mode, struct fb_info *info)
  94675. +{
  94676. + /*print_debug("bcm2708_fb_blank\n"); */
  94677. + return -1;
  94678. +}
  94679. +
  94680. +static void bcm2708_fb_fillrect(struct fb_info *info,
  94681. + const struct fb_fillrect *rect)
  94682. +{
  94683. + /* (is called) print_debug("bcm2708_fb_fillrect\n"); */
  94684. + cfb_fillrect(info, rect);
  94685. +}
  94686. +
  94687. +/* A helper function for configuring dma control block */
  94688. +static void set_dma_cb(struct bcm2708_dma_cb *cb,
  94689. + int burst_size,
  94690. + dma_addr_t dst,
  94691. + int dst_stride,
  94692. + dma_addr_t src,
  94693. + int src_stride,
  94694. + int w,
  94695. + int h)
  94696. +{
  94697. + cb->info = BCM2708_DMA_BURST(burst_size) | BCM2708_DMA_S_WIDTH |
  94698. + BCM2708_DMA_S_INC | BCM2708_DMA_D_WIDTH |
  94699. + BCM2708_DMA_D_INC | BCM2708_DMA_TDMODE;
  94700. + cb->dst = dst;
  94701. + cb->src = src;
  94702. + /*
  94703. + * This is not really obvious from the DMA documentation,
  94704. + * but the top 16 bits must be programmmed to "height -1"
  94705. + * and not "height" in 2D mode.
  94706. + */
  94707. + cb->length = ((h - 1) << 16) | w;
  94708. + cb->stride = ((dst_stride - w) << 16) | (u16)(src_stride - w);
  94709. + cb->pad[0] = 0;
  94710. + cb->pad[1] = 0;
  94711. +}
  94712. +
  94713. +static void bcm2708_fb_copyarea(struct fb_info *info,
  94714. + const struct fb_copyarea *region)
  94715. +{
  94716. + struct bcm2708_fb *fb = to_bcm2708(info);
  94717. + struct bcm2708_dma_cb *cb = fb->cb_base;
  94718. + int bytes_per_pixel = (info->var.bits_per_pixel + 7) >> 3;
  94719. + /* Channel 0 supports larger bursts and is a bit faster */
  94720. + int burst_size = (fb->dma_chan == 0) ? 8 : 2;
  94721. + int pixels = region->width * region->height;
  94722. +
  94723. + /* Fallback to cfb_copyarea() if we don't like something */
  94724. + if (bytes_per_pixel > 4 ||
  94725. + info->var.xres * info->var.yres > 1920 * 1200 ||
  94726. + region->width <= 0 || region->width > info->var.xres ||
  94727. + region->height <= 0 || region->height > info->var.yres ||
  94728. + region->sx < 0 || region->sx >= info->var.xres ||
  94729. + region->sy < 0 || region->sy >= info->var.yres ||
  94730. + region->dx < 0 || region->dx >= info->var.xres ||
  94731. + region->dy < 0 || region->dy >= info->var.yres ||
  94732. + region->sx + region->width > info->var.xres ||
  94733. + region->dx + region->width > info->var.xres ||
  94734. + region->sy + region->height > info->var.yres ||
  94735. + region->dy + region->height > info->var.yres) {
  94736. + cfb_copyarea(info, region);
  94737. + return;
  94738. + }
  94739. +
  94740. + if (region->dy == region->sy && region->dx > region->sx) {
  94741. + /*
  94742. + * A difficult case of overlapped copy. Because DMA can't
  94743. + * copy individual scanlines in backwards direction, we need
  94744. + * two-pass processing. We do it by programming a chain of dma
  94745. + * control blocks in the first 16K part of the buffer and use
  94746. + * the remaining 48K as the intermediate temporary scratch
  94747. + * buffer. The buffer size is sufficient to handle up to
  94748. + * 1920x1200 resolution at 32bpp pixel depth.
  94749. + */
  94750. + int y;
  94751. + dma_addr_t control_block_pa = fb->cb_handle;
  94752. + dma_addr_t scratchbuf = fb->cb_handle + 16 * 1024;
  94753. + int scanline_size = bytes_per_pixel * region->width;
  94754. + int scanlines_per_cb = (64 * 1024 - 16 * 1024) / scanline_size;
  94755. +
  94756. + for (y = 0; y < region->height; y += scanlines_per_cb) {
  94757. + dma_addr_t src =
  94758. + fb->fb_bus_address +
  94759. + bytes_per_pixel * region->sx +
  94760. + (region->sy + y) * fb->fb.fix.line_length;
  94761. + dma_addr_t dst =
  94762. + fb->fb_bus_address +
  94763. + bytes_per_pixel * region->dx +
  94764. + (region->dy + y) * fb->fb.fix.line_length;
  94765. +
  94766. + if (region->height - y < scanlines_per_cb)
  94767. + scanlines_per_cb = region->height - y;
  94768. +
  94769. + set_dma_cb(cb, burst_size, scratchbuf, scanline_size,
  94770. + src, fb->fb.fix.line_length,
  94771. + scanline_size, scanlines_per_cb);
  94772. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  94773. + cb->next = control_block_pa;
  94774. + cb++;
  94775. +
  94776. + set_dma_cb(cb, burst_size, dst, fb->fb.fix.line_length,
  94777. + scratchbuf, scanline_size,
  94778. + scanline_size, scanlines_per_cb);
  94779. + control_block_pa += sizeof(struct bcm2708_dma_cb);
  94780. + cb->next = control_block_pa;
  94781. + cb++;
  94782. + }
  94783. + /* move the pointer back to the last dma control block */
  94784. + cb--;
  94785. + } else {
  94786. + /* A single dma control block is enough. */
  94787. + int sy, dy, stride;
  94788. + if (region->dy <= region->sy) {
  94789. + /* processing from top to bottom */
  94790. + dy = region->dy;
  94791. + sy = region->sy;
  94792. + stride = fb->fb.fix.line_length;
  94793. + } else {
  94794. + /* processing from bottom to top */
  94795. + dy = region->dy + region->height - 1;
  94796. + sy = region->sy + region->height - 1;
  94797. + stride = -fb->fb.fix.line_length;
  94798. + }
  94799. + set_dma_cb(cb, burst_size,
  94800. + fb->fb_bus_address + dy * fb->fb.fix.line_length +
  94801. + bytes_per_pixel * region->dx,
  94802. + stride,
  94803. + fb->fb_bus_address + sy * fb->fb.fix.line_length +
  94804. + bytes_per_pixel * region->sx,
  94805. + stride,
  94806. + region->width * bytes_per_pixel,
  94807. + region->height);
  94808. + }
  94809. +
  94810. + /* end of dma control blocks chain */
  94811. + cb->next = 0;
  94812. +
  94813. +
  94814. + if (pixels < dma_busy_wait_threshold) {
  94815. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  94816. + bcm_dma_wait_idle(fb->dma_chan_base);
  94817. + } else {
  94818. + void __iomem *dma_chan = fb->dma_chan_base;
  94819. + cb->info |= BCM2708_DMA_INT_EN;
  94820. + bcm_dma_start(fb->dma_chan_base, fb->cb_handle);
  94821. + while (bcm_dma_is_busy(dma_chan)) {
  94822. + wait_event_interruptible(
  94823. + fb->dma_waitq,
  94824. + !bcm_dma_is_busy(dma_chan));
  94825. + }
  94826. + fb->stats.dma_irqs++;
  94827. + }
  94828. + fb->stats.dma_copies++;
  94829. +}
  94830. +
  94831. +static void bcm2708_fb_imageblit(struct fb_info *info,
  94832. + const struct fb_image *image)
  94833. +{
  94834. + /* (is called) print_debug("bcm2708_fb_imageblit\n"); */
  94835. + cfb_imageblit(info, image);
  94836. +}
  94837. +
  94838. +static irqreturn_t bcm2708_fb_dma_irq(int irq, void *cxt)
  94839. +{
  94840. + struct bcm2708_fb *fb = cxt;
  94841. +
  94842. + /* FIXME: should read status register to check if this is
  94843. + * actually interrupting us or not, in case this interrupt
  94844. + * ever becomes shared amongst several DMA channels
  94845. + *
  94846. + * readl(dma_chan_base + BCM2708_DMA_CS) & BCM2708_DMA_IRQ;
  94847. + */
  94848. +
  94849. + /* acknowledge the interrupt */
  94850. + writel(BCM2708_DMA_INT, fb->dma_chan_base + BCM2708_DMA_CS);
  94851. +
  94852. + wake_up(&fb->dma_waitq);
  94853. + return IRQ_HANDLED;
  94854. +}
  94855. +
  94856. +static struct fb_ops bcm2708_fb_ops = {
  94857. + .owner = THIS_MODULE,
  94858. + .fb_check_var = bcm2708_fb_check_var,
  94859. + .fb_set_par = bcm2708_fb_set_par,
  94860. + .fb_setcolreg = bcm2708_fb_setcolreg,
  94861. + .fb_blank = bcm2708_fb_blank,
  94862. + .fb_fillrect = bcm2708_fb_fillrect,
  94863. + .fb_copyarea = bcm2708_fb_copyarea,
  94864. + .fb_imageblit = bcm2708_fb_imageblit,
  94865. +};
  94866. +
  94867. +static int bcm2708_fb_register(struct bcm2708_fb *fb)
  94868. +{
  94869. + int ret;
  94870. + dma_addr_t dma;
  94871. + void *mem;
  94872. +
  94873. + mem =
  94874. + dma_alloc_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), &dma,
  94875. + GFP_KERNEL);
  94876. +
  94877. + if (NULL == mem) {
  94878. + pr_err(": unable to allocate fbinfo buffer\n");
  94879. + ret = -ENOMEM;
  94880. + } else {
  94881. + fb->info = (struct fbinfo_s *)mem;
  94882. + fb->dma = dma;
  94883. + }
  94884. + fb->fb.fbops = &bcm2708_fb_ops;
  94885. + fb->fb.flags = FBINFO_FLAG_DEFAULT | FBINFO_HWACCEL_COPYAREA;
  94886. + fb->fb.pseudo_palette = fb->cmap;
  94887. +
  94888. + strncpy(fb->fb.fix.id, bcm2708_name, sizeof(fb->fb.fix.id));
  94889. + fb->fb.fix.type = FB_TYPE_PACKED_PIXELS;
  94890. + fb->fb.fix.type_aux = 0;
  94891. + fb->fb.fix.xpanstep = 0;
  94892. + fb->fb.fix.ypanstep = 0;
  94893. + fb->fb.fix.ywrapstep = 0;
  94894. + fb->fb.fix.accel = FB_ACCEL_NONE;
  94895. +
  94896. + fb->fb.var.xres = fbwidth;
  94897. + fb->fb.var.yres = fbheight;
  94898. + fb->fb.var.xres_virtual = fbwidth;
  94899. + fb->fb.var.yres_virtual = fbheight;
  94900. + fb->fb.var.bits_per_pixel = fbdepth;
  94901. + fb->fb.var.vmode = FB_VMODE_NONINTERLACED;
  94902. + fb->fb.var.activate = FB_ACTIVATE_NOW;
  94903. + fb->fb.var.nonstd = 0;
  94904. + fb->fb.var.height = -1; /* height of picture in mm */
  94905. + fb->fb.var.width = -1; /* width of picture in mm */
  94906. + fb->fb.var.accel_flags = 0;
  94907. +
  94908. + fb->fb.monspecs.hfmin = 0;
  94909. + fb->fb.monspecs.hfmax = 100000;
  94910. + fb->fb.monspecs.vfmin = 0;
  94911. + fb->fb.monspecs.vfmax = 400;
  94912. + fb->fb.monspecs.dclkmin = 1000000;
  94913. + fb->fb.monspecs.dclkmax = 100000000;
  94914. +
  94915. + bcm2708_fb_set_bitfields(&fb->fb.var);
  94916. + init_waitqueue_head(&fb->dma_waitq);
  94917. +
  94918. + /*
  94919. + * Allocate colourmap.
  94920. + */
  94921. +
  94922. + fb_set_var(&fb->fb, &fb->fb.var);
  94923. +
  94924. + print_debug("BCM2708FB: registering framebuffer (%dx%d@%d) (%d)\n", fbwidth
  94925. + fbheight, fbdepth, fbswap);
  94926. +
  94927. + ret = register_framebuffer(&fb->fb);
  94928. + print_debug("BCM2708FB: register framebuffer (%d)\n", ret);
  94929. + if (ret == 0)
  94930. + goto out;
  94931. +
  94932. + print_debug("BCM2708FB: cannot register framebuffer (%d)\n", ret);
  94933. +out:
  94934. + return ret;
  94935. +}
  94936. +
  94937. +static int bcm2708_fb_probe(struct platform_device *dev)
  94938. +{
  94939. + struct bcm2708_fb *fb;
  94940. + int ret;
  94941. +
  94942. + fb = kzalloc(sizeof(struct bcm2708_fb), GFP_KERNEL);
  94943. + if (!fb) {
  94944. + dev_err(&dev->dev,
  94945. + "could not allocate new bcm2708_fb struct\n");
  94946. + ret = -ENOMEM;
  94947. + goto free_region;
  94948. + }
  94949. +
  94950. + bcm2708_fb_debugfs_init(fb);
  94951. +
  94952. + fb->cb_base = dma_alloc_writecombine(&dev->dev, SZ_64K,
  94953. + &fb->cb_handle, GFP_KERNEL);
  94954. + if (!fb->cb_base) {
  94955. + dev_err(&dev->dev, "cannot allocate DMA CBs\n");
  94956. + ret = -ENOMEM;
  94957. + goto free_fb;
  94958. + }
  94959. +
  94960. + pr_info("BCM2708FB: allocated DMA memory %08x\n",
  94961. + fb->cb_handle);
  94962. +
  94963. + ret = bcm_dma_chan_alloc(BCM_DMA_FEATURE_BULK,
  94964. + &fb->dma_chan_base, &fb->dma_irq);
  94965. + if (ret < 0) {
  94966. + dev_err(&dev->dev, "couldn't allocate a DMA channel\n");
  94967. + goto free_cb;
  94968. + }
  94969. + fb->dma_chan = ret;
  94970. +
  94971. + ret = request_irq(fb->dma_irq, bcm2708_fb_dma_irq,
  94972. + 0, "bcm2708_fb dma", fb);
  94973. + if (ret) {
  94974. + pr_err("%s: failed to request DMA irq\n", __func__);
  94975. + goto free_dma_chan;
  94976. + }
  94977. +
  94978. +
  94979. + pr_info("BCM2708FB: allocated DMA channel %d @ %p\n",
  94980. + fb->dma_chan, fb->dma_chan_base);
  94981. +
  94982. + fb->dev = dev;
  94983. +
  94984. + ret = bcm2708_fb_register(fb);
  94985. + if (ret == 0) {
  94986. + platform_set_drvdata(dev, fb);
  94987. + goto out;
  94988. + }
  94989. +
  94990. +free_dma_chan:
  94991. + bcm_dma_chan_free(fb->dma_chan);
  94992. +free_cb:
  94993. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  94994. +free_fb:
  94995. + kfree(fb);
  94996. +free_region:
  94997. + dev_err(&dev->dev, "probe failed, err %d\n", ret);
  94998. +out:
  94999. + return ret;
  95000. +}
  95001. +
  95002. +static int bcm2708_fb_remove(struct platform_device *dev)
  95003. +{
  95004. + struct bcm2708_fb *fb = platform_get_drvdata(dev);
  95005. +
  95006. + platform_set_drvdata(dev, NULL);
  95007. +
  95008. + if (fb->fb.screen_base)
  95009. + iounmap(fb->fb.screen_base);
  95010. + unregister_framebuffer(&fb->fb);
  95011. +
  95012. + dma_free_writecombine(&dev->dev, SZ_64K, fb->cb_base, fb->cb_handle);
  95013. + bcm_dma_chan_free(fb->dma_chan);
  95014. +
  95015. + dma_free_coherent(NULL, PAGE_ALIGN(sizeof(*fb->info)), (void *)fb->info,
  95016. + fb->dma);
  95017. + bcm2708_fb_debugfs_deinit(fb);
  95018. +
  95019. + free_irq(fb->dma_irq, fb);
  95020. +
  95021. + kfree(fb);
  95022. +
  95023. + return 0;
  95024. +}
  95025. +
  95026. +static struct platform_driver bcm2708_fb_driver = {
  95027. + .probe = bcm2708_fb_probe,
  95028. + .remove = bcm2708_fb_remove,
  95029. + .driver = {
  95030. + .name = DRIVER_NAME,
  95031. + .owner = THIS_MODULE,
  95032. + },
  95033. +};
  95034. +
  95035. +static int __init bcm2708_fb_init(void)
  95036. +{
  95037. + return platform_driver_register(&bcm2708_fb_driver);
  95038. +}
  95039. +
  95040. +module_init(bcm2708_fb_init);
  95041. +
  95042. +static void __exit bcm2708_fb_exit(void)
  95043. +{
  95044. + platform_driver_unregister(&bcm2708_fb_driver);
  95045. +}
  95046. +
  95047. +module_exit(bcm2708_fb_exit);
  95048. +
  95049. +module_param(fbwidth, int, 0644);
  95050. +module_param(fbheight, int, 0644);
  95051. +module_param(fbdepth, int, 0644);
  95052. +module_param(fbswap, int, 0644);
  95053. +
  95054. +MODULE_DESCRIPTION("BCM2708 framebuffer driver");
  95055. +MODULE_LICENSE("GPL");
  95056. +
  95057. +MODULE_PARM_DESC(fbwidth, "Width of ARM Framebuffer");
  95058. +MODULE_PARM_DESC(fbheight, "Height of ARM Framebuffer");
  95059. +MODULE_PARM_DESC(fbdepth, "Bit depth of ARM Framebuffer");
  95060. +MODULE_PARM_DESC(fbswap, "Swap order of red and blue in 24 and 32 bit modes");
  95061. diff -Nur linux-3.15/drivers/video/fbdev/core/cfbimgblt.c linux-rpi/drivers/video/fbdev/core/cfbimgblt.c
  95062. --- linux-3.15/drivers/video/fbdev/core/cfbimgblt.c 2014-06-08 20:19:54.000000000 +0200
  95063. +++ linux-rpi/drivers/video/fbdev/core/cfbimgblt.c 2014-06-11 21:05:32.000000000 +0200
  95064. @@ -28,6 +28,11 @@
  95065. *
  95066. * Also need to add code to deal with cards endians that are different than
  95067. * the native cpu endians. I also need to deal with MSB position in the word.
  95068. + * Modified by Harm Hanemaaijer (fgenfb@yahoo.com) 2013:
  95069. + * - Provide optimized versions of fast_imageblit for 16 and 32bpp that are
  95070. + * significantly faster than the previous implementation.
  95071. + * - Simplify the fast/slow_imageblit selection code, avoiding integer
  95072. + * divides.
  95073. */
  95074. #include <linux/module.h>
  95075. #include <linux/string.h>
  95076. @@ -262,6 +267,133 @@
  95077. }
  95078. }
  95079. +/*
  95080. + * Optimized fast_imageblit for bpp == 16. ppw = 2, bit_mask = 3 folded
  95081. + * into the code, main loop unrolled.
  95082. + */
  95083. +
  95084. +static inline void fast_imageblit16(const struct fb_image *image,
  95085. + struct fb_info *p, u8 __iomem * dst1,
  95086. + u32 fgcolor, u32 bgcolor)
  95087. +{
  95088. + u32 fgx = fgcolor, bgx = bgcolor;
  95089. + u32 spitch = (image->width + 7) / 8;
  95090. + u32 end_mask, eorx;
  95091. + const char *s = image->data, *src;
  95092. + u32 __iomem *dst;
  95093. + const u32 *tab = NULL;
  95094. + int i, j, k;
  95095. +
  95096. + tab = fb_be_math(p) ? cfb_tab16_be : cfb_tab16_le;
  95097. +
  95098. + fgx <<= 16;
  95099. + bgx <<= 16;
  95100. + fgx |= fgcolor;
  95101. + bgx |= bgcolor;
  95102. +
  95103. + eorx = fgx ^ bgx;
  95104. + k = image->width / 2;
  95105. +
  95106. + for (i = image->height; i--;) {
  95107. + dst = (u32 __iomem *) dst1;
  95108. + src = s;
  95109. +
  95110. + j = k;
  95111. + while (j >= 4) {
  95112. + u8 bits = *src;
  95113. + end_mask = tab[(bits >> 6) & 3];
  95114. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95115. + end_mask = tab[(bits >> 4) & 3];
  95116. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95117. + end_mask = tab[(bits >> 2) & 3];
  95118. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95119. + end_mask = tab[bits & 3];
  95120. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95121. + src++;
  95122. + j -= 4;
  95123. + }
  95124. + if (j != 0) {
  95125. + u8 bits = *src;
  95126. + end_mask = tab[(bits >> 6) & 3];
  95127. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95128. + if (j >= 2) {
  95129. + end_mask = tab[(bits >> 4) & 3];
  95130. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95131. + if (j == 3) {
  95132. + end_mask = tab[(bits >> 2) & 3];
  95133. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  95134. + }
  95135. + }
  95136. + }
  95137. + dst1 += p->fix.line_length;
  95138. + s += spitch;
  95139. + }
  95140. +}
  95141. +
  95142. +/*
  95143. + * Optimized fast_imageblit for bpp == 32. ppw = 1, bit_mask = 1 folded
  95144. + * into the code, main loop unrolled.
  95145. + */
  95146. +
  95147. +static inline void fast_imageblit32(const struct fb_image *image,
  95148. + struct fb_info *p, u8 __iomem * dst1,
  95149. + u32 fgcolor, u32 bgcolor)
  95150. +{
  95151. + u32 fgx = fgcolor, bgx = bgcolor;
  95152. + u32 spitch = (image->width + 7) / 8;
  95153. + u32 end_mask, eorx;
  95154. + const char *s = image->data, *src;
  95155. + u32 __iomem *dst;
  95156. + const u32 *tab = NULL;
  95157. + int i, j, k;
  95158. +
  95159. + tab = cfb_tab32;
  95160. +
  95161. + eorx = fgx ^ bgx;
  95162. + k = image->width;
  95163. +
  95164. + for (i = image->height; i--;) {
  95165. + dst = (u32 __iomem *) dst1;
  95166. + src = s;
  95167. +
  95168. + j = k;
  95169. + while (j >= 8) {
  95170. + u8 bits = *src;
  95171. + end_mask = tab[(bits >> 7) & 1];
  95172. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95173. + end_mask = tab[(bits >> 6) & 1];
  95174. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95175. + end_mask = tab[(bits >> 5) & 1];
  95176. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95177. + end_mask = tab[(bits >> 4) & 1];
  95178. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95179. + end_mask = tab[(bits >> 3) & 1];
  95180. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95181. + end_mask = tab[(bits >> 2) & 1];
  95182. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95183. + end_mask = tab[(bits >> 1) & 1];
  95184. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95185. + end_mask = tab[bits & 1];
  95186. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95187. + src++;
  95188. + j -= 8;
  95189. + }
  95190. + if (j != 0) {
  95191. + u32 bits = (u32) * src;
  95192. + while (j > 1) {
  95193. + end_mask = tab[(bits >> 7) & 1];
  95194. + FB_WRITEL((end_mask & eorx) ^ bgx, dst++);
  95195. + bits <<= 1;
  95196. + j--;
  95197. + }
  95198. + end_mask = tab[(bits >> 7) & 1];
  95199. + FB_WRITEL((end_mask & eorx) ^ bgx, dst);
  95200. + }
  95201. + dst1 += p->fix.line_length;
  95202. + s += spitch;
  95203. + }
  95204. +}
  95205. +
  95206. void cfb_imageblit(struct fb_info *p, const struct fb_image *image)
  95207. {
  95208. u32 fgcolor, bgcolor, start_index, bitstart, pitch_index = 0;
  95209. @@ -294,11 +426,21 @@
  95210. bgcolor = image->bg_color;
  95211. }
  95212. - if (32 % bpp == 0 && !start_index && !pitch_index &&
  95213. - ((width & (32/bpp-1)) == 0) &&
  95214. - bpp >= 8 && bpp <= 32)
  95215. - fast_imageblit(image, p, dst1, fgcolor, bgcolor);
  95216. - else
  95217. + if (!start_index && !pitch_index) {
  95218. + if (bpp == 32)
  95219. + fast_imageblit32(image, p, dst1, fgcolor,
  95220. + bgcolor);
  95221. + else if (bpp == 16 && (width & 1) == 0)
  95222. + fast_imageblit16(image, p, dst1, fgcolor,
  95223. + bgcolor);
  95224. + else if (bpp == 8 && (width & 3) == 0)
  95225. + fast_imageblit(image, p, dst1, fgcolor,
  95226. + bgcolor);
  95227. + else
  95228. + slow_imageblit(image, p, dst1, fgcolor,
  95229. + bgcolor,
  95230. + start_index, pitch_index);
  95231. + } else
  95232. slow_imageblit(image, p, dst1, fgcolor, bgcolor,
  95233. start_index, pitch_index);
  95234. } else
  95235. diff -Nur linux-3.15/drivers/video/fbdev/core/fbmem.c linux-rpi/drivers/video/fbdev/core/fbmem.c
  95236. --- linux-3.15/drivers/video/fbdev/core/fbmem.c 2014-06-08 20:19:54.000000000 +0200
  95237. +++ linux-rpi/drivers/video/fbdev/core/fbmem.c 2014-06-11 21:05:32.000000000 +0200
  95238. @@ -1083,6 +1083,25 @@
  95239. }
  95240. EXPORT_SYMBOL(fb_blank);
  95241. +static int fb_copyarea_user(struct fb_info *info,
  95242. + struct fb_copyarea *copy)
  95243. +{
  95244. + int ret = 0;
  95245. + if (!lock_fb_info(info))
  95246. + return -ENODEV;
  95247. + if (copy->dx + copy->width > info->var.xres ||
  95248. + copy->sx + copy->width > info->var.xres ||
  95249. + copy->dy + copy->height > info->var.yres ||
  95250. + copy->sy + copy->height > info->var.yres) {
  95251. + ret = -EINVAL;
  95252. + goto out;
  95253. + }
  95254. + info->fbops->fb_copyarea(info, copy);
  95255. +out:
  95256. + unlock_fb_info(info);
  95257. + return ret;
  95258. +}
  95259. +
  95260. static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
  95261. unsigned long arg)
  95262. {
  95263. @@ -1093,6 +1112,7 @@
  95264. struct fb_cmap cmap_from;
  95265. struct fb_cmap_user cmap;
  95266. struct fb_event event;
  95267. + struct fb_copyarea copy;
  95268. void __user *argp = (void __user *)arg;
  95269. long ret = 0;
  95270. @@ -1210,6 +1230,15 @@
  95271. unlock_fb_info(info);
  95272. console_unlock();
  95273. break;
  95274. + case FBIOCOPYAREA:
  95275. + if (info->flags & FBINFO_HWACCEL_COPYAREA) {
  95276. + /* only provide this ioctl if it is accelerated */
  95277. + if (copy_from_user(&copy, argp, sizeof(copy)))
  95278. + return -EFAULT;
  95279. + ret = fb_copyarea_user(info, &copy);
  95280. + break;
  95281. + }
  95282. + /* fall through */
  95283. default:
  95284. if (!lock_fb_info(info))
  95285. return -ENODEV;
  95286. @@ -1364,6 +1393,7 @@
  95287. case FBIOPAN_DISPLAY:
  95288. case FBIOGET_CON2FBMAP:
  95289. case FBIOPUT_CON2FBMAP:
  95290. + case FBIOCOPYAREA:
  95291. arg = (unsigned long) compat_ptr(arg);
  95292. case FBIOBLANK:
  95293. ret = do_fb_ioctl(info, cmd, arg);
  95294. diff -Nur linux-3.15/drivers/video/fbdev/Kconfig linux-rpi/drivers/video/fbdev/Kconfig
  95295. --- linux-3.15/drivers/video/fbdev/Kconfig 2014-06-08 20:19:54.000000000 +0200
  95296. +++ linux-rpi/drivers/video/fbdev/Kconfig 2014-06-11 21:05:32.000000000 +0200
  95297. @@ -220,6 +220,20 @@
  95298. comment "Frame buffer hardware drivers"
  95299. depends on FB
  95300. +config FB_BCM2708
  95301. + tristate "BCM2708 framebuffer support"
  95302. + depends on FB && ARM
  95303. + select FB_CFB_FILLRECT
  95304. + select FB_CFB_COPYAREA
  95305. + select FB_CFB_IMAGEBLIT
  95306. + help
  95307. + This framebuffer device driver is for the BCM2708 framebuffer.
  95308. +
  95309. + If you want to compile this as a module (=code which can be
  95310. + inserted into and removed from the running kernel), say M
  95311. + here and read <file:Documentation/kbuild/modules.txt>. The module
  95312. + will be called bcm2708_fb.
  95313. +
  95314. config FB_GRVGA
  95315. tristate "Aeroflex Gaisler framebuffer support"
  95316. depends on FB && SPARC
  95317. diff -Nur linux-3.15/drivers/video/fbdev/Makefile linux-rpi/drivers/video/fbdev/Makefile
  95318. --- linux-3.15/drivers/video/fbdev/Makefile 2014-06-08 20:19:54.000000000 +0200
  95319. +++ linux-rpi/drivers/video/fbdev/Makefile 2014-06-11 21:05:32.000000000 +0200
  95320. @@ -12,6 +12,7 @@
  95321. obj-$(CONFIG_FB_WMT_GE_ROPS) += wmt_ge_rops.o
  95322. # Hardware specific drivers go first
  95323. +obj-$(CONFIG_FB_BCM2708) += bcm2708_fb.o
  95324. obj-$(CONFIG_FB_AMIGA) += amifb.o c2p_planar.o
  95325. obj-$(CONFIG_FB_ARC) += arcfb.o
  95326. obj-$(CONFIG_FB_CLPS711X) += clps711xfb.o
  95327. diff -Nur linux-3.15/drivers/video/logo/logo_linux_clut224.ppm linux-rpi/drivers/video/logo/logo_linux_clut224.ppm
  95328. --- linux-3.15/drivers/video/logo/logo_linux_clut224.ppm 2014-06-08 20:19:54.000000000 +0200
  95329. +++ linux-rpi/drivers/video/logo/logo_linux_clut224.ppm 2014-06-11 21:03:44.000000000 +0200
  95330. @@ -1,1604 +1,883 @@
  95331. P3
  95332. -# Standard 224-color Linux logo
  95333. -80 80
  95334. +63 80
  95335. 255
  95336. - 0 0 0 0 0 0 0 0 0 0 0 0
  95337. - 0 0 0 0 0 0 0 0 0 0 0 0
  95338. - 0 0 0 0 0 0 0 0 0 0 0 0
  95339. - 0 0 0 0 0 0 0 0 0 0 0 0
  95340. - 0 0 0 0 0 0 0 0 0 0 0 0
  95341. - 0 0 0 0 0 0 0 0 0 0 0 0
  95342. - 0 0 0 0 0 0 0 0 0 0 0 0
  95343. - 0 0 0 0 0 0 0 0 0 0 0 0
  95344. - 0 0 0 0 0 0 0 0 0 0 0 0
  95345. - 6 6 6 6 6 6 10 10 10 10 10 10
  95346. - 10 10 10 6 6 6 6 6 6 6 6 6
  95347. - 0 0 0 0 0 0 0 0 0 0 0 0
  95348. - 0 0 0 0 0 0 0 0 0 0 0 0
  95349. - 0 0 0 0 0 0 0 0 0 0 0 0
  95350. - 0 0 0 0 0 0 0 0 0 0 0 0
  95351. - 0 0 0 0 0 0 0 0 0 0 0 0
  95352. - 0 0 0 0 0 0 0 0 0 0 0 0
  95353. - 0 0 0 0 0 0 0 0 0 0 0 0
  95354. - 0 0 0 0 0 0 0 0 0 0 0 0
  95355. - 0 0 0 0 0 0 0 0 0 0 0 0
  95356. - 0 0 0 0 0 0 0 0 0 0 0 0
  95357. - 0 0 0 0 0 0 0 0 0 0 0 0
  95358. - 0 0 0 0 0 0 0 0 0 0 0 0
  95359. - 0 0 0 0 0 0 0 0 0 0 0 0
  95360. - 0 0 0 0 0 0 0 0 0 0 0 0
  95361. - 0 0 0 0 0 0 0 0 0 0 0 0
  95362. - 0 0 0 0 0 0 0 0 0 0 0 0
  95363. - 0 0 0 0 0 0 0 0 0 0 0 0
  95364. - 0 0 0 6 6 6 10 10 10 14 14 14
  95365. - 22 22 22 26 26 26 30 30 30 34 34 34
  95366. - 30 30 30 30 30 30 26 26 26 18 18 18
  95367. - 14 14 14 10 10 10 6 6 6 0 0 0
  95368. - 0 0 0 0 0 0 0 0 0 0 0 0
  95369. - 0 0 0 0 0 0 0 0 0 0 0 0
  95370. - 0 0 0 0 0 0 0 0 0 0 0 0
  95371. - 0 0 0 0 0 0 0 0 0 0 0 0
  95372. - 0 0 0 0 0 0 0 0 0 0 0 0
  95373. - 0 0 0 0 0 0 0 0 0 0 0 0
  95374. - 0 0 0 0 0 0 0 0 0 0 0 0
  95375. - 0 0 0 0 0 0 0 0 0 0 0 0
  95376. - 0 0 0 0 0 0 0 0 0 0 0 0
  95377. - 0 0 0 0 0 1 0 0 1 0 0 0
  95378. - 0 0 0 0 0 0 0 0 0 0 0 0
  95379. - 0 0 0 0 0 0 0 0 0 0 0 0
  95380. - 0 0 0 0 0 0 0 0 0 0 0 0
  95381. - 0 0 0 0 0 0 0 0 0 0 0 0
  95382. - 0 0 0 0 0 0 0 0 0 0 0 0
  95383. - 0 0 0 0 0 0 0 0 0 0 0 0
  95384. - 6 6 6 14 14 14 26 26 26 42 42 42
  95385. - 54 54 54 66 66 66 78 78 78 78 78 78
  95386. - 78 78 78 74 74 74 66 66 66 54 54 54
  95387. - 42 42 42 26 26 26 18 18 18 10 10 10
  95388. - 6 6 6 0 0 0 0 0 0 0 0 0
  95389. - 0 0 0 0 0 0 0 0 0 0 0 0
  95390. - 0 0 0 0 0 0 0 0 0 0 0 0
  95391. - 0 0 0 0 0 0 0 0 0 0 0 0
  95392. - 0 0 0 0 0 0 0 0 0 0 0 0
  95393. - 0 0 0 0 0 0 0 0 0 0 0 0
  95394. - 0 0 0 0 0 0 0 0 0 0 0 0
  95395. - 0 0 0 0 0 0 0 0 0 0 0 0
  95396. - 0 0 0 0 0 0 0 0 0 0 0 0
  95397. - 0 0 1 0 0 0 0 0 0 0 0 0
  95398. - 0 0 0 0 0 0 0 0 0 0 0 0
  95399. - 0 0 0 0 0 0 0 0 0 0 0 0
  95400. - 0 0 0 0 0 0 0 0 0 0 0 0
  95401. - 0 0 0 0 0 0 0 0 0 0 0 0
  95402. - 0 0 0 0 0 0 0 0 0 0 0 0
  95403. - 0 0 0 0 0 0 0 0 0 10 10 10
  95404. - 22 22 22 42 42 42 66 66 66 86 86 86
  95405. - 66 66 66 38 38 38 38 38 38 22 22 22
  95406. - 26 26 26 34 34 34 54 54 54 66 66 66
  95407. - 86 86 86 70 70 70 46 46 46 26 26 26
  95408. - 14 14 14 6 6 6 0 0 0 0 0 0
  95409. - 0 0 0 0 0 0 0 0 0 0 0 0
  95410. - 0 0 0 0 0 0 0 0 0 0 0 0
  95411. - 0 0 0 0 0 0 0 0 0 0 0 0
  95412. - 0 0 0 0 0 0 0 0 0 0 0 0
  95413. - 0 0 0 0 0 0 0 0 0 0 0 0
  95414. - 0 0 0 0 0 0 0 0 0 0 0 0
  95415. - 0 0 0 0 0 0 0 0 0 0 0 0
  95416. - 0 0 0 0 0 0 0 0 0 0 0 0
  95417. - 0 0 1 0 0 1 0 0 1 0 0 0
  95418. - 0 0 0 0 0 0 0 0 0 0 0 0
  95419. - 0 0 0 0 0 0 0 0 0 0 0 0
  95420. - 0 0 0 0 0 0 0 0 0 0 0 0
  95421. - 0 0 0 0 0 0 0 0 0 0 0 0
  95422. - 0 0 0 0 0 0 0 0 0 0 0 0
  95423. - 0 0 0 0 0 0 10 10 10 26 26 26
  95424. - 50 50 50 82 82 82 58 58 58 6 6 6
  95425. - 2 2 6 2 2 6 2 2 6 2 2 6
  95426. - 2 2 6 2 2 6 2 2 6 2 2 6
  95427. - 6 6 6 54 54 54 86 86 86 66 66 66
  95428. - 38 38 38 18 18 18 6 6 6 0 0 0
  95429. - 0 0 0 0 0 0 0 0 0 0 0 0
  95430. - 0 0 0 0 0 0 0 0 0 0 0 0
  95431. - 0 0 0 0 0 0 0 0 0 0 0 0
  95432. - 0 0 0 0 0 0 0 0 0 0 0 0
  95433. - 0 0 0 0 0 0 0 0 0 0 0 0
  95434. - 0 0 0 0 0 0 0 0 0 0 0 0
  95435. - 0 0 0 0 0 0 0 0 0 0 0 0
  95436. - 0 0 0 0 0 0 0 0 0 0 0 0
  95437. - 0 0 0 0 0 0 0 0 0 0 0 0
  95438. - 0 0 0 0 0 0 0 0 0 0 0 0
  95439. - 0 0 0 0 0 0 0 0 0 0 0 0
  95440. - 0 0 0 0 0 0 0 0 0 0 0 0
  95441. - 0 0 0 0 0 0 0 0 0 0 0 0
  95442. - 0 0 0 0 0 0 0 0 0 0 0 0
  95443. - 0 0 0 6 6 6 22 22 22 50 50 50
  95444. - 78 78 78 34 34 34 2 2 6 2 2 6
  95445. - 2 2 6 2 2 6 2 2 6 2 2 6
  95446. - 2 2 6 2 2 6 2 2 6 2 2 6
  95447. - 2 2 6 2 2 6 6 6 6 70 70 70
  95448. - 78 78 78 46 46 46 22 22 22 6 6 6
  95449. - 0 0 0 0 0 0 0 0 0 0 0 0
  95450. - 0 0 0 0 0 0 0 0 0 0 0 0
  95451. - 0 0 0 0 0 0 0 0 0 0 0 0
  95452. - 0 0 0 0 0 0 0 0 0 0 0 0
  95453. - 0 0 0 0 0 0 0 0 0 0 0 0
  95454. - 0 0 0 0 0 0 0 0 0 0 0 0
  95455. - 0 0 0 0 0 0 0 0 0 0 0 0
  95456. - 0 0 0 0 0 0 0 0 0 0 0 0
  95457. - 0 0 1 0 0 1 0 0 1 0 0 0
  95458. - 0 0 0 0 0 0 0 0 0 0 0 0
  95459. - 0 0 0 0 0 0 0 0 0 0 0 0
  95460. - 0 0 0 0 0 0 0 0 0 0 0 0
  95461. - 0 0 0 0 0 0 0 0 0 0 0 0
  95462. - 0 0 0 0 0 0 0 0 0 0 0 0
  95463. - 6 6 6 18 18 18 42 42 42 82 82 82
  95464. - 26 26 26 2 2 6 2 2 6 2 2 6
  95465. - 2 2 6 2 2 6 2 2 6 2 2 6
  95466. - 2 2 6 2 2 6 2 2 6 14 14 14
  95467. - 46 46 46 34 34 34 6 6 6 2 2 6
  95468. - 42 42 42 78 78 78 42 42 42 18 18 18
  95469. - 6 6 6 0 0 0 0 0 0 0 0 0
  95470. - 0 0 0 0 0 0 0 0 0 0 0 0
  95471. - 0 0 0 0 0 0 0 0 0 0 0 0
  95472. - 0 0 0 0 0 0 0 0 0 0 0 0
  95473. - 0 0 0 0 0 0 0 0 0 0 0 0
  95474. - 0 0 0 0 0 0 0 0 0 0 0 0
  95475. - 0 0 0 0 0 0 0 0 0 0 0 0
  95476. - 0 0 0 0 0 0 0 0 0 0 0 0
  95477. - 0 0 1 0 0 0 0 0 1 0 0 0
  95478. - 0 0 0 0 0 0 0 0 0 0 0 0
  95479. - 0 0 0 0 0 0 0 0 0 0 0 0
  95480. - 0 0 0 0 0 0 0 0 0 0 0 0
  95481. - 0 0 0 0 0 0 0 0 0 0 0 0
  95482. - 0 0 0 0 0 0 0 0 0 0 0 0
  95483. - 10 10 10 30 30 30 66 66 66 58 58 58
  95484. - 2 2 6 2 2 6 2 2 6 2 2 6
  95485. - 2 2 6 2 2 6 2 2 6 2 2 6
  95486. - 2 2 6 2 2 6 2 2 6 26 26 26
  95487. - 86 86 86 101 101 101 46 46 46 10 10 10
  95488. - 2 2 6 58 58 58 70 70 70 34 34 34
  95489. - 10 10 10 0 0 0 0 0 0 0 0 0
  95490. - 0 0 0 0 0 0 0 0 0 0 0 0
  95491. - 0 0 0 0 0 0 0 0 0 0 0 0
  95492. - 0 0 0 0 0 0 0 0 0 0 0 0
  95493. - 0 0 0 0 0 0 0 0 0 0 0 0
  95494. - 0 0 0 0 0 0 0 0 0 0 0 0
  95495. - 0 0 0 0 0 0 0 0 0 0 0 0
  95496. - 0 0 0 0 0 0 0 0 0 0 0 0
  95497. - 0 0 1 0 0 1 0 0 1 0 0 0
  95498. - 0 0 0 0 0 0 0 0 0 0 0 0
  95499. - 0 0 0 0 0 0 0 0 0 0 0 0
  95500. - 0 0 0 0 0 0 0 0 0 0 0 0
  95501. - 0 0 0 0 0 0 0 0 0 0 0 0
  95502. - 0 0 0 0 0 0 0 0 0 0 0 0
  95503. - 14 14 14 42 42 42 86 86 86 10 10 10
  95504. - 2 2 6 2 2 6 2 2 6 2 2 6
  95505. - 2 2 6 2 2 6 2 2 6 2 2 6
  95506. - 2 2 6 2 2 6 2 2 6 30 30 30
  95507. - 94 94 94 94 94 94 58 58 58 26 26 26
  95508. - 2 2 6 6 6 6 78 78 78 54 54 54
  95509. - 22 22 22 6 6 6 0 0 0 0 0 0
  95510. - 0 0 0 0 0 0 0 0 0 0 0 0
  95511. - 0 0 0 0 0 0 0 0 0 0 0 0
  95512. - 0 0 0 0 0 0 0 0 0 0 0 0
  95513. - 0 0 0 0 0 0 0 0 0 0 0 0
  95514. - 0 0 0 0 0 0 0 0 0 0 0 0
  95515. - 0 0 0 0 0 0 0 0 0 0 0 0
  95516. - 0 0 0 0 0 0 0 0 0 0 0 0
  95517. - 0 0 0 0 0 0 0 0 0 0 0 0
  95518. - 0 0 0 0 0 0 0 0 0 0 0 0
  95519. - 0 0 0 0 0 0 0 0 0 0 0 0
  95520. - 0 0 0 0 0 0 0 0 0 0 0 0
  95521. - 0 0 0 0 0 0 0 0 0 0 0 0
  95522. - 0 0 0 0 0 0 0 0 0 6 6 6
  95523. - 22 22 22 62 62 62 62 62 62 2 2 6
  95524. - 2 2 6 2 2 6 2 2 6 2 2 6
  95525. - 2 2 6 2 2 6 2 2 6 2 2 6
  95526. - 2 2 6 2 2 6 2 2 6 26 26 26
  95527. - 54 54 54 38 38 38 18 18 18 10 10 10
  95528. - 2 2 6 2 2 6 34 34 34 82 82 82
  95529. - 38 38 38 14 14 14 0 0 0 0 0 0
  95530. - 0 0 0 0 0 0 0 0 0 0 0 0
  95531. - 0 0 0 0 0 0 0 0 0 0 0 0
  95532. - 0 0 0 0 0 0 0 0 0 0 0 0
  95533. - 0 0 0 0 0 0 0 0 0 0 0 0
  95534. - 0 0 0 0 0 0 0 0 0 0 0 0
  95535. - 0 0 0 0 0 0 0 0 0 0 0 0
  95536. - 0 0 0 0 0 0 0 0 0 0 0 0
  95537. - 0 0 0 0 0 1 0 0 1 0 0 0
  95538. - 0 0 0 0 0 0 0 0 0 0 0 0
  95539. - 0 0 0 0 0 0 0 0 0 0 0 0
  95540. - 0 0 0 0 0 0 0 0 0 0 0 0
  95541. - 0 0 0 0 0 0 0 0 0 0 0 0
  95542. - 0 0 0 0 0 0 0 0 0 6 6 6
  95543. - 30 30 30 78 78 78 30 30 30 2 2 6
  95544. - 2 2 6 2 2 6 2 2 6 2 2 6
  95545. - 2 2 6 2 2 6 2 2 6 2 2 6
  95546. - 2 2 6 2 2 6 2 2 6 10 10 10
  95547. - 10 10 10 2 2 6 2 2 6 2 2 6
  95548. - 2 2 6 2 2 6 2 2 6 78 78 78
  95549. - 50 50 50 18 18 18 6 6 6 0 0 0
  95550. - 0 0 0 0 0 0 0 0 0 0 0 0
  95551. - 0 0 0 0 0 0 0 0 0 0 0 0
  95552. - 0 0 0 0 0 0 0 0 0 0 0 0
  95553. - 0 0 0 0 0 0 0 0 0 0 0 0
  95554. - 0 0 0 0 0 0 0 0 0 0 0 0
  95555. - 0 0 0 0 0 0 0 0 0 0 0 0
  95556. - 0 0 0 0 0 0 0 0 0 0 0 0
  95557. - 0 0 1 0 0 0 0 0 0 0 0 0
  95558. - 0 0 0 0 0 0 0 0 0 0 0 0
  95559. - 0 0 0 0 0 0 0 0 0 0 0 0
  95560. - 0 0 0 0 0 0 0 0 0 0 0 0
  95561. - 0 0 0 0 0 0 0 0 0 0 0 0
  95562. - 0 0 0 0 0 0 0 0 0 10 10 10
  95563. - 38 38 38 86 86 86 14 14 14 2 2 6
  95564. - 2 2 6 2 2 6 2 2 6 2 2 6
  95565. - 2 2 6 2 2 6 2 2 6 2 2 6
  95566. - 2 2 6 2 2 6 2 2 6 2 2 6
  95567. - 2 2 6 2 2 6 2 2 6 2 2 6
  95568. - 2 2 6 2 2 6 2 2 6 54 54 54
  95569. - 66 66 66 26 26 26 6 6 6 0 0 0
  95570. - 0 0 0 0 0 0 0 0 0 0 0 0
  95571. - 0 0 0 0 0 0 0 0 0 0 0 0
  95572. - 0 0 0 0 0 0 0 0 0 0 0 0
  95573. - 0 0 0 0 0 0 0 0 0 0 0 0
  95574. - 0 0 0 0 0 0 0 0 0 0 0 0
  95575. - 0 0 0 0 0 0 0 0 0 0 0 0
  95576. - 0 0 0 0 0 0 0 0 0 0 0 0
  95577. - 0 0 0 0 0 1 0 0 1 0 0 0
  95578. - 0 0 0 0 0 0 0 0 0 0 0 0
  95579. - 0 0 0 0 0 0 0 0 0 0 0 0
  95580. - 0 0 0 0 0 0 0 0 0 0 0 0
  95581. - 0 0 0 0 0 0 0 0 0 0 0 0
  95582. - 0 0 0 0 0 0 0 0 0 14 14 14
  95583. - 42 42 42 82 82 82 2 2 6 2 2 6
  95584. - 2 2 6 6 6 6 10 10 10 2 2 6
  95585. - 2 2 6 2 2 6 2 2 6 2 2 6
  95586. - 2 2 6 2 2 6 2 2 6 6 6 6
  95587. - 14 14 14 10 10 10 2 2 6 2 2 6
  95588. - 2 2 6 2 2 6 2 2 6 18 18 18
  95589. - 82 82 82 34 34 34 10 10 10 0 0 0
  95590. - 0 0 0 0 0 0 0 0 0 0 0 0
  95591. - 0 0 0 0 0 0 0 0 0 0 0 0
  95592. - 0 0 0 0 0 0 0 0 0 0 0 0
  95593. - 0 0 0 0 0 0 0 0 0 0 0 0
  95594. - 0 0 0 0 0 0 0 0 0 0 0 0
  95595. - 0 0 0 0 0 0 0 0 0 0 0 0
  95596. - 0 0 0 0 0 0 0 0 0 0 0 0
  95597. - 0 0 1 0 0 0 0 0 0 0 0 0
  95598. - 0 0 0 0 0 0 0 0 0 0 0 0
  95599. - 0 0 0 0 0 0 0 0 0 0 0 0
  95600. - 0 0 0 0 0 0 0 0 0 0 0 0
  95601. - 0 0 0 0 0 0 0 0 0 0 0 0
  95602. - 0 0 0 0 0 0 0 0 0 14 14 14
  95603. - 46 46 46 86 86 86 2 2 6 2 2 6
  95604. - 6 6 6 6 6 6 22 22 22 34 34 34
  95605. - 6 6 6 2 2 6 2 2 6 2 2 6
  95606. - 2 2 6 2 2 6 18 18 18 34 34 34
  95607. - 10 10 10 50 50 50 22 22 22 2 2 6
  95608. - 2 2 6 2 2 6 2 2 6 10 10 10
  95609. - 86 86 86 42 42 42 14 14 14 0 0 0
  95610. - 0 0 0 0 0 0 0 0 0 0 0 0
  95611. - 0 0 0 0 0 0 0 0 0 0 0 0
  95612. - 0 0 0 0 0 0 0 0 0 0 0 0
  95613. - 0 0 0 0 0 0 0 0 0 0 0 0
  95614. - 0 0 0 0 0 0 0 0 0 0 0 0
  95615. - 0 0 0 0 0 0 0 0 0 0 0 0
  95616. - 0 0 0 0 0 0 0 0 0 0 0 0
  95617. - 0 0 1 0 0 1 0 0 1 0 0 0
  95618. - 0 0 0 0 0 0 0 0 0 0 0 0
  95619. - 0 0 0 0 0 0 0 0 0 0 0 0
  95620. - 0 0 0 0 0 0 0 0 0 0 0 0
  95621. - 0 0 0 0 0 0 0 0 0 0 0 0
  95622. - 0 0 0 0 0 0 0 0 0 14 14 14
  95623. - 46 46 46 86 86 86 2 2 6 2 2 6
  95624. - 38 38 38 116 116 116 94 94 94 22 22 22
  95625. - 22 22 22 2 2 6 2 2 6 2 2 6
  95626. - 14 14 14 86 86 86 138 138 138 162 162 162
  95627. -154 154 154 38 38 38 26 26 26 6 6 6
  95628. - 2 2 6 2 2 6 2 2 6 2 2 6
  95629. - 86 86 86 46 46 46 14 14 14 0 0 0
  95630. - 0 0 0 0 0 0 0 0 0 0 0 0
  95631. - 0 0 0 0 0 0 0 0 0 0 0 0
  95632. - 0 0 0 0 0 0 0 0 0 0 0 0
  95633. - 0 0 0 0 0 0 0 0 0 0 0 0
  95634. - 0 0 0 0 0 0 0 0 0 0 0 0
  95635. - 0 0 0 0 0 0 0 0 0 0 0 0
  95636. - 0 0 0 0 0 0 0 0 0 0 0 0
  95637. - 0 0 0 0 0 0 0 0 0 0 0 0
  95638. - 0 0 0 0 0 0 0 0 0 0 0 0
  95639. - 0 0 0 0 0 0 0 0 0 0 0 0
  95640. - 0 0 0 0 0 0 0 0 0 0 0 0
  95641. - 0 0 0 0 0 0 0 0 0 0 0 0
  95642. - 0 0 0 0 0 0 0 0 0 14 14 14
  95643. - 46 46 46 86 86 86 2 2 6 14 14 14
  95644. -134 134 134 198 198 198 195 195 195 116 116 116
  95645. - 10 10 10 2 2 6 2 2 6 6 6 6
  95646. -101 98 89 187 187 187 210 210 210 218 218 218
  95647. -214 214 214 134 134 134 14 14 14 6 6 6
  95648. - 2 2 6 2 2 6 2 2 6 2 2 6
  95649. - 86 86 86 50 50 50 18 18 18 6 6 6
  95650. - 0 0 0 0 0 0 0 0 0 0 0 0
  95651. - 0 0 0 0 0 0 0 0 0 0 0 0
  95652. - 0 0 0 0 0 0 0 0 0 0 0 0
  95653. - 0 0 0 0 0 0 0 0 0 0 0 0
  95654. - 0 0 0 0 0 0 0 0 0 0 0 0
  95655. - 0 0 0 0 0 0 0 0 0 0 0 0
  95656. - 0 0 0 0 0 0 0 0 1 0 0 0
  95657. - 0 0 1 0 0 1 0 0 1 0 0 0
  95658. - 0 0 0 0 0 0 0 0 0 0 0 0
  95659. - 0 0 0 0 0 0 0 0 0 0 0 0
  95660. - 0 0 0 0 0 0 0 0 0 0 0 0
  95661. - 0 0 0 0 0 0 0 0 0 0 0 0
  95662. - 0 0 0 0 0 0 0 0 0 14 14 14
  95663. - 46 46 46 86 86 86 2 2 6 54 54 54
  95664. -218 218 218 195 195 195 226 226 226 246 246 246
  95665. - 58 58 58 2 2 6 2 2 6 30 30 30
  95666. -210 210 210 253 253 253 174 174 174 123 123 123
  95667. -221 221 221 234 234 234 74 74 74 2 2 6
  95668. - 2 2 6 2 2 6 2 2 6 2 2 6
  95669. - 70 70 70 58 58 58 22 22 22 6 6 6
  95670. - 0 0 0 0 0 0 0 0 0 0 0 0
  95671. - 0 0 0 0 0 0 0 0 0 0 0 0
  95672. - 0 0 0 0 0 0 0 0 0 0 0 0
  95673. - 0 0 0 0 0 0 0 0 0 0 0 0
  95674. - 0 0 0 0 0 0 0 0 0 0 0 0
  95675. - 0 0 0 0 0 0 0 0 0 0 0 0
  95676. - 0 0 0 0 0 0 0 0 0 0 0 0
  95677. - 0 0 0 0 0 0 0 0 0 0 0 0
  95678. - 0 0 0 0 0 0 0 0 0 0 0 0
  95679. - 0 0 0 0 0 0 0 0 0 0 0 0
  95680. - 0 0 0 0 0 0 0 0 0 0 0 0
  95681. - 0 0 0 0 0 0 0 0 0 0 0 0
  95682. - 0 0 0 0 0 0 0 0 0 14 14 14
  95683. - 46 46 46 82 82 82 2 2 6 106 106 106
  95684. -170 170 170 26 26 26 86 86 86 226 226 226
  95685. -123 123 123 10 10 10 14 14 14 46 46 46
  95686. -231 231 231 190 190 190 6 6 6 70 70 70
  95687. - 90 90 90 238 238 238 158 158 158 2 2 6
  95688. - 2 2 6 2 2 6 2 2 6 2 2 6
  95689. - 70 70 70 58 58 58 22 22 22 6 6 6
  95690. - 0 0 0 0 0 0 0 0 0 0 0 0
  95691. - 0 0 0 0 0 0 0 0 0 0 0 0
  95692. - 0 0 0 0 0 0 0 0 0 0 0 0
  95693. - 0 0 0 0 0 0 0 0 0 0 0 0
  95694. - 0 0 0 0 0 0 0 0 0 0 0 0
  95695. - 0 0 0 0 0 0 0 0 0 0 0 0
  95696. - 0 0 0 0 0 0 0 0 1 0 0 0
  95697. - 0 0 1 0 0 1 0 0 1 0 0 0
  95698. - 0 0 0 0 0 0 0 0 0 0 0 0
  95699. - 0 0 0 0 0 0 0 0 0 0 0 0
  95700. - 0 0 0 0 0 0 0 0 0 0 0 0
  95701. - 0 0 0 0 0 0 0 0 0 0 0 0
  95702. - 0 0 0 0 0 0 0 0 0 14 14 14
  95703. - 42 42 42 86 86 86 6 6 6 116 116 116
  95704. -106 106 106 6 6 6 70 70 70 149 149 149
  95705. -128 128 128 18 18 18 38 38 38 54 54 54
  95706. -221 221 221 106 106 106 2 2 6 14 14 14
  95707. - 46 46 46 190 190 190 198 198 198 2 2 6
  95708. - 2 2 6 2 2 6 2 2 6 2 2 6
  95709. - 74 74 74 62 62 62 22 22 22 6 6 6
  95710. - 0 0 0 0 0 0 0 0 0 0 0 0
  95711. - 0 0 0 0 0 0 0 0 0 0 0 0
  95712. - 0 0 0 0 0 0 0 0 0 0 0 0
  95713. - 0 0 0 0 0 0 0 0 0 0 0 0
  95714. - 0 0 0 0 0 0 0 0 0 0 0 0
  95715. - 0 0 0 0 0 0 0 0 0 0 0 0
  95716. - 0 0 0 0 0 0 0 0 1 0 0 0
  95717. - 0 0 1 0 0 0 0 0 1 0 0 0
  95718. - 0 0 0 0 0 0 0 0 0 0 0 0
  95719. - 0 0 0 0 0 0 0 0 0 0 0 0
  95720. - 0 0 0 0 0 0 0 0 0 0 0 0
  95721. - 0 0 0 0 0 0 0 0 0 0 0 0
  95722. - 0 0 0 0 0 0 0 0 0 14 14 14
  95723. - 42 42 42 94 94 94 14 14 14 101 101 101
  95724. -128 128 128 2 2 6 18 18 18 116 116 116
  95725. -118 98 46 121 92 8 121 92 8 98 78 10
  95726. -162 162 162 106 106 106 2 2 6 2 2 6
  95727. - 2 2 6 195 195 195 195 195 195 6 6 6
  95728. - 2 2 6 2 2 6 2 2 6 2 2 6
  95729. - 74 74 74 62 62 62 22 22 22 6 6 6
  95730. - 0 0 0 0 0 0 0 0 0 0 0 0
  95731. - 0 0 0 0 0 0 0 0 0 0 0 0
  95732. - 0 0 0 0 0 0 0 0 0 0 0 0
  95733. - 0 0 0 0 0 0 0 0 0 0 0 0
  95734. - 0 0 0 0 0 0 0 0 0 0 0 0
  95735. - 0 0 0 0 0 0 0 0 0 0 0 0
  95736. - 0 0 0 0 0 0 0 0 1 0 0 1
  95737. - 0 0 1 0 0 0 0 0 1 0 0 0
  95738. - 0 0 0 0 0 0 0 0 0 0 0 0
  95739. - 0 0 0 0 0 0 0 0 0 0 0 0
  95740. - 0 0 0 0 0 0 0 0 0 0 0 0
  95741. - 0 0 0 0 0 0 0 0 0 0 0 0
  95742. - 0 0 0 0 0 0 0 0 0 10 10 10
  95743. - 38 38 38 90 90 90 14 14 14 58 58 58
  95744. -210 210 210 26 26 26 54 38 6 154 114 10
  95745. -226 170 11 236 186 11 225 175 15 184 144 12
  95746. -215 174 15 175 146 61 37 26 9 2 2 6
  95747. - 70 70 70 246 246 246 138 138 138 2 2 6
  95748. - 2 2 6 2 2 6 2 2 6 2 2 6
  95749. - 70 70 70 66 66 66 26 26 26 6 6 6
  95750. - 0 0 0 0 0 0 0 0 0 0 0 0
  95751. - 0 0 0 0 0 0 0 0 0 0 0 0
  95752. - 0 0 0 0 0 0 0 0 0 0 0 0
  95753. - 0 0 0 0 0 0 0 0 0 0 0 0
  95754. - 0 0 0 0 0 0 0 0 0 0 0 0
  95755. - 0 0 0 0 0 0 0 0 0 0 0 0
  95756. - 0 0 0 0 0 0 0 0 0 0 0 0
  95757. - 0 0 0 0 0 0 0 0 0 0 0 0
  95758. - 0 0 0 0 0 0 0 0 0 0 0 0
  95759. - 0 0 0 0 0 0 0 0 0 0 0 0
  95760. - 0 0 0 0 0 0 0 0 0 0 0 0
  95761. - 0 0 0 0 0 0 0 0 0 0 0 0
  95762. - 0 0 0 0 0 0 0 0 0 10 10 10
  95763. - 38 38 38 86 86 86 14 14 14 10 10 10
  95764. -195 195 195 188 164 115 192 133 9 225 175 15
  95765. -239 182 13 234 190 10 232 195 16 232 200 30
  95766. -245 207 45 241 208 19 232 195 16 184 144 12
  95767. -218 194 134 211 206 186 42 42 42 2 2 6
  95768. - 2 2 6 2 2 6 2 2 6 2 2 6
  95769. - 50 50 50 74 74 74 30 30 30 6 6 6
  95770. - 0 0 0 0 0 0 0 0 0 0 0 0
  95771. - 0 0 0 0 0 0 0 0 0 0 0 0
  95772. - 0 0 0 0 0 0 0 0 0 0 0 0
  95773. - 0 0 0 0 0 0 0 0 0 0 0 0
  95774. - 0 0 0 0 0 0 0 0 0 0 0 0
  95775. - 0 0 0 0 0 0 0 0 0 0 0 0
  95776. - 0 0 0 0 0 0 0 0 0 0 0 0
  95777. - 0 0 0 0 0 0 0 0 0 0 0 0
  95778. - 0 0 0 0 0 0 0 0 0 0 0 0
  95779. - 0 0 0 0 0 0 0 0 0 0 0 0
  95780. - 0 0 0 0 0 0 0 0 0 0 0 0
  95781. - 0 0 0 0 0 0 0 0 0 0 0 0
  95782. - 0 0 0 0 0 0 0 0 0 10 10 10
  95783. - 34 34 34 86 86 86 14 14 14 2 2 6
  95784. -121 87 25 192 133 9 219 162 10 239 182 13
  95785. -236 186 11 232 195 16 241 208 19 244 214 54
  95786. -246 218 60 246 218 38 246 215 20 241 208 19
  95787. -241 208 19 226 184 13 121 87 25 2 2 6
  95788. - 2 2 6 2 2 6 2 2 6 2 2 6
  95789. - 50 50 50 82 82 82 34 34 34 10 10 10
  95790. - 0 0 0 0 0 0 0 0 0 0 0 0
  95791. - 0 0 0 0 0 0 0 0 0 0 0 0
  95792. - 0 0 0 0 0 0 0 0 0 0 0 0
  95793. - 0 0 0 0 0 0 0 0 0 0 0 0
  95794. - 0 0 0 0 0 0 0 0 0 0 0 0
  95795. - 0 0 0 0 0 0 0 0 0 0 0 0
  95796. - 0 0 0 0 0 0 0 0 0 0 0 0
  95797. - 0 0 0 0 0 0 0 0 0 0 0 0
  95798. - 0 0 0 0 0 0 0 0 0 0 0 0
  95799. - 0 0 0 0 0 0 0 0 0 0 0 0
  95800. - 0 0 0 0 0 0 0 0 0 0 0 0
  95801. - 0 0 0 0 0 0 0 0 0 0 0 0
  95802. - 0 0 0 0 0 0 0 0 0 10 10 10
  95803. - 34 34 34 82 82 82 30 30 30 61 42 6
  95804. -180 123 7 206 145 10 230 174 11 239 182 13
  95805. -234 190 10 238 202 15 241 208 19 246 218 74
  95806. -246 218 38 246 215 20 246 215 20 246 215 20
  95807. -226 184 13 215 174 15 184 144 12 6 6 6
  95808. - 2 2 6 2 2 6 2 2 6 2 2 6
  95809. - 26 26 26 94 94 94 42 42 42 14 14 14
  95810. - 0 0 0 0 0 0 0 0 0 0 0 0
  95811. - 0 0 0 0 0 0 0 0 0 0 0 0
  95812. - 0 0 0 0 0 0 0 0 0 0 0 0
  95813. - 0 0 0 0 0 0 0 0 0 0 0 0
  95814. - 0 0 0 0 0 0 0 0 0 0 0 0
  95815. - 0 0 0 0 0 0 0 0 0 0 0 0
  95816. - 0 0 0 0 0 0 0 0 0 0 0 0
  95817. - 0 0 0 0 0 0 0 0 0 0 0 0
  95818. - 0 0 0 0 0 0 0 0 0 0 0 0
  95819. - 0 0 0 0 0 0 0 0 0 0 0 0
  95820. - 0 0 0 0 0 0 0 0 0 0 0 0
  95821. - 0 0 0 0 0 0 0 0 0 0 0 0
  95822. - 0 0 0 0 0 0 0 0 0 10 10 10
  95823. - 30 30 30 78 78 78 50 50 50 104 69 6
  95824. -192 133 9 216 158 10 236 178 12 236 186 11
  95825. -232 195 16 241 208 19 244 214 54 245 215 43
  95826. -246 215 20 246 215 20 241 208 19 198 155 10
  95827. -200 144 11 216 158 10 156 118 10 2 2 6
  95828. - 2 2 6 2 2 6 2 2 6 2 2 6
  95829. - 6 6 6 90 90 90 54 54 54 18 18 18
  95830. - 6 6 6 0 0 0 0 0 0 0 0 0
  95831. - 0 0 0 0 0 0 0 0 0 0 0 0
  95832. - 0 0 0 0 0 0 0 0 0 0 0 0
  95833. - 0 0 0 0 0 0 0 0 0 0 0 0
  95834. - 0 0 0 0 0 0 0 0 0 0 0 0
  95835. - 0 0 0 0 0 0 0 0 0 0 0 0
  95836. - 0 0 0 0 0 0 0 0 0 0 0 0
  95837. - 0 0 0 0 0 0 0 0 0 0 0 0
  95838. - 0 0 0 0 0 0 0 0 0 0 0 0
  95839. - 0 0 0 0 0 0 0 0 0 0 0 0
  95840. - 0 0 0 0 0 0 0 0 0 0 0 0
  95841. - 0 0 0 0 0 0 0 0 0 0 0 0
  95842. - 0 0 0 0 0 0 0 0 0 10 10 10
  95843. - 30 30 30 78 78 78 46 46 46 22 22 22
  95844. -137 92 6 210 162 10 239 182 13 238 190 10
  95845. -238 202 15 241 208 19 246 215 20 246 215 20
  95846. -241 208 19 203 166 17 185 133 11 210 150 10
  95847. -216 158 10 210 150 10 102 78 10 2 2 6
  95848. - 6 6 6 54 54 54 14 14 14 2 2 6
  95849. - 2 2 6 62 62 62 74 74 74 30 30 30
  95850. - 10 10 10 0 0 0 0 0 0 0 0 0
  95851. - 0 0 0 0 0 0 0 0 0 0 0 0
  95852. - 0 0 0 0 0 0 0 0 0 0 0 0
  95853. - 0 0 0 0 0 0 0 0 0 0 0 0
  95854. - 0 0 0 0 0 0 0 0 0 0 0 0
  95855. - 0 0 0 0 0 0 0 0 0 0 0 0
  95856. - 0 0 0 0 0 0 0 0 0 0 0 0
  95857. - 0 0 0 0 0 0 0 0 0 0 0 0
  95858. - 0 0 0 0 0 0 0 0 0 0 0 0
  95859. - 0 0 0 0 0 0 0 0 0 0 0 0
  95860. - 0 0 0 0 0 0 0 0 0 0 0 0
  95861. - 0 0 0 0 0 0 0 0 0 0 0 0
  95862. - 0 0 0 0 0 0 0 0 0 10 10 10
  95863. - 34 34 34 78 78 78 50 50 50 6 6 6
  95864. - 94 70 30 139 102 15 190 146 13 226 184 13
  95865. -232 200 30 232 195 16 215 174 15 190 146 13
  95866. -168 122 10 192 133 9 210 150 10 213 154 11
  95867. -202 150 34 182 157 106 101 98 89 2 2 6
  95868. - 2 2 6 78 78 78 116 116 116 58 58 58
  95869. - 2 2 6 22 22 22 90 90 90 46 46 46
  95870. - 18 18 18 6 6 6 0 0 0 0 0 0
  95871. - 0 0 0 0 0 0 0 0 0 0 0 0
  95872. - 0 0 0 0 0 0 0 0 0 0 0 0
  95873. - 0 0 0 0 0 0 0 0 0 0 0 0
  95874. - 0 0 0 0 0 0 0 0 0 0 0 0
  95875. - 0 0 0 0 0 0 0 0 0 0 0 0
  95876. - 0 0 0 0 0 0 0 0 0 0 0 0
  95877. - 0 0 0 0 0 0 0 0 0 0 0 0
  95878. - 0 0 0 0 0 0 0 0 0 0 0 0
  95879. - 0 0 0 0 0 0 0 0 0 0 0 0
  95880. - 0 0 0 0 0 0 0 0 0 0 0 0
  95881. - 0 0 0 0 0 0 0 0 0 0 0 0
  95882. - 0 0 0 0 0 0 0 0 0 10 10 10
  95883. - 38 38 38 86 86 86 50 50 50 6 6 6
  95884. -128 128 128 174 154 114 156 107 11 168 122 10
  95885. -198 155 10 184 144 12 197 138 11 200 144 11
  95886. -206 145 10 206 145 10 197 138 11 188 164 115
  95887. -195 195 195 198 198 198 174 174 174 14 14 14
  95888. - 2 2 6 22 22 22 116 116 116 116 116 116
  95889. - 22 22 22 2 2 6 74 74 74 70 70 70
  95890. - 30 30 30 10 10 10 0 0 0 0 0 0
  95891. - 0 0 0 0 0 0 0 0 0 0 0 0
  95892. - 0 0 0 0 0 0 0 0 0 0 0 0
  95893. - 0 0 0 0 0 0 0 0 0 0 0 0
  95894. - 0 0 0 0 0 0 0 0 0 0 0 0
  95895. - 0 0 0 0 0 0 0 0 0 0 0 0
  95896. - 0 0 0 0 0 0 0 0 0 0 0 0
  95897. - 0 0 0 0 0 0 0 0 0 0 0 0
  95898. - 0 0 0 0 0 0 0 0 0 0 0 0
  95899. - 0 0 0 0 0 0 0 0 0 0 0 0
  95900. - 0 0 0 0 0 0 0 0 0 0 0 0
  95901. - 0 0 0 0 0 0 0 0 0 0 0 0
  95902. - 0 0 0 0 0 0 6 6 6 18 18 18
  95903. - 50 50 50 101 101 101 26 26 26 10 10 10
  95904. -138 138 138 190 190 190 174 154 114 156 107 11
  95905. -197 138 11 200 144 11 197 138 11 192 133 9
  95906. -180 123 7 190 142 34 190 178 144 187 187 187
  95907. -202 202 202 221 221 221 214 214 214 66 66 66
  95908. - 2 2 6 2 2 6 50 50 50 62 62 62
  95909. - 6 6 6 2 2 6 10 10 10 90 90 90
  95910. - 50 50 50 18 18 18 6 6 6 0 0 0
  95911. - 0 0 0 0 0 0 0 0 0 0 0 0
  95912. - 0 0 0 0 0 0 0 0 0 0 0 0
  95913. - 0 0 0 0 0 0 0 0 0 0 0 0
  95914. - 0 0 0 0 0 0 0 0 0 0 0 0
  95915. - 0 0 0 0 0 0 0 0 0 0 0 0
  95916. - 0 0 0 0 0 0 0 0 0 0 0 0
  95917. - 0 0 0 0 0 0 0 0 0 0 0 0
  95918. - 0 0 0 0 0 0 0 0 0 0 0 0
  95919. - 0 0 0 0 0 0 0 0 0 0 0 0
  95920. - 0 0 0 0 0 0 0 0 0 0 0 0
  95921. - 0 0 0 0 0 0 0 0 0 0 0 0
  95922. - 0 0 0 0 0 0 10 10 10 34 34 34
  95923. - 74 74 74 74 74 74 2 2 6 6 6 6
  95924. -144 144 144 198 198 198 190 190 190 178 166 146
  95925. -154 121 60 156 107 11 156 107 11 168 124 44
  95926. -174 154 114 187 187 187 190 190 190 210 210 210
  95927. -246 246 246 253 253 253 253 253 253 182 182 182
  95928. - 6 6 6 2 2 6 2 2 6 2 2 6
  95929. - 2 2 6 2 2 6 2 2 6 62 62 62
  95930. - 74 74 74 34 34 34 14 14 14 0 0 0
  95931. - 0 0 0 0 0 0 0 0 0 0 0 0
  95932. - 0 0 0 0 0 0 0 0 0 0 0 0
  95933. - 0 0 0 0 0 0 0 0 0 0 0 0
  95934. - 0 0 0 0 0 0 0 0 0 0 0 0
  95935. - 0 0 0 0 0 0 0 0 0 0 0 0
  95936. - 0 0 0 0 0 0 0 0 0 0 0 0
  95937. - 0 0 0 0 0 0 0 0 0 0 0 0
  95938. - 0 0 0 0 0 0 0 0 0 0 0 0
  95939. - 0 0 0 0 0 0 0 0 0 0 0 0
  95940. - 0 0 0 0 0 0 0 0 0 0 0 0
  95941. - 0 0 0 0 0 0 0 0 0 0 0 0
  95942. - 0 0 0 10 10 10 22 22 22 54 54 54
  95943. - 94 94 94 18 18 18 2 2 6 46 46 46
  95944. -234 234 234 221 221 221 190 190 190 190 190 190
  95945. -190 190 190 187 187 187 187 187 187 190 190 190
  95946. -190 190 190 195 195 195 214 214 214 242 242 242
  95947. -253 253 253 253 253 253 253 253 253 253 253 253
  95948. - 82 82 82 2 2 6 2 2 6 2 2 6
  95949. - 2 2 6 2 2 6 2 2 6 14 14 14
  95950. - 86 86 86 54 54 54 22 22 22 6 6 6
  95951. - 0 0 0 0 0 0 0 0 0 0 0 0
  95952. - 0 0 0 0 0 0 0 0 0 0 0 0
  95953. - 0 0 0 0 0 0 0 0 0 0 0 0
  95954. - 0 0 0 0 0 0 0 0 0 0 0 0
  95955. - 0 0 0 0 0 0 0 0 0 0 0 0
  95956. - 0 0 0 0 0 0 0 0 0 0 0 0
  95957. - 0 0 0 0 0 0 0 0 0 0 0 0
  95958. - 0 0 0 0 0 0 0 0 0 0 0 0
  95959. - 0 0 0 0 0 0 0 0 0 0 0 0
  95960. - 0 0 0 0 0 0 0 0 0 0 0 0
  95961. - 0 0 0 0 0 0 0 0 0 0 0 0
  95962. - 6 6 6 18 18 18 46 46 46 90 90 90
  95963. - 46 46 46 18 18 18 6 6 6 182 182 182
  95964. -253 253 253 246 246 246 206 206 206 190 190 190
  95965. -190 190 190 190 190 190 190 190 190 190 190 190
  95966. -206 206 206 231 231 231 250 250 250 253 253 253
  95967. -253 253 253 253 253 253 253 253 253 253 253 253
  95968. -202 202 202 14 14 14 2 2 6 2 2 6
  95969. - 2 2 6 2 2 6 2 2 6 2 2 6
  95970. - 42 42 42 86 86 86 42 42 42 18 18 18
  95971. - 6 6 6 0 0 0 0 0 0 0 0 0
  95972. - 0 0 0 0 0 0 0 0 0 0 0 0
  95973. - 0 0 0 0 0 0 0 0 0 0 0 0
  95974. - 0 0 0 0 0 0 0 0 0 0 0 0
  95975. - 0 0 0 0 0 0 0 0 0 0 0 0
  95976. - 0 0 0 0 0 0 0 0 0 0 0 0
  95977. - 0 0 0 0 0 0 0 0 0 0 0 0
  95978. - 0 0 0 0 0 0 0 0 0 0 0 0
  95979. - 0 0 0 0 0 0 0 0 0 0 0 0
  95980. - 0 0 0 0 0 0 0 0 0 0 0 0
  95981. - 0 0 0 0 0 0 0 0 0 6 6 6
  95982. - 14 14 14 38 38 38 74 74 74 66 66 66
  95983. - 2 2 6 6 6 6 90 90 90 250 250 250
  95984. -253 253 253 253 253 253 238 238 238 198 198 198
  95985. -190 190 190 190 190 190 195 195 195 221 221 221
  95986. -246 246 246 253 253 253 253 253 253 253 253 253
  95987. -253 253 253 253 253 253 253 253 253 253 253 253
  95988. -253 253 253 82 82 82 2 2 6 2 2 6
  95989. - 2 2 6 2 2 6 2 2 6 2 2 6
  95990. - 2 2 6 78 78 78 70 70 70 34 34 34
  95991. - 14 14 14 6 6 6 0 0 0 0 0 0
  95992. - 0 0 0 0 0 0 0 0 0 0 0 0
  95993. - 0 0 0 0 0 0 0 0 0 0 0 0
  95994. - 0 0 0 0 0 0 0 0 0 0 0 0
  95995. - 0 0 0 0 0 0 0 0 0 0 0 0
  95996. - 0 0 0 0 0 0 0 0 0 0 0 0
  95997. - 0 0 0 0 0 0 0 0 0 0 0 0
  95998. - 0 0 0 0 0 0 0 0 0 0 0 0
  95999. - 0 0 0 0 0 0 0 0 0 0 0 0
  96000. - 0 0 0 0 0 0 0 0 0 0 0 0
  96001. - 0 0 0 0 0 0 0 0 0 14 14 14
  96002. - 34 34 34 66 66 66 78 78 78 6 6 6
  96003. - 2 2 6 18 18 18 218 218 218 253 253 253
  96004. -253 253 253 253 253 253 253 253 253 246 246 246
  96005. -226 226 226 231 231 231 246 246 246 253 253 253
  96006. -253 253 253 253 253 253 253 253 253 253 253 253
  96007. -253 253 253 253 253 253 253 253 253 253 253 253
  96008. -253 253 253 178 178 178 2 2 6 2 2 6
  96009. - 2 2 6 2 2 6 2 2 6 2 2 6
  96010. - 2 2 6 18 18 18 90 90 90 62 62 62
  96011. - 30 30 30 10 10 10 0 0 0 0 0 0
  96012. - 0 0 0 0 0 0 0 0 0 0 0 0
  96013. - 0 0 0 0 0 0 0 0 0 0 0 0
  96014. - 0 0 0 0 0 0 0 0 0 0 0 0
  96015. - 0 0 0 0 0 0 0 0 0 0 0 0
  96016. - 0 0 0 0 0 0 0 0 0 0 0 0
  96017. - 0 0 0 0 0 0 0 0 0 0 0 0
  96018. - 0 0 0 0 0 0 0 0 0 0 0 0
  96019. - 0 0 0 0 0 0 0 0 0 0 0 0
  96020. - 0 0 0 0 0 0 0 0 0 0 0 0
  96021. - 0 0 0 0 0 0 10 10 10 26 26 26
  96022. - 58 58 58 90 90 90 18 18 18 2 2 6
  96023. - 2 2 6 110 110 110 253 253 253 253 253 253
  96024. -253 253 253 253 253 253 253 253 253 253 253 253
  96025. -250 250 250 253 253 253 253 253 253 253 253 253
  96026. -253 253 253 253 253 253 253 253 253 253 253 253
  96027. -253 253 253 253 253 253 253 253 253 253 253 253
  96028. -253 253 253 231 231 231 18 18 18 2 2 6
  96029. - 2 2 6 2 2 6 2 2 6 2 2 6
  96030. - 2 2 6 2 2 6 18 18 18 94 94 94
  96031. - 54 54 54 26 26 26 10 10 10 0 0 0
  96032. - 0 0 0 0 0 0 0 0 0 0 0 0
  96033. - 0 0 0 0 0 0 0 0 0 0 0 0
  96034. - 0 0 0 0 0 0 0 0 0 0 0 0
  96035. - 0 0 0 0 0 0 0 0 0 0 0 0
  96036. - 0 0 0 0 0 0 0 0 0 0 0 0
  96037. - 0 0 0 0 0 0 0 0 0 0 0 0
  96038. - 0 0 0 0 0 0 0 0 0 0 0 0
  96039. - 0 0 0 0 0 0 0 0 0 0 0 0
  96040. - 0 0 0 0 0 0 0 0 0 0 0 0
  96041. - 0 0 0 6 6 6 22 22 22 50 50 50
  96042. - 90 90 90 26 26 26 2 2 6 2 2 6
  96043. - 14 14 14 195 195 195 250 250 250 253 253 253
  96044. -253 253 253 253 253 253 253 253 253 253 253 253
  96045. -253 253 253 253 253 253 253 253 253 253 253 253
  96046. -253 253 253 253 253 253 253 253 253 253 253 253
  96047. -253 253 253 253 253 253 253 253 253 253 253 253
  96048. -250 250 250 242 242 242 54 54 54 2 2 6
  96049. - 2 2 6 2 2 6 2 2 6 2 2 6
  96050. - 2 2 6 2 2 6 2 2 6 38 38 38
  96051. - 86 86 86 50 50 50 22 22 22 6 6 6
  96052. - 0 0 0 0 0 0 0 0 0 0 0 0
  96053. - 0 0 0 0 0 0 0 0 0 0 0 0
  96054. - 0 0 0 0 0 0 0 0 0 0 0 0
  96055. - 0 0 0 0 0 0 0 0 0 0 0 0
  96056. - 0 0 0 0 0 0 0 0 0 0 0 0
  96057. - 0 0 0 0 0 0 0 0 0 0 0 0
  96058. - 0 0 0 0 0 0 0 0 0 0 0 0
  96059. - 0 0 0 0 0 0 0 0 0 0 0 0
  96060. - 0 0 0 0 0 0 0 0 0 0 0 0
  96061. - 6 6 6 14 14 14 38 38 38 82 82 82
  96062. - 34 34 34 2 2 6 2 2 6 2 2 6
  96063. - 42 42 42 195 195 195 246 246 246 253 253 253
  96064. -253 253 253 253 253 253 253 253 253 250 250 250
  96065. -242 242 242 242 242 242 250 250 250 253 253 253
  96066. -253 253 253 253 253 253 253 253 253 253 253 253
  96067. -253 253 253 250 250 250 246 246 246 238 238 238
  96068. -226 226 226 231 231 231 101 101 101 6 6 6
  96069. - 2 2 6 2 2 6 2 2 6 2 2 6
  96070. - 2 2 6 2 2 6 2 2 6 2 2 6
  96071. - 38 38 38 82 82 82 42 42 42 14 14 14
  96072. - 6 6 6 0 0 0 0 0 0 0 0 0
  96073. - 0 0 0 0 0 0 0 0 0 0 0 0
  96074. - 0 0 0 0 0 0 0 0 0 0 0 0
  96075. - 0 0 0 0 0 0 0 0 0 0 0 0
  96076. - 0 0 0 0 0 0 0 0 0 0 0 0
  96077. - 0 0 0 0 0 0 0 0 0 0 0 0
  96078. - 0 0 0 0 0 0 0 0 0 0 0 0
  96079. - 0 0 0 0 0 0 0 0 0 0 0 0
  96080. - 0 0 0 0 0 0 0 0 0 0 0 0
  96081. - 10 10 10 26 26 26 62 62 62 66 66 66
  96082. - 2 2 6 2 2 6 2 2 6 6 6 6
  96083. - 70 70 70 170 170 170 206 206 206 234 234 234
  96084. -246 246 246 250 250 250 250 250 250 238 238 238
  96085. -226 226 226 231 231 231 238 238 238 250 250 250
  96086. -250 250 250 250 250 250 246 246 246 231 231 231
  96087. -214 214 214 206 206 206 202 202 202 202 202 202
  96088. -198 198 198 202 202 202 182 182 182 18 18 18
  96089. - 2 2 6 2 2 6 2 2 6 2 2 6
  96090. - 2 2 6 2 2 6 2 2 6 2 2 6
  96091. - 2 2 6 62 62 62 66 66 66 30 30 30
  96092. - 10 10 10 0 0 0 0 0 0 0 0 0
  96093. - 0 0 0 0 0 0 0 0 0 0 0 0
  96094. - 0 0 0 0 0 0 0 0 0 0 0 0
  96095. - 0 0 0 0 0 0 0 0 0 0 0 0
  96096. - 0 0 0 0 0 0 0 0 0 0 0 0
  96097. - 0 0 0 0 0 0 0 0 0 0 0 0
  96098. - 0 0 0 0 0 0 0 0 0 0 0 0
  96099. - 0 0 0 0 0 0 0 0 0 0 0 0
  96100. - 0 0 0 0 0 0 0 0 0 0 0 0
  96101. - 14 14 14 42 42 42 82 82 82 18 18 18
  96102. - 2 2 6 2 2 6 2 2 6 10 10 10
  96103. - 94 94 94 182 182 182 218 218 218 242 242 242
  96104. -250 250 250 253 253 253 253 253 253 250 250 250
  96105. -234 234 234 253 253 253 253 253 253 253 253 253
  96106. -253 253 253 253 253 253 253 253 253 246 246 246
  96107. -238 238 238 226 226 226 210 210 210 202 202 202
  96108. -195 195 195 195 195 195 210 210 210 158 158 158
  96109. - 6 6 6 14 14 14 50 50 50 14 14 14
  96110. - 2 2 6 2 2 6 2 2 6 2 2 6
  96111. - 2 2 6 6 6 6 86 86 86 46 46 46
  96112. - 18 18 18 6 6 6 0 0 0 0 0 0
  96113. - 0 0 0 0 0 0 0 0 0 0 0 0
  96114. - 0 0 0 0 0 0 0 0 0 0 0 0
  96115. - 0 0 0 0 0 0 0 0 0 0 0 0
  96116. - 0 0 0 0 0 0 0 0 0 0 0 0
  96117. - 0 0 0 0 0 0 0 0 0 0 0 0
  96118. - 0 0 0 0 0 0 0 0 0 0 0 0
  96119. - 0 0 0 0 0 0 0 0 0 0 0 0
  96120. - 0 0 0 0 0 0 0 0 0 6 6 6
  96121. - 22 22 22 54 54 54 70 70 70 2 2 6
  96122. - 2 2 6 10 10 10 2 2 6 22 22 22
  96123. -166 166 166 231 231 231 250 250 250 253 253 253
  96124. -253 253 253 253 253 253 253 253 253 250 250 250
  96125. -242 242 242 253 253 253 253 253 253 253 253 253
  96126. -253 253 253 253 253 253 253 253 253 253 253 253
  96127. -253 253 253 253 253 253 253 253 253 246 246 246
  96128. -231 231 231 206 206 206 198 198 198 226 226 226
  96129. - 94 94 94 2 2 6 6 6 6 38 38 38
  96130. - 30 30 30 2 2 6 2 2 6 2 2 6
  96131. - 2 2 6 2 2 6 62 62 62 66 66 66
  96132. - 26 26 26 10 10 10 0 0 0 0 0 0
  96133. - 0 0 0 0 0 0 0 0 0 0 0 0
  96134. - 0 0 0 0 0 0 0 0 0 0 0 0
  96135. - 0 0 0 0 0 0 0 0 0 0 0 0
  96136. - 0 0 0 0 0 0 0 0 0 0 0 0
  96137. - 0 0 0 0 0 0 0 0 0 0 0 0
  96138. - 0 0 0 0 0 0 0 0 0 0 0 0
  96139. - 0 0 0 0 0 0 0 0 0 0 0 0
  96140. - 0 0 0 0 0 0 0 0 0 10 10 10
  96141. - 30 30 30 74 74 74 50 50 50 2 2 6
  96142. - 26 26 26 26 26 26 2 2 6 106 106 106
  96143. -238 238 238 253 253 253 253 253 253 253 253 253
  96144. -253 253 253 253 253 253 253 253 253 253 253 253
  96145. -253 253 253 253 253 253 253 253 253 253 253 253
  96146. -253 253 253 253 253 253 253 253 253 253 253 253
  96147. -253 253 253 253 253 253 253 253 253 253 253 253
  96148. -253 253 253 246 246 246 218 218 218 202 202 202
  96149. -210 210 210 14 14 14 2 2 6 2 2 6
  96150. - 30 30 30 22 22 22 2 2 6 2 2 6
  96151. - 2 2 6 2 2 6 18 18 18 86 86 86
  96152. - 42 42 42 14 14 14 0 0 0 0 0 0
  96153. - 0 0 0 0 0 0 0 0 0 0 0 0
  96154. - 0 0 0 0 0 0 0 0 0 0 0 0
  96155. - 0 0 0 0 0 0 0 0 0 0 0 0
  96156. - 0 0 0 0 0 0 0 0 0 0 0 0
  96157. - 0 0 0 0 0 0 0 0 0 0 0 0
  96158. - 0 0 0 0 0 0 0 0 0 0 0 0
  96159. - 0 0 0 0 0 0 0 0 0 0 0 0
  96160. - 0 0 0 0 0 0 0 0 0 14 14 14
  96161. - 42 42 42 90 90 90 22 22 22 2 2 6
  96162. - 42 42 42 2 2 6 18 18 18 218 218 218
  96163. -253 253 253 253 253 253 253 253 253 253 253 253
  96164. -253 253 253 253 253 253 253 253 253 253 253 253
  96165. -253 253 253 253 253 253 253 253 253 253 253 253
  96166. -253 253 253 253 253 253 253 253 253 253 253 253
  96167. -253 253 253 253 253 253 253 253 253 253 253 253
  96168. -253 253 253 253 253 253 250 250 250 221 221 221
  96169. -218 218 218 101 101 101 2 2 6 14 14 14
  96170. - 18 18 18 38 38 38 10 10 10 2 2 6
  96171. - 2 2 6 2 2 6 2 2 6 78 78 78
  96172. - 58 58 58 22 22 22 6 6 6 0 0 0
  96173. - 0 0 0 0 0 0 0 0 0 0 0 0
  96174. - 0 0 0 0 0 0 0 0 0 0 0 0
  96175. - 0 0 0 0 0 0 0 0 0 0 0 0
  96176. - 0 0 0 0 0 0 0 0 0 0 0 0
  96177. - 0 0 0 0 0 0 0 0 0 0 0 0
  96178. - 0 0 0 0 0 0 0 0 0 0 0 0
  96179. - 0 0 0 0 0 0 0 0 0 0 0 0
  96180. - 0 0 0 0 0 0 6 6 6 18 18 18
  96181. - 54 54 54 82 82 82 2 2 6 26 26 26
  96182. - 22 22 22 2 2 6 123 123 123 253 253 253
  96183. -253 253 253 253 253 253 253 253 253 253 253 253
  96184. -253 253 253 253 253 253 253 253 253 253 253 253
  96185. -253 253 253 253 253 253 253 253 253 253 253 253
  96186. -253 253 253 253 253 253 253 253 253 253 253 253
  96187. -253 253 253 253 253 253 253 253 253 253 253 253
  96188. -253 253 253 253 253 253 253 253 253 250 250 250
  96189. -238 238 238 198 198 198 6 6 6 38 38 38
  96190. - 58 58 58 26 26 26 38 38 38 2 2 6
  96191. - 2 2 6 2 2 6 2 2 6 46 46 46
  96192. - 78 78 78 30 30 30 10 10 10 0 0 0
  96193. - 0 0 0 0 0 0 0 0 0 0 0 0
  96194. - 0 0 0 0 0 0 0 0 0 0 0 0
  96195. - 0 0 0 0 0 0 0 0 0 0 0 0
  96196. - 0 0 0 0 0 0 0 0 0 0 0 0
  96197. - 0 0 0 0 0 0 0 0 0 0 0 0
  96198. - 0 0 0 0 0 0 0 0 0 0 0 0
  96199. - 0 0 0 0 0 0 0 0 0 0 0 0
  96200. - 0 0 0 0 0 0 10 10 10 30 30 30
  96201. - 74 74 74 58 58 58 2 2 6 42 42 42
  96202. - 2 2 6 22 22 22 231 231 231 253 253 253
  96203. -253 253 253 253 253 253 253 253 253 253 253 253
  96204. -253 253 253 253 253 253 253 253 253 250 250 250
  96205. -253 253 253 253 253 253 253 253 253 253 253 253
  96206. -253 253 253 253 253 253 253 253 253 253 253 253
  96207. -253 253 253 253 253 253 253 253 253 253 253 253
  96208. -253 253 253 253 253 253 253 253 253 253 253 253
  96209. -253 253 253 246 246 246 46 46 46 38 38 38
  96210. - 42 42 42 14 14 14 38 38 38 14 14 14
  96211. - 2 2 6 2 2 6 2 2 6 6 6 6
  96212. - 86 86 86 46 46 46 14 14 14 0 0 0
  96213. - 0 0 0 0 0 0 0 0 0 0 0 0
  96214. - 0 0 0 0 0 0 0 0 0 0 0 0
  96215. - 0 0 0 0 0 0 0 0 0 0 0 0
  96216. - 0 0 0 0 0 0 0 0 0 0 0 0
  96217. - 0 0 0 0 0 0 0 0 0 0 0 0
  96218. - 0 0 0 0 0 0 0 0 0 0 0 0
  96219. - 0 0 0 0 0 0 0 0 0 0 0 0
  96220. - 0 0 0 6 6 6 14 14 14 42 42 42
  96221. - 90 90 90 18 18 18 18 18 18 26 26 26
  96222. - 2 2 6 116 116 116 253 253 253 253 253 253
  96223. -253 253 253 253 253 253 253 253 253 253 253 253
  96224. -253 253 253 253 253 253 250 250 250 238 238 238
  96225. -253 253 253 253 253 253 253 253 253 253 253 253
  96226. -253 253 253 253 253 253 253 253 253 253 253 253
  96227. -253 253 253 253 253 253 253 253 253 253 253 253
  96228. -253 253 253 253 253 253 253 253 253 253 253 253
  96229. -253 253 253 253 253 253 94 94 94 6 6 6
  96230. - 2 2 6 2 2 6 10 10 10 34 34 34
  96231. - 2 2 6 2 2 6 2 2 6 2 2 6
  96232. - 74 74 74 58 58 58 22 22 22 6 6 6
  96233. - 0 0 0 0 0 0 0 0 0 0 0 0
  96234. - 0 0 0 0 0 0 0 0 0 0 0 0
  96235. - 0 0 0 0 0 0 0 0 0 0 0 0
  96236. - 0 0 0 0 0 0 0 0 0 0 0 0
  96237. - 0 0 0 0 0 0 0 0 0 0 0 0
  96238. - 0 0 0 0 0 0 0 0 0 0 0 0
  96239. - 0 0 0 0 0 0 0 0 0 0 0 0
  96240. - 0 0 0 10 10 10 26 26 26 66 66 66
  96241. - 82 82 82 2 2 6 38 38 38 6 6 6
  96242. - 14 14 14 210 210 210 253 253 253 253 253 253
  96243. -253 253 253 253 253 253 253 253 253 253 253 253
  96244. -253 253 253 253 253 253 246 246 246 242 242 242
  96245. -253 253 253 253 253 253 253 253 253 253 253 253
  96246. -253 253 253 253 253 253 253 253 253 253 253 253
  96247. -253 253 253 253 253 253 253 253 253 253 253 253
  96248. -253 253 253 253 253 253 253 253 253 253 253 253
  96249. -253 253 253 253 253 253 144 144 144 2 2 6
  96250. - 2 2 6 2 2 6 2 2 6 46 46 46
  96251. - 2 2 6 2 2 6 2 2 6 2 2 6
  96252. - 42 42 42 74 74 74 30 30 30 10 10 10
  96253. - 0 0 0 0 0 0 0 0 0 0 0 0
  96254. - 0 0 0 0 0 0 0 0 0 0 0 0
  96255. - 0 0 0 0 0 0 0 0 0 0 0 0
  96256. - 0 0 0 0 0 0 0 0 0 0 0 0
  96257. - 0 0 0 0 0 0 0 0 0 0 0 0
  96258. - 0 0 0 0 0 0 0 0 0 0 0 0
  96259. - 0 0 0 0 0 0 0 0 0 0 0 0
  96260. - 6 6 6 14 14 14 42 42 42 90 90 90
  96261. - 26 26 26 6 6 6 42 42 42 2 2 6
  96262. - 74 74 74 250 250 250 253 253 253 253 253 253
  96263. -253 253 253 253 253 253 253 253 253 253 253 253
  96264. -253 253 253 253 253 253 242 242 242 242 242 242
  96265. -253 253 253 253 253 253 253 253 253 253 253 253
  96266. -253 253 253 253 253 253 253 253 253 253 253 253
  96267. -253 253 253 253 253 253 253 253 253 253 253 253
  96268. -253 253 253 253 253 253 253 253 253 253 253 253
  96269. -253 253 253 253 253 253 182 182 182 2 2 6
  96270. - 2 2 6 2 2 6 2 2 6 46 46 46
  96271. - 2 2 6 2 2 6 2 2 6 2 2 6
  96272. - 10 10 10 86 86 86 38 38 38 10 10 10
  96273. - 0 0 0 0 0 0 0 0 0 0 0 0
  96274. - 0 0 0 0 0 0 0 0 0 0 0 0
  96275. - 0 0 0 0 0 0 0 0 0 0 0 0
  96276. - 0 0 0 0 0 0 0 0 0 0 0 0
  96277. - 0 0 0 0 0 0 0 0 0 0 0 0
  96278. - 0 0 0 0 0 0 0 0 0 0 0 0
  96279. - 0 0 0 0 0 0 0 0 0 0 0 0
  96280. - 10 10 10 26 26 26 66 66 66 82 82 82
  96281. - 2 2 6 22 22 22 18 18 18 2 2 6
  96282. -149 149 149 253 253 253 253 253 253 253 253 253
  96283. -253 253 253 253 253 253 253 253 253 253 253 253
  96284. -253 253 253 253 253 253 234 234 234 242 242 242
  96285. -253 253 253 253 253 253 253 253 253 253 253 253
  96286. -253 253 253 253 253 253 253 253 253 253 253 253
  96287. -253 253 253 253 253 253 253 253 253 253 253 253
  96288. -253 253 253 253 253 253 253 253 253 253 253 253
  96289. -253 253 253 253 253 253 206 206 206 2 2 6
  96290. - 2 2 6 2 2 6 2 2 6 38 38 38
  96291. - 2 2 6 2 2 6 2 2 6 2 2 6
  96292. - 6 6 6 86 86 86 46 46 46 14 14 14
  96293. - 0 0 0 0 0 0 0 0 0 0 0 0
  96294. - 0 0 0 0 0 0 0 0 0 0 0 0
  96295. - 0 0 0 0 0 0 0 0 0 0 0 0
  96296. - 0 0 0 0 0 0 0 0 0 0 0 0
  96297. - 0 0 0 0 0 0 0 0 0 0 0 0
  96298. - 0 0 0 0 0 0 0 0 0 0 0 0
  96299. - 0 0 0 0 0 0 0 0 0 6 6 6
  96300. - 18 18 18 46 46 46 86 86 86 18 18 18
  96301. - 2 2 6 34 34 34 10 10 10 6 6 6
  96302. -210 210 210 253 253 253 253 253 253 253 253 253
  96303. -253 253 253 253 253 253 253 253 253 253 253 253
  96304. -253 253 253 253 253 253 234 234 234 242 242 242
  96305. -253 253 253 253 253 253 253 253 253 253 253 253
  96306. -253 253 253 253 253 253 253 253 253 253 253 253
  96307. -253 253 253 253 253 253 253 253 253 253 253 253
  96308. -253 253 253 253 253 253 253 253 253 253 253 253
  96309. -253 253 253 253 253 253 221 221 221 6 6 6
  96310. - 2 2 6 2 2 6 6 6 6 30 30 30
  96311. - 2 2 6 2 2 6 2 2 6 2 2 6
  96312. - 2 2 6 82 82 82 54 54 54 18 18 18
  96313. - 6 6 6 0 0 0 0 0 0 0 0 0
  96314. - 0 0 0 0 0 0 0 0 0 0 0 0
  96315. - 0 0 0 0 0 0 0 0 0 0 0 0
  96316. - 0 0 0 0 0 0 0 0 0 0 0 0
  96317. - 0 0 0 0 0 0 0 0 0 0 0 0
  96318. - 0 0 0 0 0 0 0 0 0 0 0 0
  96319. - 0 0 0 0 0 0 0 0 0 10 10 10
  96320. - 26 26 26 66 66 66 62 62 62 2 2 6
  96321. - 2 2 6 38 38 38 10 10 10 26 26 26
  96322. -238 238 238 253 253 253 253 253 253 253 253 253
  96323. -253 253 253 253 253 253 253 253 253 253 253 253
  96324. -253 253 253 253 253 253 231 231 231 238 238 238
  96325. -253 253 253 253 253 253 253 253 253 253 253 253
  96326. -253 253 253 253 253 253 253 253 253 253 253 253
  96327. -253 253 253 253 253 253 253 253 253 253 253 253
  96328. -253 253 253 253 253 253 253 253 253 253 253 253
  96329. -253 253 253 253 253 253 231 231 231 6 6 6
  96330. - 2 2 6 2 2 6 10 10 10 30 30 30
  96331. - 2 2 6 2 2 6 2 2 6 2 2 6
  96332. - 2 2 6 66 66 66 58 58 58 22 22 22
  96333. - 6 6 6 0 0 0 0 0 0 0 0 0
  96334. - 0 0 0 0 0 0 0 0 0 0 0 0
  96335. - 0 0 0 0 0 0 0 0 0 0 0 0
  96336. - 0 0 0 0 0 0 0 0 0 0 0 0
  96337. - 0 0 0 0 0 0 0 0 0 0 0 0
  96338. - 0 0 0 0 0 0 0 0 0 0 0 0
  96339. - 0 0 0 0 0 0 0 0 0 10 10 10
  96340. - 38 38 38 78 78 78 6 6 6 2 2 6
  96341. - 2 2 6 46 46 46 14 14 14 42 42 42
  96342. -246 246 246 253 253 253 253 253 253 253 253 253
  96343. -253 253 253 253 253 253 253 253 253 253 253 253
  96344. -253 253 253 253 253 253 231 231 231 242 242 242
  96345. -253 253 253 253 253 253 253 253 253 253 253 253
  96346. -253 253 253 253 253 253 253 253 253 253 253 253
  96347. -253 253 253 253 253 253 253 253 253 253 253 253
  96348. -253 253 253 253 253 253 253 253 253 253 253 253
  96349. -253 253 253 253 253 253 234 234 234 10 10 10
  96350. - 2 2 6 2 2 6 22 22 22 14 14 14
  96351. - 2 2 6 2 2 6 2 2 6 2 2 6
  96352. - 2 2 6 66 66 66 62 62 62 22 22 22
  96353. - 6 6 6 0 0 0 0 0 0 0 0 0
  96354. - 0 0 0 0 0 0 0 0 0 0 0 0
  96355. - 0 0 0 0 0 0 0 0 0 0 0 0
  96356. - 0 0 0 0 0 0 0 0 0 0 0 0
  96357. - 0 0 0 0 0 0 0 0 0 0 0 0
  96358. - 0 0 0 0 0 0 0 0 0 0 0 0
  96359. - 0 0 0 0 0 0 6 6 6 18 18 18
  96360. - 50 50 50 74 74 74 2 2 6 2 2 6
  96361. - 14 14 14 70 70 70 34 34 34 62 62 62
  96362. -250 250 250 253 253 253 253 253 253 253 253 253
  96363. -253 253 253 253 253 253 253 253 253 253 253 253
  96364. -253 253 253 253 253 253 231 231 231 246 246 246
  96365. -253 253 253 253 253 253 253 253 253 253 253 253
  96366. -253 253 253 253 253 253 253 253 253 253 253 253
  96367. -253 253 253 253 253 253 253 253 253 253 253 253
  96368. -253 253 253 253 253 253 253 253 253 253 253 253
  96369. -253 253 253 253 253 253 234 234 234 14 14 14
  96370. - 2 2 6 2 2 6 30 30 30 2 2 6
  96371. - 2 2 6 2 2 6 2 2 6 2 2 6
  96372. - 2 2 6 66 66 66 62 62 62 22 22 22
  96373. - 6 6 6 0 0 0 0 0 0 0 0 0
  96374. - 0 0 0 0 0 0 0 0 0 0 0 0
  96375. - 0 0 0 0 0 0 0 0 0 0 0 0
  96376. - 0 0 0 0 0 0 0 0 0 0 0 0
  96377. - 0 0 0 0 0 0 0 0 0 0 0 0
  96378. - 0 0 0 0 0 0 0 0 0 0 0 0
  96379. - 0 0 0 0 0 0 6 6 6 18 18 18
  96380. - 54 54 54 62 62 62 2 2 6 2 2 6
  96381. - 2 2 6 30 30 30 46 46 46 70 70 70
  96382. -250 250 250 253 253 253 253 253 253 253 253 253
  96383. -253 253 253 253 253 253 253 253 253 253 253 253
  96384. -253 253 253 253 253 253 231 231 231 246 246 246
  96385. -253 253 253 253 253 253 253 253 253 253 253 253
  96386. -253 253 253 253 253 253 253 253 253 253 253 253
  96387. -253 253 253 253 253 253 253 253 253 253 253 253
  96388. -253 253 253 253 253 253 253 253 253 253 253 253
  96389. -253 253 253 253 253 253 226 226 226 10 10 10
  96390. - 2 2 6 6 6 6 30 30 30 2 2 6
  96391. - 2 2 6 2 2 6 2 2 6 2 2 6
  96392. - 2 2 6 66 66 66 58 58 58 22 22 22
  96393. - 6 6 6 0 0 0 0 0 0 0 0 0
  96394. - 0 0 0 0 0 0 0 0 0 0 0 0
  96395. - 0 0 0 0 0 0 0 0 0 0 0 0
  96396. - 0 0 0 0 0 0 0 0 0 0 0 0
  96397. - 0 0 0 0 0 0 0 0 0 0 0 0
  96398. - 0 0 0 0 0 0 0 0 0 0 0 0
  96399. - 0 0 0 0 0 0 6 6 6 22 22 22
  96400. - 58 58 58 62 62 62 2 2 6 2 2 6
  96401. - 2 2 6 2 2 6 30 30 30 78 78 78
  96402. -250 250 250 253 253 253 253 253 253 253 253 253
  96403. -253 253 253 253 253 253 253 253 253 253 253 253
  96404. -253 253 253 253 253 253 231 231 231 246 246 246
  96405. -253 253 253 253 253 253 253 253 253 253 253 253
  96406. -253 253 253 253 253 253 253 253 253 253 253 253
  96407. -253 253 253 253 253 253 253 253 253 253 253 253
  96408. -253 253 253 253 253 253 253 253 253 253 253 253
  96409. -253 253 253 253 253 253 206 206 206 2 2 6
  96410. - 22 22 22 34 34 34 18 14 6 22 22 22
  96411. - 26 26 26 18 18 18 6 6 6 2 2 6
  96412. - 2 2 6 82 82 82 54 54 54 18 18 18
  96413. - 6 6 6 0 0 0 0 0 0 0 0 0
  96414. - 0 0 0 0 0 0 0 0 0 0 0 0
  96415. - 0 0 0 0 0 0 0 0 0 0 0 0
  96416. - 0 0 0 0 0 0 0 0 0 0 0 0
  96417. - 0 0 0 0 0 0 0 0 0 0 0 0
  96418. - 0 0 0 0 0 0 0 0 0 0 0 0
  96419. - 0 0 0 0 0 0 6 6 6 26 26 26
  96420. - 62 62 62 106 106 106 74 54 14 185 133 11
  96421. -210 162 10 121 92 8 6 6 6 62 62 62
  96422. -238 238 238 253 253 253 253 253 253 253 253 253
  96423. -253 253 253 253 253 253 253 253 253 253 253 253
  96424. -253 253 253 253 253 253 231 231 231 246 246 246
  96425. -253 253 253 253 253 253 253 253 253 253 253 253
  96426. -253 253 253 253 253 253 253 253 253 253 253 253
  96427. -253 253 253 253 253 253 253 253 253 253 253 253
  96428. -253 253 253 253 253 253 253 253 253 253 253 253
  96429. -253 253 253 253 253 253 158 158 158 18 18 18
  96430. - 14 14 14 2 2 6 2 2 6 2 2 6
  96431. - 6 6 6 18 18 18 66 66 66 38 38 38
  96432. - 6 6 6 94 94 94 50 50 50 18 18 18
  96433. - 6 6 6 0 0 0 0 0 0 0 0 0
  96434. - 0 0 0 0 0 0 0 0 0 0 0 0
  96435. - 0 0 0 0 0 0 0 0 0 0 0 0
  96436. - 0 0 0 0 0 0 0 0 0 0 0 0
  96437. - 0 0 0 0 0 0 0 0 0 0 0 0
  96438. - 0 0 0 0 0 0 0 0 0 6 6 6
  96439. - 10 10 10 10 10 10 18 18 18 38 38 38
  96440. - 78 78 78 142 134 106 216 158 10 242 186 14
  96441. -246 190 14 246 190 14 156 118 10 10 10 10
  96442. - 90 90 90 238 238 238 253 253 253 253 253 253
  96443. -253 253 253 253 253 253 253 253 253 253 253 253
  96444. -253 253 253 253 253 253 231 231 231 250 250 250
  96445. -253 253 253 253 253 253 253 253 253 253 253 253
  96446. -253 253 253 253 253 253 253 253 253 253 253 253
  96447. -253 253 253 253 253 253 253 253 253 253 253 253
  96448. -253 253 253 253 253 253 253 253 253 246 230 190
  96449. -238 204 91 238 204 91 181 142 44 37 26 9
  96450. - 2 2 6 2 2 6 2 2 6 2 2 6
  96451. - 2 2 6 2 2 6 38 38 38 46 46 46
  96452. - 26 26 26 106 106 106 54 54 54 18 18 18
  96453. - 6 6 6 0 0 0 0 0 0 0 0 0
  96454. - 0 0 0 0 0 0 0 0 0 0 0 0
  96455. - 0 0 0 0 0 0 0 0 0 0 0 0
  96456. - 0 0 0 0 0 0 0 0 0 0 0 0
  96457. - 0 0 0 0 0 0 0 0 0 0 0 0
  96458. - 0 0 0 6 6 6 14 14 14 22 22 22
  96459. - 30 30 30 38 38 38 50 50 50 70 70 70
  96460. -106 106 106 190 142 34 226 170 11 242 186 14
  96461. -246 190 14 246 190 14 246 190 14 154 114 10
  96462. - 6 6 6 74 74 74 226 226 226 253 253 253
  96463. -253 253 253 253 253 253 253 253 253 253 253 253
  96464. -253 253 253 253 253 253 231 231 231 250 250 250
  96465. -253 253 253 253 253 253 253 253 253 253 253 253
  96466. -253 253 253 253 253 253 253 253 253 253 253 253
  96467. -253 253 253 253 253 253 253 253 253 253 253 253
  96468. -253 253 253 253 253 253 253 253 253 228 184 62
  96469. -241 196 14 241 208 19 232 195 16 38 30 10
  96470. - 2 2 6 2 2 6 2 2 6 2 2 6
  96471. - 2 2 6 6 6 6 30 30 30 26 26 26
  96472. -203 166 17 154 142 90 66 66 66 26 26 26
  96473. - 6 6 6 0 0 0 0 0 0 0 0 0
  96474. - 0 0 0 0 0 0 0 0 0 0 0 0
  96475. - 0 0 0 0 0 0 0 0 0 0 0 0
  96476. - 0 0 0 0 0 0 0 0 0 0 0 0
  96477. - 0 0 0 0 0 0 0 0 0 0 0 0
  96478. - 6 6 6 18 18 18 38 38 38 58 58 58
  96479. - 78 78 78 86 86 86 101 101 101 123 123 123
  96480. -175 146 61 210 150 10 234 174 13 246 186 14
  96481. -246 190 14 246 190 14 246 190 14 238 190 10
  96482. -102 78 10 2 2 6 46 46 46 198 198 198
  96483. -253 253 253 253 253 253 253 253 253 253 253 253
  96484. -253 253 253 253 253 253 234 234 234 242 242 242
  96485. -253 253 253 253 253 253 253 253 253 253 253 253
  96486. -253 253 253 253 253 253 253 253 253 253 253 253
  96487. -253 253 253 253 253 253 253 253 253 253 253 253
  96488. -253 253 253 253 253 253 253 253 253 224 178 62
  96489. -242 186 14 241 196 14 210 166 10 22 18 6
  96490. - 2 2 6 2 2 6 2 2 6 2 2 6
  96491. - 2 2 6 2 2 6 6 6 6 121 92 8
  96492. -238 202 15 232 195 16 82 82 82 34 34 34
  96493. - 10 10 10 0 0 0 0 0 0 0 0 0
  96494. - 0 0 0 0 0 0 0 0 0 0 0 0
  96495. - 0 0 0 0 0 0 0 0 0 0 0 0
  96496. - 0 0 0 0 0 0 0 0 0 0 0 0
  96497. - 0 0 0 0 0 0 0 0 0 0 0 0
  96498. - 14 14 14 38 38 38 70 70 70 154 122 46
  96499. -190 142 34 200 144 11 197 138 11 197 138 11
  96500. -213 154 11 226 170 11 242 186 14 246 190 14
  96501. -246 190 14 246 190 14 246 190 14 246 190 14
  96502. -225 175 15 46 32 6 2 2 6 22 22 22
  96503. -158 158 158 250 250 250 253 253 253 253 253 253
  96504. -253 253 253 253 253 253 253 253 253 253 253 253
  96505. -253 253 253 253 253 253 253 253 253 253 253 253
  96506. -253 253 253 253 253 253 253 253 253 253 253 253
  96507. -253 253 253 253 253 253 253 253 253 253 253 253
  96508. -253 253 253 250 250 250 242 242 242 224 178 62
  96509. -239 182 13 236 186 11 213 154 11 46 32 6
  96510. - 2 2 6 2 2 6 2 2 6 2 2 6
  96511. - 2 2 6 2 2 6 61 42 6 225 175 15
  96512. -238 190 10 236 186 11 112 100 78 42 42 42
  96513. - 14 14 14 0 0 0 0 0 0 0 0 0
  96514. - 0 0 0 0 0 0 0 0 0 0 0 0
  96515. - 0 0 0 0 0 0 0 0 0 0 0 0
  96516. - 0 0 0 0 0 0 0 0 0 0 0 0
  96517. - 0 0 0 0 0 0 0 0 0 6 6 6
  96518. - 22 22 22 54 54 54 154 122 46 213 154 11
  96519. -226 170 11 230 174 11 226 170 11 226 170 11
  96520. -236 178 12 242 186 14 246 190 14 246 190 14
  96521. -246 190 14 246 190 14 246 190 14 246 190 14
  96522. -241 196 14 184 144 12 10 10 10 2 2 6
  96523. - 6 6 6 116 116 116 242 242 242 253 253 253
  96524. -253 253 253 253 253 253 253 253 253 253 253 253
  96525. -253 253 253 253 253 253 253 253 253 253 253 253
  96526. -253 253 253 253 253 253 253 253 253 253 253 253
  96527. -253 253 253 253 253 253 253 253 253 253 253 253
  96528. -253 253 253 231 231 231 198 198 198 214 170 54
  96529. -236 178 12 236 178 12 210 150 10 137 92 6
  96530. - 18 14 6 2 2 6 2 2 6 2 2 6
  96531. - 6 6 6 70 47 6 200 144 11 236 178 12
  96532. -239 182 13 239 182 13 124 112 88 58 58 58
  96533. - 22 22 22 6 6 6 0 0 0 0 0 0
  96534. - 0 0 0 0 0 0 0 0 0 0 0 0
  96535. - 0 0 0 0 0 0 0 0 0 0 0 0
  96536. - 0 0 0 0 0 0 0 0 0 0 0 0
  96537. - 0 0 0 0 0 0 0 0 0 10 10 10
  96538. - 30 30 30 70 70 70 180 133 36 226 170 11
  96539. -239 182 13 242 186 14 242 186 14 246 186 14
  96540. -246 190 14 246 190 14 246 190 14 246 190 14
  96541. -246 190 14 246 190 14 246 190 14 246 190 14
  96542. -246 190 14 232 195 16 98 70 6 2 2 6
  96543. - 2 2 6 2 2 6 66 66 66 221 221 221
  96544. -253 253 253 253 253 253 253 253 253 253 253 253
  96545. -253 253 253 253 253 253 253 253 253 253 253 253
  96546. -253 253 253 253 253 253 253 253 253 253 253 253
  96547. -253 253 253 253 253 253 253 253 253 253 253 253
  96548. -253 253 253 206 206 206 198 198 198 214 166 58
  96549. -230 174 11 230 174 11 216 158 10 192 133 9
  96550. -163 110 8 116 81 8 102 78 10 116 81 8
  96551. -167 114 7 197 138 11 226 170 11 239 182 13
  96552. -242 186 14 242 186 14 162 146 94 78 78 78
  96553. - 34 34 34 14 14 14 6 6 6 0 0 0
  96554. - 0 0 0 0 0 0 0 0 0 0 0 0
  96555. - 0 0 0 0 0 0 0 0 0 0 0 0
  96556. - 0 0 0 0 0 0 0 0 0 0 0 0
  96557. - 0 0 0 0 0 0 0 0 0 6 6 6
  96558. - 30 30 30 78 78 78 190 142 34 226 170 11
  96559. -239 182 13 246 190 14 246 190 14 246 190 14
  96560. -246 190 14 246 190 14 246 190 14 246 190 14
  96561. -246 190 14 246 190 14 246 190 14 246 190 14
  96562. -246 190 14 241 196 14 203 166 17 22 18 6
  96563. - 2 2 6 2 2 6 2 2 6 38 38 38
  96564. -218 218 218 253 253 253 253 253 253 253 253 253
  96565. -253 253 253 253 253 253 253 253 253 253 253 253
  96566. -253 253 253 253 253 253 253 253 253 253 253 253
  96567. -253 253 253 253 253 253 253 253 253 253 253 253
  96568. -250 250 250 206 206 206 198 198 198 202 162 69
  96569. -226 170 11 236 178 12 224 166 10 210 150 10
  96570. -200 144 11 197 138 11 192 133 9 197 138 11
  96571. -210 150 10 226 170 11 242 186 14 246 190 14
  96572. -246 190 14 246 186 14 225 175 15 124 112 88
  96573. - 62 62 62 30 30 30 14 14 14 6 6 6
  96574. - 0 0 0 0 0 0 0 0 0 0 0 0
  96575. - 0 0 0 0 0 0 0 0 0 0 0 0
  96576. - 0 0 0 0 0 0 0 0 0 0 0 0
  96577. - 0 0 0 0 0 0 0 0 0 10 10 10
  96578. - 30 30 30 78 78 78 174 135 50 224 166 10
  96579. -239 182 13 246 190 14 246 190 14 246 190 14
  96580. -246 190 14 246 190 14 246 190 14 246 190 14
  96581. -246 190 14 246 190 14 246 190 14 246 190 14
  96582. -246 190 14 246 190 14 241 196 14 139 102 15
  96583. - 2 2 6 2 2 6 2 2 6 2 2 6
  96584. - 78 78 78 250 250 250 253 253 253 253 253 253
  96585. -253 253 253 253 253 253 253 253 253 253 253 253
  96586. -253 253 253 253 253 253 253 253 253 253 253 253
  96587. -253 253 253 253 253 253 253 253 253 253 253 253
  96588. -250 250 250 214 214 214 198 198 198 190 150 46
  96589. -219 162 10 236 178 12 234 174 13 224 166 10
  96590. -216 158 10 213 154 11 213 154 11 216 158 10
  96591. -226 170 11 239 182 13 246 190 14 246 190 14
  96592. -246 190 14 246 190 14 242 186 14 206 162 42
  96593. -101 101 101 58 58 58 30 30 30 14 14 14
  96594. - 6 6 6 0 0 0 0 0 0 0 0 0
  96595. - 0 0 0 0 0 0 0 0 0 0 0 0
  96596. - 0 0 0 0 0 0 0 0 0 0 0 0
  96597. - 0 0 0 0 0 0 0 0 0 10 10 10
  96598. - 30 30 30 74 74 74 174 135 50 216 158 10
  96599. -236 178 12 246 190 14 246 190 14 246 190 14
  96600. -246 190 14 246 190 14 246 190 14 246 190 14
  96601. -246 190 14 246 190 14 246 190 14 246 190 14
  96602. -246 190 14 246 190 14 241 196 14 226 184 13
  96603. - 61 42 6 2 2 6 2 2 6 2 2 6
  96604. - 22 22 22 238 238 238 253 253 253 253 253 253
  96605. -253 253 253 253 253 253 253 253 253 253 253 253
  96606. -253 253 253 253 253 253 253 253 253 253 253 253
  96607. -253 253 253 253 253 253 253 253 253 253 253 253
  96608. -253 253 253 226 226 226 187 187 187 180 133 36
  96609. -216 158 10 236 178 12 239 182 13 236 178 12
  96610. -230 174 11 226 170 11 226 170 11 230 174 11
  96611. -236 178 12 242 186 14 246 190 14 246 190 14
  96612. -246 190 14 246 190 14 246 186 14 239 182 13
  96613. -206 162 42 106 106 106 66 66 66 34 34 34
  96614. - 14 14 14 6 6 6 0 0 0 0 0 0
  96615. - 0 0 0 0 0 0 0 0 0 0 0 0
  96616. - 0 0 0 0 0 0 0 0 0 0 0 0
  96617. - 0 0 0 0 0 0 0 0 0 6 6 6
  96618. - 26 26 26 70 70 70 163 133 67 213 154 11
  96619. -236 178 12 246 190 14 246 190 14 246 190 14
  96620. -246 190 14 246 190 14 246 190 14 246 190 14
  96621. -246 190 14 246 190 14 246 190 14 246 190 14
  96622. -246 190 14 246 190 14 246 190 14 241 196 14
  96623. -190 146 13 18 14 6 2 2 6 2 2 6
  96624. - 46 46 46 246 246 246 253 253 253 253 253 253
  96625. -253 253 253 253 253 253 253 253 253 253 253 253
  96626. -253 253 253 253 253 253 253 253 253 253 253 253
  96627. -253 253 253 253 253 253 253 253 253 253 253 253
  96628. -253 253 253 221 221 221 86 86 86 156 107 11
  96629. -216 158 10 236 178 12 242 186 14 246 186 14
  96630. -242 186 14 239 182 13 239 182 13 242 186 14
  96631. -242 186 14 246 186 14 246 190 14 246 190 14
  96632. -246 190 14 246 190 14 246 190 14 246 190 14
  96633. -242 186 14 225 175 15 142 122 72 66 66 66
  96634. - 30 30 30 10 10 10 0 0 0 0 0 0
  96635. - 0 0 0 0 0 0 0 0 0 0 0 0
  96636. - 0 0 0 0 0 0 0 0 0 0 0 0
  96637. - 0 0 0 0 0 0 0 0 0 6 6 6
  96638. - 26 26 26 70 70 70 163 133 67 210 150 10
  96639. -236 178 12 246 190 14 246 190 14 246 190 14
  96640. -246 190 14 246 190 14 246 190 14 246 190 14
  96641. -246 190 14 246 190 14 246 190 14 246 190 14
  96642. -246 190 14 246 190 14 246 190 14 246 190 14
  96643. -232 195 16 121 92 8 34 34 34 106 106 106
  96644. -221 221 221 253 253 253 253 253 253 253 253 253
  96645. -253 253 253 253 253 253 253 253 253 253 253 253
  96646. -253 253 253 253 253 253 253 253 253 253 253 253
  96647. -253 253 253 253 253 253 253 253 253 253 253 253
  96648. -242 242 242 82 82 82 18 14 6 163 110 8
  96649. -216 158 10 236 178 12 242 186 14 246 190 14
  96650. -246 190 14 246 190 14 246 190 14 246 190 14
  96651. -246 190 14 246 190 14 246 190 14 246 190 14
  96652. -246 190 14 246 190 14 246 190 14 246 190 14
  96653. -246 190 14 246 190 14 242 186 14 163 133 67
  96654. - 46 46 46 18 18 18 6 6 6 0 0 0
  96655. - 0 0 0 0 0 0 0 0 0 0 0 0
  96656. - 0 0 0 0 0 0 0 0 0 0 0 0
  96657. - 0 0 0 0 0 0 0 0 0 10 10 10
  96658. - 30 30 30 78 78 78 163 133 67 210 150 10
  96659. -236 178 12 246 186 14 246 190 14 246 190 14
  96660. -246 190 14 246 190 14 246 190 14 246 190 14
  96661. -246 190 14 246 190 14 246 190 14 246 190 14
  96662. -246 190 14 246 190 14 246 190 14 246 190 14
  96663. -241 196 14 215 174 15 190 178 144 253 253 253
  96664. -253 253 253 253 253 253 253 253 253 253 253 253
  96665. -253 253 253 253 253 253 253 253 253 253 253 253
  96666. -253 253 253 253 253 253 253 253 253 253 253 253
  96667. -253 253 253 253 253 253 253 253 253 218 218 218
  96668. - 58 58 58 2 2 6 22 18 6 167 114 7
  96669. -216 158 10 236 178 12 246 186 14 246 190 14
  96670. -246 190 14 246 190 14 246 190 14 246 190 14
  96671. -246 190 14 246 190 14 246 190 14 246 190 14
  96672. -246 190 14 246 190 14 246 190 14 246 190 14
  96673. -246 190 14 246 186 14 242 186 14 190 150 46
  96674. - 54 54 54 22 22 22 6 6 6 0 0 0
  96675. - 0 0 0 0 0 0 0 0 0 0 0 0
  96676. - 0 0 0 0 0 0 0 0 0 0 0 0
  96677. - 0 0 0 0 0 0 0 0 0 14 14 14
  96678. - 38 38 38 86 86 86 180 133 36 213 154 11
  96679. -236 178 12 246 186 14 246 190 14 246 190 14
  96680. -246 190 14 246 190 14 246 190 14 246 190 14
  96681. -246 190 14 246 190 14 246 190 14 246 190 14
  96682. -246 190 14 246 190 14 246 190 14 246 190 14
  96683. -246 190 14 232 195 16 190 146 13 214 214 214
  96684. -253 253 253 253 253 253 253 253 253 253 253 253
  96685. -253 253 253 253 253 253 253 253 253 253 253 253
  96686. -253 253 253 253 253 253 253 253 253 253 253 253
  96687. -253 253 253 250 250 250 170 170 170 26 26 26
  96688. - 2 2 6 2 2 6 37 26 9 163 110 8
  96689. -219 162 10 239 182 13 246 186 14 246 190 14
  96690. -246 190 14 246 190 14 246 190 14 246 190 14
  96691. -246 190 14 246 190 14 246 190 14 246 190 14
  96692. -246 190 14 246 190 14 246 190 14 246 190 14
  96693. -246 186 14 236 178 12 224 166 10 142 122 72
  96694. - 46 46 46 18 18 18 6 6 6 0 0 0
  96695. - 0 0 0 0 0 0 0 0 0 0 0 0
  96696. - 0 0 0 0 0 0 0 0 0 0 0 0
  96697. - 0 0 0 0 0 0 6 6 6 18 18 18
  96698. - 50 50 50 109 106 95 192 133 9 224 166 10
  96699. -242 186 14 246 190 14 246 190 14 246 190 14
  96700. -246 190 14 246 190 14 246 190 14 246 190 14
  96701. -246 190 14 246 190 14 246 190 14 246 190 14
  96702. -246 190 14 246 190 14 246 190 14 246 190 14
  96703. -242 186 14 226 184 13 210 162 10 142 110 46
  96704. -226 226 226 253 253 253 253 253 253 253 253 253
  96705. -253 253 253 253 253 253 253 253 253 253 253 253
  96706. -253 253 253 253 253 253 253 253 253 253 253 253
  96707. -198 198 198 66 66 66 2 2 6 2 2 6
  96708. - 2 2 6 2 2 6 50 34 6 156 107 11
  96709. -219 162 10 239 182 13 246 186 14 246 190 14
  96710. -246 190 14 246 190 14 246 190 14 246 190 14
  96711. -246 190 14 246 190 14 246 190 14 246 190 14
  96712. -246 190 14 246 190 14 246 190 14 242 186 14
  96713. -234 174 13 213 154 11 154 122 46 66 66 66
  96714. - 30 30 30 10 10 10 0 0 0 0 0 0
  96715. - 0 0 0 0 0 0 0 0 0 0 0 0
  96716. - 0 0 0 0 0 0 0 0 0 0 0 0
  96717. - 0 0 0 0 0 0 6 6 6 22 22 22
  96718. - 58 58 58 154 121 60 206 145 10 234 174 13
  96719. -242 186 14 246 186 14 246 190 14 246 190 14
  96720. -246 190 14 246 190 14 246 190 14 246 190 14
  96721. -246 190 14 246 190 14 246 190 14 246 190 14
  96722. -246 190 14 246 190 14 246 190 14 246 190 14
  96723. -246 186 14 236 178 12 210 162 10 163 110 8
  96724. - 61 42 6 138 138 138 218 218 218 250 250 250
  96725. -253 253 253 253 253 253 253 253 253 250 250 250
  96726. -242 242 242 210 210 210 144 144 144 66 66 66
  96727. - 6 6 6 2 2 6 2 2 6 2 2 6
  96728. - 2 2 6 2 2 6 61 42 6 163 110 8
  96729. -216 158 10 236 178 12 246 190 14 246 190 14
  96730. -246 190 14 246 190 14 246 190 14 246 190 14
  96731. -246 190 14 246 190 14 246 190 14 246 190 14
  96732. -246 190 14 239 182 13 230 174 11 216 158 10
  96733. -190 142 34 124 112 88 70 70 70 38 38 38
  96734. - 18 18 18 6 6 6 0 0 0 0 0 0
  96735. - 0 0 0 0 0 0 0 0 0 0 0 0
  96736. - 0 0 0 0 0 0 0 0 0 0 0 0
  96737. - 0 0 0 0 0 0 6 6 6 22 22 22
  96738. - 62 62 62 168 124 44 206 145 10 224 166 10
  96739. -236 178 12 239 182 13 242 186 14 242 186 14
  96740. -246 186 14 246 190 14 246 190 14 246 190 14
  96741. -246 190 14 246 190 14 246 190 14 246 190 14
  96742. -246 190 14 246 190 14 246 190 14 246 190 14
  96743. -246 190 14 236 178 12 216 158 10 175 118 6
  96744. - 80 54 7 2 2 6 6 6 6 30 30 30
  96745. - 54 54 54 62 62 62 50 50 50 38 38 38
  96746. - 14 14 14 2 2 6 2 2 6 2 2 6
  96747. - 2 2 6 2 2 6 2 2 6 2 2 6
  96748. - 2 2 6 6 6 6 80 54 7 167 114 7
  96749. -213 154 11 236 178 12 246 190 14 246 190 14
  96750. -246 190 14 246 190 14 246 190 14 246 190 14
  96751. -246 190 14 242 186 14 239 182 13 239 182 13
  96752. -230 174 11 210 150 10 174 135 50 124 112 88
  96753. - 82 82 82 54 54 54 34 34 34 18 18 18
  96754. - 6 6 6 0 0 0 0 0 0 0 0 0
  96755. - 0 0 0 0 0 0 0 0 0 0 0 0
  96756. - 0 0 0 0 0 0 0 0 0 0 0 0
  96757. - 0 0 0 0 0 0 6 6 6 18 18 18
  96758. - 50 50 50 158 118 36 192 133 9 200 144 11
  96759. -216 158 10 219 162 10 224 166 10 226 170 11
  96760. -230 174 11 236 178 12 239 182 13 239 182 13
  96761. -242 186 14 246 186 14 246 190 14 246 190 14
  96762. -246 190 14 246 190 14 246 190 14 246 190 14
  96763. -246 186 14 230 174 11 210 150 10 163 110 8
  96764. -104 69 6 10 10 10 2 2 6 2 2 6
  96765. - 2 2 6 2 2 6 2 2 6 2 2 6
  96766. - 2 2 6 2 2 6 2 2 6 2 2 6
  96767. - 2 2 6 2 2 6 2 2 6 2 2 6
  96768. - 2 2 6 6 6 6 91 60 6 167 114 7
  96769. -206 145 10 230 174 11 242 186 14 246 190 14
  96770. -246 190 14 246 190 14 246 186 14 242 186 14
  96771. -239 182 13 230 174 11 224 166 10 213 154 11
  96772. -180 133 36 124 112 88 86 86 86 58 58 58
  96773. - 38 38 38 22 22 22 10 10 10 6 6 6
  96774. - 0 0 0 0 0 0 0 0 0 0 0 0
  96775. - 0 0 0 0 0 0 0 0 0 0 0 0
  96776. - 0 0 0 0 0 0 0 0 0 0 0 0
  96777. - 0 0 0 0 0 0 0 0 0 14 14 14
  96778. - 34 34 34 70 70 70 138 110 50 158 118 36
  96779. -167 114 7 180 123 7 192 133 9 197 138 11
  96780. -200 144 11 206 145 10 213 154 11 219 162 10
  96781. -224 166 10 230 174 11 239 182 13 242 186 14
  96782. -246 186 14 246 186 14 246 186 14 246 186 14
  96783. -239 182 13 216 158 10 185 133 11 152 99 6
  96784. -104 69 6 18 14 6 2 2 6 2 2 6
  96785. - 2 2 6 2 2 6 2 2 6 2 2 6
  96786. - 2 2 6 2 2 6 2 2 6 2 2 6
  96787. - 2 2 6 2 2 6 2 2 6 2 2 6
  96788. - 2 2 6 6 6 6 80 54 7 152 99 6
  96789. -192 133 9 219 162 10 236 178 12 239 182 13
  96790. -246 186 14 242 186 14 239 182 13 236 178 12
  96791. -224 166 10 206 145 10 192 133 9 154 121 60
  96792. - 94 94 94 62 62 62 42 42 42 22 22 22
  96793. - 14 14 14 6 6 6 0 0 0 0 0 0
  96794. - 0 0 0 0 0 0 0 0 0 0 0 0
  96795. - 0 0 0 0 0 0 0 0 0 0 0 0
  96796. - 0 0 0 0 0 0 0 0 0 0 0 0
  96797. - 0 0 0 0 0 0 0 0 0 6 6 6
  96798. - 18 18 18 34 34 34 58 58 58 78 78 78
  96799. -101 98 89 124 112 88 142 110 46 156 107 11
  96800. -163 110 8 167 114 7 175 118 6 180 123 7
  96801. -185 133 11 197 138 11 210 150 10 219 162 10
  96802. -226 170 11 236 178 12 236 178 12 234 174 13
  96803. -219 162 10 197 138 11 163 110 8 130 83 6
  96804. - 91 60 6 10 10 10 2 2 6 2 2 6
  96805. - 18 18 18 38 38 38 38 38 38 38 38 38
  96806. - 38 38 38 38 38 38 38 38 38 38 38 38
  96807. - 38 38 38 38 38 38 26 26 26 2 2 6
  96808. - 2 2 6 6 6 6 70 47 6 137 92 6
  96809. -175 118 6 200 144 11 219 162 10 230 174 11
  96810. -234 174 13 230 174 11 219 162 10 210 150 10
  96811. -192 133 9 163 110 8 124 112 88 82 82 82
  96812. - 50 50 50 30 30 30 14 14 14 6 6 6
  96813. - 0 0 0 0 0 0 0 0 0 0 0 0
  96814. - 0 0 0 0 0 0 0 0 0 0 0 0
  96815. - 0 0 0 0 0 0 0 0 0 0 0 0
  96816. - 0 0 0 0 0 0 0 0 0 0 0 0
  96817. - 0 0 0 0 0 0 0 0 0 0 0 0
  96818. - 6 6 6 14 14 14 22 22 22 34 34 34
  96819. - 42 42 42 58 58 58 74 74 74 86 86 86
  96820. -101 98 89 122 102 70 130 98 46 121 87 25
  96821. -137 92 6 152 99 6 163 110 8 180 123 7
  96822. -185 133 11 197 138 11 206 145 10 200 144 11
  96823. -180 123 7 156 107 11 130 83 6 104 69 6
  96824. - 50 34 6 54 54 54 110 110 110 101 98 89
  96825. - 86 86 86 82 82 82 78 78 78 78 78 78
  96826. - 78 78 78 78 78 78 78 78 78 78 78 78
  96827. - 78 78 78 82 82 82 86 86 86 94 94 94
  96828. -106 106 106 101 101 101 86 66 34 124 80 6
  96829. -156 107 11 180 123 7 192 133 9 200 144 11
  96830. -206 145 10 200 144 11 192 133 9 175 118 6
  96831. -139 102 15 109 106 95 70 70 70 42 42 42
  96832. - 22 22 22 10 10 10 0 0 0 0 0 0
  96833. - 0 0 0 0 0 0 0 0 0 0 0 0
  96834. - 0 0 0 0 0 0 0 0 0 0 0 0
  96835. - 0 0 0 0 0 0 0 0 0 0 0 0
  96836. - 0 0 0 0 0 0 0 0 0 0 0 0
  96837. - 0 0 0 0 0 0 0 0 0 0 0 0
  96838. - 0 0 0 0 0 0 6 6 6 10 10 10
  96839. - 14 14 14 22 22 22 30 30 30 38 38 38
  96840. - 50 50 50 62 62 62 74 74 74 90 90 90
  96841. -101 98 89 112 100 78 121 87 25 124 80 6
  96842. -137 92 6 152 99 6 152 99 6 152 99 6
  96843. -138 86 6 124 80 6 98 70 6 86 66 30
  96844. -101 98 89 82 82 82 58 58 58 46 46 46
  96845. - 38 38 38 34 34 34 34 34 34 34 34 34
  96846. - 34 34 34 34 34 34 34 34 34 34 34 34
  96847. - 34 34 34 34 34 34 38 38 38 42 42 42
  96848. - 54 54 54 82 82 82 94 86 76 91 60 6
  96849. -134 86 6 156 107 11 167 114 7 175 118 6
  96850. -175 118 6 167 114 7 152 99 6 121 87 25
  96851. -101 98 89 62 62 62 34 34 34 18 18 18
  96852. - 6 6 6 0 0 0 0 0 0 0 0 0
  96853. - 0 0 0 0 0 0 0 0 0 0 0 0
  96854. - 0 0 0 0 0 0 0 0 0 0 0 0
  96855. - 0 0 0 0 0 0 0 0 0 0 0 0
  96856. - 0 0 0 0 0 0 0 0 0 0 0 0
  96857. - 0 0 0 0 0 0 0 0 0 0 0 0
  96858. - 0 0 0 0 0 0 0 0 0 0 0 0
  96859. - 0 0 0 6 6 6 6 6 6 10 10 10
  96860. - 18 18 18 22 22 22 30 30 30 42 42 42
  96861. - 50 50 50 66 66 66 86 86 86 101 98 89
  96862. -106 86 58 98 70 6 104 69 6 104 69 6
  96863. -104 69 6 91 60 6 82 62 34 90 90 90
  96864. - 62 62 62 38 38 38 22 22 22 14 14 14
  96865. - 10 10 10 10 10 10 10 10 10 10 10 10
  96866. - 10 10 10 10 10 10 6 6 6 10 10 10
  96867. - 10 10 10 10 10 10 10 10 10 14 14 14
  96868. - 22 22 22 42 42 42 70 70 70 89 81 66
  96869. - 80 54 7 104 69 6 124 80 6 137 92 6
  96870. -134 86 6 116 81 8 100 82 52 86 86 86
  96871. - 58 58 58 30 30 30 14 14 14 6 6 6
  96872. - 0 0 0 0 0 0 0 0 0 0 0 0
  96873. - 0 0 0 0 0 0 0 0 0 0 0 0
  96874. - 0 0 0 0 0 0 0 0 0 0 0 0
  96875. - 0 0 0 0 0 0 0 0 0 0 0 0
  96876. - 0 0 0 0 0 0 0 0 0 0 0 0
  96877. - 0 0 0 0 0 0 0 0 0 0 0 0
  96878. - 0 0 0 0 0 0 0 0 0 0 0 0
  96879. - 0 0 0 0 0 0 0 0 0 0 0 0
  96880. - 0 0 0 6 6 6 10 10 10 14 14 14
  96881. - 18 18 18 26 26 26 38 38 38 54 54 54
  96882. - 70 70 70 86 86 86 94 86 76 89 81 66
  96883. - 89 81 66 86 86 86 74 74 74 50 50 50
  96884. - 30 30 30 14 14 14 6 6 6 0 0 0
  96885. - 0 0 0 0 0 0 0 0 0 0 0 0
  96886. - 0 0 0 0 0 0 0 0 0 0 0 0
  96887. - 0 0 0 0 0 0 0 0 0 0 0 0
  96888. - 6 6 6 18 18 18 34 34 34 58 58 58
  96889. - 82 82 82 89 81 66 89 81 66 89 81 66
  96890. - 94 86 66 94 86 76 74 74 74 50 50 50
  96891. - 26 26 26 14 14 14 6 6 6 0 0 0
  96892. - 0 0 0 0 0 0 0 0 0 0 0 0
  96893. - 0 0 0 0 0 0 0 0 0 0 0 0
  96894. - 0 0 0 0 0 0 0 0 0 0 0 0
  96895. - 0 0 0 0 0 0 0 0 0 0 0 0
  96896. - 0 0 0 0 0 0 0 0 0 0 0 0
  96897. - 0 0 0 0 0 0 0 0 0 0 0 0
  96898. - 0 0 0 0 0 0 0 0 0 0 0 0
  96899. - 0 0 0 0 0 0 0 0 0 0 0 0
  96900. - 0 0 0 0 0 0 0 0 0 0 0 0
  96901. - 6 6 6 6 6 6 14 14 14 18 18 18
  96902. - 30 30 30 38 38 38 46 46 46 54 54 54
  96903. - 50 50 50 42 42 42 30 30 30 18 18 18
  96904. - 10 10 10 0 0 0 0 0 0 0 0 0
  96905. - 0 0 0 0 0 0 0 0 0 0 0 0
  96906. - 0 0 0 0 0 0 0 0 0 0 0 0
  96907. - 0 0 0 0 0 0 0 0 0 0 0 0
  96908. - 0 0 0 6 6 6 14 14 14 26 26 26
  96909. - 38 38 38 50 50 50 58 58 58 58 58 58
  96910. - 54 54 54 42 42 42 30 30 30 18 18 18
  96911. - 10 10 10 0 0 0 0 0 0 0 0 0
  96912. - 0 0 0 0 0 0 0 0 0 0 0 0
  96913. - 0 0 0 0 0 0 0 0 0 0 0 0
  96914. - 0 0 0 0 0 0 0 0 0 0 0 0
  96915. - 0 0 0 0 0 0 0 0 0 0 0 0
  96916. - 0 0 0 0 0 0 0 0 0 0 0 0
  96917. - 0 0 0 0 0 0 0 0 0 0 0 0
  96918. - 0 0 0 0 0 0 0 0 0 0 0 0
  96919. - 0 0 0 0 0 0 0 0 0 0 0 0
  96920. - 0 0 0 0 0 0 0 0 0 0 0 0
  96921. - 0 0 0 0 0 0 0 0 0 6 6 6
  96922. - 6 6 6 10 10 10 14 14 14 18 18 18
  96923. - 18 18 18 14 14 14 10 10 10 6 6 6
  96924. - 0 0 0 0 0 0 0 0 0 0 0 0
  96925. - 0 0 0 0 0 0 0 0 0 0 0 0
  96926. - 0 0 0 0 0 0 0 0 0 0 0 0
  96927. - 0 0 0 0 0 0 0 0 0 0 0 0
  96928. - 0 0 0 0 0 0 0 0 0 6 6 6
  96929. - 14 14 14 18 18 18 22 22 22 22 22 22
  96930. - 18 18 18 14 14 14 10 10 10 6 6 6
  96931. - 0 0 0 0 0 0 0 0 0 0 0 0
  96932. - 0 0 0 0 0 0 0 0 0 0 0 0
  96933. - 0 0 0 0 0 0 0 0 0 0 0 0
  96934. - 0 0 0 0 0 0 0 0 0 0 0 0
  96935. - 0 0 0 0 0 0 0 0 0 0 0 0
  96936. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96937. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96938. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96939. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96940. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96941. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96942. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96943. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96944. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96945. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96946. +0 0 0 0 0 0 0 0 0
  96947. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96948. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96949. +0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0
  96950. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96951. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96952. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96953. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96954. +0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0
  96955. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96956. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96957. +0 0 0 0 0 0 0 0 0
  96958. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96959. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  96960. +10 15 3 2 3 1 12 18 4 42 61 14 19 27 6 11 16 4
  96961. +38 55 13 10 15 3 3 4 1 10 15 3 0 0 0 0 0 0
  96962. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96963. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96964. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 3 1
  96965. +12 18 4 1 1 0 23 34 8 31 45 11 10 15 3 32 47 11
  96966. +34 49 12 3 4 1 3 4 1 3 4 1 0 0 0 0 0 0
  96967. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96968. +0 0 0 0 0 0 0 0 0
  96969. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96970. +0 0 0 0 0 0 10 15 3 29 42 10 26 37 9 12 18 4
  96971. +55 80 19 81 118 28 55 80 19 92 132 31 106 153 36 69 100 23
  96972. +100 144 34 80 116 27 42 61 14 81 118 28 23 34 8 27 40 9
  96973. +15 21 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96974. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96975. +0 0 0 0 0 0 1 1 0 29 42 10 15 21 5 50 72 17
  96976. +74 107 25 45 64 15 102 148 35 80 116 27 84 121 28 111 160 38
  96977. +69 100 23 65 94 22 81 118 28 29 42 10 17 25 6 29 42 10
  96978. +23 34 8 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  96979. +0 0 0 0 0 0 0 0 0
  96980. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  96981. +15 21 5 15 21 5 34 49 12 101 146 34 111 161 38 97 141 33
  96982. +97 141 33 119 172 41 117 170 40 116 167 40 118 170 40 118 171 40
  96983. +117 169 40 118 170 40 111 160 38 118 170 40 96 138 32 89 128 30
  96984. +81 118 28 11 16 4 10 15 3 1 1 0 0 0 0 0 0 0
  96985. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  96986. +3 4 1 3 4 1 34 49 12 101 146 34 79 115 27 111 160 38
  96987. +114 165 39 113 163 39 118 170 40 117 169 40 118 171 40 117 169 40
  96988. +116 167 40 119 172 41 113 163 39 92 132 31 105 151 36 113 163 39
  96989. +75 109 26 19 27 6 16 23 5 11 16 4 0 1 0 0 0 0
  96990. +0 0 0 0 0 0 0 0 0
  96991. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  96992. +80 116 27 106 153 36 105 151 36 114 165 39 118 170 40 118 171 40
  96993. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96994. +117 169 40 117 169 40 117 170 40 117 169 40 118 170 40 118 170 40
  96995. +117 170 40 75 109 26 75 109 26 34 49 12 0 0 0 0 0 0
  96996. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 1
  96997. +64 92 22 65 94 22 100 144 34 118 171 40 118 170 40 117 169 40
  96998. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  96999. +117 169 40 117 169 40 117 169 40 118 171 41 118 170 40 117 169 40
  97000. +109 158 37 105 151 36 104 150 35 47 69 16 0 0 0 0 0 0
  97001. +0 0 0 0 0 0 0 0 0
  97002. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97003. +42 61 14 115 167 39 118 170 40 117 169 40 117 169 40 117 169 40
  97004. +117 170 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  97005. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97006. +117 169 40 117 169 40 118 170 40 96 138 32 17 25 6 0 0 0
  97007. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 47 69 16
  97008. +114 165 39 117 168 40 117 170 40 117 169 40 117 169 40 117 169 40
  97009. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97010. +117 169 40 117 169 40 118 170 40 117 169 40 117 169 40 117 169 40
  97011. +117 170 40 119 172 41 96 138 32 12 18 4 0 0 0 0 0 0
  97012. +0 0 0 0 0 0 0 0 0
  97013. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 15 3
  97014. +32 47 11 105 151 36 118 170 40 117 169 40 117 169 40 116 168 40
  97015. +109 157 37 111 160 38 117 169 40 118 171 40 117 169 40 117 169 40
  97016. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97017. +117 169 40 117 169 40 117 169 40 118 171 40 69 100 23 2 3 1
  97018. +0 0 0 0 0 0 0 0 0 0 0 0 19 27 6 101 146 34
  97019. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97020. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 170 40
  97021. +118 171 40 115 166 39 107 154 36 111 161 38 117 169 40 117 169 40
  97022. +117 169 40 118 171 40 75 109 26 19 27 6 2 3 1 0 0 0
  97023. +0 0 0 0 0 0 0 0 0
  97024. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 23 5
  97025. +89 128 30 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97026. +111 160 38 92 132 31 79 115 27 96 138 32 115 166 39 119 171 41
  97027. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97028. +117 169 40 117 169 40 117 169 40 118 170 40 109 157 37 26 37 9
  97029. +0 0 0 0 0 0 0 0 0 0 0 0 64 92 22 118 171 40
  97030. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97031. +117 169 40 117 169 40 117 169 40 118 170 40 118 171 40 109 157 37
  97032. +89 128 30 81 118 28 100 144 34 115 166 39 117 169 40 117 169 40
  97033. +117 169 40 117 170 40 113 163 39 60 86 20 1 1 0 0 0 0
  97034. +0 0 0 0 0 0 0 0 0
  97035. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97036. +27 40 9 96 138 32 118 170 40 117 169 40 117 169 40 117 169 40
  97037. +117 170 40 117 169 40 101 146 34 67 96 23 55 80 19 84 121 28
  97038. +113 163 39 119 171 41 117 169 40 117 169 40 117 169 40 117 169 40
  97039. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 65 94 22
  97040. +0 0 0 0 0 0 0 0 0 15 21 5 101 146 34 118 171 40
  97041. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97042. +117 169 40 118 170 40 118 171 40 104 150 35 69 100 23 53 76 18
  97043. +81 118 28 111 160 38 118 170 40 117 169 40 117 169 40 117 169 40
  97044. +117 169 40 114 165 39 69 100 23 10 15 3 0 0 0 0 0 0
  97045. +0 0 0 0 0 0 0 0 0
  97046. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  97047. +31 45 11 77 111 26 117 169 40 117 169 40 117 169 40 117 169 40
  97048. +117 169 40 117 169 40 118 170 40 116 168 40 92 132 31 47 69 16
  97049. +38 55 13 81 118 28 113 163 39 119 171 41 117 169 40 117 169 40
  97050. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 41 92 132 31
  97051. +10 15 3 0 0 0 0 0 0 36 52 12 115 166 39 117 169 40
  97052. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  97053. +118 171 40 102 148 35 64 92 22 34 49 12 65 94 22 106 153 36
  97054. +118 171 40 117 170 40 117 169 40 117 169 40 117 169 40 117 169 40
  97055. +118 170 40 107 154 36 55 80 19 15 21 5 0 0 0 0 0 0
  97056. +0 0 0 0 0 0 0 0 0
  97057. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97058. +29 42 10 101 146 34 118 171 40 117 169 40 117 169 40 117 169 40
  97059. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 113 163 39
  97060. +75 109 26 27 40 9 36 52 12 89 128 30 116 167 40 118 171 40
  97061. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 104 150 35
  97062. +16 23 5 0 0 0 0 0 0 53 76 18 118 171 40 117 169 40
  97063. +117 169 40 117 169 40 117 169 40 117 169 40 119 171 41 109 157 37
  97064. +67 96 23 23 34 8 42 61 14 96 138 32 118 170 40 118 170 40
  97065. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97066. +117 169 40 117 169 40 74 107 25 10 15 3 0 0 0 0 0 0
  97067. +0 0 0 0 0 0 0 0 0
  97068. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97069. +0 0 0 31 45 11 101 146 34 118 170 40 117 169 40 117 169 40
  97070. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97071. +119 171 41 102 148 35 47 69 16 14 20 5 50 72 17 102 148 35
  97072. +118 171 40 117 169 40 117 169 40 117 169 40 118 170 40 102 148 35
  97073. +15 21 5 0 0 0 0 0 0 50 72 17 118 170 40 117 169 40
  97074. +117 169 40 117 169 40 118 170 40 116 167 40 84 121 28 27 40 9
  97075. +19 27 6 74 107 25 114 165 39 118 171 40 117 169 40 117 169 40
  97076. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97077. +117 169 40 75 109 26 10 15 4 0 0 0 0 0 0 0 0 0
  97078. +0 0 0 0 0 0 0 0 0
  97079. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97080. +0 0 0 38 55 13 102 148 35 118 171 40 117 169 40 117 169 40
  97081. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97082. +117 169 40 118 170 40 115 167 39 77 111 26 17 25 6 19 27 6
  97083. +77 111 26 115 166 39 118 170 40 117 169 40 119 172 41 81 118 28
  97084. +3 4 1 0 0 0 0 0 0 27 40 9 111 160 38 118 170 40
  97085. +117 169 40 118 171 40 105 151 36 50 72 17 10 15 3 38 55 13
  97086. +100 144 34 118 171 40 117 169 40 117 169 40 117 169 40 117 169 40
  97087. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97088. +117 169 40 79 115 27 15 21 5 0 0 0 0 0 0 0 0 0
  97089. +0 0 0 0 0 0 0 0 0
  97090. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97091. +0 0 0 10 15 3 64 92 22 111 160 38 117 169 40 117 169 40
  97092. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97093. +117 169 40 117 169 40 117 169 40 118 171 40 96 138 32 32 47 11
  97094. +3 4 1 50 72 17 107 154 36 120 173 41 105 151 36 31 45 11
  97095. +0 0 0 0 0 0 0 0 0 3 4 1 65 94 22 117 169 40
  97096. +118 170 40 89 128 30 26 37 9 3 4 1 60 86 20 111 161 38
  97097. +118 171 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97098. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97099. +97 141 33 36 52 12 1 1 0 0 0 0 0 0 0 0 0 0
  97100. +0 0 0 0 0 0 0 0 0
  97101. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97102. +0 0 0 0 0 0 14 20 5 75 109 26 117 168 40 117 169 40
  97103. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97104. +117 169 40 117 169 40 117 169 40 117 169 40 118 171 40 107 154 36
  97105. +45 64 15 2 3 1 31 45 11 75 109 26 32 47 11 0 1 0
  97106. +0 0 0 0 0 0 0 0 0 0 0 0 10 15 3 55 80 19
  97107. +65 94 22 11 16 4 11 16 4 75 109 26 116 168 40 118 170 40
  97108. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97109. +117 169 40 117 169 40 117 169 40 117 169 40 118 170 40 107 154 36
  97110. +47 69 16 3 4 1 0 0 0 0 0 0 0 0 0 0 0 0
  97111. +0 0 0 0 0 0 0 0 0
  97112. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97113. +0 0 0 0 0 0 12 18 4 69 100 23 111 161 38 118 171 40
  97114. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97115. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 118 170 40
  97116. +111 160 38 50 72 17 2 3 1 2 3 1 0 0 0 0 0 0
  97117. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0
  97118. +1 1 0 12 18 4 81 118 28 118 170 40 117 169 40 117 169 40
  97119. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97120. +117 169 40 117 169 40 117 169 40 117 170 40 118 171 40 101 146 34
  97121. +42 61 14 2 3 1 0 0 0 0 0 0 0 0 0 0 0 0
  97122. +0 0 0 0 0 0 0 0 0
  97123. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97124. +0 0 0 0 0 0 0 0 0 3 4 1 36 52 12 89 128 30
  97125. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97126. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97127. +118 171 41 101 146 34 14 20 5 0 0 0 0 0 0 0 0 0
  97128. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97129. +0 0 0 47 69 16 118 170 40 117 169 40 117 169 40 117 169 40
  97130. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97131. +117 169 40 117 169 40 117 170 40 111 160 38 69 100 23 19 27 6
  97132. +0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97133. +0 0 0 0 0 0 0 0 0
  97134. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97135. +0 0 0 0 0 0 0 0 0 0 0 0 11 16 4 69 100 23
  97136. +115 167 39 119 172 41 117 169 40 117 169 40 117 169 40 117 169 40
  97137. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97138. +119 172 41 75 109 26 3 4 1 0 0 0 0 0 0 0 0 0
  97139. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97140. +0 0 0 23 34 8 106 153 36 118 170 40 117 169 40 117 169 40
  97141. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97142. +117 169 40 118 170 40 119 172 41 105 151 36 42 61 14 2 3 1
  97143. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97144. +0 0 0 0 0 0 0 0 0
  97145. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97146. +0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 15 21 5
  97147. +45 64 15 80 116 27 114 165 39 118 170 40 117 169 40 117 169 40
  97148. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 119 172 41
  97149. +97 141 33 20 30 7 0 0 0 0 0 0 0 0 0 0 0 0
  97150. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97151. +0 0 0 1 1 0 53 76 18 114 165 39 118 171 40 117 169 40
  97152. +117 169 40 117 169 40 117 169 40 117 169 40 117 169 40 117 169 40
  97153. +118 171 40 104 150 35 64 92 22 31 45 11 10 15 3 0 0 0
  97154. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97155. +0 0 0 0 0 0 0 0 0
  97156. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97157. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97158. +0 0 0 36 52 12 97 141 33 109 158 37 113 163 39 116 168 40
  97159. +117 169 40 117 170 40 118 170 40 119 172 41 115 167 39 84 121 28
  97160. +23 34 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97161. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97162. +0 0 0 0 0 0 3 4 1 50 72 17 102 148 35 118 171 40
  97163. +119 171 41 118 170 40 117 169 40 117 169 40 115 166 39 111 161 38
  97164. +109 157 37 79 115 27 12 18 4 0 0 0 0 0 0 0 0 0
  97165. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97166. +0 0 0 0 0 0 0 0 0
  97167. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97168. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97169. +0 0 0 3 4 1 15 21 5 23 34 8 45 64 15 106 153 36
  97170. +116 167 40 111 160 38 101 146 34 79 115 27 42 61 14 10 15 3
  97171. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97172. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97173. +0 0 0 0 0 0 0 0 0 1 1 0 20 30 7 60 86 20
  97174. +89 128 30 106 153 36 113 163 39 117 169 40 84 121 28 29 42 10
  97175. +19 27 6 10 15 3 2 3 1 0 0 0 0 0 0 0 0 0
  97176. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97177. +0 0 0 0 0 0 0 0 0
  97178. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97179. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97180. +0 0 0 0 0 0 0 0 0 0 0 0 16 23 5 38 55 13
  97181. +36 52 12 26 37 9 12 18 4 2 3 1 0 0 0 0 0 0
  97182. +0 0 0 0 0 0 0 0 0 1 0 0 19 2 7 52 5 18
  97183. +78 7 27 88 8 31 81 7 29 56 5 19 25 2 9 3 0 1
  97184. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97185. +3 4 1 19 27 6 31 45 11 38 55 13 32 47 11 3 4 1
  97186. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97187. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97188. +0 0 0 0 0 0 0 0 0
  97189. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97190. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97191. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  97192. +9 0 3 12 1 4 9 0 3 4 0 1 0 0 0 0 0 0
  97193. +0 0 0 0 0 0 28 3 10 99 9 35 156 14 55 182 16 64
  97194. +189 17 66 190 17 67 189 17 66 184 17 65 166 15 58 118 13 41
  97195. +45 4 16 3 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  97196. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97197. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97198. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97199. +0 0 0 0 0 0 0 0 0
  97200. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97201. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97202. +0 0 0 0 0 0 11 1 4 52 5 18 101 9 35 134 12 47
  97203. +151 14 53 154 14 54 151 14 53 113 10 40 11 1 4 0 0 0
  97204. +3 0 1 67 6 24 159 14 56 190 17 67 190 17 67 188 17 66
  97205. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 191 17 67
  97206. +174 16 61 101 9 35 14 1 5 0 0 0 35 3 12 108 10 38
  97207. +122 11 43 122 11 43 112 10 39 87 8 30 50 5 17 13 1 5
  97208. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97209. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97210. +0 0 0 0 0 0 0 0 0
  97211. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97212. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97213. +3 0 1 56 5 19 141 13 49 182 16 64 191 17 67 191 17 67
  97214. +190 17 67 190 17 67 191 17 67 113 10 40 3 0 1 1 0 0
  97215. +79 7 28 180 16 63 190 17 67 188 17 66 188 17 66 188 17 66
  97216. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97217. +189 17 66 188 17 66 122 11 43 11 1 4 41 4 14 176 16 62
  97218. +191 17 67 191 17 67 191 17 67 190 17 67 181 16 63 146 13 51
  97219. +75 7 26 10 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97220. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97221. +0 0 0 0 0 0 0 0 0
  97222. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97223. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 1 2
  97224. +90 8 32 178 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  97225. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 41 4 14
  97226. +173 16 61 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97227. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97228. +188 17 66 188 17 66 188 17 66 88 8 31 1 0 0 89 8 31
  97229. +185 17 65 189 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  97230. +186 17 65 124 11 43 25 2 9 0 0 0 0 0 0 0 0 0
  97231. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97232. +0 0 0 0 0 0 0 0 0
  97233. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97234. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 89 8 31
  97235. +184 17 65 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97236. +190 17 67 151 14 53 34 3 12 0 0 0 0 0 0 79 7 28
  97237. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97238. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97239. +188 17 66 188 17 66 191 17 67 146 13 51 9 1 3 7 1 2
  97240. +108 10 38 187 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  97241. +188 17 66 190 17 67 141 13 49 22 2 8 0 0 0 0 0 0
  97242. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97243. +0 0 0 0 0 0 0 0 0
  97244. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97245. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 176 16 62
  97246. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97247. +151 14 53 38 3 13 0 0 0 0 0 0 0 0 0 50 5 17
  97248. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97249. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97250. +188 17 66 188 17 66 191 17 67 141 13 49 7 1 3 0 0 0
  97251. +11 1 4 112 10 39 187 17 66 189 17 66 188 17 66 188 17 66
  97252. +188 17 66 188 17 66 190 17 67 113 10 40 5 0 2 0 0 0
  97253. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97254. +0 0 0 0 0 0 0 0 0
  97255. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97256. +0 0 0 0 0 0 0 0 0 7 1 3 132 12 46 191 17 67
  97257. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 146 13 51
  97258. +35 3 12 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97259. +101 9 35 185 17 65 190 17 67 188 17 66 188 17 66 188 17 66
  97260. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97261. +188 17 66 190 17 67 180 16 63 67 6 24 0 0 0 0 0 0
  97262. +0 0 0 11 1 4 108 10 38 186 17 65 189 17 66 188 17 66
  97263. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  97264. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97265. +0 0 0 0 0 0 0 0 0
  97266. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97267. +0 0 0 0 0 0 0 0 0 44 4 15 177 16 62 189 17 66
  97268. +188 17 66 188 17 66 189 17 66 189 17 66 134 12 47 28 3 10
  97269. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97270. +8 1 3 79 7 28 159 14 56 188 17 66 191 17 67 190 17 67
  97271. +189 17 66 189 17 66 189 17 66 189 17 66 190 17 67 191 17 67
  97272. +188 17 66 158 14 55 72 7 25 4 0 1 0 0 0 0 0 0
  97273. +0 0 0 0 0 0 8 1 3 95 9 33 182 16 64 189 17 67
  97274. +188 17 66 188 17 66 188 17 66 191 17 67 122 11 43 3 0 1
  97275. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97276. +0 0 0 0 0 0 0 0 0
  97277. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97278. +0 0 0 0 0 0 0 0 0 88 8 31 190 17 67 188 17 66
  97279. +188 17 66 189 17 66 185 17 65 113 10 40 18 2 6 0 0 0
  97280. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97281. +0 0 0 1 0 0 24 2 8 77 7 27 124 11 43 154 14 54
  97282. +168 15 59 173 16 61 173 16 61 168 15 59 154 14 54 124 11 43
  97283. +77 7 27 22 2 8 0 0 0 0 0 0 0 0 0 0 0 0
  97284. +0 0 0 0 0 0 0 0 0 5 0 2 77 7 27 173 16 61
  97285. +190 17 67 188 17 66 188 17 66 190 17 67 164 15 57 23 2 8
  97286. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97287. +0 0 0 0 0 0 0 0 0
  97288. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97289. +0 0 0 0 0 0 1 0 0 118 13 41 191 17 67 188 17 66
  97290. +190 17 67 174 16 61 87 8 30 8 1 3 0 0 0 0 0 0
  97291. +0 0 0 0 0 0 10 1 4 29 3 10 40 4 14 36 3 13
  97292. +18 2 6 2 0 1 0 0 0 0 0 0 3 0 1 14 1 5
  97293. +26 2 9 33 3 11 32 3 11 25 2 9 13 1 5 3 0 1
  97294. +0 0 0 14 1 5 56 5 19 95 9 33 109 10 38 101 9 35
  97295. +77 7 27 35 3 12 5 0 2 0 0 0 1 0 0 56 5 19
  97296. +156 14 55 190 17 67 188 17 66 188 17 66 182 16 64 50 5 17
  97297. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97298. +0 0 0 0 0 0 0 0 0
  97299. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97300. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 189 17 66
  97301. +151 14 53 52 5 18 2 0 1 0 0 0 0 0 0 1 0 0
  97302. +28 3 10 90 8 32 146 13 51 170 15 60 178 16 62 174 16 61
  97303. +158 14 55 112 10 39 40 4 14 1 0 0 0 0 0 0 0 0
  97304. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 0 1
  97305. +56 5 19 146 13 51 183 17 64 191 17 67 191 17 67 191 17 67
  97306. +188 17 66 173 16 61 122 11 43 41 4 14 1 0 0 0 0 0
  97307. +30 3 10 124 11 43 185 17 65 190 17 67 187 17 66 67 6 24
  97308. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97309. +0 0 0 0 0 0 0 0 0
  97310. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97311. +0 0 0 0 0 0 6 1 2 134 12 47 168 15 59 99 9 35
  97312. +21 2 7 0 0 0 0 0 0 0 0 0 6 1 2 77 7 27
  97313. +162 15 57 190 17 67 191 17 67 189 17 66 189 17 66 189 17 66
  97314. +190 17 67 191 17 67 169 15 59 75 7 26 3 0 1 0 0 0
  97315. +0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 79 7 28
  97316. +178 16 62 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97317. +188 17 66 189 17 66 191 17 67 170 15 60 79 7 28 5 0 2
  97318. +0 0 0 10 1 3 78 7 27 159 14 56 188 17 66 75 7 26
  97319. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97320. +0 0 0 0 0 0 0 0 0
  97321. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97322. +0 0 0 0 0 0 1 0 0 35 3 12 29 3 10 2 0 1
  97323. +0 0 0 0 0 0 0 0 0 9 1 3 101 9 35 183 17 64
  97324. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97325. +188 17 66 188 17 66 190 17 67 178 16 63 67 6 23 0 0 0
  97326. +0 0 0 0 0 0 0 0 0 0 0 0 52 5 18 174 16 61
  97327. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97328. +188 17 66 188 17 66 188 17 66 190 17 67 182 16 64 89 8 31
  97329. +4 0 1 0 0 0 0 0 0 25 2 9 73 7 26 31 3 11
  97330. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97331. +0 0 0 0 0 0 0 0 0
  97332. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97333. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97334. +0 0 0 0 0 0 4 0 1 98 9 34 187 17 66 189 17 66
  97335. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97336. +188 17 66 188 17 66 188 17 66 190 17 67 158 14 55 25 2 9
  97337. +0 0 0 0 0 0 0 0 0 8 1 3 134 12 47 191 17 67
  97338. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97339. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 180 16 63
  97340. +68 6 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97341. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97342. +0 0 0 0 0 0 0 0 0
  97343. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97344. +0 0 0 6 1 2 19 2 7 3 0 1 0 0 0 0 0 0
  97345. +0 0 0 0 0 0 65 6 23 180 16 63 189 17 66 188 17 66
  97346. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97347. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 83 8 29
  97348. +0 0 0 0 0 0 0 0 0 41 4 14 177 16 62 189 17 66
  97349. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97350. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97351. +159 14 56 28 3 10 0 0 0 0 0 0 0 0 0 23 2 8
  97352. +41 4 14 5 0 2 0 0 0 0 0 0 0 0 0 0 0 0
  97353. +0 0 0 0 0 0 0 0 0
  97354. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97355. +23 2 8 113 10 40 159 14 56 65 6 23 0 0 0 0 0 0
  97356. +0 0 0 16 1 6 146 13 51 191 17 67 188 17 66 188 17 66
  97357. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97358. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 132 12 46
  97359. +5 0 2 0 0 0 0 0 0 77 7 27 189 17 66 188 17 66
  97360. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97361. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97362. +190 17 67 98 9 34 0 0 0 0 0 0 12 1 4 134 12 47
  97363. +178 16 63 108 10 38 16 1 6 0 0 0 0 0 0 0 0 0
  97364. +0 0 0 0 0 0 0 0 0
  97365. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 30 3 10
  97366. +141 13 49 190 17 67 191 17 67 134 12 47 6 1 2 0 0 0
  97367. +0 0 0 68 6 24 186 17 65 188 17 66 188 17 66 188 17 66
  97368. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97369. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 156 14 55
  97370. +14 1 5 0 0 0 0 0 0 98 9 34 191 17 67 188 17 66
  97371. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97372. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97373. +190 17 67 156 14 55 19 2 7 0 0 0 47 4 16 181 16 63
  97374. +190 17 67 189 17 66 126 14 44 17 2 6 0 0 0 0 0 0
  97375. +0 0 0 0 0 0 0 0 0
  97376. +0 0 0 0 0 0 0 0 0 0 0 0 16 1 6 134 12 47
  97377. +191 17 67 188 17 66 190 17 67 162 15 57 19 2 7 0 0 0
  97378. +3 0 1 123 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  97379. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97380. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 163 15 57
  97381. +20 2 7 0 0 0 0 0 0 101 9 35 191 17 67 188 17 66
  97382. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97383. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97384. +188 17 66 182 16 64 52 5 18 0 0 0 73 7 26 188 17 66
  97385. +188 17 66 188 17 66 189 17 66 109 10 38 5 0 2 0 0 0
  97386. +0 0 0 0 0 0 0 0 0
  97387. +0 0 0 0 0 0 0 0 0 0 0 0 95 9 33 189 17 66
  97388. +188 17 66 188 17 66 189 17 66 171 15 60 29 3 10 0 0 0
  97389. +16 1 6 156 14 55 190 17 67 188 17 66 188 17 66 188 17 66
  97390. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97391. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 158 14 55
  97392. +17 2 6 0 0 0 0 0 0 85 8 30 190 17 67 188 17 66
  97393. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97394. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97395. +188 17 66 189 17 66 81 7 29 0 0 0 85 8 30 190 17 67
  97396. +188 17 66 188 17 66 189 17 66 180 16 63 56 5 19 0 0 0
  97397. +0 0 0 0 0 0 0 0 0
  97398. +0 0 0 0 0 0 0 0 0 25 2 9 162 15 57 190 17 67
  97399. +188 17 66 188 17 66 189 17 66 173 16 61 31 3 11 0 0 0
  97400. +30 3 10 171 15 60 189 17 66 188 17 66 188 17 66 188 17 66
  97401. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97402. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 141 13 49
  97403. +7 1 2 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  97404. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97405. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97406. +188 17 66 191 17 67 98 9 34 0 0 0 88 8 31 190 17 67
  97407. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 5 0 2
  97408. +0 0 0 0 0 0 0 0 0
  97409. +0 0 0 0 0 0 0 0 0 68 6 24 187 17 66 188 17 66
  97410. +188 17 66 188 17 66 189 17 66 170 15 60 28 3 10 0 0 0
  97411. +34 3 12 174 16 61 189 17 66 188 17 66 188 17 66 188 17 66
  97412. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97413. +188 17 66 188 17 66 188 17 66 188 17 66 191 17 67 101 9 35
  97414. +0 0 0 0 0 0 0 0 0 21 2 7 159 14 56 190 17 67
  97415. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97416. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97417. +188 17 66 191 17 67 98 9 34 0 0 0 81 7 29 189 17 66
  97418. +188 17 66 188 17 66 188 17 66 189 17 66 168 15 59 28 3 10
  97419. +0 0 0 0 0 0 0 0 0
  97420. +0 0 0 0 0 0 0 0 0 109 10 38 191 17 67 188 17 66
  97421. +188 17 66 188 17 66 190 17 67 163 15 57 21 2 7 0 0 0
  97422. +26 2 9 168 15 59 189 17 66 188 17 66 188 17 66 188 17 66
  97423. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97424. +188 17 66 188 17 66 188 17 66 189 17 66 180 16 63 47 4 16
  97425. +0 0 0 0 0 0 0 0 0 0 0 0 108 10 38 190 17 67
  97426. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97427. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97428. +188 17 66 189 17 66 78 7 27 0 0 0 68 6 24 187 17 66
  97429. +188 17 66 188 17 66 188 17 66 188 17 66 183 17 64 56 5 19
  97430. +0 0 0 0 0 0 0 0 0
  97431. +0 0 0 0 0 0 3 0 1 131 12 46 191 17 67 188 17 66
  97432. +188 17 66 188 17 66 190 17 67 151 14 53 12 1 4 0 0 0
  97433. +11 1 4 146 13 51 190 17 67 188 17 66 188 17 66 188 17 66
  97434. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97435. +188 17 66 188 17 66 188 17 66 191 17 67 126 14 44 7 1 2
  97436. +0 0 0 0 0 0 0 0 0 0 0 0 32 3 11 164 15 58
  97437. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97438. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97439. +189 17 66 178 16 62 44 4 15 0 0 0 50 5 17 182 16 64
  97440. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  97441. +0 0 0 0 0 0 0 0 0
  97442. +0 0 0 0 0 0 5 0 2 134 12 47 191 17 67 188 17 66
  97443. +188 17 66 188 17 66 191 17 67 131 12 46 3 0 1 0 0 0
  97444. +0 0 0 101 9 35 190 17 67 188 17 66 188 17 66 188 17 66
  97445. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97446. +188 17 66 188 17 66 190 17 67 170 15 60 44 4 15 0 0 0
  97447. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 77 7 27
  97448. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97449. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97450. +191 17 67 134 12 47 9 1 3 0 0 0 31 3 11 171 15 60
  97451. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 72 7 25
  97452. +0 0 0 0 0 0 0 0 0
  97453. +0 0 0 0 0 0 2 0 1 124 11 43 191 17 67 188 17 66
  97454. +188 17 66 188 17 66 191 17 67 101 9 35 0 0 0 0 0 0
  97455. +0 0 0 35 3 12 168 15 59 190 17 67 188 17 66 188 17 66
  97456. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97457. +188 17 66 189 17 66 182 16 64 77 7 27 0 0 0 0 0 0
  97458. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 1 2
  97459. +99 9 35 185 17 65 189 17 66 188 17 66 188 17 66 188 17 66
  97460. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97461. +177 16 62 56 5 19 0 0 0 0 0 0 13 1 5 151 14 53
  97462. +190 17 67 188 17 66 188 17 66 188 17 66 185 17 65 56 5 19
  97463. +0 0 0 0 0 0 0 0 0
  97464. +0 0 0 0 0 0 0 0 0 99 9 35 191 17 67 188 17 66
  97465. +188 17 66 188 17 66 186 17 65 65 6 23 0 0 0 0 0 0
  97466. +0 0 0 0 0 0 79 7 28 182 16 64 190 17 67 188 17 66
  97467. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97468. +191 17 67 177 16 62 83 8 29 4 0 1 0 0 0 0 0 0
  97469. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97470. +8 1 3 89 8 31 175 16 62 191 17 67 189 17 66 188 17 66
  97471. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 181 16 63
  97472. +85 8 30 3 0 1 0 0 0 0 0 0 1 0 0 118 13 41
  97473. +191 17 67 188 17 66 188 17 66 189 17 66 173 16 61 34 3 12
  97474. +0 0 0 0 0 0 0 0 0
  97475. +0 0 0 0 0 0 0 0 0 56 5 19 183 17 64 188 17 66
  97476. +188 17 66 189 17 66 169 15 59 30 3 10 0 0 0 0 0 0
  97477. +0 0 0 0 0 0 5 0 2 83 8 29 173 16 61 191 17 67
  97478. +190 17 67 189 17 66 189 17 66 190 17 67 191 17 67 187 17 66
  97479. +151 14 53 56 5 19 3 0 1 0 0 0 16 1 6 50 5 17
  97480. +79 7 28 95 9 33 95 9 33 75 7 26 41 4 14 10 1 4
  97481. +0 0 0 2 0 1 50 5 17 132 12 46 178 16 62 190 17 67
  97482. +191 17 67 191 17 67 191 17 67 186 17 65 154 14 54 68 6 24
  97483. +4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  97484. +187 17 66 188 17 66 188 17 66 191 17 67 141 13 49 9 1 3
  97485. +0 0 0 0 0 0 0 0 0
  97486. +0 0 0 0 0 0 0 0 0 14 1 5 151 14 53 190 17 67
  97487. +188 17 66 191 17 67 131 12 46 5 0 2 0 0 0 0 0 0
  97488. +0 0 0 0 0 0 0 0 0 2 0 1 44 4 15 113 10 40
  97489. +156 14 55 173 16 61 174 16 61 164 15 58 134 12 47 77 7 27
  97490. +18 2 6 0 0 0 16 1 6 85 8 30 151 14 53 182 16 64
  97491. +189 17 66 191 17 67 190 17 67 188 17 66 177 16 62 141 13 49
  97492. +68 6 24 8 1 3 0 0 0 8 1 3 44 4 15 88 8 31
  97493. +113 10 40 122 11 43 108 10 38 67 6 24 20 2 7 0 0 0
  97494. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 28 3 10
  97495. +166 15 58 190 17 67 188 17 66 187 17 66 79 7 28 0 0 0
  97496. +0 0 0 0 0 0 0 0 0
  97497. +0 0 0 0 0 0 0 0 0 0 0 0 73 7 26 185 17 65
  97498. +189 17 66 184 17 65 65 6 23 0 0 0 0 0 0 0 0 0
  97499. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1
  97500. +17 2 6 32 3 11 34 3 12 22 2 8 6 1 2 0 0 0
  97501. +0 0 0 38 3 13 141 13 49 188 17 66 190 17 67 188 17 66
  97502. +188 17 66 188 17 66 188 17 66 188 17 66 189 17 66 191 17 67
  97503. +184 17 65 122 11 43 21 2 7 0 0 0 0 0 0 0 0 0
  97504. +0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97505. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  97506. +108 10 38 191 17 67 191 17 67 141 13 49 16 1 6 0 0 0
  97507. +0 0 0 0 0 0 0 0 0
  97508. +0 0 0 0 0 0 0 0 0 0 0 0 8 1 3 112 10 39
  97509. +186 17 65 124 11 43 10 1 4 0 0 0 0 0 0 0 0 0
  97510. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97511. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97512. +36 3 13 156 14 55 191 17 67 188 17 66 188 17 66 188 17 66
  97513. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97514. +189 17 66 190 17 67 134 12 47 18 2 6 0 0 0 0 0 0
  97515. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97516. +0 0 0 7 1 2 41 4 14 75 7 26 66 5 23 19 2 7
  97517. +26 2 9 144 13 50 154 14 54 40 4 14 0 0 0 0 0 0
  97518. +0 0 0 0 0 0 0 0 0
  97519. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  97520. +56 5 19 19 2 7 0 0 0 7 1 2 29 3 10 35 3 12
  97521. +19 2 7 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0
  97522. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 13 1 5
  97523. +134 12 47 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97524. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97525. +188 17 66 188 17 66 189 17 67 108 10 38 3 0 1 0 0 0
  97526. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  97527. +40 4 14 124 11 43 177 16 62 188 17 66 187 17 66 144 13 50
  97528. +24 2 8 17 2 6 22 2 8 0 0 0 0 0 0 0 0 0
  97529. +0 0 0 0 0 0 0 0 0
  97530. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97531. +0 0 0 0 0 0 19 2 7 122 11 43 171 15 60 175 16 62
  97532. +159 14 56 112 10 39 40 4 14 2 0 1 0 0 0 0 0 0
  97533. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 72 7 25
  97534. +186 17 65 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97535. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97536. +188 17 66 188 17 66 189 17 66 174 16 61 41 4 14 0 0 0
  97537. +0 0 0 0 0 0 0 0 0 0 0 0 3 0 1 72 7 25
  97538. +168 15 59 191 17 67 189 17 66 188 17 66 188 17 66 190 17 67
  97539. +95 9 33 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97540. +0 0 0 0 0 0 0 0 0
  97541. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97542. +0 0 0 0 0 0 95 9 33 191 17 67 189 17 66 189 17 66
  97543. +190 17 67 191 17 67 171 15 60 90 8 32 12 1 4 0 0 0
  97544. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 132 12 46
  97545. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97546. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97547. +188 17 66 188 17 66 188 17 66 190 17 67 98 9 34 0 0 0
  97548. +0 0 0 0 0 0 0 0 0 5 0 2 88 8 31 180 16 63
  97549. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 191 17 67
  97550. +146 13 51 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97551. +0 0 0 0 0 0 0 0 0
  97552. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97553. +0 0 0 9 1 3 144 13 50 191 17 67 188 17 66 188 17 66
  97554. +188 17 66 188 17 66 189 17 66 187 17 66 123 11 43 20 2 7
  97555. +0 0 0 0 0 0 0 0 0 0 0 0 21 2 7 163 15 57
  97556. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97557. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97558. +188 17 66 188 17 66 188 17 66 191 17 67 134 12 47 5 0 2
  97559. +0 0 0 0 0 0 3 0 1 88 8 31 182 16 64 189 17 66
  97560. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97561. +171 15 60 31 3 11 0 0 0 0 0 0 0 0 0 0 0 0
  97562. +0 0 0 0 0 0 0 0 0
  97563. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97564. +0 0 0 20 2 7 162 15 57 190 17 67 188 17 66 188 17 66
  97565. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 132 12 46
  97566. +20 2 7 0 0 0 0 0 0 0 0 0 32 3 11 173 16 61
  97567. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97568. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97569. +188 17 66 188 17 66 188 17 66 190 17 67 151 14 53 12 1 4
  97570. +0 0 0 0 0 0 72 7 25 180 16 63 189 17 66 188 17 66
  97571. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97572. +181 16 63 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  97573. +0 0 0 0 0 0 0 0 0
  97574. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97575. +0 0 0 21 2 7 163 15 57 190 17 67 188 17 66 188 17 66
  97576. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97577. +122 11 43 9 1 3 0 0 0 0 0 0 30 3 10 171 15 60
  97578. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97579. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97580. +188 17 66 188 17 66 188 17 66 190 17 67 146 13 51 10 1 4
  97581. +0 0 0 38 3 13 166 15 58 190 17 67 188 17 66 188 17 66
  97582. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97583. +183 17 64 52 5 18 0 0 0 0 0 0 0 0 0 0 0 0
  97584. +0 0 0 0 0 0 0 0 0
  97585. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97586. +0 0 0 13 1 5 154 14 54 190 17 67 188 17 66 188 17 66
  97587. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97588. +186 17 65 79 7 28 0 0 0 0 0 0 14 1 5 156 14 54
  97589. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97590. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97591. +188 17 66 188 17 66 188 17 66 191 17 67 124 11 43 2 0 1
  97592. +5 0 2 122 11 43 191 17 67 188 17 66 188 17 66 188 17 66
  97593. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97594. +182 16 64 47 4 16 0 0 0 0 0 0 0 0 0 0 0 0
  97595. +0 0 0 0 0 0 0 0 0
  97596. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97597. +0 0 0 3 0 1 126 14 44 191 17 67 188 17 66 188 17 66
  97598. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97599. +190 17 67 158 14 55 23 2 8 0 0 0 1 0 0 113 10 40
  97600. +191 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97601. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97602. +188 17 66 188 17 66 188 17 66 188 17 66 78 7 27 0 0 0
  97603. +47 4 16 177 16 62 189 17 66 188 17 66 188 17 66 188 17 66
  97604. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 189 17 66
  97605. +173 16 61 34 3 12 0 0 0 0 0 0 0 0 0 0 0 0
  97606. +0 0 0 0 0 0 0 0 0
  97607. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97608. +0 0 0 0 0 0 85 8 30 189 17 66 188 17 66 188 17 66
  97609. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97610. +188 17 66 188 17 66 79 7 28 0 0 0 0 0 0 47 4 16
  97611. +175 16 62 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97612. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97613. +188 17 66 188 17 66 190 17 67 156 14 55 22 2 8 0 0 0
  97614. +109 10 38 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97615. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97616. +151 14 53 13 1 5 0 0 0 0 0 0 0 0 0 0 0 0
  97617. +0 0 0 0 0 0 0 0 0
  97618. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97619. +0 0 0 0 0 0 35 3 12 173 16 61 189 17 66 188 17 66
  97620. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97621. +188 17 66 191 17 67 134 12 47 7 1 2 0 0 0 3 0 1
  97622. +99 9 35 188 17 66 189 17 66 188 17 66 188 17 66 188 17 66
  97623. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97624. +188 17 66 189 17 66 181 16 63 68 6 24 0 0 0 18 2 6
  97625. +156 14 55 190 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97626. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 190 17 67
  97627. +101 9 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97628. +0 0 0 0 0 0 0 0 0
  97629. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97630. +0 0 0 0 0 0 3 0 1 118 13 41 191 17 67 188 17 66
  97631. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97632. +188 17 66 189 17 66 168 15 59 28 3 10 0 0 0 0 0 0
  97633. +12 1 4 113 10 40 187 17 66 189 17 67 188 17 66 188 17 66
  97634. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97635. +190 17 67 180 16 63 88 8 31 4 0 1 0 0 0 47 4 16
  97636. +180 16 63 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97637. +188 17 66 188 17 66 188 17 66 188 17 66 190 17 67 168 15 59
  97638. +36 3 13 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97639. +0 0 0 0 0 0 0 0 0
  97640. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97641. +0 0 0 0 0 0 0 0 0 38 3 13 164 15 58 190 17 67
  97642. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97643. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  97644. +0 0 0 11 1 4 90 8 32 169 15 59 190 17 67 190 17 67
  97645. +189 17 66 189 17 66 189 17 66 189 17 66 191 17 67 189 17 66
  97646. +158 14 55 68 6 24 4 0 1 0 0 0 0 0 0 73 7 26
  97647. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97648. +188 17 66 188 17 66 188 17 66 189 17 66 185 17 65 83 8 29
  97649. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97650. +0 0 0 0 0 0 0 0 0
  97651. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97652. +0 0 0 0 0 0 0 0 0 0 0 0 65 6 23 174 16 61
  97653. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97654. +188 17 66 188 17 66 185 17 65 56 5 19 0 0 0 0 0 0
  97655. +0 0 0 0 0 0 2 0 1 35 3 12 99 9 35 146 13 51
  97656. +170 15 60 177 16 62 177 16 62 166 15 58 141 13 49 85 8 30
  97657. +24 2 8 0 0 0 0 0 0 0 0 0 0 0 0 85 8 30
  97658. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97659. +188 17 66 188 17 66 188 17 66 189 17 66 112 10 39 8 1 3
  97660. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97661. +0 0 0 0 0 0 0 0 0
  97662. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97663. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 68 6 24
  97664. +170 15 60 191 17 67 188 17 66 188 17 66 188 17 66 188 17 66
  97665. +188 17 66 188 17 66 182 16 64 50 5 17 0 0 0 0 0 0
  97666. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 11 1 4
  97667. +28 3 10 40 4 14 38 3 13 25 2 9 8 1 3 0 0 0
  97668. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 78 7 27
  97669. +189 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97670. +188 17 66 189 17 66 187 17 66 113 10 40 14 1 5 0 0 0
  97671. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97672. +0 0 0 0 0 0 0 0 0
  97673. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97674. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
  97675. +47 4 16 141 13 49 186 17 65 191 17 67 190 17 67 189 17 66
  97676. +189 17 66 191 17 67 156 14 55 20 2 7 0 0 0 0 0 0
  97677. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97678. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97679. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 44 4 15
  97680. +178 16 62 190 17 67 188 17 66 188 17 66 188 17 66 190 17 67
  97681. +191 17 67 173 16 61 90 8 32 10 1 4 0 0 0 0 0 0
  97682. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97683. +0 0 0 0 0 0 0 0 0
  97684. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97685. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97686. +0 0 0 14 1 5 68 6 24 131 12 46 162 15 57 174 16 61
  97687. +171 15 60 146 13 51 56 5 19 0 0 0 0 0 0 0 0 0
  97688. +0 0 0 0 0 0 0 0 0 3 0 1 14 1 5 29 3 10
  97689. +41 4 14 47 4 16 50 5 17 45 4 16 34 3 12 18 2 6
  97690. +5 0 2 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97691. +90 8 32 169 15 59 185 17 65 187 17 66 182 16 64 163 15 57
  97692. +113 10 40 41 4 14 2 0 1 0 0 0 0 0 0 0 0 0
  97693. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97694. +0 0 0 0 0 0 0 0 0
  97695. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97696. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97697. +0 0 0 0 0 0 0 0 0 5 0 2 21 2 7 34 3 12
  97698. +29 3 10 11 1 4 0 0 0 0 0 0 0 0 0 0 0 0
  97699. +3 0 1 32 3 11 79 7 28 124 11 43 154 14 54 171 15 60
  97700. +180 16 63 182 16 64 182 16 64 180 16 63 174 16 61 159 14 56
  97701. +132 12 46 88 8 31 34 3 12 3 0 1 0 0 0 0 0 0
  97702. +3 0 1 29 3 10 56 5 19 65 6 23 50 5 17 23 2 8
  97703. +3 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97704. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97705. +0 0 0 0 0 0 0 0 0
  97706. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97707. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97708. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97709. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 25 2 9
  97710. +109 10 38 169 15 59 189 17 66 191 17 67 190 17 67 189 17 66
  97711. +189 17 66 188 17 66 188 17 66 188 17 66 189 17 66 190 17 67
  97712. +191 17 67 190 17 67 171 15 60 98 9 34 10 1 3 0 0 0
  97713. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97714. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97715. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97716. +0 0 0 0 0 0 0 0 0
  97717. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97718. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97719. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97720. +0 0 0 0 0 0 0 0 0 0 0 0 14 1 5 141 13 49
  97721. +191 17 67 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97722. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97723. +188 17 66 188 17 66 189 17 67 186 17 65 65 6 23 0 0 0
  97724. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97725. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97726. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97727. +0 0 0 0 0 0 0 0 0
  97728. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97729. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97730. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97731. +0 0 0 0 0 0 0 0 0 0 0 0 23 2 8 166 15 58
  97732. +190 17 67 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97733. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97734. +188 17 66 188 17 66 189 17 66 176 16 62 45 4 16 0 0 0
  97735. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97736. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97737. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97738. +0 0 0 0 0 0 0 0 0
  97739. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97740. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97741. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97742. +0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 83 8 29
  97743. +183 17 64 189 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97744. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97745. +188 17 66 189 17 66 185 17 65 95 9 33 3 0 1 0 0 0
  97746. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97747. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97748. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97749. +0 0 0 0 0 0 0 0 0
  97750. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97751. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97752. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97753. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 2
  97754. +85 8 30 176 16 62 191 17 67 188 17 66 188 17 66 188 17 66
  97755. +188 17 66 188 17 66 188 17 66 188 17 66 188 17 66 188 17 66
  97756. +191 17 67 180 16 63 95 9 33 7 1 3 0 0 0 0 0 0
  97757. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97758. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97759. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97760. +0 0 0 0 0 0 0 0 0
  97761. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97762. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97763. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97764. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97765. +2 0 1 52 5 18 141 13 49 185 17 65 191 17 67 189 17 67
  97766. +189 17 66 188 17 66 188 17 66 189 17 66 191 17 67 187 17 66
  97767. +146 13 51 56 5 19 4 0 1 0 0 0 0 0 0 0 0 0
  97768. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97769. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97770. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97771. +0 0 0 0 0 0 0 0 0
  97772. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97773. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97774. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97775. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97776. +0 0 0 0 0 0 14 1 5 68 6 24 131 12 46 166 15 58
  97777. +180 16 63 183 17 64 180 16 63 168 15 59 134 12 47 75 7 26
  97778. +17 2 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97779. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97780. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97781. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97782. +0 0 0 0 0 0 0 0 0
  97783. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97784. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97785. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97786. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97787. +0 0 0 0 0 0 0 0 0 0 0 0 5 0 2 24 2 8
  97788. +44 4 15 52 5 18 45 4 16 26 2 9 6 1 2 0 0 0
  97789. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97790. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97791. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97792. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97793. +0 0 0 0 0 0 0 0 0
  97794. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97795. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97796. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97797. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97798. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97799. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97800. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97801. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97802. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97803. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97804. +0 0 0 0 0 0 0 0 0
  97805. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97806. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97807. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97808. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97809. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97810. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97811. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97812. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97813. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97814. +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  97815. +0 0 0 0 0 0 0 0 0
  97816. diff -Nur linux-3.15/drivers/w1/masters/w1-gpio.c linux-rpi/drivers/w1/masters/w1-gpio.c
  97817. --- linux-3.15/drivers/w1/masters/w1-gpio.c 2014-06-08 20:19:54.000000000 +0200
  97818. +++ linux-rpi/drivers/w1/masters/w1-gpio.c 2014-06-11 21:05:32.000000000 +0200
  97819. @@ -23,6 +23,15 @@
  97820. #include "../w1.h"
  97821. #include "../w1_int.h"
  97822. +static int w1_gpio_pullup = -1;
  97823. +static int w1_gpio_pullup_orig = -1;
  97824. +module_param_named(pullup, w1_gpio_pullup, int, 0);
  97825. +MODULE_PARM_DESC(pullup, "GPIO pin pullup number");
  97826. +static int w1_gpio_pin = -1;
  97827. +static int w1_gpio_pin_orig = -1;
  97828. +module_param_named(gpiopin, w1_gpio_pin, int, 0);
  97829. +MODULE_PARM_DESC(gpiopin, "GPIO pin number");
  97830. +
  97831. static u8 w1_gpio_set_pullup(void *data, int delay)
  97832. {
  97833. struct w1_gpio_platform_data *pdata = data;
  97834. @@ -67,6 +76,16 @@
  97835. return gpio_get_value(pdata->pin) ? 1 : 0;
  97836. }
  97837. +static void w1_gpio_bitbang_pullup(void *data, u8 on)
  97838. +{
  97839. + struct w1_gpio_platform_data *pdata = data;
  97840. +
  97841. + if (on)
  97842. + gpio_direction_output(pdata->pin, 1);
  97843. + else
  97844. + gpio_direction_input(pdata->pin);
  97845. +}
  97846. +
  97847. #if defined(CONFIG_OF)
  97848. static struct of_device_id w1_gpio_dt_ids[] = {
  97849. { .compatible = "w1-gpio" },
  97850. @@ -113,13 +132,15 @@
  97851. static int w1_gpio_probe(struct platform_device *pdev)
  97852. {
  97853. struct w1_bus_master *master;
  97854. - struct w1_gpio_platform_data *pdata;
  97855. + struct w1_gpio_platform_data *pdata = pdev->dev.platform_data;
  97856. int err;
  97857. - if (of_have_populated_dt()) {
  97858. - err = w1_gpio_probe_dt(pdev);
  97859. - if (err < 0)
  97860. - return err;
  97861. + if(pdata == NULL) {
  97862. + if (of_have_populated_dt()) {
  97863. + err = w1_gpio_probe_dt(pdev);
  97864. + if (err < 0)
  97865. + return err;
  97866. + }
  97867. }
  97868. pdata = dev_get_platdata(&pdev->dev);
  97869. @@ -136,6 +157,19 @@
  97870. return -ENOMEM;
  97871. }
  97872. + w1_gpio_pin_orig = pdata->pin;
  97873. + w1_gpio_pullup_orig = pdata->ext_pullup_enable_pin;
  97874. +
  97875. + if(gpio_is_valid(w1_gpio_pin)) {
  97876. + pdata->pin = w1_gpio_pin;
  97877. + pdata->ext_pullup_enable_pin = -1;
  97878. + }
  97879. + if(gpio_is_valid(w1_gpio_pullup)) {
  97880. + pdata->ext_pullup_enable_pin = w1_gpio_pullup;
  97881. + }
  97882. +
  97883. + dev_info(&pdev->dev, "gpio pin %d, gpio pullup pin %d\n", pdata->pin, pdata->ext_pullup_enable_pin);
  97884. +
  97885. err = devm_gpio_request(&pdev->dev, pdata->pin, "w1");
  97886. if (err) {
  97887. dev_err(&pdev->dev, "gpio_request (pin) failed\n");
  97888. @@ -165,6 +199,14 @@
  97889. master->set_pullup = w1_gpio_set_pullup;
  97890. }
  97891. + if (gpio_is_valid(w1_gpio_pullup)) {
  97892. + if (pdata->is_open_drain)
  97893. + printk(KERN_ERR "w1-gpio 'pullup' option "
  97894. + "doesn't work with open drain GPIO\n");
  97895. + else
  97896. + master->bitbang_pullup = w1_gpio_bitbang_pullup;
  97897. + }
  97898. +
  97899. err = w1_add_master_device(master);
  97900. if (err) {
  97901. dev_err(&pdev->dev, "w1_add_master device failed\n");
  97902. @@ -195,6 +237,9 @@
  97903. w1_remove_master_device(master);
  97904. + pdata->pin = w1_gpio_pin_orig;
  97905. + pdata->ext_pullup_enable_pin = w1_gpio_pullup_orig;
  97906. +
  97907. return 0;
  97908. }
  97909. diff -Nur linux-3.15/drivers/w1/w1.h linux-rpi/drivers/w1/w1.h
  97910. --- linux-3.15/drivers/w1/w1.h 2014-06-08 20:19:54.000000000 +0200
  97911. +++ linux-rpi/drivers/w1/w1.h 2014-06-11 21:05:32.000000000 +0200
  97912. @@ -171,6 +171,12 @@
  97913. u8 (*set_pullup)(void *, int);
  97914. + /**
  97915. + * Turns the pullup on/off in bitbanging mode, takes an on/off argument.
  97916. + * @return -1=Error, 0=completed
  97917. + */
  97918. + void (*bitbang_pullup) (void *, u8);
  97919. +
  97920. void (*search)(void *, struct w1_master *,
  97921. u8, w1_slave_found_callback);
  97922. };
  97923. diff -Nur linux-3.15/drivers/w1/w1_int.c linux-rpi/drivers/w1/w1_int.c
  97924. --- linux-3.15/drivers/w1/w1_int.c 2014-06-08 20:19:54.000000000 +0200
  97925. +++ linux-rpi/drivers/w1/w1_int.c 2014-06-11 21:05:32.000000000 +0200
  97926. @@ -124,6 +124,20 @@
  97927. return(-EINVAL);
  97928. }
  97929. + /* bitbanging hardware uses bitbang_pullup, other hardware uses set_pullup
  97930. + * and takes care of timing itself */
  97931. + if (!master->write_byte && !master->touch_bit && master->set_pullup) {
  97932. + printk(KERN_ERR "w1_add_master_device: set_pullup requires "
  97933. + "write_byte or touch_bit, disabling\n");
  97934. + master->set_pullup = NULL;
  97935. + }
  97936. +
  97937. + if (master->set_pullup && master->bitbang_pullup) {
  97938. + printk(KERN_ERR "w1_add_master_device: set_pullup should not "
  97939. + "be set when bitbang_pullup is used, disabling\n");
  97940. + master->set_pullup = NULL;
  97941. + }
  97942. +
  97943. /* Lock until the device is added (or not) to w1_masters. */
  97944. mutex_lock(&w1_mlock);
  97945. /* Search for the first available id (starting at 1). */
  97946. diff -Nur linux-3.15/drivers/w1/w1_io.c linux-rpi/drivers/w1/w1_io.c
  97947. --- linux-3.15/drivers/w1/w1_io.c 2014-06-08 20:19:54.000000000 +0200
  97948. +++ linux-rpi/drivers/w1/w1_io.c 2014-06-11 21:05:32.000000000 +0200
  97949. @@ -134,10 +134,22 @@
  97950. static void w1_post_write(struct w1_master *dev)
  97951. {
  97952. if (dev->pullup_duration) {
  97953. - if (dev->enable_pullup && dev->bus_master->set_pullup)
  97954. - dev->bus_master->set_pullup(dev->bus_master->data, 0);
  97955. - else
  97956. + if (dev->enable_pullup) {
  97957. + if (dev->bus_master->set_pullup) {
  97958. + dev->bus_master->set_pullup(dev->
  97959. + bus_master->data,
  97960. + 0);
  97961. + } else if (dev->bus_master->bitbang_pullup) {
  97962. + dev->bus_master->
  97963. + bitbang_pullup(dev->bus_master->data, 1);
  97964. msleep(dev->pullup_duration);
  97965. + dev->bus_master->
  97966. + bitbang_pullup(dev->bus_master->data, 0);
  97967. + }
  97968. + } else {
  97969. + msleep(dev->pullup_duration);
  97970. + }
  97971. +
  97972. dev->pullup_duration = 0;
  97973. }
  97974. }
  97975. diff -Nur linux-3.15/drivers/watchdog/bcm2708_wdog.c linux-rpi/drivers/watchdog/bcm2708_wdog.c
  97976. --- linux-3.15/drivers/watchdog/bcm2708_wdog.c 1970-01-01 01:00:00.000000000 +0100
  97977. +++ linux-rpi/drivers/watchdog/bcm2708_wdog.c 2014-06-11 21:05:32.000000000 +0200
  97978. @@ -0,0 +1,382 @@
  97979. +/*
  97980. + * Broadcom BCM2708 watchdog driver.
  97981. + *
  97982. + * (c) Copyright 2010 Broadcom Europe Ltd
  97983. + *
  97984. + * This program is free software; you can redistribute it and/or
  97985. + * modify it under the terms of the GNU General Public License
  97986. + * as published by the Free Software Foundation; either version
  97987. + * 2 of the License, or (at your option) any later version.
  97988. + *
  97989. + * BCM2708 watchdog driver. Loosely based on wdt driver.
  97990. + */
  97991. +
  97992. +#include <linux/interrupt.h>
  97993. +#include <linux/module.h>
  97994. +#include <linux/moduleparam.h>
  97995. +#include <linux/types.h>
  97996. +#include <linux/miscdevice.h>
  97997. +#include <linux/watchdog.h>
  97998. +#include <linux/fs.h>
  97999. +#include <linux/ioport.h>
  98000. +#include <linux/notifier.h>
  98001. +#include <linux/reboot.h>
  98002. +#include <linux/init.h>
  98003. +#include <linux/io.h>
  98004. +#include <linux/uaccess.h>
  98005. +#include <mach/platform.h>
  98006. +
  98007. +#define SECS_TO_WDOG_TICKS(x) ((x) << 16)
  98008. +#define WDOG_TICKS_TO_SECS(x) ((x) >> 16)
  98009. +
  98010. +static unsigned long wdog_is_open;
  98011. +static uint32_t wdog_ticks; /* Ticks to load into wdog timer */
  98012. +static char expect_close;
  98013. +
  98014. +/*
  98015. + * Module parameters
  98016. + */
  98017. +
  98018. +#define WD_TIMO 10 /* Default heartbeat = 60 seconds */
  98019. +static int heartbeat = WD_TIMO; /* Heartbeat in seconds */
  98020. +
  98021. +module_param(heartbeat, int, 0);
  98022. +MODULE_PARM_DESC(heartbeat,
  98023. + "Watchdog heartbeat in seconds. (0 < heartbeat < 65536, default="
  98024. + __MODULE_STRING(WD_TIMO) ")");
  98025. +
  98026. +static int nowayout = WATCHDOG_NOWAYOUT;
  98027. +module_param(nowayout, int, 0);
  98028. +MODULE_PARM_DESC(nowayout,
  98029. + "Watchdog cannot be stopped once started (default="
  98030. + __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
  98031. +
  98032. +static DEFINE_SPINLOCK(wdog_lock);
  98033. +
  98034. +/**
  98035. + * Start the watchdog driver.
  98036. + */
  98037. +
  98038. +static int wdog_start(unsigned long timeout)
  98039. +{
  98040. + uint32_t cur;
  98041. + unsigned long flags;
  98042. + spin_lock_irqsave(&wdog_lock, flags);
  98043. +
  98044. + /* enable the watchdog */
  98045. + iowrite32(PM_PASSWORD | (timeout & PM_WDOG_TIME_SET),
  98046. + __io_address(PM_WDOG));
  98047. + cur = ioread32(__io_address(PM_RSTC));
  98048. + iowrite32(PM_PASSWORD | (cur & PM_RSTC_WRCFG_CLR) |
  98049. + PM_RSTC_WRCFG_FULL_RESET, __io_address(PM_RSTC));
  98050. +
  98051. + spin_unlock_irqrestore(&wdog_lock, flags);
  98052. + return 0;
  98053. +}
  98054. +
  98055. +/**
  98056. + * Stop the watchdog driver.
  98057. + */
  98058. +
  98059. +static int wdog_stop(void)
  98060. +{
  98061. + iowrite32(PM_PASSWORD | PM_RSTC_RESET, __io_address(PM_RSTC));
  98062. + printk(KERN_INFO "watchdog stopped\n");
  98063. + return 0;
  98064. +}
  98065. +
  98066. +/**
  98067. + * Reload counter one with the watchdog heartbeat. We don't bother
  98068. + * reloading the cascade counter.
  98069. + */
  98070. +
  98071. +static void wdog_ping(void)
  98072. +{
  98073. + wdog_start(wdog_ticks);
  98074. +}
  98075. +
  98076. +/**
  98077. + * @t: the new heartbeat value that needs to be set.
  98078. + *
  98079. + * Set a new heartbeat value for the watchdog device. If the heartbeat
  98080. + * value is incorrect we keep the old value and return -EINVAL. If
  98081. + * successful we return 0.
  98082. + */
  98083. +
  98084. +static int wdog_set_heartbeat(int t)
  98085. +{
  98086. + if (t < 1 || t > WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET))
  98087. + return -EINVAL;
  98088. +
  98089. + heartbeat = t;
  98090. + wdog_ticks = SECS_TO_WDOG_TICKS(t);
  98091. + return 0;
  98092. +}
  98093. +
  98094. +/**
  98095. + * @file: file handle to the watchdog
  98096. + * @buf: buffer to write (unused as data does not matter here
  98097. + * @count: count of bytes
  98098. + * @ppos: pointer to the position to write. No seeks allowed
  98099. + *
  98100. + * A write to a watchdog device is defined as a keepalive signal.
  98101. + *
  98102. + * if 'nowayout' is set then normally a close() is ignored. But
  98103. + * if you write 'V' first then the close() will stop the timer.
  98104. + */
  98105. +
  98106. +static ssize_t wdog_write(struct file *file, const char __user *buf,
  98107. + size_t count, loff_t *ppos)
  98108. +{
  98109. + if (count) {
  98110. + if (!nowayout) {
  98111. + size_t i;
  98112. +
  98113. + /* In case it was set long ago */
  98114. + expect_close = 0;
  98115. +
  98116. + for (i = 0; i != count; i++) {
  98117. + char c;
  98118. + if (get_user(c, buf + i))
  98119. + return -EFAULT;
  98120. + if (c == 'V')
  98121. + expect_close = 42;
  98122. + }
  98123. + }
  98124. + wdog_ping();
  98125. + }
  98126. + return count;
  98127. +}
  98128. +
  98129. +static int wdog_get_status(void)
  98130. +{
  98131. + unsigned long flags;
  98132. + int status = 0;
  98133. + spin_lock_irqsave(&wdog_lock, flags);
  98134. + /* FIXME: readback reset reason */
  98135. + spin_unlock_irqrestore(&wdog_lock, flags);
  98136. + return status;
  98137. +}
  98138. +
  98139. +static uint32_t wdog_get_remaining(void)
  98140. +{
  98141. + uint32_t ret = ioread32(__io_address(PM_WDOG));
  98142. + return ret & PM_WDOG_TIME_SET;
  98143. +}
  98144. +
  98145. +/**
  98146. + * @file: file handle to the device
  98147. + * @cmd: watchdog command
  98148. + * @arg: argument pointer
  98149. + *
  98150. + * The watchdog API defines a common set of functions for all watchdogs
  98151. + * according to their available features. We only actually usefully support
  98152. + * querying capabilities and current status.
  98153. + */
  98154. +
  98155. +static long wdog_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  98156. +{
  98157. + void __user *argp = (void __user *)arg;
  98158. + int __user *p = argp;
  98159. + int new_heartbeat;
  98160. + int status;
  98161. + int options;
  98162. + uint32_t remaining;
  98163. +
  98164. + struct watchdog_info ident = {
  98165. + .options = WDIOF_SETTIMEOUT|
  98166. + WDIOF_MAGICCLOSE|
  98167. + WDIOF_KEEPALIVEPING,
  98168. + .firmware_version = 1,
  98169. + .identity = "BCM2708",
  98170. + };
  98171. +
  98172. + switch (cmd) {
  98173. + case WDIOC_GETSUPPORT:
  98174. + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT : 0;
  98175. + case WDIOC_GETSTATUS:
  98176. + status = wdog_get_status();
  98177. + return put_user(status, p);
  98178. + case WDIOC_GETBOOTSTATUS:
  98179. + return put_user(0, p);
  98180. + case WDIOC_KEEPALIVE:
  98181. + wdog_ping();
  98182. + return 0;
  98183. + case WDIOC_SETTIMEOUT:
  98184. + if (get_user(new_heartbeat, p))
  98185. + return -EFAULT;
  98186. + if (wdog_set_heartbeat(new_heartbeat))
  98187. + return -EINVAL;
  98188. + wdog_ping();
  98189. + /* Fall */
  98190. + case WDIOC_GETTIMEOUT:
  98191. + return put_user(heartbeat, p);
  98192. + case WDIOC_GETTIMELEFT:
  98193. + remaining = WDOG_TICKS_TO_SECS(wdog_get_remaining());
  98194. + return put_user(remaining, p);
  98195. + case WDIOC_SETOPTIONS:
  98196. + if (get_user(options, p))
  98197. + return -EFAULT;
  98198. + if (options & WDIOS_DISABLECARD)
  98199. + wdog_stop();
  98200. + if (options & WDIOS_ENABLECARD)
  98201. + wdog_start(wdog_ticks);
  98202. + return 0;
  98203. + default:
  98204. + return -ENOTTY;
  98205. + }
  98206. +}
  98207. +
  98208. +/**
  98209. + * @inode: inode of device
  98210. + * @file: file handle to device
  98211. + *
  98212. + * The watchdog device has been opened. The watchdog device is single
  98213. + * open and on opening we load the counters.
  98214. + */
  98215. +
  98216. +static int wdog_open(struct inode *inode, struct file *file)
  98217. +{
  98218. + if (test_and_set_bit(0, &wdog_is_open))
  98219. + return -EBUSY;
  98220. + /*
  98221. + * Activate
  98222. + */
  98223. + wdog_start(wdog_ticks);
  98224. + return nonseekable_open(inode, file);
  98225. +}
  98226. +
  98227. +/**
  98228. + * @inode: inode to board
  98229. + * @file: file handle to board
  98230. + *
  98231. + * The watchdog has a configurable API. There is a religious dispute
  98232. + * between people who want their watchdog to be able to shut down and
  98233. + * those who want to be sure if the watchdog manager dies the machine
  98234. + * reboots. In the former case we disable the counters, in the latter
  98235. + * case you have to open it again very soon.
  98236. + */
  98237. +
  98238. +static int wdog_release(struct inode *inode, struct file *file)
  98239. +{
  98240. + if (expect_close == 42) {
  98241. + wdog_stop();
  98242. + } else {
  98243. + printk(KERN_CRIT
  98244. + "wdt: WDT device closed unexpectedly. WDT will not stop!\n");
  98245. + wdog_ping();
  98246. + }
  98247. + clear_bit(0, &wdog_is_open);
  98248. + expect_close = 0;
  98249. + return 0;
  98250. +}
  98251. +
  98252. +/**
  98253. + * @this: our notifier block
  98254. + * @code: the event being reported
  98255. + * @unused: unused
  98256. + *
  98257. + * Our notifier is called on system shutdowns. Turn the watchdog
  98258. + * off so that it does not fire during the next reboot.
  98259. + */
  98260. +
  98261. +static int wdog_notify_sys(struct notifier_block *this, unsigned long code,
  98262. + void *unused)
  98263. +{
  98264. + if (code == SYS_DOWN || code == SYS_HALT)
  98265. + wdog_stop();
  98266. + return NOTIFY_DONE;
  98267. +}
  98268. +
  98269. +/*
  98270. + * Kernel Interfaces
  98271. + */
  98272. +
  98273. +
  98274. +static const struct file_operations wdog_fops = {
  98275. + .owner = THIS_MODULE,
  98276. + .llseek = no_llseek,
  98277. + .write = wdog_write,
  98278. + .unlocked_ioctl = wdog_ioctl,
  98279. + .open = wdog_open,
  98280. + .release = wdog_release,
  98281. +};
  98282. +
  98283. +static struct miscdevice wdog_miscdev = {
  98284. + .minor = WATCHDOG_MINOR,
  98285. + .name = "watchdog",
  98286. + .fops = &wdog_fops,
  98287. +};
  98288. +
  98289. +/*
  98290. + * The WDT card needs to learn about soft shutdowns in order to
  98291. + * turn the timebomb registers off.
  98292. + */
  98293. +
  98294. +static struct notifier_block wdog_notifier = {
  98295. + .notifier_call = wdog_notify_sys,
  98296. +};
  98297. +
  98298. +/**
  98299. + * cleanup_module:
  98300. + *
  98301. + * Unload the watchdog. You cannot do this with any file handles open.
  98302. + * If your watchdog is set to continue ticking on close and you unload
  98303. + * it, well it keeps ticking. We won't get the interrupt but the board
  98304. + * will not touch PC memory so all is fine. You just have to load a new
  98305. + * module in 60 seconds or reboot.
  98306. + */
  98307. +
  98308. +static void __exit wdog_exit(void)
  98309. +{
  98310. + misc_deregister(&wdog_miscdev);
  98311. + unregister_reboot_notifier(&wdog_notifier);
  98312. +}
  98313. +
  98314. +static int __init wdog_init(void)
  98315. +{
  98316. + int ret;
  98317. +
  98318. + /* Check that the heartbeat value is within it's range;
  98319. + if not reset to the default */
  98320. + if (wdog_set_heartbeat(heartbeat)) {
  98321. + wdog_set_heartbeat(WD_TIMO);
  98322. + printk(KERN_INFO "bcm2708_wdog: heartbeat value must be "
  98323. + "0 < heartbeat < %d, using %d\n",
  98324. + WDOG_TICKS_TO_SECS(PM_WDOG_TIME_SET),
  98325. + WD_TIMO);
  98326. + }
  98327. +
  98328. + ret = register_reboot_notifier(&wdog_notifier);
  98329. + if (ret) {
  98330. + printk(KERN_ERR
  98331. + "wdt: cannot register reboot notifier (err=%d)\n", ret);
  98332. + goto out_reboot;
  98333. + }
  98334. +
  98335. + ret = misc_register(&wdog_miscdev);
  98336. + if (ret) {
  98337. + printk(KERN_ERR
  98338. + "wdt: cannot register miscdev on minor=%d (err=%d)\n",
  98339. + WATCHDOG_MINOR, ret);
  98340. + goto out_misc;
  98341. + }
  98342. +
  98343. + printk(KERN_INFO "bcm2708 watchdog, heartbeat=%d sec (nowayout=%d)\n",
  98344. + heartbeat, nowayout);
  98345. + return 0;
  98346. +
  98347. +out_misc:
  98348. + unregister_reboot_notifier(&wdog_notifier);
  98349. +out_reboot:
  98350. + return ret;
  98351. +}
  98352. +
  98353. +module_init(wdog_init);
  98354. +module_exit(wdog_exit);
  98355. +
  98356. +MODULE_AUTHOR("Luke Diamand");
  98357. +MODULE_DESCRIPTION("Driver for BCM2708 watchdog");
  98358. +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
  98359. +MODULE_ALIAS_MISCDEV(TEMP_MINOR);
  98360. +MODULE_LICENSE("GPL");
  98361. diff -Nur linux-3.15/drivers/watchdog/Kconfig linux-rpi/drivers/watchdog/Kconfig
  98362. --- linux-3.15/drivers/watchdog/Kconfig 2014-06-08 20:19:54.000000000 +0200
  98363. +++ linux-rpi/drivers/watchdog/Kconfig 2014-06-11 21:05:32.000000000 +0200
  98364. @@ -411,6 +411,12 @@
  98365. To compile this driver as a module, choose M here: the
  98366. module will be called retu_wdt.
  98367. +config BCM2708_WDT
  98368. + tristate "BCM2708 Watchdog"
  98369. + depends on ARCH_BCM2708
  98370. + help
  98371. + Enables BCM2708 watchdog support.
  98372. +
  98373. config MOXART_WDT
  98374. tristate "MOXART watchdog"
  98375. depends on ARCH_MOXART
  98376. diff -Nur linux-3.15/drivers/watchdog/Makefile linux-rpi/drivers/watchdog/Makefile
  98377. --- linux-3.15/drivers/watchdog/Makefile 2014-06-08 20:19:54.000000000 +0200
  98378. +++ linux-rpi/drivers/watchdog/Makefile 2014-06-11 21:05:32.000000000 +0200
  98379. @@ -54,6 +54,7 @@
  98380. obj-$(CONFIG_IMX2_WDT) += imx2_wdt.o
  98381. obj-$(CONFIG_UX500_WATCHDOG) += ux500_wdt.o
  98382. obj-$(CONFIG_RETU_WATCHDOG) += retu_wdt.o
  98383. +obj-$(CONFIG_BCM2708_WDT) += bcm2708_wdog.o
  98384. obj-$(CONFIG_BCM2835_WDT) += bcm2835_wdt.o
  98385. obj-$(CONFIG_MOXART_WDT) += moxart_wdt.o
  98386. obj-$(CONFIG_SIRFSOC_WATCHDOG) += sirfsoc_wdt.o
  98387. diff -Nur linux-3.15/include/linux/broadcom/vc_cma.h linux-rpi/include/linux/broadcom/vc_cma.h
  98388. --- linux-3.15/include/linux/broadcom/vc_cma.h 1970-01-01 01:00:00.000000000 +0100
  98389. +++ linux-rpi/include/linux/broadcom/vc_cma.h 2014-06-11 21:03:52.000000000 +0200
  98390. @@ -0,0 +1,29 @@
  98391. +/*****************************************************************************
  98392. +* Copyright 2012 Broadcom Corporation. All rights reserved.
  98393. +*
  98394. +* Unless you and Broadcom execute a separate written software license
  98395. +* agreement governing use of this software, this software is licensed to you
  98396. +* under the terms of the GNU General Public License version 2, available at
  98397. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98398. +*
  98399. +* Notwithstanding the above, under no circumstances may you combine this
  98400. +* software in any way with any other Broadcom software provided under a
  98401. +* license other than the GPL, without Broadcom's express prior written
  98402. +* consent.
  98403. +*****************************************************************************/
  98404. +
  98405. +#if !defined( VC_CMA_H )
  98406. +#define VC_CMA_H
  98407. +
  98408. +#include <linux/ioctl.h>
  98409. +
  98410. +#define VC_CMA_IOC_MAGIC 0xc5
  98411. +
  98412. +#define VC_CMA_IOC_RESERVE _IO(VC_CMA_IOC_MAGIC, 0)
  98413. +
  98414. +#ifdef __KERNEL__
  98415. +extern void __init vc_cma_early_init(void);
  98416. +extern void __init vc_cma_reserve(void);
  98417. +#endif
  98418. +
  98419. +#endif /* VC_CMA_H */
  98420. diff -Nur linux-3.15/include/linux/mmc/host.h linux-rpi/include/linux/mmc/host.h
  98421. --- linux-3.15/include/linux/mmc/host.h 2014-06-08 20:19:54.000000000 +0200
  98422. +++ linux-rpi/include/linux/mmc/host.h 2014-06-11 21:05:34.000000000 +0200
  98423. @@ -278,6 +278,7 @@
  98424. #define MMC_CAP2_PACKED_CMD (MMC_CAP2_PACKED_RD | \
  98425. MMC_CAP2_PACKED_WR)
  98426. #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */
  98427. +#define MMC_CAP2_FORCE_MULTIBLOCK (1 << 31) /* Always use multiblock transfers */
  98428. mmc_pm_flag_t pm_caps; /* supported pm features */
  98429. diff -Nur linux-3.15/include/linux/mmc/sdhci.h linux-rpi/include/linux/mmc/sdhci.h
  98430. --- linux-3.15/include/linux/mmc/sdhci.h 2014-06-08 20:19:54.000000000 +0200
  98431. +++ linux-rpi/include/linux/mmc/sdhci.h 2014-06-11 21:05:34.000000000 +0200
  98432. @@ -104,6 +104,7 @@
  98433. #define SDHCI_QUIRK2_BROKEN_DDR50 (1<<7)
  98434. int irq; /* Device IRQ */
  98435. + int second_irq; /* Additional IRQ to disable/enable in low-latency mode */
  98436. void __iomem *ioaddr; /* Mapped address */
  98437. const struct sdhci_ops *ops; /* Low level hw interface */
  98438. @@ -135,6 +136,7 @@
  98439. #define SDHCI_SDIO_IRQ_ENABLED (1<<9) /* SDIO irq enabled */
  98440. #define SDHCI_SDR104_NEEDS_TUNING (1<<10) /* SDR104/HS200 needs tuning */
  98441. #define SDHCI_USING_RETUNING_TIMER (1<<11) /* Host is using a retuning timer for the card */
  98442. +#define SDHCI_USE_PLATDMA (1<<12) /* Host uses 3rd party DMA */
  98443. unsigned int version; /* SDHCI spec. version */
  98444. @@ -150,6 +152,7 @@
  98445. struct mmc_request *mrq; /* Current request */
  98446. struct mmc_command *cmd; /* Current command */
  98447. + int last_cmdop; /* Opcode of last cmd sent */
  98448. struct mmc_data *data; /* Current data request */
  98449. unsigned int data_early:1; /* Data finished before cmd */
  98450. diff -Nur linux-3.15/include/uapi/linux/fb.h linux-rpi/include/uapi/linux/fb.h
  98451. --- linux-3.15/include/uapi/linux/fb.h 2014-06-08 20:19:54.000000000 +0200
  98452. +++ linux-rpi/include/uapi/linux/fb.h 2014-06-11 21:03:54.000000000 +0200
  98453. @@ -34,6 +34,11 @@
  98454. #define FBIOPUT_MODEINFO 0x4617
  98455. #define FBIOGET_DISPINFO 0x4618
  98456. #define FBIO_WAITFORVSYNC _IOW('F', 0x20, __u32)
  98457. +/*
  98458. + * HACK: use 'z' in order not to clash with any other ioctl numbers which might
  98459. + * be concurrently added to the mainline kernel
  98460. + */
  98461. +#define FBIOCOPYAREA _IOW('z', 0x21, struct fb_copyarea)
  98462. #define FB_TYPE_PACKED_PIXELS 0 /* Packed Pixels */
  98463. #define FB_TYPE_PLANES 1 /* Non interleaved planes */
  98464. diff -Nur linux-3.15/kernel/cgroup.c linux-rpi/kernel/cgroup.c
  98465. --- linux-3.15/kernel/cgroup.c 2014-06-08 20:19:54.000000000 +0200
  98466. +++ linux-rpi/kernel/cgroup.c 2014-06-11 21:05:40.000000000 +0200
  98467. @@ -4620,6 +4620,29 @@
  98468. }
  98469. __setup("cgroup_disable=", cgroup_disable);
  98470. +static int __init cgroup_enable(char *str)
  98471. +{
  98472. + struct cgroup_subsys *ss;
  98473. + char *token;
  98474. + int i;
  98475. +
  98476. + while ((token = strsep(&str, ",")) != NULL) {
  98477. + if (!*token)
  98478. + continue;
  98479. +
  98480. + for_each_subsys(ss, i) {
  98481. + if (!strcmp(token, ss->name)) {
  98482. + ss->disabled = 0;
  98483. + printk(KERN_INFO "Enabling %s control group"
  98484. + " subsystem\n", ss->name);
  98485. + break;
  98486. + }
  98487. + }
  98488. + }
  98489. + return 1;
  98490. +}
  98491. +__setup("cgroup_enable=", cgroup_enable);
  98492. +
  98493. /**
  98494. * css_tryget_from_dir - get corresponding css from the dentry of a cgroup dir
  98495. * @dentry: directory dentry of interest
  98496. diff -Nur linux-3.15/mm/memcontrol.c linux-rpi/mm/memcontrol.c
  98497. --- linux-3.15/mm/memcontrol.c 2014-06-08 20:19:54.000000000 +0200
  98498. +++ linux-rpi/mm/memcontrol.c 2014-06-11 21:05:41.000000000 +0200
  98499. @@ -7157,6 +7157,7 @@
  98500. .bind = mem_cgroup_bind,
  98501. .base_cftypes = mem_cgroup_files,
  98502. .early_init = 0,
  98503. + .disabled = 1,
  98504. };
  98505. #ifdef CONFIG_MEMCG_SWAP
  98506. diff -Nur linux-3.15/sound/arm/bcm2835.c linux-rpi/sound/arm/bcm2835.c
  98507. --- linux-3.15/sound/arm/bcm2835.c 1970-01-01 01:00:00.000000000 +0100
  98508. +++ linux-rpi/sound/arm/bcm2835.c 2014-06-11 21:03:57.000000000 +0200
  98509. @@ -0,0 +1,420 @@
  98510. +/*****************************************************************************
  98511. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98512. +*
  98513. +* Unless you and Broadcom execute a separate written software license
  98514. +* agreement governing use of this software, this software is licensed to you
  98515. +* under the terms of the GNU General Public License version 2, available at
  98516. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98517. +*
  98518. +* Notwithstanding the above, under no circumstances may you combine this
  98519. +* software in any way with any other Broadcom software provided under a
  98520. +* license other than the GPL, without Broadcom's express prior written
  98521. +* consent.
  98522. +*****************************************************************************/
  98523. +
  98524. +#include <linux/platform_device.h>
  98525. +
  98526. +#include <linux/init.h>
  98527. +#include <linux/slab.h>
  98528. +#include <linux/module.h>
  98529. +
  98530. +#include "bcm2835.h"
  98531. +
  98532. +/* module parameters (see "Module Parameters") */
  98533. +/* SNDRV_CARDS: maximum number of cards supported by this module */
  98534. +static int index[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = -1 };
  98535. +static char *id[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = NULL };
  98536. +static int enable[MAX_SUBSTREAMS] = {[0 ... (MAX_SUBSTREAMS - 1)] = 1 };
  98537. +
  98538. +/* HACKY global pointers needed for successive probes to work : ssp
  98539. + * But compared against the changes we will have to do in VC audio_ipc code
  98540. + * to export 8 audio_ipc devices as a single IPC device and then monitor all
  98541. + * four devices in a thread, this gets things done quickly and should be easier
  98542. + * to debug if we run into issues
  98543. + */
  98544. +
  98545. +static struct snd_card *g_card = NULL;
  98546. +static bcm2835_chip_t *g_chip = NULL;
  98547. +
  98548. +static int snd_bcm2835_free(bcm2835_chip_t * chip)
  98549. +{
  98550. + kfree(chip);
  98551. + return 0;
  98552. +}
  98553. +
  98554. +/* component-destructor
  98555. + * (see "Management of Cards and Components")
  98556. + */
  98557. +static int snd_bcm2835_dev_free(struct snd_device *device)
  98558. +{
  98559. + return snd_bcm2835_free(device->device_data);
  98560. +}
  98561. +
  98562. +/* chip-specific constructor
  98563. + * (see "Management of Cards and Components")
  98564. + */
  98565. +static int snd_bcm2835_create(struct snd_card *card,
  98566. + struct platform_device *pdev,
  98567. + bcm2835_chip_t ** rchip)
  98568. +{
  98569. + bcm2835_chip_t *chip;
  98570. + int err;
  98571. + static struct snd_device_ops ops = {
  98572. + .dev_free = snd_bcm2835_dev_free,
  98573. + };
  98574. +
  98575. + *rchip = NULL;
  98576. +
  98577. + chip = kzalloc(sizeof(*chip), GFP_KERNEL);
  98578. + if (chip == NULL)
  98579. + return -ENOMEM;
  98580. +
  98581. + chip->card = card;
  98582. +
  98583. + err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  98584. + if (err < 0) {
  98585. + snd_bcm2835_free(chip);
  98586. + return err;
  98587. + }
  98588. +
  98589. + *rchip = chip;
  98590. + return 0;
  98591. +}
  98592. +
  98593. +static int snd_bcm2835_alsa_probe(struct platform_device *pdev)
  98594. +{
  98595. + static int dev;
  98596. + bcm2835_chip_t *chip;
  98597. + struct snd_card *card;
  98598. + int err;
  98599. +
  98600. + if (dev >= MAX_SUBSTREAMS)
  98601. + return -ENODEV;
  98602. +
  98603. + if (!enable[dev]) {
  98604. + dev++;
  98605. + return -ENOENT;
  98606. + }
  98607. +
  98608. + if (dev > 0)
  98609. + goto add_register_map;
  98610. +
  98611. + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &g_card);
  98612. + if (err < 0)
  98613. + goto out;
  98614. +
  98615. + snd_card_set_dev(g_card, &pdev->dev);
  98616. + strcpy(g_card->driver, "bcm2835");
  98617. + strcpy(g_card->shortname, "bcm2835 ALSA");
  98618. + sprintf(g_card->longname, "%s", g_card->shortname);
  98619. +
  98620. + err = snd_bcm2835_create(g_card, pdev, &chip);
  98621. + if (err < 0) {
  98622. + dev_err(&pdev->dev, "Failed to create bcm2835 chip\n");
  98623. + goto out_bcm2835_create;
  98624. + }
  98625. +
  98626. + g_chip = chip;
  98627. + err = snd_bcm2835_new_pcm(chip);
  98628. + if (err < 0) {
  98629. + dev_err(&pdev->dev, "Failed to create new BCM2835 pcm device\n");
  98630. + goto out_bcm2835_new_pcm;
  98631. + }
  98632. +
  98633. + err = snd_bcm2835_new_spdif_pcm(chip);
  98634. + if (err < 0) {
  98635. + dev_err(&pdev->dev, "Failed to create new BCM2835 spdif pcm device\n");
  98636. + goto out_bcm2835_new_spdif;
  98637. + }
  98638. +
  98639. + err = snd_bcm2835_new_ctl(chip);
  98640. + if (err < 0) {
  98641. + dev_err(&pdev->dev, "Failed to create new BCM2835 ctl\n");
  98642. + goto out_bcm2835_new_ctl;
  98643. + }
  98644. +
  98645. +add_register_map:
  98646. + card = g_card;
  98647. + chip = g_chip;
  98648. +
  98649. + BUG_ON(!(card && chip));
  98650. +
  98651. + chip->avail_substreams |= (1 << dev);
  98652. + chip->pdev[dev] = pdev;
  98653. +
  98654. + if (dev == 0) {
  98655. + err = snd_card_register(card);
  98656. + if (err < 0) {
  98657. + dev_err(&pdev->dev,
  98658. + "Failed to register bcm2835 ALSA card \n");
  98659. + goto out_card_register;
  98660. + }
  98661. + platform_set_drvdata(pdev, card);
  98662. + audio_info("bcm2835 ALSA card created!\n");
  98663. + } else {
  98664. + audio_info("bcm2835 ALSA chip created!\n");
  98665. + platform_set_drvdata(pdev, (void *)dev);
  98666. + }
  98667. +
  98668. + dev++;
  98669. +
  98670. + return 0;
  98671. +
  98672. +out_card_register:
  98673. +out_bcm2835_new_ctl:
  98674. +out_bcm2835_new_spdif:
  98675. +out_bcm2835_new_pcm:
  98676. +out_bcm2835_create:
  98677. + BUG_ON(!g_card);
  98678. + if (snd_card_free(g_card))
  98679. + dev_err(&pdev->dev, "Failed to free Registered alsa card\n");
  98680. + g_card = NULL;
  98681. +out:
  98682. + dev = SNDRV_CARDS; /* stop more avail_substreams from being probed */
  98683. + dev_err(&pdev->dev, "BCM2835 ALSA Probe failed !!\n");
  98684. + return err;
  98685. +}
  98686. +
  98687. +static int snd_bcm2835_alsa_remove(struct platform_device *pdev)
  98688. +{
  98689. + uint32_t idx;
  98690. + void *drv_data;
  98691. +
  98692. + drv_data = platform_get_drvdata(pdev);
  98693. +
  98694. + if (drv_data == (void *)g_card) {
  98695. + /* This is the card device */
  98696. + snd_card_free((struct snd_card *)drv_data);
  98697. + g_card = NULL;
  98698. + g_chip = NULL;
  98699. + } else {
  98700. + idx = (uint32_t) drv_data;
  98701. + if (g_card != NULL) {
  98702. + BUG_ON(!g_chip);
  98703. + /* We pass chip device numbers in audio ipc devices
  98704. + * other than the one we registered our card with
  98705. + */
  98706. + idx = (uint32_t) drv_data;
  98707. + BUG_ON(!idx || idx > MAX_SUBSTREAMS);
  98708. + g_chip->avail_substreams &= ~(1 << idx);
  98709. + /* There should be atleast one substream registered
  98710. + * after we are done here, as it wil be removed when
  98711. + * the *remove* is called for the card device
  98712. + */
  98713. + BUG_ON(!g_chip->avail_substreams);
  98714. + }
  98715. + }
  98716. +
  98717. + platform_set_drvdata(pdev, NULL);
  98718. +
  98719. + return 0;
  98720. +}
  98721. +
  98722. +#ifdef CONFIG_PM
  98723. +static int snd_bcm2835_alsa_suspend(struct platform_device *pdev,
  98724. + pm_message_t state)
  98725. +{
  98726. + return 0;
  98727. +}
  98728. +
  98729. +static int snd_bcm2835_alsa_resume(struct platform_device *pdev)
  98730. +{
  98731. + return 0;
  98732. +}
  98733. +
  98734. +#endif
  98735. +
  98736. +static struct platform_driver bcm2835_alsa0_driver = {
  98737. + .probe = snd_bcm2835_alsa_probe,
  98738. + .remove = snd_bcm2835_alsa_remove,
  98739. +#ifdef CONFIG_PM
  98740. + .suspend = snd_bcm2835_alsa_suspend,
  98741. + .resume = snd_bcm2835_alsa_resume,
  98742. +#endif
  98743. + .driver = {
  98744. + .name = "bcm2835_AUD0",
  98745. + .owner = THIS_MODULE,
  98746. + },
  98747. +};
  98748. +
  98749. +static struct platform_driver bcm2835_alsa1_driver = {
  98750. + .probe = snd_bcm2835_alsa_probe,
  98751. + .remove = snd_bcm2835_alsa_remove,
  98752. +#ifdef CONFIG_PM
  98753. + .suspend = snd_bcm2835_alsa_suspend,
  98754. + .resume = snd_bcm2835_alsa_resume,
  98755. +#endif
  98756. + .driver = {
  98757. + .name = "bcm2835_AUD1",
  98758. + .owner = THIS_MODULE,
  98759. + },
  98760. +};
  98761. +
  98762. +static struct platform_driver bcm2835_alsa2_driver = {
  98763. + .probe = snd_bcm2835_alsa_probe,
  98764. + .remove = snd_bcm2835_alsa_remove,
  98765. +#ifdef CONFIG_PM
  98766. + .suspend = snd_bcm2835_alsa_suspend,
  98767. + .resume = snd_bcm2835_alsa_resume,
  98768. +#endif
  98769. + .driver = {
  98770. + .name = "bcm2835_AUD2",
  98771. + .owner = THIS_MODULE,
  98772. + },
  98773. +};
  98774. +
  98775. +static struct platform_driver bcm2835_alsa3_driver = {
  98776. + .probe = snd_bcm2835_alsa_probe,
  98777. + .remove = snd_bcm2835_alsa_remove,
  98778. +#ifdef CONFIG_PM
  98779. + .suspend = snd_bcm2835_alsa_suspend,
  98780. + .resume = snd_bcm2835_alsa_resume,
  98781. +#endif
  98782. + .driver = {
  98783. + .name = "bcm2835_AUD3",
  98784. + .owner = THIS_MODULE,
  98785. + },
  98786. +};
  98787. +
  98788. +static struct platform_driver bcm2835_alsa4_driver = {
  98789. + .probe = snd_bcm2835_alsa_probe,
  98790. + .remove = snd_bcm2835_alsa_remove,
  98791. +#ifdef CONFIG_PM
  98792. + .suspend = snd_bcm2835_alsa_suspend,
  98793. + .resume = snd_bcm2835_alsa_resume,
  98794. +#endif
  98795. + .driver = {
  98796. + .name = "bcm2835_AUD4",
  98797. + .owner = THIS_MODULE,
  98798. + },
  98799. +};
  98800. +
  98801. +static struct platform_driver bcm2835_alsa5_driver = {
  98802. + .probe = snd_bcm2835_alsa_probe,
  98803. + .remove = snd_bcm2835_alsa_remove,
  98804. +#ifdef CONFIG_PM
  98805. + .suspend = snd_bcm2835_alsa_suspend,
  98806. + .resume = snd_bcm2835_alsa_resume,
  98807. +#endif
  98808. + .driver = {
  98809. + .name = "bcm2835_AUD5",
  98810. + .owner = THIS_MODULE,
  98811. + },
  98812. +};
  98813. +
  98814. +static struct platform_driver bcm2835_alsa6_driver = {
  98815. + .probe = snd_bcm2835_alsa_probe,
  98816. + .remove = snd_bcm2835_alsa_remove,
  98817. +#ifdef CONFIG_PM
  98818. + .suspend = snd_bcm2835_alsa_suspend,
  98819. + .resume = snd_bcm2835_alsa_resume,
  98820. +#endif
  98821. + .driver = {
  98822. + .name = "bcm2835_AUD6",
  98823. + .owner = THIS_MODULE,
  98824. + },
  98825. +};
  98826. +
  98827. +static struct platform_driver bcm2835_alsa7_driver = {
  98828. + .probe = snd_bcm2835_alsa_probe,
  98829. + .remove = snd_bcm2835_alsa_remove,
  98830. +#ifdef CONFIG_PM
  98831. + .suspend = snd_bcm2835_alsa_suspend,
  98832. + .resume = snd_bcm2835_alsa_resume,
  98833. +#endif
  98834. + .driver = {
  98835. + .name = "bcm2835_AUD7",
  98836. + .owner = THIS_MODULE,
  98837. + },
  98838. +};
  98839. +
  98840. +static int bcm2835_alsa_device_init(void)
  98841. +{
  98842. + int err;
  98843. + err = platform_driver_register(&bcm2835_alsa0_driver);
  98844. + if (err) {
  98845. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98846. + goto out;
  98847. + }
  98848. +
  98849. + err = platform_driver_register(&bcm2835_alsa1_driver);
  98850. + if (err) {
  98851. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98852. + goto unregister_0;
  98853. + }
  98854. +
  98855. + err = platform_driver_register(&bcm2835_alsa2_driver);
  98856. + if (err) {
  98857. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98858. + goto unregister_1;
  98859. + }
  98860. +
  98861. + err = platform_driver_register(&bcm2835_alsa3_driver);
  98862. + if (err) {
  98863. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98864. + goto unregister_2;
  98865. + }
  98866. +
  98867. + err = platform_driver_register(&bcm2835_alsa4_driver);
  98868. + if (err) {
  98869. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98870. + goto unregister_3;
  98871. + }
  98872. +
  98873. + err = platform_driver_register(&bcm2835_alsa5_driver);
  98874. + if (err) {
  98875. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98876. + goto unregister_4;
  98877. + }
  98878. +
  98879. + err = platform_driver_register(&bcm2835_alsa6_driver);
  98880. + if (err) {
  98881. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98882. + goto unregister_5;
  98883. + }
  98884. +
  98885. + err = platform_driver_register(&bcm2835_alsa7_driver);
  98886. + if (err) {
  98887. + pr_err("Error registering bcm2835_alsa0_driver %d .\n", err);
  98888. + goto unregister_6;
  98889. + }
  98890. +
  98891. + return 0;
  98892. +
  98893. +unregister_6:
  98894. + platform_driver_unregister(&bcm2835_alsa6_driver);
  98895. +unregister_5:
  98896. + platform_driver_unregister(&bcm2835_alsa5_driver);
  98897. +unregister_4:
  98898. + platform_driver_unregister(&bcm2835_alsa4_driver);
  98899. +unregister_3:
  98900. + platform_driver_unregister(&bcm2835_alsa3_driver);
  98901. +unregister_2:
  98902. + platform_driver_unregister(&bcm2835_alsa2_driver);
  98903. +unregister_1:
  98904. + platform_driver_unregister(&bcm2835_alsa1_driver);
  98905. +unregister_0:
  98906. + platform_driver_unregister(&bcm2835_alsa0_driver);
  98907. +out:
  98908. + return err;
  98909. +}
  98910. +
  98911. +static void bcm2835_alsa_device_exit(void)
  98912. +{
  98913. + platform_driver_unregister(&bcm2835_alsa0_driver);
  98914. + platform_driver_unregister(&bcm2835_alsa1_driver);
  98915. + platform_driver_unregister(&bcm2835_alsa2_driver);
  98916. + platform_driver_unregister(&bcm2835_alsa3_driver);
  98917. + platform_driver_unregister(&bcm2835_alsa4_driver);
  98918. + platform_driver_unregister(&bcm2835_alsa5_driver);
  98919. + platform_driver_unregister(&bcm2835_alsa6_driver);
  98920. + platform_driver_unregister(&bcm2835_alsa7_driver);
  98921. +}
  98922. +
  98923. +late_initcall(bcm2835_alsa_device_init);
  98924. +module_exit(bcm2835_alsa_device_exit);
  98925. +
  98926. +MODULE_AUTHOR("Dom Cobley");
  98927. +MODULE_DESCRIPTION("Alsa driver for BCM2835 chip");
  98928. +MODULE_LICENSE("GPL");
  98929. +MODULE_ALIAS("platform:bcm2835_alsa");
  98930. diff -Nur linux-3.15/sound/arm/bcm2835-ctl.c linux-rpi/sound/arm/bcm2835-ctl.c
  98931. --- linux-3.15/sound/arm/bcm2835-ctl.c 1970-01-01 01:00:00.000000000 +0100
  98932. +++ linux-rpi/sound/arm/bcm2835-ctl.c 2014-06-11 21:03:57.000000000 +0200
  98933. @@ -0,0 +1,323 @@
  98934. +/*****************************************************************************
  98935. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  98936. +*
  98937. +* Unless you and Broadcom execute a separate written software license
  98938. +* agreement governing use of this software, this software is licensed to you
  98939. +* under the terms of the GNU General Public License version 2, available at
  98940. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  98941. +*
  98942. +* Notwithstanding the above, under no circumstances may you combine this
  98943. +* software in any way with any other Broadcom software provided under a
  98944. +* license other than the GPL, without Broadcom's express prior written
  98945. +* consent.
  98946. +*****************************************************************************/
  98947. +
  98948. +#include <linux/platform_device.h>
  98949. +#include <linux/init.h>
  98950. +#include <linux/io.h>
  98951. +#include <linux/jiffies.h>
  98952. +#include <linux/slab.h>
  98953. +#include <linux/time.h>
  98954. +#include <linux/wait.h>
  98955. +#include <linux/delay.h>
  98956. +#include <linux/moduleparam.h>
  98957. +#include <linux/sched.h>
  98958. +
  98959. +#include <sound/core.h>
  98960. +#include <sound/control.h>
  98961. +#include <sound/pcm.h>
  98962. +#include <sound/pcm_params.h>
  98963. +#include <sound/rawmidi.h>
  98964. +#include <sound/initval.h>
  98965. +#include <sound/tlv.h>
  98966. +#include <sound/asoundef.h>
  98967. +
  98968. +#include "bcm2835.h"
  98969. +
  98970. +/* volume maximum and minimum in terms of 0.01dB */
  98971. +#define CTRL_VOL_MAX 400
  98972. +#define CTRL_VOL_MIN -10239 /* originally -10240 */
  98973. +
  98974. +
  98975. +static int snd_bcm2835_ctl_info(struct snd_kcontrol *kcontrol,
  98976. + struct snd_ctl_elem_info *uinfo)
  98977. +{
  98978. + audio_info(" ... IN\n");
  98979. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  98980. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  98981. + uinfo->count = 1;
  98982. + uinfo->value.integer.min = CTRL_VOL_MIN;
  98983. + uinfo->value.integer.max = CTRL_VOL_MAX; /* 2303 */
  98984. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  98985. + uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  98986. + uinfo->count = 1;
  98987. + uinfo->value.integer.min = 0;
  98988. + uinfo->value.integer.max = 1;
  98989. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  98990. + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  98991. + uinfo->count = 1;
  98992. + uinfo->value.integer.min = 0;
  98993. + uinfo->value.integer.max = AUDIO_DEST_MAX-1;
  98994. + }
  98995. + audio_info(" ... OUT\n");
  98996. + return 0;
  98997. +}
  98998. +
  98999. +/* toggles mute on or off depending on the value of nmute, and returns
  99000. + * 1 if the mute value was changed, otherwise 0
  99001. + */
  99002. +static int toggle_mute(struct bcm2835_chip *chip, int nmute)
  99003. +{
  99004. + /* if settings are ok, just return 0 */
  99005. + if(chip->mute == nmute)
  99006. + return 0;
  99007. +
  99008. + /* if the sound is muted then we need to unmute */
  99009. + if(chip->mute == CTRL_VOL_MUTE)
  99010. + {
  99011. + chip->volume = chip->old_volume; /* copy the old volume back */
  99012. + audio_info("Unmuting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  99013. + }
  99014. + else /* otherwise we mute */
  99015. + {
  99016. + chip->old_volume = chip->volume;
  99017. + chip->volume = 26214; /* set volume to minimum level AKA mute */
  99018. + audio_info("Muting, old_volume = %d, volume = %d ...\n", chip->old_volume, chip->volume);
  99019. + }
  99020. +
  99021. + chip->mute = nmute;
  99022. + return 1;
  99023. +}
  99024. +
  99025. +static int snd_bcm2835_ctl_get(struct snd_kcontrol *kcontrol,
  99026. + struct snd_ctl_elem_value *ucontrol)
  99027. +{
  99028. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99029. +
  99030. + BUG_ON(!chip && !(chip->avail_substreams & AVAIL_SUBSTREAMS_MASK));
  99031. +
  99032. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME)
  99033. + ucontrol->value.integer.value[0] = chip2alsa(chip->volume);
  99034. + else if (kcontrol->private_value == PCM_PLAYBACK_MUTE)
  99035. + ucontrol->value.integer.value[0] = chip->mute;
  99036. + else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE)
  99037. + ucontrol->value.integer.value[0] = chip->dest;
  99038. +
  99039. + return 0;
  99040. +}
  99041. +
  99042. +static int snd_bcm2835_ctl_put(struct snd_kcontrol *kcontrol,
  99043. + struct snd_ctl_elem_value *ucontrol)
  99044. +{
  99045. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99046. + int changed = 0;
  99047. +
  99048. + if (kcontrol->private_value == PCM_PLAYBACK_VOLUME) {
  99049. + audio_info("Volume change attempted.. volume = %d new_volume = %d\n", chip->volume, (int)ucontrol->value.integer.value[0]);
  99050. + if (chip->mute == CTRL_VOL_MUTE) {
  99051. + /* changed = toggle_mute(chip, CTRL_VOL_UNMUTE); */
  99052. + return 1; /* should return 0 to signify no change but the mixer takes this as the opposite sign (no idea why) */
  99053. + }
  99054. + if (changed
  99055. + || (ucontrol->value.integer.value[0] != chip2alsa(chip->volume))) {
  99056. +
  99057. + chip->volume = alsa2chip(ucontrol->value.integer.value[0]);
  99058. + changed = 1;
  99059. + }
  99060. +
  99061. + } else if (kcontrol->private_value == PCM_PLAYBACK_MUTE) {
  99062. + /* Now implemented */
  99063. + audio_info(" Mute attempted\n");
  99064. + changed = toggle_mute(chip, ucontrol->value.integer.value[0]);
  99065. +
  99066. + } else if (kcontrol->private_value == PCM_PLAYBACK_DEVICE) {
  99067. + if (ucontrol->value.integer.value[0] != chip->dest) {
  99068. + chip->dest = ucontrol->value.integer.value[0];
  99069. + changed = 1;
  99070. + }
  99071. + }
  99072. +
  99073. + if (changed) {
  99074. + if (bcm2835_audio_set_ctls(chip))
  99075. + printk(KERN_ERR "Failed to set ALSA controls..\n");
  99076. + }
  99077. +
  99078. + return changed;
  99079. +}
  99080. +
  99081. +static DECLARE_TLV_DB_SCALE(snd_bcm2835_db_scale, CTRL_VOL_MIN, 1, 1);
  99082. +
  99083. +static struct snd_kcontrol_new snd_bcm2835_ctl[] = {
  99084. + {
  99085. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99086. + .name = "PCM Playback Volume",
  99087. + .index = 0,
  99088. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
  99089. + .private_value = PCM_PLAYBACK_VOLUME,
  99090. + .info = snd_bcm2835_ctl_info,
  99091. + .get = snd_bcm2835_ctl_get,
  99092. + .put = snd_bcm2835_ctl_put,
  99093. + .count = 1,
  99094. + .tlv = {.p = snd_bcm2835_db_scale}
  99095. + },
  99096. + {
  99097. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99098. + .name = "PCM Playback Switch",
  99099. + .index = 0,
  99100. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  99101. + .private_value = PCM_PLAYBACK_MUTE,
  99102. + .info = snd_bcm2835_ctl_info,
  99103. + .get = snd_bcm2835_ctl_get,
  99104. + .put = snd_bcm2835_ctl_put,
  99105. + .count = 1,
  99106. + },
  99107. + {
  99108. + .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  99109. + .name = "PCM Playback Route",
  99110. + .index = 0,
  99111. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
  99112. + .private_value = PCM_PLAYBACK_DEVICE,
  99113. + .info = snd_bcm2835_ctl_info,
  99114. + .get = snd_bcm2835_ctl_get,
  99115. + .put = snd_bcm2835_ctl_put,
  99116. + .count = 1,
  99117. + },
  99118. +};
  99119. +
  99120. +static int snd_bcm2835_spdif_default_info(struct snd_kcontrol *kcontrol,
  99121. + struct snd_ctl_elem_info *uinfo)
  99122. +{
  99123. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99124. + uinfo->count = 1;
  99125. + return 0;
  99126. +}
  99127. +
  99128. +static int snd_bcm2835_spdif_default_get(struct snd_kcontrol *kcontrol,
  99129. + struct snd_ctl_elem_value *ucontrol)
  99130. +{
  99131. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99132. + int i;
  99133. +
  99134. + for (i = 0; i < 4; i++)
  99135. + ucontrol->value.iec958.status[i] =
  99136. + (chip->spdif_status >> (i * 8)) && 0xff;
  99137. +
  99138. + return 0;
  99139. +}
  99140. +
  99141. +static int snd_bcm2835_spdif_default_put(struct snd_kcontrol *kcontrol,
  99142. + struct snd_ctl_elem_value *ucontrol)
  99143. +{
  99144. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99145. + unsigned int val = 0;
  99146. + int i, change;
  99147. +
  99148. + for (i = 0; i < 4; i++)
  99149. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  99150. +
  99151. + change = val != chip->spdif_status;
  99152. + chip->spdif_status = val;
  99153. +
  99154. + return change;
  99155. +}
  99156. +
  99157. +static int snd_bcm2835_spdif_mask_info(struct snd_kcontrol *kcontrol,
  99158. + struct snd_ctl_elem_info *uinfo)
  99159. +{
  99160. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99161. + uinfo->count = 1;
  99162. + return 0;
  99163. +}
  99164. +
  99165. +static int snd_bcm2835_spdif_mask_get(struct snd_kcontrol *kcontrol,
  99166. + struct snd_ctl_elem_value *ucontrol)
  99167. +{
  99168. + /* bcm2835 supports only consumer mode and sets all other format flags
  99169. + * automatically. So the only thing left is signalling non-audio
  99170. + * content */
  99171. + ucontrol->value.iec958.status[0] = IEC958_AES0_NONAUDIO;
  99172. + return 0;
  99173. +}
  99174. +
  99175. +static int snd_bcm2835_spdif_stream_info(struct snd_kcontrol *kcontrol,
  99176. + struct snd_ctl_elem_info *uinfo)
  99177. +{
  99178. + uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  99179. + uinfo->count = 1;
  99180. + return 0;
  99181. +}
  99182. +
  99183. +static int snd_bcm2835_spdif_stream_get(struct snd_kcontrol *kcontrol,
  99184. + struct snd_ctl_elem_value *ucontrol)
  99185. +{
  99186. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99187. + int i;
  99188. +
  99189. + for (i = 0; i < 4; i++)
  99190. + ucontrol->value.iec958.status[i] =
  99191. + (chip->spdif_status >> (i * 8)) & 0xff;
  99192. + return 0;
  99193. +}
  99194. +
  99195. +static int snd_bcm2835_spdif_stream_put(struct snd_kcontrol *kcontrol,
  99196. + struct snd_ctl_elem_value *ucontrol)
  99197. +{
  99198. + struct bcm2835_chip *chip = snd_kcontrol_chip(kcontrol);
  99199. + unsigned int val = 0;
  99200. + int i, change;
  99201. +
  99202. + for (i = 0; i < 4; i++)
  99203. + val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
  99204. + change = val != chip->spdif_status;
  99205. + chip->spdif_status = val;
  99206. +
  99207. + return change;
  99208. +}
  99209. +
  99210. +static struct snd_kcontrol_new snd_bcm2835_spdif[] = {
  99211. + {
  99212. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99213. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  99214. + .info = snd_bcm2835_spdif_default_info,
  99215. + .get = snd_bcm2835_spdif_default_get,
  99216. + .put = snd_bcm2835_spdif_default_put
  99217. + },
  99218. + {
  99219. + .access = SNDRV_CTL_ELEM_ACCESS_READ,
  99220. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99221. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  99222. + .info = snd_bcm2835_spdif_mask_info,
  99223. + .get = snd_bcm2835_spdif_mask_get,
  99224. + },
  99225. + {
  99226. + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  99227. + SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  99228. + .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  99229. + .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  99230. + .info = snd_bcm2835_spdif_stream_info,
  99231. + .get = snd_bcm2835_spdif_stream_get,
  99232. + .put = snd_bcm2835_spdif_stream_put,
  99233. + },
  99234. +};
  99235. +
  99236. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip)
  99237. +{
  99238. + int err;
  99239. + unsigned int idx;
  99240. +
  99241. + strcpy(chip->card->mixername, "Broadcom Mixer");
  99242. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_ctl); idx++) {
  99243. + err =
  99244. + snd_ctl_add(chip->card,
  99245. + snd_ctl_new1(&snd_bcm2835_ctl[idx], chip));
  99246. + if (err < 0)
  99247. + return err;
  99248. + }
  99249. + for (idx = 0; idx < ARRAY_SIZE(snd_bcm2835_spdif); idx++) {
  99250. + err = snd_ctl_add(chip->card,
  99251. + snd_ctl_new1(&snd_bcm2835_spdif[idx], chip));
  99252. + if (err < 0)
  99253. + return err;
  99254. + }
  99255. + return 0;
  99256. +}
  99257. diff -Nur linux-3.15/sound/arm/bcm2835.h linux-rpi/sound/arm/bcm2835.h
  99258. --- linux-3.15/sound/arm/bcm2835.h 1970-01-01 01:00:00.000000000 +0100
  99259. +++ linux-rpi/sound/arm/bcm2835.h 2014-06-11 21:03:57.000000000 +0200
  99260. @@ -0,0 +1,166 @@
  99261. +/*****************************************************************************
  99262. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99263. +*
  99264. +* Unless you and Broadcom execute a separate written software license
  99265. +* agreement governing use of this software, this software is licensed to you
  99266. +* under the terms of the GNU General Public License version 2, available at
  99267. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99268. +*
  99269. +* Notwithstanding the above, under no circumstances may you combine this
  99270. +* software in any way with any other Broadcom software provided under a
  99271. +* license other than the GPL, without Broadcom's express prior written
  99272. +* consent.
  99273. +*****************************************************************************/
  99274. +
  99275. +#ifndef __SOUND_ARM_BCM2835_H
  99276. +#define __SOUND_ARM_BCM2835_H
  99277. +
  99278. +#include <linux/device.h>
  99279. +#include <linux/list.h>
  99280. +#include <linux/interrupt.h>
  99281. +#include <linux/wait.h>
  99282. +#include <sound/core.h>
  99283. +#include <sound/initval.h>
  99284. +#include <sound/pcm.h>
  99285. +#include <sound/pcm_params.h>
  99286. +#include <sound/pcm-indirect.h>
  99287. +#include <linux/workqueue.h>
  99288. +
  99289. +/*
  99290. +#define AUDIO_DEBUG_ENABLE
  99291. +#define AUDIO_VERBOSE_DEBUG_ENABLE
  99292. +*/
  99293. +
  99294. +/* Debug macros */
  99295. +
  99296. +#ifdef AUDIO_DEBUG_ENABLE
  99297. +#ifdef AUDIO_VERBOSE_DEBUG_ENABLE
  99298. +
  99299. +#define audio_debug(fmt, arg...) \
  99300. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  99301. +
  99302. +#define audio_info(fmt, arg...) \
  99303. + printk(KERN_INFO"%s:%d " fmt, __func__, __LINE__, ##arg)
  99304. +
  99305. +#else
  99306. +
  99307. +#define audio_debug(fmt, arg...)
  99308. +
  99309. +#define audio_info(fmt, arg...)
  99310. +
  99311. +#endif /* AUDIO_VERBOSE_DEBUG_ENABLE */
  99312. +
  99313. +#else
  99314. +
  99315. +#define audio_debug(fmt, arg...)
  99316. +
  99317. +#define audio_info(fmt, arg...)
  99318. +
  99319. +#endif /* AUDIO_DEBUG_ENABLE */
  99320. +
  99321. +#define audio_error(fmt, arg...) \
  99322. + printk(KERN_ERR"%s:%d " fmt, __func__, __LINE__, ##arg)
  99323. +
  99324. +#define audio_warning(fmt, arg...) \
  99325. + printk(KERN_WARNING"%s:%d " fmt, __func__, __LINE__, ##arg)
  99326. +
  99327. +#define audio_alert(fmt, arg...) \
  99328. + printk(KERN_ALERT"%s:%d " fmt, __func__, __LINE__, ##arg)
  99329. +
  99330. +#define MAX_SUBSTREAMS (8)
  99331. +#define AVAIL_SUBSTREAMS_MASK (0xff)
  99332. +enum {
  99333. + CTRL_VOL_MUTE,
  99334. + CTRL_VOL_UNMUTE
  99335. +};
  99336. +
  99337. +/* macros for alsa2chip and chip2alsa, instead of functions */
  99338. +
  99339. +#define alsa2chip(vol) (uint)(-((vol << 8) / 100)) /* convert alsa to chip volume (defined as macro rather than function call) */
  99340. +#define chip2alsa(vol) -((vol * 100) >> 8) /* convert chip to alsa volume */
  99341. +
  99342. +/* Some constants for values .. */
  99343. +typedef enum {
  99344. + AUDIO_DEST_AUTO = 0,
  99345. + AUDIO_DEST_HEADPHONES = 1,
  99346. + AUDIO_DEST_HDMI = 2,
  99347. + AUDIO_DEST_MAX,
  99348. +} SND_BCM2835_ROUTE_T;
  99349. +
  99350. +typedef enum {
  99351. + PCM_PLAYBACK_VOLUME,
  99352. + PCM_PLAYBACK_MUTE,
  99353. + PCM_PLAYBACK_DEVICE,
  99354. +} SND_BCM2835_CTRL_T;
  99355. +
  99356. +/* definition of the chip-specific record */
  99357. +typedef struct bcm2835_chip {
  99358. + struct snd_card *card;
  99359. + struct snd_pcm *pcm;
  99360. + struct snd_pcm *pcm_spdif;
  99361. + /* Bitmat for valid reg_base and irq numbers */
  99362. + uint32_t avail_substreams;
  99363. + struct platform_device *pdev[MAX_SUBSTREAMS];
  99364. + struct bcm2835_alsa_stream *alsa_stream[MAX_SUBSTREAMS];
  99365. +
  99366. + int volume;
  99367. + int old_volume; /* stores the volume value whist muted */
  99368. + int dest;
  99369. + int mute;
  99370. +
  99371. + unsigned int opened;
  99372. + unsigned int spdif_status;
  99373. +} bcm2835_chip_t;
  99374. +
  99375. +typedef struct bcm2835_alsa_stream {
  99376. + bcm2835_chip_t *chip;
  99377. + struct snd_pcm_substream *substream;
  99378. + struct snd_pcm_indirect pcm_indirect;
  99379. +
  99380. + struct semaphore buffers_update_sem;
  99381. + struct semaphore control_sem;
  99382. + spinlock_t lock;
  99383. + volatile uint32_t control;
  99384. + volatile uint32_t status;
  99385. +
  99386. + int open;
  99387. + int running;
  99388. + int draining;
  99389. +
  99390. + int channels;
  99391. + int params_rate;
  99392. + int pcm_format_width;
  99393. +
  99394. + unsigned int pos;
  99395. + unsigned int buffer_size;
  99396. + unsigned int period_size;
  99397. +
  99398. + uint32_t enable_fifo_irq;
  99399. + irq_handler_t fifo_irq_handler;
  99400. +
  99401. + atomic_t retrieved;
  99402. + struct opaque_AUDIO_INSTANCE_T *instance;
  99403. + struct workqueue_struct *my_wq;
  99404. + int idx;
  99405. +} bcm2835_alsa_stream_t;
  99406. +
  99407. +int snd_bcm2835_new_ctl(bcm2835_chip_t * chip);
  99408. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip);
  99409. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip);
  99410. +
  99411. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream);
  99412. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream);
  99413. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  99414. + uint32_t channels, uint32_t samplerate,
  99415. + uint32_t bps);
  99416. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream);
  99417. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream);
  99418. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream);
  99419. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip);
  99420. +int bcm2835_audio_write(bcm2835_alsa_stream_t * alsa_stream, uint32_t count,
  99421. + void *src);
  99422. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99423. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99424. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream);
  99425. +
  99426. +#endif /* __SOUND_ARM_BCM2835_H */
  99427. diff -Nur linux-3.15/sound/arm/bcm2835-pcm.c linux-rpi/sound/arm/bcm2835-pcm.c
  99428. --- linux-3.15/sound/arm/bcm2835-pcm.c 1970-01-01 01:00:00.000000000 +0100
  99429. +++ linux-rpi/sound/arm/bcm2835-pcm.c 2014-06-11 21:03:57.000000000 +0200
  99430. @@ -0,0 +1,518 @@
  99431. +/*****************************************************************************
  99432. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99433. +*
  99434. +* Unless you and Broadcom execute a separate written software license
  99435. +* agreement governing use of this software, this software is licensed to you
  99436. +* under the terms of the GNU General Public License version 2, available at
  99437. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99438. +*
  99439. +* Notwithstanding the above, under no circumstances may you combine this
  99440. +* software in any way with any other Broadcom software provided under a
  99441. +* license other than the GPL, without Broadcom's express prior written
  99442. +* consent.
  99443. +*****************************************************************************/
  99444. +
  99445. +#include <linux/interrupt.h>
  99446. +#include <linux/slab.h>
  99447. +
  99448. +#include <sound/asoundef.h>
  99449. +
  99450. +#include "bcm2835.h"
  99451. +
  99452. +/* hardware definition */
  99453. +static struct snd_pcm_hardware snd_bcm2835_playback_hw = {
  99454. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  99455. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  99456. + .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
  99457. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
  99458. + .rate_min = 8000,
  99459. + .rate_max = 48000,
  99460. + .channels_min = 1,
  99461. + .channels_max = 2,
  99462. + .buffer_bytes_max = 128 * 1024,
  99463. + .period_bytes_min = 1 * 1024,
  99464. + .period_bytes_max = 128 * 1024,
  99465. + .periods_min = 1,
  99466. + .periods_max = 128,
  99467. +};
  99468. +
  99469. +static struct snd_pcm_hardware snd_bcm2835_playback_spdif_hw = {
  99470. + .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
  99471. + SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
  99472. + .formats = SNDRV_PCM_FMTBIT_S16_LE,
  99473. + .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_44100 |
  99474. + SNDRV_PCM_RATE_48000,
  99475. + .rate_min = 44100,
  99476. + .rate_max = 48000,
  99477. + .channels_min = 2,
  99478. + .channels_max = 2,
  99479. + .buffer_bytes_max = 128 * 1024,
  99480. + .period_bytes_min = 1 * 1024,
  99481. + .period_bytes_max = 128 * 1024,
  99482. + .periods_min = 1,
  99483. + .periods_max = 128,
  99484. +};
  99485. +
  99486. +static void snd_bcm2835_playback_free(struct snd_pcm_runtime *runtime)
  99487. +{
  99488. + audio_info("Freeing up alsa stream here ..\n");
  99489. + if (runtime->private_data)
  99490. + kfree(runtime->private_data);
  99491. + runtime->private_data = NULL;
  99492. +}
  99493. +
  99494. +static irqreturn_t bcm2835_playback_fifo_irq(int irq, void *dev_id)
  99495. +{
  99496. + bcm2835_alsa_stream_t *alsa_stream = (bcm2835_alsa_stream_t *) dev_id;
  99497. + uint32_t consumed = 0;
  99498. + int new_period = 0;
  99499. +
  99500. + audio_info(" .. IN\n");
  99501. +
  99502. + audio_info("alsa_stream=%p substream=%p\n", alsa_stream,
  99503. + alsa_stream ? alsa_stream->substream : 0);
  99504. +
  99505. + if (alsa_stream->open)
  99506. + consumed = bcm2835_audio_retrieve_buffers(alsa_stream);
  99507. +
  99508. + /* We get called only if playback was triggered, So, the number of buffers we retrieve in
  99509. + * each iteration are the buffers that have been played out already
  99510. + */
  99511. +
  99512. + if (alsa_stream->period_size) {
  99513. + if ((alsa_stream->pos / alsa_stream->period_size) !=
  99514. + ((alsa_stream->pos + consumed) / alsa_stream->period_size))
  99515. + new_period = 1;
  99516. + }
  99517. + audio_debug("updating pos cur: %d + %d max:%d period_bytes:%d, hw_ptr: %d new_period:%d\n",
  99518. + alsa_stream->pos,
  99519. + consumed,
  99520. + alsa_stream->buffer_size,
  99521. + (int)(alsa_stream->period_size*alsa_stream->substream->runtime->periods),
  99522. + frames_to_bytes(alsa_stream->substream->runtime, alsa_stream->substream->runtime->status->hw_ptr),
  99523. + new_period);
  99524. + if (alsa_stream->buffer_size) {
  99525. + alsa_stream->pos += consumed &~ (1<<30);
  99526. + alsa_stream->pos %= alsa_stream->buffer_size;
  99527. + }
  99528. +
  99529. + if (alsa_stream->substream) {
  99530. + if (new_period)
  99531. + snd_pcm_period_elapsed(alsa_stream->substream);
  99532. + } else {
  99533. + audio_warning(" unexpected NULL substream\n");
  99534. + }
  99535. + audio_info(" .. OUT\n");
  99536. +
  99537. + return IRQ_HANDLED;
  99538. +}
  99539. +
  99540. +/* open callback */
  99541. +static int snd_bcm2835_playback_open_generic(
  99542. + struct snd_pcm_substream *substream, int spdif)
  99543. +{
  99544. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  99545. + struct snd_pcm_runtime *runtime = substream->runtime;
  99546. + bcm2835_alsa_stream_t *alsa_stream;
  99547. + int idx;
  99548. + int err;
  99549. +
  99550. + audio_info(" .. IN (%d)\n", substream->number);
  99551. +
  99552. + audio_info("Alsa open (%d)\n", substream->number);
  99553. + idx = substream->number;
  99554. +
  99555. + if (spdif && chip->opened != 0)
  99556. + return -EBUSY;
  99557. + else if (!spdif && (chip->opened & (1 << idx)))
  99558. + return -EBUSY;
  99559. +
  99560. + if (idx > MAX_SUBSTREAMS) {
  99561. + audio_error
  99562. + ("substream(%d) device doesn't exist max(%d) substreams allowed\n",
  99563. + idx, MAX_SUBSTREAMS);
  99564. + err = -ENODEV;
  99565. + goto out;
  99566. + }
  99567. +
  99568. + /* Check if we are ready */
  99569. + if (!(chip->avail_substreams & (1 << idx))) {
  99570. + /* We are not ready yet */
  99571. + audio_error("substream(%d) device is not ready yet\n", idx);
  99572. + err = -EAGAIN;
  99573. + goto out;
  99574. + }
  99575. +
  99576. + alsa_stream = kzalloc(sizeof(bcm2835_alsa_stream_t), GFP_KERNEL);
  99577. + if (alsa_stream == NULL) {
  99578. + return -ENOMEM;
  99579. + }
  99580. +
  99581. + /* Initialise alsa_stream */
  99582. + alsa_stream->chip = chip;
  99583. + alsa_stream->substream = substream;
  99584. + alsa_stream->idx = idx;
  99585. +
  99586. + sema_init(&alsa_stream->buffers_update_sem, 0);
  99587. + sema_init(&alsa_stream->control_sem, 0);
  99588. + spin_lock_init(&alsa_stream->lock);
  99589. +
  99590. + /* Enabled in start trigger, called on each "fifo irq" after that */
  99591. + alsa_stream->enable_fifo_irq = 0;
  99592. + alsa_stream->fifo_irq_handler = bcm2835_playback_fifo_irq;
  99593. +
  99594. + err = bcm2835_audio_open(alsa_stream);
  99595. + if (err != 0) {
  99596. + kfree(alsa_stream);
  99597. + return err;
  99598. + }
  99599. + runtime->private_data = alsa_stream;
  99600. + runtime->private_free = snd_bcm2835_playback_free;
  99601. + if (spdif) {
  99602. + runtime->hw = snd_bcm2835_playback_spdif_hw;
  99603. + } else {
  99604. + /* clear spdif status, as we are not in spdif mode */
  99605. + chip->spdif_status = 0;
  99606. + runtime->hw = snd_bcm2835_playback_hw;
  99607. + }
  99608. + /* minimum 16 bytes alignment (for vchiq bulk transfers) */
  99609. + snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  99610. + 16);
  99611. +
  99612. + chip->alsa_stream[idx] = alsa_stream;
  99613. +
  99614. + chip->opened |= (1 << idx);
  99615. + alsa_stream->open = 1;
  99616. + alsa_stream->draining = 1;
  99617. +
  99618. +out:
  99619. + audio_info(" .. OUT =%d\n", err);
  99620. +
  99621. + return err;
  99622. +}
  99623. +
  99624. +static int snd_bcm2835_playback_open(struct snd_pcm_substream *substream)
  99625. +{
  99626. + return snd_bcm2835_playback_open_generic(substream, 0);
  99627. +}
  99628. +
  99629. +static int snd_bcm2835_playback_spdif_open(struct snd_pcm_substream *substream)
  99630. +{
  99631. + return snd_bcm2835_playback_open_generic(substream, 1);
  99632. +}
  99633. +
  99634. +/* close callback */
  99635. +static int snd_bcm2835_playback_close(struct snd_pcm_substream *substream)
  99636. +{
  99637. + /* the hardware-specific codes will be here */
  99638. +
  99639. + struct snd_pcm_runtime *runtime = substream->runtime;
  99640. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99641. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  99642. +
  99643. + audio_info(" .. IN\n");
  99644. + audio_info("Alsa close\n");
  99645. +
  99646. + /*
  99647. + * Call stop if it's still running. This happens when app
  99648. + * is force killed and we don't get a stop trigger.
  99649. + */
  99650. + if (alsa_stream->running) {
  99651. + int err;
  99652. + err = bcm2835_audio_stop(alsa_stream);
  99653. + alsa_stream->running = 0;
  99654. + if (err != 0)
  99655. + audio_error(" Failed to STOP alsa device\n");
  99656. + }
  99657. +
  99658. + alsa_stream->period_size = 0;
  99659. + alsa_stream->buffer_size = 0;
  99660. +
  99661. + if (alsa_stream->open) {
  99662. + alsa_stream->open = 0;
  99663. + bcm2835_audio_close(alsa_stream);
  99664. + }
  99665. + if (alsa_stream->chip)
  99666. + alsa_stream->chip->alsa_stream[alsa_stream->idx] = NULL;
  99667. + /*
  99668. + * Do not free up alsa_stream here, it will be freed up by
  99669. + * runtime->private_free callback we registered in *_open above
  99670. + */
  99671. +
  99672. + chip->opened &= ~(1 << substream->number);
  99673. +
  99674. + audio_info(" .. OUT\n");
  99675. +
  99676. + return 0;
  99677. +}
  99678. +
  99679. +/* hw_params callback */
  99680. +static int snd_bcm2835_pcm_hw_params(struct snd_pcm_substream *substream,
  99681. + struct snd_pcm_hw_params *params)
  99682. +{
  99683. + struct snd_pcm_runtime *runtime = substream->runtime;
  99684. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99685. + int err;
  99686. +
  99687. + audio_info(" .. IN\n");
  99688. +
  99689. + err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  99690. + if (err < 0) {
  99691. + audio_error
  99692. + (" pcm_lib_malloc failed to allocated pages for buffers\n");
  99693. + return err;
  99694. + }
  99695. +
  99696. + alsa_stream->channels = params_channels(params);
  99697. + alsa_stream->params_rate = params_rate(params);
  99698. + alsa_stream->pcm_format_width = snd_pcm_format_width(params_format (params));
  99699. + audio_info(" .. OUT\n");
  99700. +
  99701. + return err;
  99702. +}
  99703. +
  99704. +/* hw_free callback */
  99705. +static int snd_bcm2835_pcm_hw_free(struct snd_pcm_substream *substream)
  99706. +{
  99707. + audio_info(" .. IN\n");
  99708. + return snd_pcm_lib_free_pages(substream);
  99709. +}
  99710. +
  99711. +/* prepare callback */
  99712. +static int snd_bcm2835_pcm_prepare(struct snd_pcm_substream *substream)
  99713. +{
  99714. + bcm2835_chip_t *chip = snd_pcm_substream_chip(substream);
  99715. + struct snd_pcm_runtime *runtime = substream->runtime;
  99716. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99717. + int channels;
  99718. + int err;
  99719. +
  99720. + audio_info(" .. IN\n");
  99721. +
  99722. + /* notify the vchiq that it should enter spdif passthrough mode by
  99723. + * setting channels=0 (see
  99724. + * https://github.com/raspberrypi/linux/issues/528) */
  99725. + if (chip->spdif_status & IEC958_AES0_NONAUDIO)
  99726. + channels = 0;
  99727. + else
  99728. + channels = alsa_stream->channels;
  99729. +
  99730. + err = bcm2835_audio_set_params(alsa_stream, channels,
  99731. + alsa_stream->params_rate,
  99732. + alsa_stream->pcm_format_width);
  99733. + if (err < 0) {
  99734. + audio_error(" error setting hw params\n");
  99735. + }
  99736. +
  99737. + bcm2835_audio_setup(alsa_stream);
  99738. +
  99739. + /* in preparation of the stream, set the controls (volume level) of the stream */
  99740. + bcm2835_audio_set_ctls(alsa_stream->chip);
  99741. +
  99742. +
  99743. + memset(&alsa_stream->pcm_indirect, 0, sizeof(alsa_stream->pcm_indirect));
  99744. +
  99745. + alsa_stream->pcm_indirect.hw_buffer_size =
  99746. + alsa_stream->pcm_indirect.sw_buffer_size =
  99747. + snd_pcm_lib_buffer_bytes(substream);
  99748. +
  99749. + alsa_stream->buffer_size = snd_pcm_lib_buffer_bytes(substream);
  99750. + alsa_stream->period_size = snd_pcm_lib_period_bytes(substream);
  99751. + alsa_stream->pos = 0;
  99752. +
  99753. + audio_debug("buffer_size=%d, period_size=%d pos=%d frame_bits=%d\n",
  99754. + alsa_stream->buffer_size, alsa_stream->period_size,
  99755. + alsa_stream->pos, runtime->frame_bits);
  99756. +
  99757. + audio_info(" .. OUT\n");
  99758. + return 0;
  99759. +}
  99760. +
  99761. +static void snd_bcm2835_pcm_transfer(struct snd_pcm_substream *substream,
  99762. + struct snd_pcm_indirect *rec, size_t bytes)
  99763. +{
  99764. + struct snd_pcm_runtime *runtime = substream->runtime;
  99765. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99766. + void *src = (void *)(substream->runtime->dma_area + rec->sw_data);
  99767. + int err;
  99768. +
  99769. + err = bcm2835_audio_write(alsa_stream, bytes, src);
  99770. + if (err)
  99771. + audio_error(" Failed to transfer to alsa device (%d)\n", err);
  99772. +
  99773. +}
  99774. +
  99775. +static int snd_bcm2835_pcm_ack(struct snd_pcm_substream *substream)
  99776. +{
  99777. + struct snd_pcm_runtime *runtime = substream->runtime;
  99778. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99779. + struct snd_pcm_indirect *pcm_indirect = &alsa_stream->pcm_indirect;
  99780. +
  99781. + pcm_indirect->hw_queue_size = runtime->hw.buffer_bytes_max;
  99782. + snd_pcm_indirect_playback_transfer(substream, pcm_indirect,
  99783. + snd_bcm2835_pcm_transfer);
  99784. + return 0;
  99785. +}
  99786. +
  99787. +/* trigger callback */
  99788. +static int snd_bcm2835_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
  99789. +{
  99790. + struct snd_pcm_runtime *runtime = substream->runtime;
  99791. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99792. + int err = 0;
  99793. +
  99794. + audio_info(" .. IN\n");
  99795. +
  99796. + switch (cmd) {
  99797. + case SNDRV_PCM_TRIGGER_START:
  99798. + audio_debug("bcm2835_AUDIO_TRIGGER_START running=%d\n",
  99799. + alsa_stream->running);
  99800. + if (!alsa_stream->running) {
  99801. + err = bcm2835_audio_start(alsa_stream);
  99802. + if (err == 0) {
  99803. + alsa_stream->pcm_indirect.hw_io =
  99804. + alsa_stream->pcm_indirect.hw_data =
  99805. + bytes_to_frames(runtime,
  99806. + alsa_stream->pos);
  99807. + substream->ops->ack(substream);
  99808. + alsa_stream->running = 1;
  99809. + alsa_stream->draining = 1;
  99810. + } else {
  99811. + audio_error(" Failed to START alsa device (%d)\n", err);
  99812. + }
  99813. + }
  99814. + break;
  99815. + case SNDRV_PCM_TRIGGER_STOP:
  99816. + audio_debug
  99817. + ("bcm2835_AUDIO_TRIGGER_STOP running=%d draining=%d\n",
  99818. + alsa_stream->running, runtime->status->state == SNDRV_PCM_STATE_DRAINING);
  99819. + if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
  99820. + audio_info("DRAINING\n");
  99821. + alsa_stream->draining = 1;
  99822. + } else {
  99823. + audio_info("DROPPING\n");
  99824. + alsa_stream->draining = 0;
  99825. + }
  99826. + if (alsa_stream->running) {
  99827. + err = bcm2835_audio_stop(alsa_stream);
  99828. + if (err != 0)
  99829. + audio_error(" Failed to STOP alsa device (%d)\n", err);
  99830. + alsa_stream->running = 0;
  99831. + }
  99832. + break;
  99833. + default:
  99834. + err = -EINVAL;
  99835. + }
  99836. +
  99837. + audio_info(" .. OUT\n");
  99838. + return err;
  99839. +}
  99840. +
  99841. +/* pointer callback */
  99842. +static snd_pcm_uframes_t
  99843. +snd_bcm2835_pcm_pointer(struct snd_pcm_substream *substream)
  99844. +{
  99845. + struct snd_pcm_runtime *runtime = substream->runtime;
  99846. + bcm2835_alsa_stream_t *alsa_stream = runtime->private_data;
  99847. +
  99848. + audio_info(" .. IN\n");
  99849. +
  99850. + audio_debug("pcm_pointer... (%d) hwptr=%d appl=%d pos=%d\n", 0,
  99851. + frames_to_bytes(runtime, runtime->status->hw_ptr),
  99852. + frames_to_bytes(runtime, runtime->control->appl_ptr),
  99853. + alsa_stream->pos);
  99854. +
  99855. + audio_info(" .. OUT\n");
  99856. + return snd_pcm_indirect_playback_pointer(substream,
  99857. + &alsa_stream->pcm_indirect,
  99858. + alsa_stream->pos);
  99859. +}
  99860. +
  99861. +static int snd_bcm2835_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  99862. + unsigned int cmd, void *arg)
  99863. +{
  99864. + int ret = snd_pcm_lib_ioctl(substream, cmd, arg);
  99865. + audio_info(" .. substream=%p, cmd=%d, arg=%p (%x) ret=%d\n", substream,
  99866. + cmd, arg, arg ? *(unsigned *)arg : 0, ret);
  99867. + return ret;
  99868. +}
  99869. +
  99870. +/* operators */
  99871. +static struct snd_pcm_ops snd_bcm2835_playback_ops = {
  99872. + .open = snd_bcm2835_playback_open,
  99873. + .close = snd_bcm2835_playback_close,
  99874. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  99875. + .hw_params = snd_bcm2835_pcm_hw_params,
  99876. + .hw_free = snd_bcm2835_pcm_hw_free,
  99877. + .prepare = snd_bcm2835_pcm_prepare,
  99878. + .trigger = snd_bcm2835_pcm_trigger,
  99879. + .pointer = snd_bcm2835_pcm_pointer,
  99880. + .ack = snd_bcm2835_pcm_ack,
  99881. +};
  99882. +
  99883. +static struct snd_pcm_ops snd_bcm2835_playback_spdif_ops = {
  99884. + .open = snd_bcm2835_playback_spdif_open,
  99885. + .close = snd_bcm2835_playback_close,
  99886. + .ioctl = snd_bcm2835_pcm_lib_ioctl,
  99887. + .hw_params = snd_bcm2835_pcm_hw_params,
  99888. + .hw_free = snd_bcm2835_pcm_hw_free,
  99889. + .prepare = snd_bcm2835_pcm_prepare,
  99890. + .trigger = snd_bcm2835_pcm_trigger,
  99891. + .pointer = snd_bcm2835_pcm_pointer,
  99892. + .ack = snd_bcm2835_pcm_ack,
  99893. +};
  99894. +
  99895. +/* create a pcm device */
  99896. +int snd_bcm2835_new_pcm(bcm2835_chip_t * chip)
  99897. +{
  99898. + struct snd_pcm *pcm;
  99899. + int err;
  99900. +
  99901. + audio_info(" .. IN\n");
  99902. + err =
  99903. + snd_pcm_new(chip->card, "bcm2835 ALSA", 0, MAX_SUBSTREAMS, 0, &pcm);
  99904. + if (err < 0)
  99905. + return err;
  99906. + pcm->private_data = chip;
  99907. + strcpy(pcm->name, "bcm2835 ALSA");
  99908. + chip->pcm = pcm;
  99909. + chip->dest = AUDIO_DEST_AUTO;
  99910. + chip->volume = alsa2chip(0);
  99911. + chip->mute = CTRL_VOL_UNMUTE; /*disable mute on startup */
  99912. + /* set operators */
  99913. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  99914. + &snd_bcm2835_playback_ops);
  99915. +
  99916. + /* pre-allocation of buffers */
  99917. + /* NOTE: this may fail */
  99918. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  99919. + snd_dma_continuous_data
  99920. + (GFP_KERNEL), 64 * 1024,
  99921. + 64 * 1024);
  99922. +
  99923. + audio_info(" .. OUT\n");
  99924. +
  99925. + return 0;
  99926. +}
  99927. +
  99928. +int snd_bcm2835_new_spdif_pcm(bcm2835_chip_t * chip)
  99929. +{
  99930. + struct snd_pcm *pcm;
  99931. + int err;
  99932. +
  99933. + err = snd_pcm_new(chip->card, "bcm2835 ALSA", 1, 1, 0, &pcm);
  99934. + if (err < 0)
  99935. + return err;
  99936. +
  99937. + pcm->private_data = chip;
  99938. + strcpy(pcm->name, "bcm2835 IEC958/HDMI");
  99939. + chip->pcm_spdif = pcm;
  99940. + snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  99941. + &snd_bcm2835_playback_spdif_ops);
  99942. +
  99943. + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  99944. + snd_dma_continuous_data (GFP_KERNEL),
  99945. + 64 * 1024, 64 * 1024);
  99946. +
  99947. + return 0;
  99948. +}
  99949. diff -Nur linux-3.15/sound/arm/bcm2835-vchiq.c linux-rpi/sound/arm/bcm2835-vchiq.c
  99950. --- linux-3.15/sound/arm/bcm2835-vchiq.c 1970-01-01 01:00:00.000000000 +0100
  99951. +++ linux-rpi/sound/arm/bcm2835-vchiq.c 2014-06-11 21:03:57.000000000 +0200
  99952. @@ -0,0 +1,879 @@
  99953. +/*****************************************************************************
  99954. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  99955. +*
  99956. +* Unless you and Broadcom execute a separate written software license
  99957. +* agreement governing use of this software, this software is licensed to you
  99958. +* under the terms of the GNU General Public License version 2, available at
  99959. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  99960. +*
  99961. +* Notwithstanding the above, under no circumstances may you combine this
  99962. +* software in any way with any other Broadcom software provided under a
  99963. +* license other than the GPL, without Broadcom's express prior written
  99964. +* consent.
  99965. +*****************************************************************************/
  99966. +
  99967. +#include <linux/device.h>
  99968. +#include <sound/core.h>
  99969. +#include <sound/initval.h>
  99970. +#include <sound/pcm.h>
  99971. +#include <linux/io.h>
  99972. +#include <linux/interrupt.h>
  99973. +#include <linux/fs.h>
  99974. +#include <linux/file.h>
  99975. +#include <linux/mm.h>
  99976. +#include <linux/syscalls.h>
  99977. +#include <asm/uaccess.h>
  99978. +#include <linux/slab.h>
  99979. +#include <linux/delay.h>
  99980. +#include <linux/atomic.h>
  99981. +#include <linux/module.h>
  99982. +#include <linux/completion.h>
  99983. +
  99984. +#include "bcm2835.h"
  99985. +
  99986. +/* ---- Include Files -------------------------------------------------------- */
  99987. +
  99988. +#include "interface/vchi/vchi.h"
  99989. +#include "vc_vchi_audioserv_defs.h"
  99990. +
  99991. +/* ---- Private Constants and Types ------------------------------------------ */
  99992. +
  99993. +#define BCM2835_AUDIO_STOP 0
  99994. +#define BCM2835_AUDIO_START 1
  99995. +#define BCM2835_AUDIO_WRITE 2
  99996. +
  99997. +/* Logging macros (for remapping to other logging mechanisms, i.e., printf) */
  99998. +#ifdef AUDIO_DEBUG_ENABLE
  99999. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100000. + #define LOG_WARN( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100001. + #define LOG_INFO( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100002. + #define LOG_DBG( fmt, arg... ) pr_info( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100003. +#else
  100004. + #define LOG_ERR( fmt, arg... ) pr_err( "%s:%d " fmt, __func__, __LINE__, ##arg)
  100005. + #define LOG_WARN( fmt, arg... )
  100006. + #define LOG_INFO( fmt, arg... )
  100007. + #define LOG_DBG( fmt, arg... )
  100008. +#endif
  100009. +
  100010. +typedef struct opaque_AUDIO_INSTANCE_T {
  100011. + uint32_t num_connections;
  100012. + VCHI_SERVICE_HANDLE_T vchi_handle[VCHI_MAX_NUM_CONNECTIONS];
  100013. + struct completion msg_avail_comp;
  100014. + struct mutex vchi_mutex;
  100015. + bcm2835_alsa_stream_t *alsa_stream;
  100016. + int32_t result;
  100017. + short peer_version;
  100018. +} AUDIO_INSTANCE_T;
  100019. +
  100020. +bool force_bulk = false;
  100021. +
  100022. +/* ---- Private Variables ---------------------------------------------------- */
  100023. +
  100024. +/* ---- Private Function Prototypes ------------------------------------------ */
  100025. +
  100026. +/* ---- Private Functions ---------------------------------------------------- */
  100027. +
  100028. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream);
  100029. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream);
  100030. +static int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  100031. + uint32_t count, void *src);
  100032. +
  100033. +typedef struct {
  100034. + struct work_struct my_work;
  100035. + bcm2835_alsa_stream_t *alsa_stream;
  100036. + int cmd;
  100037. + void *src;
  100038. + uint32_t count;
  100039. +} my_work_t;
  100040. +
  100041. +static void my_wq_function(struct work_struct *work)
  100042. +{
  100043. + my_work_t *w = (my_work_t *) work;
  100044. + int ret = -9;
  100045. + LOG_DBG(" .. IN %p:%d\n", w->alsa_stream, w->cmd);
  100046. + switch (w->cmd) {
  100047. + case BCM2835_AUDIO_START:
  100048. + ret = bcm2835_audio_start_worker(w->alsa_stream);
  100049. + break;
  100050. + case BCM2835_AUDIO_STOP:
  100051. + ret = bcm2835_audio_stop_worker(w->alsa_stream);
  100052. + break;
  100053. + case BCM2835_AUDIO_WRITE:
  100054. + ret = bcm2835_audio_write_worker(w->alsa_stream, w->count,
  100055. + w->src);
  100056. + break;
  100057. + default:
  100058. + LOG_ERR(" Unexpected work: %p:%d\n", w->alsa_stream, w->cmd);
  100059. + break;
  100060. + }
  100061. + kfree((void *)work);
  100062. + LOG_DBG(" .. OUT %d\n", ret);
  100063. +}
  100064. +
  100065. +int bcm2835_audio_start(bcm2835_alsa_stream_t * alsa_stream)
  100066. +{
  100067. + int ret = -1;
  100068. + LOG_DBG(" .. IN\n");
  100069. + if (alsa_stream->my_wq) {
  100070. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100071. + /*--- Queue some work (item 1) ---*/
  100072. + if (work) {
  100073. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100074. + work->alsa_stream = alsa_stream;
  100075. + work->cmd = BCM2835_AUDIO_START;
  100076. + if (queue_work
  100077. + (alsa_stream->my_wq, (struct work_struct *)work))
  100078. + ret = 0;
  100079. + } else
  100080. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100081. + }
  100082. + LOG_DBG(" .. OUT %d\n", ret);
  100083. + return ret;
  100084. +}
  100085. +
  100086. +int bcm2835_audio_stop(bcm2835_alsa_stream_t * alsa_stream)
  100087. +{
  100088. + int ret = -1;
  100089. + LOG_DBG(" .. IN\n");
  100090. + if (alsa_stream->my_wq) {
  100091. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100092. + /*--- Queue some work (item 1) ---*/
  100093. + if (work) {
  100094. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100095. + work->alsa_stream = alsa_stream;
  100096. + work->cmd = BCM2835_AUDIO_STOP;
  100097. + if (queue_work
  100098. + (alsa_stream->my_wq, (struct work_struct *)work))
  100099. + ret = 0;
  100100. + } else
  100101. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100102. + }
  100103. + LOG_DBG(" .. OUT %d\n", ret);
  100104. + return ret;
  100105. +}
  100106. +
  100107. +int bcm2835_audio_write(bcm2835_alsa_stream_t *alsa_stream,
  100108. + uint32_t count, void *src)
  100109. +{
  100110. + int ret = -1;
  100111. + LOG_DBG(" .. IN\n");
  100112. + if (alsa_stream->my_wq) {
  100113. + my_work_t *work = kmalloc(sizeof(my_work_t), GFP_ATOMIC);
  100114. + /*--- Queue some work (item 1) ---*/
  100115. + if (work) {
  100116. + INIT_WORK((struct work_struct *)work, my_wq_function);
  100117. + work->alsa_stream = alsa_stream;
  100118. + work->cmd = BCM2835_AUDIO_WRITE;
  100119. + work->src = src;
  100120. + work->count = count;
  100121. + if (queue_work
  100122. + (alsa_stream->my_wq, (struct work_struct *)work))
  100123. + ret = 0;
  100124. + } else
  100125. + LOG_ERR(" .. Error: NULL work kmalloc\n");
  100126. + }
  100127. + LOG_DBG(" .. OUT %d\n", ret);
  100128. + return ret;
  100129. +}
  100130. +
  100131. +void my_workqueue_init(bcm2835_alsa_stream_t * alsa_stream)
  100132. +{
  100133. + alsa_stream->my_wq = alloc_workqueue("my_queue", WQ_HIGHPRI, 1);
  100134. + return;
  100135. +}
  100136. +
  100137. +void my_workqueue_quit(bcm2835_alsa_stream_t * alsa_stream)
  100138. +{
  100139. + if (alsa_stream->my_wq) {
  100140. + flush_workqueue(alsa_stream->my_wq);
  100141. + destroy_workqueue(alsa_stream->my_wq);
  100142. + alsa_stream->my_wq = NULL;
  100143. + }
  100144. + return;
  100145. +}
  100146. +
  100147. +static void audio_vchi_callback(void *param,
  100148. + const VCHI_CALLBACK_REASON_T reason,
  100149. + void *msg_handle)
  100150. +{
  100151. + AUDIO_INSTANCE_T *instance = (AUDIO_INSTANCE_T *) param;
  100152. + int32_t status;
  100153. + int32_t msg_len;
  100154. + VC_AUDIO_MSG_T m;
  100155. + bcm2835_alsa_stream_t *alsa_stream = 0;
  100156. + LOG_DBG(" .. IN instance=%p, param=%p, reason=%d, handle=%p\n",
  100157. + instance, param, reason, msg_handle);
  100158. +
  100159. + if (!instance || reason != VCHI_CALLBACK_MSG_AVAILABLE) {
  100160. + return;
  100161. + }
  100162. + alsa_stream = instance->alsa_stream;
  100163. + status = vchi_msg_dequeue(instance->vchi_handle[0],
  100164. + &m, sizeof m, &msg_len, VCHI_FLAGS_NONE);
  100165. + if (m.type == VC_AUDIO_MSG_TYPE_RESULT) {
  100166. + LOG_DBG
  100167. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_RESULT, success=%d\n",
  100168. + instance, m.u.result.success);
  100169. + instance->result = m.u.result.success;
  100170. + complete(&instance->msg_avail_comp);
  100171. + } else if (m.type == VC_AUDIO_MSG_TYPE_COMPLETE) {
  100172. + irq_handler_t callback = (irq_handler_t) m.u.complete.callback;
  100173. + LOG_DBG
  100174. + (" .. instance=%p, m.type=VC_AUDIO_MSG_TYPE_COMPLETE, complete=%d\n",
  100175. + instance, m.u.complete.count);
  100176. + if (alsa_stream && callback) {
  100177. + atomic_add(m.u.complete.count, &alsa_stream->retrieved);
  100178. + callback(0, alsa_stream);
  100179. + } else {
  100180. + LOG_DBG(" .. unexpected alsa_stream=%p, callback=%p\n",
  100181. + alsa_stream, callback);
  100182. + }
  100183. + } else {
  100184. + LOG_DBG(" .. unexpected m.type=%d\n", m.type);
  100185. + }
  100186. + LOG_DBG(" .. OUT\n");
  100187. +}
  100188. +
  100189. +static AUDIO_INSTANCE_T *vc_vchi_audio_init(VCHI_INSTANCE_T vchi_instance,
  100190. + VCHI_CONNECTION_T **
  100191. + vchi_connections,
  100192. + uint32_t num_connections)
  100193. +{
  100194. + uint32_t i;
  100195. + AUDIO_INSTANCE_T *instance;
  100196. + int status;
  100197. +
  100198. + LOG_DBG("%s: start", __func__);
  100199. +
  100200. + if (num_connections > VCHI_MAX_NUM_CONNECTIONS) {
  100201. + LOG_ERR("%s: unsupported number of connections %u (max=%u)\n",
  100202. + __func__, num_connections, VCHI_MAX_NUM_CONNECTIONS);
  100203. +
  100204. + return NULL;
  100205. + }
  100206. + /* Allocate memory for this instance */
  100207. + instance = kmalloc(sizeof(*instance), GFP_KERNEL);
  100208. +
  100209. + memset(instance, 0, sizeof(*instance));
  100210. + instance->num_connections = num_connections;
  100211. +
  100212. + /* Create a lock for exclusive, serialized VCHI connection access */
  100213. + mutex_init(&instance->vchi_mutex);
  100214. + /* Open the VCHI service connections */
  100215. + for (i = 0; i < num_connections; i++) {
  100216. + SERVICE_CREATION_T params = {
  100217. + VCHI_VERSION_EX(VC_AUDIOSERV_VER, VC_AUDIOSERV_MIN_VER),
  100218. + VC_AUDIO_SERVER_NAME, // 4cc service code
  100219. + vchi_connections[i], // passed in fn pointers
  100220. + 0, // rx fifo size (unused)
  100221. + 0, // tx fifo size (unused)
  100222. + audio_vchi_callback, // service callback
  100223. + instance, // service callback parameter
  100224. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk recieves
  100225. + 1, //TODO: remove VCOS_FALSE, // unaligned bulk transmits
  100226. + 0 // want crc check on bulk transfers
  100227. + };
  100228. +
  100229. + status = vchi_service_open(vchi_instance, &params,
  100230. + &instance->vchi_handle[i]);
  100231. + if (status) {
  100232. + LOG_ERR
  100233. + ("%s: failed to open VCHI service connection (status=%d)\n",
  100234. + __func__, status);
  100235. +
  100236. + goto err_close_services;
  100237. + }
  100238. + /* Finished with the service for now */
  100239. + vchi_service_release(instance->vchi_handle[i]);
  100240. + }
  100241. +
  100242. + return instance;
  100243. +
  100244. +err_close_services:
  100245. + for (i = 0; i < instance->num_connections; i++) {
  100246. + vchi_service_close(instance->vchi_handle[i]);
  100247. + }
  100248. +
  100249. + kfree(instance);
  100250. +
  100251. + return NULL;
  100252. +}
  100253. +
  100254. +static int32_t vc_vchi_audio_deinit(AUDIO_INSTANCE_T * instance)
  100255. +{
  100256. + uint32_t i;
  100257. +
  100258. + LOG_DBG(" .. IN\n");
  100259. +
  100260. + if (instance == NULL) {
  100261. + LOG_ERR("%s: invalid handle %p\n", __func__, instance);
  100262. +
  100263. + return -1;
  100264. + }
  100265. +
  100266. + LOG_DBG(" .. about to lock (%d)\n", instance->num_connections);
  100267. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100268. + {
  100269. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100270. + return -EINTR;
  100271. + }
  100272. +
  100273. + /* Close all VCHI service connections */
  100274. + for (i = 0; i < instance->num_connections; i++) {
  100275. + int32_t success;
  100276. + LOG_DBG(" .. %i:closing %p\n", i, instance->vchi_handle[i]);
  100277. + vchi_service_use(instance->vchi_handle[i]);
  100278. +
  100279. + success = vchi_service_close(instance->vchi_handle[i]);
  100280. + if (success != 0) {
  100281. + LOG_ERR
  100282. + ("%s: failed to close VCHI service connection (status=%d)\n",
  100283. + __func__, success);
  100284. + }
  100285. + }
  100286. +
  100287. + mutex_unlock(&instance->vchi_mutex);
  100288. +
  100289. + kfree(instance);
  100290. +
  100291. + LOG_DBG(" .. OUT\n");
  100292. +
  100293. + return 0;
  100294. +}
  100295. +
  100296. +static int bcm2835_audio_open_connection(bcm2835_alsa_stream_t * alsa_stream)
  100297. +{
  100298. + static VCHI_INSTANCE_T vchi_instance;
  100299. + static VCHI_CONNECTION_T *vchi_connection;
  100300. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100301. + int ret;
  100302. + LOG_DBG(" .. IN\n");
  100303. +
  100304. + LOG_INFO("%s: start", __func__);
  100305. + //BUG_ON(instance);
  100306. + if (instance) {
  100307. + LOG_ERR("%s: VCHI instance already open (%p)\n",
  100308. + __func__, instance);
  100309. + instance->alsa_stream = alsa_stream;
  100310. + alsa_stream->instance = instance;
  100311. + ret = 0; // xxx todo -1;
  100312. + goto err_free_mem;
  100313. + }
  100314. +
  100315. + /* Initialize and create a VCHI connection */
  100316. + ret = vchi_initialise(&vchi_instance);
  100317. + if (ret != 0) {
  100318. + LOG_ERR("%s: failed to initialise VCHI instance (ret=%d)\n",
  100319. + __func__, ret);
  100320. +
  100321. + ret = -EIO;
  100322. + goto err_free_mem;
  100323. + }
  100324. + ret = vchi_connect(NULL, 0, vchi_instance);
  100325. + if (ret != 0) {
  100326. + LOG_ERR("%s: failed to connect VCHI instance (ret=%d)\n",
  100327. + __func__, ret);
  100328. +
  100329. + ret = -EIO;
  100330. + goto err_free_mem;
  100331. + }
  100332. +
  100333. + /* Initialize an instance of the audio service */
  100334. + instance = vc_vchi_audio_init(vchi_instance, &vchi_connection, 1);
  100335. +
  100336. + if (instance == NULL /*|| audio_handle != instance */ ) {
  100337. + LOG_ERR("%s: failed to initialize audio service\n", __func__);
  100338. +
  100339. + ret = -EPERM;
  100340. + goto err_free_mem;
  100341. + }
  100342. +
  100343. + instance->alsa_stream = alsa_stream;
  100344. + alsa_stream->instance = instance;
  100345. +
  100346. + LOG_DBG(" success !\n");
  100347. +err_free_mem:
  100348. + LOG_DBG(" .. OUT\n");
  100349. +
  100350. + return ret;
  100351. +}
  100352. +
  100353. +int bcm2835_audio_open(bcm2835_alsa_stream_t * alsa_stream)
  100354. +{
  100355. + AUDIO_INSTANCE_T *instance;
  100356. + VC_AUDIO_MSG_T m;
  100357. + int32_t success;
  100358. + int ret;
  100359. + LOG_DBG(" .. IN\n");
  100360. +
  100361. + my_workqueue_init(alsa_stream);
  100362. +
  100363. + ret = bcm2835_audio_open_connection(alsa_stream);
  100364. + if (ret != 0) {
  100365. + ret = -1;
  100366. + goto exit;
  100367. + }
  100368. + instance = alsa_stream->instance;
  100369. +
  100370. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100371. + {
  100372. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100373. + return -EINTR;
  100374. + }
  100375. + vchi_service_use(instance->vchi_handle[0]);
  100376. +
  100377. + m.type = VC_AUDIO_MSG_TYPE_OPEN;
  100378. +
  100379. + /* Send the message to the videocore */
  100380. + success = vchi_msg_queue(instance->vchi_handle[0],
  100381. + &m, sizeof m,
  100382. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100383. +
  100384. + if (success != 0) {
  100385. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  100386. + __func__, success);
  100387. +
  100388. + ret = -1;
  100389. + goto unlock;
  100390. + }
  100391. +
  100392. + ret = 0;
  100393. +
  100394. +unlock:
  100395. + vchi_service_release(instance->vchi_handle[0]);
  100396. + mutex_unlock(&instance->vchi_mutex);
  100397. +exit:
  100398. + LOG_DBG(" .. OUT\n");
  100399. + return ret;
  100400. +}
  100401. +
  100402. +static int bcm2835_audio_set_ctls_chan(bcm2835_alsa_stream_t * alsa_stream,
  100403. + bcm2835_chip_t * chip)
  100404. +{
  100405. + VC_AUDIO_MSG_T m;
  100406. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100407. + int32_t success;
  100408. + int ret;
  100409. + LOG_DBG(" .. IN\n");
  100410. +
  100411. + LOG_INFO
  100412. + (" Setting ALSA dest(%d), volume(%d)\n", chip->dest, chip->volume);
  100413. +
  100414. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100415. + {
  100416. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100417. + return -EINTR;
  100418. + }
  100419. + vchi_service_use(instance->vchi_handle[0]);
  100420. +
  100421. + instance->result = -1;
  100422. +
  100423. + m.type = VC_AUDIO_MSG_TYPE_CONTROL;
  100424. + m.u.control.dest = chip->dest;
  100425. + m.u.control.volume = chip->volume;
  100426. +
  100427. + /* Create the message available completion */
  100428. + init_completion(&instance->msg_avail_comp);
  100429. +
  100430. + /* Send the message to the videocore */
  100431. + success = vchi_msg_queue(instance->vchi_handle[0],
  100432. + &m, sizeof m,
  100433. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100434. +
  100435. + if (success != 0) {
  100436. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  100437. + __func__, success);
  100438. +
  100439. + ret = -1;
  100440. + goto unlock;
  100441. + }
  100442. +
  100443. + /* We are expecting a reply from the videocore */
  100444. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  100445. + if (ret) {
  100446. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  100447. + __func__, success);
  100448. + goto unlock;
  100449. + }
  100450. +
  100451. + if (instance->result != 0) {
  100452. + LOG_ERR("%s: result=%d\n", __func__, instance->result);
  100453. +
  100454. + ret = -1;
  100455. + goto unlock;
  100456. + }
  100457. +
  100458. + ret = 0;
  100459. +
  100460. +unlock:
  100461. + vchi_service_release(instance->vchi_handle[0]);
  100462. + mutex_unlock(&instance->vchi_mutex);
  100463. +
  100464. + LOG_DBG(" .. OUT\n");
  100465. + return ret;
  100466. +}
  100467. +
  100468. +int bcm2835_audio_set_ctls(bcm2835_chip_t * chip)
  100469. +{
  100470. + int i;
  100471. + int ret = 0;
  100472. + LOG_DBG(" .. IN\n");
  100473. +
  100474. + /* change ctls for all substreams */
  100475. + for (i = 0; i < MAX_SUBSTREAMS; i++) {
  100476. + if (chip->avail_substreams & (1 << i)) {
  100477. + if (!chip->alsa_stream[i])
  100478. + {
  100479. + LOG_DBG(" No ALSA stream available?! %i:%p (%x)\n", i, chip->alsa_stream[i], chip->avail_substreams);
  100480. + ret = 0;
  100481. + }
  100482. + else if (bcm2835_audio_set_ctls_chan /* returns 0 on success */
  100483. + (chip->alsa_stream[i], chip) != 0)
  100484. + {
  100485. + LOG_DBG("Couldn't set the controls for stream %d\n", i);
  100486. + ret = -1;
  100487. + }
  100488. + else LOG_DBG(" Controls set for stream %d\n", i);
  100489. + }
  100490. + }
  100491. + LOG_DBG(" .. OUT ret=%d\n", ret);
  100492. + return ret;
  100493. +}
  100494. +
  100495. +int bcm2835_audio_set_params(bcm2835_alsa_stream_t * alsa_stream,
  100496. + uint32_t channels, uint32_t samplerate,
  100497. + uint32_t bps)
  100498. +{
  100499. + VC_AUDIO_MSG_T m;
  100500. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100501. + int32_t success;
  100502. + int ret;
  100503. + LOG_DBG(" .. IN\n");
  100504. +
  100505. + LOG_INFO
  100506. + (" Setting ALSA channels(%d), samplerate(%d), bits-per-sample(%d)\n",
  100507. + channels, samplerate, bps);
  100508. +
  100509. + /* resend ctls - alsa_stream may not have been open when first send */
  100510. + ret = bcm2835_audio_set_ctls_chan(alsa_stream, alsa_stream->chip);
  100511. + if (ret != 0) {
  100512. + LOG_ERR(" Alsa controls not supported\n");
  100513. + return -EINVAL;
  100514. + }
  100515. +
  100516. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100517. + {
  100518. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100519. + return -EINTR;
  100520. + }
  100521. + vchi_service_use(instance->vchi_handle[0]);
  100522. +
  100523. + instance->result = -1;
  100524. +
  100525. + m.type = VC_AUDIO_MSG_TYPE_CONFIG;
  100526. + m.u.config.channels = channels;
  100527. + m.u.config.samplerate = samplerate;
  100528. + m.u.config.bps = bps;
  100529. +
  100530. + /* Create the message available completion */
  100531. + init_completion(&instance->msg_avail_comp);
  100532. +
  100533. + /* Send the message to the videocore */
  100534. + success = vchi_msg_queue(instance->vchi_handle[0],
  100535. + &m, sizeof m,
  100536. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100537. +
  100538. + if (success != 0) {
  100539. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)\n",
  100540. + __func__, success);
  100541. +
  100542. + ret = -1;
  100543. + goto unlock;
  100544. + }
  100545. +
  100546. + /* We are expecting a reply from the videocore */
  100547. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  100548. + if (ret) {
  100549. + LOG_ERR("%s: failed on waiting for event (status=%d)\n",
  100550. + __func__, success);
  100551. + goto unlock;
  100552. + }
  100553. +
  100554. + if (instance->result != 0) {
  100555. + LOG_ERR("%s: result=%d", __func__, instance->result);
  100556. +
  100557. + ret = -1;
  100558. + goto unlock;
  100559. + }
  100560. +
  100561. + ret = 0;
  100562. +
  100563. +unlock:
  100564. + vchi_service_release(instance->vchi_handle[0]);
  100565. + mutex_unlock(&instance->vchi_mutex);
  100566. +
  100567. + LOG_DBG(" .. OUT\n");
  100568. + return ret;
  100569. +}
  100570. +
  100571. +int bcm2835_audio_setup(bcm2835_alsa_stream_t * alsa_stream)
  100572. +{
  100573. + LOG_DBG(" .. IN\n");
  100574. +
  100575. + LOG_DBG(" .. OUT\n");
  100576. +
  100577. + return 0;
  100578. +}
  100579. +
  100580. +static int bcm2835_audio_start_worker(bcm2835_alsa_stream_t * alsa_stream)
  100581. +{
  100582. + VC_AUDIO_MSG_T m;
  100583. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100584. + int32_t success;
  100585. + int ret;
  100586. + LOG_DBG(" .. IN\n");
  100587. +
  100588. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100589. + {
  100590. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100591. + return -EINTR;
  100592. + }
  100593. + vchi_service_use(instance->vchi_handle[0]);
  100594. +
  100595. + m.type = VC_AUDIO_MSG_TYPE_START;
  100596. +
  100597. + /* Send the message to the videocore */
  100598. + success = vchi_msg_queue(instance->vchi_handle[0],
  100599. + &m, sizeof m,
  100600. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100601. +
  100602. + if (success != 0) {
  100603. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  100604. + __func__, success);
  100605. +
  100606. + ret = -1;
  100607. + goto unlock;
  100608. + }
  100609. +
  100610. + ret = 0;
  100611. +
  100612. +unlock:
  100613. + vchi_service_release(instance->vchi_handle[0]);
  100614. + mutex_unlock(&instance->vchi_mutex);
  100615. + LOG_DBG(" .. OUT\n");
  100616. + return ret;
  100617. +}
  100618. +
  100619. +static int bcm2835_audio_stop_worker(bcm2835_alsa_stream_t * alsa_stream)
  100620. +{
  100621. + VC_AUDIO_MSG_T m;
  100622. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100623. + int32_t success;
  100624. + int ret;
  100625. + LOG_DBG(" .. IN\n");
  100626. +
  100627. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100628. + {
  100629. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100630. + return -EINTR;
  100631. + }
  100632. + vchi_service_use(instance->vchi_handle[0]);
  100633. +
  100634. + m.type = VC_AUDIO_MSG_TYPE_STOP;
  100635. + m.u.stop.draining = alsa_stream->draining;
  100636. +
  100637. + /* Send the message to the videocore */
  100638. + success = vchi_msg_queue(instance->vchi_handle[0],
  100639. + &m, sizeof m,
  100640. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100641. +
  100642. + if (success != 0) {
  100643. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  100644. + __func__, success);
  100645. +
  100646. + ret = -1;
  100647. + goto unlock;
  100648. + }
  100649. +
  100650. + ret = 0;
  100651. +
  100652. +unlock:
  100653. + vchi_service_release(instance->vchi_handle[0]);
  100654. + mutex_unlock(&instance->vchi_mutex);
  100655. + LOG_DBG(" .. OUT\n");
  100656. + return ret;
  100657. +}
  100658. +
  100659. +int bcm2835_audio_close(bcm2835_alsa_stream_t * alsa_stream)
  100660. +{
  100661. + VC_AUDIO_MSG_T m;
  100662. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100663. + int32_t success;
  100664. + int ret;
  100665. + LOG_DBG(" .. IN\n");
  100666. +
  100667. + my_workqueue_quit(alsa_stream);
  100668. +
  100669. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100670. + {
  100671. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100672. + return -EINTR;
  100673. + }
  100674. + vchi_service_use(instance->vchi_handle[0]);
  100675. +
  100676. + m.type = VC_AUDIO_MSG_TYPE_CLOSE;
  100677. +
  100678. + /* Create the message available completion */
  100679. + init_completion(&instance->msg_avail_comp);
  100680. +
  100681. + /* Send the message to the videocore */
  100682. + success = vchi_msg_queue(instance->vchi_handle[0],
  100683. + &m, sizeof m,
  100684. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100685. +
  100686. + if (success != 0) {
  100687. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  100688. + __func__, success);
  100689. + ret = -1;
  100690. + goto unlock;
  100691. + }
  100692. +
  100693. + ret = wait_for_completion_interruptible(&instance->msg_avail_comp);
  100694. + if (ret) {
  100695. + LOG_ERR("%s: failed on waiting for event (status=%d)",
  100696. + __func__, success);
  100697. + goto unlock;
  100698. + }
  100699. + if (instance->result != 0) {
  100700. + LOG_ERR("%s: failed result (status=%d)",
  100701. + __func__, instance->result);
  100702. +
  100703. + ret = -1;
  100704. + goto unlock;
  100705. + }
  100706. +
  100707. + ret = 0;
  100708. +
  100709. +unlock:
  100710. + vchi_service_release(instance->vchi_handle[0]);
  100711. + mutex_unlock(&instance->vchi_mutex);
  100712. +
  100713. + /* Stop the audio service */
  100714. + if (instance) {
  100715. + vc_vchi_audio_deinit(instance);
  100716. + alsa_stream->instance = NULL;
  100717. + }
  100718. + LOG_DBG(" .. OUT\n");
  100719. + return ret;
  100720. +}
  100721. +
  100722. +int bcm2835_audio_write_worker(bcm2835_alsa_stream_t *alsa_stream,
  100723. + uint32_t count, void *src)
  100724. +{
  100725. + VC_AUDIO_MSG_T m;
  100726. + AUDIO_INSTANCE_T *instance = alsa_stream->instance;
  100727. + int32_t success;
  100728. + int ret;
  100729. +
  100730. + LOG_DBG(" .. IN\n");
  100731. +
  100732. + LOG_INFO(" Writing %d bytes from %p\n", count, src);
  100733. +
  100734. + if(mutex_lock_interruptible(&instance->vchi_mutex))
  100735. + {
  100736. + LOG_DBG("Interrupted whilst waiting for lock on (%d)\n",instance->num_connections);
  100737. + return -EINTR;
  100738. + }
  100739. + vchi_service_use(instance->vchi_handle[0]);
  100740. +
  100741. + if ( instance->peer_version==0 && vchi_get_peer_version(instance->vchi_handle[0], &instance->peer_version) == 0 ) {
  100742. + LOG_DBG("%s: client version %d connected\n", __func__, instance->peer_version);
  100743. + }
  100744. + m.type = VC_AUDIO_MSG_TYPE_WRITE;
  100745. + m.u.write.count = count;
  100746. + // old version uses bulk, new version uses control
  100747. + m.u.write.max_packet = instance->peer_version < 2 || force_bulk ? 0:4000;
  100748. + m.u.write.callback = alsa_stream->fifo_irq_handler;
  100749. + m.u.write.cookie = alsa_stream;
  100750. + m.u.write.silence = src == NULL;
  100751. +
  100752. + /* Send the message to the videocore */
  100753. + success = vchi_msg_queue(instance->vchi_handle[0],
  100754. + &m, sizeof m,
  100755. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100756. +
  100757. + if (success != 0) {
  100758. + LOG_ERR("%s: failed on vchi_msg_queue (status=%d)",
  100759. + __func__, success);
  100760. +
  100761. + ret = -1;
  100762. + goto unlock;
  100763. + }
  100764. + if (!m.u.write.silence) {
  100765. + if (m.u.write.max_packet == 0) {
  100766. + /* Send the message to the videocore */
  100767. + success = vchi_bulk_queue_transmit(instance->vchi_handle[0],
  100768. + src, count,
  100769. + 0 *
  100770. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED
  100771. + +
  100772. + 1 *
  100773. + VCHI_FLAGS_BLOCK_UNTIL_DATA_READ,
  100774. + NULL);
  100775. + } else {
  100776. + while (count > 0) {
  100777. + int bytes = min((int)m.u.write.max_packet, (int)count);
  100778. + success = vchi_msg_queue(instance->vchi_handle[0],
  100779. + src, bytes,
  100780. + VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL);
  100781. + src = (char *)src + bytes;
  100782. + count -= bytes;
  100783. + }
  100784. + }
  100785. + if (success != 0) {
  100786. + LOG_ERR
  100787. + ("%s: failed on vchi_bulk_queue_transmit (status=%d)",
  100788. + __func__, success);
  100789. +
  100790. + ret = -1;
  100791. + goto unlock;
  100792. + }
  100793. + }
  100794. + ret = 0;
  100795. +
  100796. +unlock:
  100797. + vchi_service_release(instance->vchi_handle[0]);
  100798. + mutex_unlock(&instance->vchi_mutex);
  100799. + LOG_DBG(" .. OUT\n");
  100800. + return ret;
  100801. +}
  100802. +
  100803. +/**
  100804. + * Returns all buffers from arm->vc
  100805. + */
  100806. +void bcm2835_audio_flush_buffers(bcm2835_alsa_stream_t * alsa_stream)
  100807. +{
  100808. + LOG_DBG(" .. IN\n");
  100809. + LOG_DBG(" .. OUT\n");
  100810. + return;
  100811. +}
  100812. +
  100813. +/**
  100814. + * Forces VC to flush(drop) its filled playback buffers and
  100815. + * return them the us. (VC->ARM)
  100816. + */
  100817. +void bcm2835_audio_flush_playback_buffers(bcm2835_alsa_stream_t * alsa_stream)
  100818. +{
  100819. + LOG_DBG(" .. IN\n");
  100820. + LOG_DBG(" .. OUT\n");
  100821. +}
  100822. +
  100823. +uint32_t bcm2835_audio_retrieve_buffers(bcm2835_alsa_stream_t * alsa_stream)
  100824. +{
  100825. + uint32_t count = atomic_read(&alsa_stream->retrieved);
  100826. + atomic_sub(count, &alsa_stream->retrieved);
  100827. + return count;
  100828. +}
  100829. +
  100830. +module_param(force_bulk, bool, 0444);
  100831. +MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk for audio");
  100832. diff -Nur linux-3.15/sound/arm/Kconfig linux-rpi/sound/arm/Kconfig
  100833. --- linux-3.15/sound/arm/Kconfig 2014-06-08 20:19:54.000000000 +0200
  100834. +++ linux-rpi/sound/arm/Kconfig 2014-06-11 21:03:57.000000000 +0200
  100835. @@ -39,5 +39,12 @@
  100836. Say Y or M if you want to support any AC97 codec attached to
  100837. the PXA2xx AC97 interface.
  100838. +config SND_BCM2835
  100839. + tristate "BCM2835 ALSA driver"
  100840. + depends on ARCH_BCM2708 && BCM2708_VCHIQ && SND
  100841. + select SND_PCM
  100842. + help
  100843. + Say Y or M if you want to support BCM2835 Alsa pcm card driver
  100844. +
  100845. endif # SND_ARM
  100846. diff -Nur linux-3.15/sound/arm/Makefile linux-rpi/sound/arm/Makefile
  100847. --- linux-3.15/sound/arm/Makefile 2014-06-08 20:19:54.000000000 +0200
  100848. +++ linux-rpi/sound/arm/Makefile 2014-06-11 21:03:57.000000000 +0200
  100849. @@ -14,3 +14,8 @@
  100850. obj-$(CONFIG_SND_PXA2XX_AC97) += snd-pxa2xx-ac97.o
  100851. snd-pxa2xx-ac97-objs := pxa2xx-ac97.o
  100852. +
  100853. +obj-$(CONFIG_SND_BCM2835) += snd-bcm2835.o
  100854. +snd-bcm2835-objs := bcm2835.o bcm2835-ctl.o bcm2835-pcm.o bcm2835-vchiq.o
  100855. +
  100856. +ccflags-y += -Idrivers/misc/vc04_services -Idrivers/misc/vc04_services/interface/vcos/linuxkernel -D__VCCOREVER__=0x04000000
  100857. diff -Nur linux-3.15/sound/arm/vc_vchi_audioserv_defs.h linux-rpi/sound/arm/vc_vchi_audioserv_defs.h
  100858. --- linux-3.15/sound/arm/vc_vchi_audioserv_defs.h 1970-01-01 01:00:00.000000000 +0100
  100859. +++ linux-rpi/sound/arm/vc_vchi_audioserv_defs.h 2014-06-11 21:03:57.000000000 +0200
  100860. @@ -0,0 +1,116 @@
  100861. +/*****************************************************************************
  100862. +* Copyright 2011 Broadcom Corporation. All rights reserved.
  100863. +*
  100864. +* Unless you and Broadcom execute a separate written software license
  100865. +* agreement governing use of this software, this software is licensed to you
  100866. +* under the terms of the GNU General Public License version 2, available at
  100867. +* http://www.broadcom.com/licenses/GPLv2.php (the "GPL").
  100868. +*
  100869. +* Notwithstanding the above, under no circumstances may you combine this
  100870. +* software in any way with any other Broadcom software provided under a
  100871. +* license other than the GPL, without Broadcom's express prior written
  100872. +* consent.
  100873. +*****************************************************************************/
  100874. +
  100875. +#ifndef _VC_AUDIO_DEFS_H_
  100876. +#define _VC_AUDIO_DEFS_H_
  100877. +
  100878. +#define VC_AUDIOSERV_MIN_VER 1
  100879. +#define VC_AUDIOSERV_VER 2
  100880. +
  100881. +// FourCC code used for VCHI connection
  100882. +#define VC_AUDIO_SERVER_NAME MAKE_FOURCC("AUDS")
  100883. +
  100884. +// Maximum message length
  100885. +#define VC_AUDIO_MAX_MSG_LEN (sizeof( VC_AUDIO_MSG_T ))
  100886. +
  100887. +// List of screens that are currently supported
  100888. +// All message types supported for HOST->VC direction
  100889. +typedef enum {
  100890. + VC_AUDIO_MSG_TYPE_RESULT, // Generic result
  100891. + VC_AUDIO_MSG_TYPE_COMPLETE, // Generic result
  100892. + VC_AUDIO_MSG_TYPE_CONFIG, // Configure audio
  100893. + VC_AUDIO_MSG_TYPE_CONTROL, // Configure audio
  100894. + VC_AUDIO_MSG_TYPE_OPEN, // Configure audio
  100895. + VC_AUDIO_MSG_TYPE_CLOSE, // Configure audio
  100896. + VC_AUDIO_MSG_TYPE_START, // Configure audio
  100897. + VC_AUDIO_MSG_TYPE_STOP, // Configure audio
  100898. + VC_AUDIO_MSG_TYPE_WRITE, // Configure audio
  100899. + VC_AUDIO_MSG_TYPE_MAX
  100900. +} VC_AUDIO_MSG_TYPE;
  100901. +
  100902. +// configure the audio
  100903. +typedef struct {
  100904. + uint32_t channels;
  100905. + uint32_t samplerate;
  100906. + uint32_t bps;
  100907. +
  100908. +} VC_AUDIO_CONFIG_T;
  100909. +
  100910. +typedef struct {
  100911. + uint32_t volume;
  100912. + uint32_t dest;
  100913. +
  100914. +} VC_AUDIO_CONTROL_T;
  100915. +
  100916. +// audio
  100917. +typedef struct {
  100918. + uint32_t dummy;
  100919. +
  100920. +} VC_AUDIO_OPEN_T;
  100921. +
  100922. +// audio
  100923. +typedef struct {
  100924. + uint32_t dummy;
  100925. +
  100926. +} VC_AUDIO_CLOSE_T;
  100927. +// audio
  100928. +typedef struct {
  100929. + uint32_t dummy;
  100930. +
  100931. +} VC_AUDIO_START_T;
  100932. +// audio
  100933. +typedef struct {
  100934. + uint32_t draining;
  100935. +
  100936. +} VC_AUDIO_STOP_T;
  100937. +
  100938. +// configure the write audio samples
  100939. +typedef struct {
  100940. + uint32_t count; // in bytes
  100941. + void *callback;
  100942. + void *cookie;
  100943. + uint16_t silence;
  100944. + uint16_t max_packet;
  100945. +} VC_AUDIO_WRITE_T;
  100946. +
  100947. +// Generic result for a request (VC->HOST)
  100948. +typedef struct {
  100949. + int32_t success; // Success value
  100950. +
  100951. +} VC_AUDIO_RESULT_T;
  100952. +
  100953. +// Generic result for a request (VC->HOST)
  100954. +typedef struct {
  100955. + int32_t count; // Success value
  100956. + void *callback;
  100957. + void *cookie;
  100958. +} VC_AUDIO_COMPLETE_T;
  100959. +
  100960. +// Message header for all messages in HOST->VC direction
  100961. +typedef struct {
  100962. + int32_t type; // Message type (VC_AUDIO_MSG_TYPE)
  100963. + union {
  100964. + VC_AUDIO_CONFIG_T config;
  100965. + VC_AUDIO_CONTROL_T control;
  100966. + VC_AUDIO_OPEN_T open;
  100967. + VC_AUDIO_CLOSE_T close;
  100968. + VC_AUDIO_START_T start;
  100969. + VC_AUDIO_STOP_T stop;
  100970. + VC_AUDIO_WRITE_T write;
  100971. + VC_AUDIO_RESULT_T result;
  100972. + VC_AUDIO_COMPLETE_T complete;
  100973. + } u;
  100974. +} VC_AUDIO_MSG_T;
  100975. +
  100976. +#endif // _VC_AUDIO_DEFS_H_
  100977. diff -Nur linux-3.15/sound/soc/bcm/bcm2708-i2s.c linux-rpi/sound/soc/bcm/bcm2708-i2s.c
  100978. --- linux-3.15/sound/soc/bcm/bcm2708-i2s.c 1970-01-01 01:00:00.000000000 +0100
  100979. +++ linux-rpi/sound/soc/bcm/bcm2708-i2s.c 2014-06-11 21:03:58.000000000 +0200
  100980. @@ -0,0 +1,946 @@
  100981. +/*
  100982. + * ALSA SoC I2S Audio Layer for Broadcom BCM2708 SoC
  100983. + *
  100984. + * Author: Florian Meier <florian.meier@koalo.de>
  100985. + * Copyright 2013
  100986. + *
  100987. + * Based on
  100988. + * Raspberry Pi PCM I2S ALSA Driver
  100989. + * Copyright (c) by Phil Poole 2013
  100990. + *
  100991. + * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
  100992. + * Vladimir Barinov, <vbarinov@embeddedalley.com>
  100993. + * Copyright (C) 2007 MontaVista Software, Inc., <source@mvista.com>
  100994. + *
  100995. + * OMAP ALSA SoC DAI driver using McBSP port
  100996. + * Copyright (C) 2008 Nokia Corporation
  100997. + * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
  100998. + * Peter Ujfalusi <peter.ujfalusi@ti.com>
  100999. + *
  101000. + * Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
  101001. + * Author: Timur Tabi <timur@freescale.com>
  101002. + * Copyright 2007-2010 Freescale Semiconductor, Inc.
  101003. + *
  101004. + * This program is free software; you can redistribute it and/or
  101005. + * modify it under the terms of the GNU General Public License
  101006. + * version 2 as published by the Free Software Foundation.
  101007. + *
  101008. + * This program is distributed in the hope that it will be useful, but
  101009. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  101010. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101011. + * General Public License for more details.
  101012. + */
  101013. +
  101014. +#include <linux/init.h>
  101015. +#include <linux/module.h>
  101016. +#include <linux/device.h>
  101017. +#include <linux/slab.h>
  101018. +#include <linux/delay.h>
  101019. +#include <linux/io.h>
  101020. +#include <linux/clk.h>
  101021. +
  101022. +#include <sound/core.h>
  101023. +#include <sound/pcm.h>
  101024. +#include <sound/pcm_params.h>
  101025. +#include <sound/initval.h>
  101026. +#include <sound/soc.h>
  101027. +#include <sound/dmaengine_pcm.h>
  101028. +
  101029. +/* Clock registers */
  101030. +#define BCM2708_CLK_PCMCTL_REG 0x00
  101031. +#define BCM2708_CLK_PCMDIV_REG 0x04
  101032. +
  101033. +/* Clock register settings */
  101034. +#define BCM2708_CLK_PASSWD (0x5a000000)
  101035. +#define BCM2708_CLK_PASSWD_MASK (0xff000000)
  101036. +#define BCM2708_CLK_MASH(v) ((v) << 9)
  101037. +#define BCM2708_CLK_FLIP BIT(8)
  101038. +#define BCM2708_CLK_BUSY BIT(7)
  101039. +#define BCM2708_CLK_KILL BIT(5)
  101040. +#define BCM2708_CLK_ENAB BIT(4)
  101041. +#define BCM2708_CLK_SRC(v) (v)
  101042. +
  101043. +#define BCM2708_CLK_SHIFT (12)
  101044. +#define BCM2708_CLK_DIVI(v) ((v) << BCM2708_CLK_SHIFT)
  101045. +#define BCM2708_CLK_DIVF(v) (v)
  101046. +#define BCM2708_CLK_DIVF_MASK (0xFFF)
  101047. +
  101048. +enum {
  101049. + BCM2708_CLK_MASH_0 = 0,
  101050. + BCM2708_CLK_MASH_1,
  101051. + BCM2708_CLK_MASH_2,
  101052. + BCM2708_CLK_MASH_3,
  101053. +};
  101054. +
  101055. +enum {
  101056. + BCM2708_CLK_SRC_GND = 0,
  101057. + BCM2708_CLK_SRC_OSC,
  101058. + BCM2708_CLK_SRC_DBG0,
  101059. + BCM2708_CLK_SRC_DBG1,
  101060. + BCM2708_CLK_SRC_PLLA,
  101061. + BCM2708_CLK_SRC_PLLC,
  101062. + BCM2708_CLK_SRC_PLLD,
  101063. + BCM2708_CLK_SRC_HDMI,
  101064. +};
  101065. +
  101066. +/* Most clocks are not useable (freq = 0) */
  101067. +static const unsigned int bcm2708_clk_freq[BCM2708_CLK_SRC_HDMI+1] = {
  101068. + [BCM2708_CLK_SRC_GND] = 0,
  101069. + [BCM2708_CLK_SRC_OSC] = 19200000,
  101070. + [BCM2708_CLK_SRC_DBG0] = 0,
  101071. + [BCM2708_CLK_SRC_DBG1] = 0,
  101072. + [BCM2708_CLK_SRC_PLLA] = 0,
  101073. + [BCM2708_CLK_SRC_PLLC] = 0,
  101074. + [BCM2708_CLK_SRC_PLLD] = 500000000,
  101075. + [BCM2708_CLK_SRC_HDMI] = 0,
  101076. +};
  101077. +
  101078. +/* I2S registers */
  101079. +#define BCM2708_I2S_CS_A_REG 0x00
  101080. +#define BCM2708_I2S_FIFO_A_REG 0x04
  101081. +#define BCM2708_I2S_MODE_A_REG 0x08
  101082. +#define BCM2708_I2S_RXC_A_REG 0x0c
  101083. +#define BCM2708_I2S_TXC_A_REG 0x10
  101084. +#define BCM2708_I2S_DREQ_A_REG 0x14
  101085. +#define BCM2708_I2S_INTEN_A_REG 0x18
  101086. +#define BCM2708_I2S_INTSTC_A_REG 0x1c
  101087. +#define BCM2708_I2S_GRAY_REG 0x20
  101088. +
  101089. +/* I2S register settings */
  101090. +#define BCM2708_I2S_STBY BIT(25)
  101091. +#define BCM2708_I2S_SYNC BIT(24)
  101092. +#define BCM2708_I2S_RXSEX BIT(23)
  101093. +#define BCM2708_I2S_RXF BIT(22)
  101094. +#define BCM2708_I2S_TXE BIT(21)
  101095. +#define BCM2708_I2S_RXD BIT(20)
  101096. +#define BCM2708_I2S_TXD BIT(19)
  101097. +#define BCM2708_I2S_RXR BIT(18)
  101098. +#define BCM2708_I2S_TXW BIT(17)
  101099. +#define BCM2708_I2S_CS_RXERR BIT(16)
  101100. +#define BCM2708_I2S_CS_TXERR BIT(15)
  101101. +#define BCM2708_I2S_RXSYNC BIT(14)
  101102. +#define BCM2708_I2S_TXSYNC BIT(13)
  101103. +#define BCM2708_I2S_DMAEN BIT(9)
  101104. +#define BCM2708_I2S_RXTHR(v) ((v) << 7)
  101105. +#define BCM2708_I2S_TXTHR(v) ((v) << 5)
  101106. +#define BCM2708_I2S_RXCLR BIT(4)
  101107. +#define BCM2708_I2S_TXCLR BIT(3)
  101108. +#define BCM2708_I2S_TXON BIT(2)
  101109. +#define BCM2708_I2S_RXON BIT(1)
  101110. +#define BCM2708_I2S_EN (1)
  101111. +
  101112. +#define BCM2708_I2S_CLKDIS BIT(28)
  101113. +#define BCM2708_I2S_PDMN BIT(27)
  101114. +#define BCM2708_I2S_PDME BIT(26)
  101115. +#define BCM2708_I2S_FRXP BIT(25)
  101116. +#define BCM2708_I2S_FTXP BIT(24)
  101117. +#define BCM2708_I2S_CLKM BIT(23)
  101118. +#define BCM2708_I2S_CLKI BIT(22)
  101119. +#define BCM2708_I2S_FSM BIT(21)
  101120. +#define BCM2708_I2S_FSI BIT(20)
  101121. +#define BCM2708_I2S_FLEN(v) ((v) << 10)
  101122. +#define BCM2708_I2S_FSLEN(v) (v)
  101123. +
  101124. +#define BCM2708_I2S_CHWEX BIT(15)
  101125. +#define BCM2708_I2S_CHEN BIT(14)
  101126. +#define BCM2708_I2S_CHPOS(v) ((v) << 4)
  101127. +#define BCM2708_I2S_CHWID(v) (v)
  101128. +#define BCM2708_I2S_CH1(v) ((v) << 16)
  101129. +#define BCM2708_I2S_CH2(v) (v)
  101130. +
  101131. +#define BCM2708_I2S_TX_PANIC(v) ((v) << 24)
  101132. +#define BCM2708_I2S_RX_PANIC(v) ((v) << 16)
  101133. +#define BCM2708_I2S_TX(v) ((v) << 8)
  101134. +#define BCM2708_I2S_RX(v) (v)
  101135. +
  101136. +#define BCM2708_I2S_INT_RXERR BIT(3)
  101137. +#define BCM2708_I2S_INT_TXERR BIT(2)
  101138. +#define BCM2708_I2S_INT_RXR BIT(1)
  101139. +#define BCM2708_I2S_INT_TXW BIT(0)
  101140. +
  101141. +/* I2S DMA interface */
  101142. +#define BCM2708_I2S_FIFO_PHYSICAL_ADDR 0x7E203004
  101143. +#define BCM2708_DMA_DREQ_PCM_TX 2
  101144. +#define BCM2708_DMA_DREQ_PCM_RX 3
  101145. +
  101146. +/* General device struct */
  101147. +struct bcm2708_i2s_dev {
  101148. + struct device *dev;
  101149. + struct snd_dmaengine_dai_dma_data dma_data[2];
  101150. + unsigned int fmt;
  101151. + unsigned int bclk_ratio;
  101152. +
  101153. + struct regmap *i2s_regmap;
  101154. + struct regmap *clk_regmap;
  101155. +};
  101156. +
  101157. +static void bcm2708_i2s_start_clock(struct bcm2708_i2s_dev *dev)
  101158. +{
  101159. + /* Start the clock if in master mode */
  101160. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  101161. +
  101162. + switch (master) {
  101163. + case SND_SOC_DAIFMT_CBS_CFS:
  101164. + case SND_SOC_DAIFMT_CBS_CFM:
  101165. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101166. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101167. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  101168. + break;
  101169. + default:
  101170. + break;
  101171. + }
  101172. +}
  101173. +
  101174. +static void bcm2708_i2s_stop_clock(struct bcm2708_i2s_dev *dev)
  101175. +{
  101176. + uint32_t clkreg;
  101177. + int timeout = 1000;
  101178. +
  101179. + /* Stop clock */
  101180. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101181. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101182. + BCM2708_CLK_PASSWD);
  101183. +
  101184. + /* Wait for the BUSY flag going down */
  101185. + while (--timeout) {
  101186. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  101187. + if (!(clkreg & BCM2708_CLK_BUSY))
  101188. + break;
  101189. + }
  101190. +
  101191. + if (!timeout) {
  101192. + /* KILL the clock */
  101193. + dev_err(dev->dev, "I2S clock didn't stop. Kill the clock!\n");
  101194. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101195. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD_MASK,
  101196. + BCM2708_CLK_KILL | BCM2708_CLK_PASSWD);
  101197. + }
  101198. +}
  101199. +
  101200. +static void bcm2708_i2s_clear_fifos(struct bcm2708_i2s_dev *dev,
  101201. + bool tx, bool rx)
  101202. +{
  101203. + int timeout = 1000;
  101204. + uint32_t syncval;
  101205. + uint32_t csreg;
  101206. + uint32_t i2s_active_state;
  101207. + uint32_t clkreg;
  101208. + uint32_t clk_active_state;
  101209. + uint32_t off;
  101210. + uint32_t clr;
  101211. +
  101212. + off = tx ? BCM2708_I2S_TXON : 0;
  101213. + off |= rx ? BCM2708_I2S_RXON : 0;
  101214. +
  101215. + clr = tx ? BCM2708_I2S_TXCLR : 0;
  101216. + clr |= rx ? BCM2708_I2S_RXCLR : 0;
  101217. +
  101218. + /* Backup the current state */
  101219. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101220. + i2s_active_state = csreg & (BCM2708_I2S_RXON | BCM2708_I2S_TXON);
  101221. +
  101222. + regmap_read(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, &clkreg);
  101223. + clk_active_state = clkreg & BCM2708_CLK_ENAB;
  101224. +
  101225. + /* Start clock if not running */
  101226. + if (!clk_active_state) {
  101227. + regmap_update_bits(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG,
  101228. + BCM2708_CLK_PASSWD_MASK | BCM2708_CLK_ENAB,
  101229. + BCM2708_CLK_PASSWD | BCM2708_CLK_ENAB);
  101230. + }
  101231. +
  101232. + /* Stop I2S module */
  101233. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, off, 0);
  101234. +
  101235. + /*
  101236. + * Clear the FIFOs
  101237. + * Requires at least 2 PCM clock cycles to take effect
  101238. + */
  101239. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, clr, clr);
  101240. +
  101241. + /* Wait for 2 PCM clock cycles */
  101242. +
  101243. + /*
  101244. + * Toggle the SYNC flag. After 2 PCM clock cycles it can be read back
  101245. + * FIXME: This does not seem to work for slave mode!
  101246. + */
  101247. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &syncval);
  101248. + syncval &= BCM2708_I2S_SYNC;
  101249. +
  101250. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101251. + BCM2708_I2S_SYNC, ~syncval);
  101252. +
  101253. + /* Wait for the SYNC flag changing it's state */
  101254. + while (--timeout) {
  101255. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101256. + if ((csreg & BCM2708_I2S_SYNC) != syncval)
  101257. + break;
  101258. + }
  101259. +
  101260. + if (!timeout)
  101261. + dev_err(dev->dev, "I2S SYNC error!\n");
  101262. +
  101263. + /* Stop clock if it was not running before */
  101264. + if (!clk_active_state)
  101265. + bcm2708_i2s_stop_clock(dev);
  101266. +
  101267. + /* Restore I2S state */
  101268. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101269. + BCM2708_I2S_RXON | BCM2708_I2S_TXON, i2s_active_state);
  101270. +}
  101271. +
  101272. +static int bcm2708_i2s_set_dai_fmt(struct snd_soc_dai *dai,
  101273. + unsigned int fmt)
  101274. +{
  101275. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101276. + dev->fmt = fmt;
  101277. + return 0;
  101278. +}
  101279. +
  101280. +static int bcm2708_i2s_set_dai_bclk_ratio(struct snd_soc_dai *dai,
  101281. + unsigned int ratio)
  101282. +{
  101283. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101284. + dev->bclk_ratio = ratio;
  101285. + return 0;
  101286. +}
  101287. +
  101288. +
  101289. +static void bcm2708_i2s_setup_gpio(void)
  101290. +{
  101291. + /*
  101292. + * This is the common way to handle the GPIO pins for
  101293. + * the Raspberry Pi.
  101294. + * TODO Better way would be to handle
  101295. + * this in the device tree!
  101296. + */
  101297. +#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
  101298. +#define SET_GPIO_ALT(g,a) *(gpio+(((g)/10))) |= (((a)<=3?(a)+4:(a)==4?3:2)<<(((g)%10)*3))
  101299. +
  101300. + unsigned int *gpio;
  101301. + int pin;
  101302. + gpio = ioremap(GPIO_BASE, SZ_16K);
  101303. +
  101304. + /* SPI is on GPIO 7..11 */
  101305. + for (pin = 28; pin <= 31; pin++) {
  101306. + INP_GPIO(pin); /* set mode to GPIO input first */
  101307. + SET_GPIO_ALT(pin, 2); /* set mode to ALT 0 */
  101308. + }
  101309. +#undef INP_GPIO
  101310. +#undef SET_GPIO_ALT
  101311. +}
  101312. +
  101313. +static int bcm2708_i2s_hw_params(struct snd_pcm_substream *substream,
  101314. + struct snd_pcm_hw_params *params,
  101315. + struct snd_soc_dai *dai)
  101316. +{
  101317. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101318. +
  101319. + unsigned int sampling_rate = params_rate(params);
  101320. + unsigned int data_length, data_delay, bclk_ratio;
  101321. + unsigned int ch1pos, ch2pos, mode, format;
  101322. + unsigned int mash = BCM2708_CLK_MASH_1;
  101323. + unsigned int divi, divf, target_frequency;
  101324. + int clk_src = -1;
  101325. + unsigned int master = dev->fmt & SND_SOC_DAIFMT_MASTER_MASK;
  101326. + bool bit_master = (master == SND_SOC_DAIFMT_CBS_CFS
  101327. + || master == SND_SOC_DAIFMT_CBS_CFM);
  101328. +
  101329. + bool frame_master = (master == SND_SOC_DAIFMT_CBS_CFS
  101330. + || master == SND_SOC_DAIFMT_CBM_CFS);
  101331. + uint32_t csreg;
  101332. +
  101333. + /*
  101334. + * If a stream is already enabled,
  101335. + * the registers are already set properly.
  101336. + */
  101337. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &csreg);
  101338. +
  101339. + if (csreg & (BCM2708_I2S_TXON | BCM2708_I2S_RXON))
  101340. + return 0;
  101341. +
  101342. +
  101343. + bcm2708_i2s_setup_gpio();
  101344. +
  101345. + /*
  101346. + * Adjust the data length according to the format.
  101347. + * We prefill the half frame length with an integer
  101348. + * divider of 2400 as explained at the clock settings.
  101349. + * Maybe it is overwritten there, if the Integer mode
  101350. + * does not apply.
  101351. + */
  101352. + switch (params_format(params)) {
  101353. + case SNDRV_PCM_FORMAT_S16_LE:
  101354. + data_length = 16;
  101355. + bclk_ratio = 40;
  101356. + break;
  101357. + case SNDRV_PCM_FORMAT_S24_LE:
  101358. + data_length = 24;
  101359. + bclk_ratio = 40;
  101360. + break;
  101361. + case SNDRV_PCM_FORMAT_S32_LE:
  101362. + data_length = 32;
  101363. + bclk_ratio = 80;
  101364. + break;
  101365. + default:
  101366. + return -EINVAL;
  101367. + }
  101368. +
  101369. + /* If bclk_ratio already set, use that one. */
  101370. + if (dev->bclk_ratio)
  101371. + bclk_ratio = dev->bclk_ratio;
  101372. +
  101373. + /*
  101374. + * Clock Settings
  101375. + *
  101376. + * The target frequency of the bit clock is
  101377. + * sampling rate * frame length
  101378. + *
  101379. + * Integer mode:
  101380. + * Sampling rates that are multiples of 8000 kHz
  101381. + * can be driven by the oscillator of 19.2 MHz
  101382. + * with an integer divider as long as the frame length
  101383. + * is an integer divider of 19200000/8000=2400 as set up above.
  101384. + * This is no longer possible if the sampling rate
  101385. + * is too high (e.g. 192 kHz), because the oscillator is too slow.
  101386. + *
  101387. + * MASH mode:
  101388. + * For all other sampling rates, it is not possible to
  101389. + * have an integer divider. Approximate the clock
  101390. + * with the MASH module that induces a slight frequency
  101391. + * variance. To minimize that it is best to have the fastest
  101392. + * clock here. That is PLLD with 500 MHz.
  101393. + */
  101394. + target_frequency = sampling_rate * bclk_ratio;
  101395. + clk_src = BCM2708_CLK_SRC_OSC;
  101396. + mash = BCM2708_CLK_MASH_0;
  101397. +
  101398. + if (bcm2708_clk_freq[clk_src] % target_frequency == 0
  101399. + && bit_master && frame_master) {
  101400. + divi = bcm2708_clk_freq[clk_src] / target_frequency;
  101401. + divf = 0;
  101402. + } else {
  101403. + uint64_t dividend;
  101404. +
  101405. + if (!dev->bclk_ratio) {
  101406. + /*
  101407. + * Overwrite bclk_ratio, because the
  101408. + * above trick is not needed or can
  101409. + * not be used.
  101410. + */
  101411. + bclk_ratio = 2 * data_length;
  101412. + }
  101413. +
  101414. + target_frequency = sampling_rate * bclk_ratio;
  101415. +
  101416. + clk_src = BCM2708_CLK_SRC_PLLD;
  101417. + mash = BCM2708_CLK_MASH_1;
  101418. +
  101419. + dividend = bcm2708_clk_freq[clk_src];
  101420. + dividend <<= BCM2708_CLK_SHIFT;
  101421. + do_div(dividend, target_frequency);
  101422. + divi = dividend >> BCM2708_CLK_SHIFT;
  101423. + divf = dividend & BCM2708_CLK_DIVF_MASK;
  101424. + }
  101425. +
  101426. + /* Set clock divider */
  101427. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
  101428. + | BCM2708_CLK_DIVI(divi)
  101429. + | BCM2708_CLK_DIVF(divf));
  101430. +
  101431. + /* Setup clock, but don't start it yet */
  101432. + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
  101433. + | BCM2708_CLK_MASH(mash)
  101434. + | BCM2708_CLK_SRC(clk_src));
  101435. +
  101436. + /* Setup the frame format */
  101437. + format = BCM2708_I2S_CHEN;
  101438. +
  101439. + if (data_length >= 24)
  101440. + format |= BCM2708_I2S_CHWEX;
  101441. +
  101442. + format |= BCM2708_I2S_CHWID((data_length-8)&0xf);
  101443. +
  101444. + switch (dev->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  101445. + case SND_SOC_DAIFMT_I2S:
  101446. + data_delay = 1;
  101447. + break;
  101448. + default:
  101449. + /*
  101450. + * TODO
  101451. + * Others are possible but are not implemented at the moment.
  101452. + */
  101453. + dev_err(dev->dev, "%s:bad format\n", __func__);
  101454. + return -EINVAL;
  101455. + }
  101456. +
  101457. + ch1pos = data_delay;
  101458. + ch2pos = bclk_ratio / 2 + data_delay;
  101459. +
  101460. + switch (params_channels(params)) {
  101461. + case 2:
  101462. + format = BCM2708_I2S_CH1(format) | BCM2708_I2S_CH2(format);
  101463. + format |= BCM2708_I2S_CH1(BCM2708_I2S_CHPOS(ch1pos));
  101464. + format |= BCM2708_I2S_CH2(BCM2708_I2S_CHPOS(ch2pos));
  101465. + break;
  101466. + default:
  101467. + return -EINVAL;
  101468. + }
  101469. +
  101470. + /*
  101471. + * Set format for both streams.
  101472. + * We cannot set another frame length
  101473. + * (and therefore word length) anyway,
  101474. + * so the format will be the same.
  101475. + */
  101476. + regmap_write(dev->i2s_regmap, BCM2708_I2S_RXC_A_REG, format);
  101477. + regmap_write(dev->i2s_regmap, BCM2708_I2S_TXC_A_REG, format);
  101478. +
  101479. + /* Setup the I2S mode */
  101480. + mode = 0;
  101481. +
  101482. + if (data_length <= 16) {
  101483. + /*
  101484. + * Use frame packed mode (2 channels per 32 bit word)
  101485. + * We cannot set another frame length in the second stream
  101486. + * (and therefore word length) anyway,
  101487. + * so the format will be the same.
  101488. + */
  101489. + mode |= BCM2708_I2S_FTXP | BCM2708_I2S_FRXP;
  101490. + }
  101491. +
  101492. + mode |= BCM2708_I2S_FLEN(bclk_ratio - 1);
  101493. + mode |= BCM2708_I2S_FSLEN(bclk_ratio / 2);
  101494. +
  101495. + /* Master or slave? */
  101496. + switch (dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  101497. + case SND_SOC_DAIFMT_CBS_CFS:
  101498. + /* CPU is master */
  101499. + break;
  101500. + case SND_SOC_DAIFMT_CBM_CFS:
  101501. + /*
  101502. + * CODEC is bit clock master
  101503. + * CPU is frame master
  101504. + */
  101505. + mode |= BCM2708_I2S_CLKM;
  101506. + break;
  101507. + case SND_SOC_DAIFMT_CBS_CFM:
  101508. + /*
  101509. + * CODEC is frame master
  101510. + * CPU is bit clock master
  101511. + */
  101512. + mode |= BCM2708_I2S_FSM;
  101513. + break;
  101514. + case SND_SOC_DAIFMT_CBM_CFM:
  101515. + /* CODEC is master */
  101516. + mode |= BCM2708_I2S_CLKM;
  101517. + mode |= BCM2708_I2S_FSM;
  101518. + break;
  101519. + default:
  101520. + dev_err(dev->dev, "%s:bad master\n", __func__);
  101521. + return -EINVAL;
  101522. + }
  101523. +
  101524. + /*
  101525. + * Invert clocks?
  101526. + *
  101527. + * The BCM approach seems to be inverted to the classical I2S approach.
  101528. + */
  101529. + switch (dev->fmt & SND_SOC_DAIFMT_INV_MASK) {
  101530. + case SND_SOC_DAIFMT_NB_NF:
  101531. + /* None. Therefore, both for BCM */
  101532. + mode |= BCM2708_I2S_CLKI;
  101533. + mode |= BCM2708_I2S_FSI;
  101534. + break;
  101535. + case SND_SOC_DAIFMT_IB_IF:
  101536. + /* Both. Therefore, none for BCM */
  101537. + break;
  101538. + case SND_SOC_DAIFMT_NB_IF:
  101539. + /*
  101540. + * Invert only frame sync. Therefore,
  101541. + * invert only bit clock for BCM
  101542. + */
  101543. + mode |= BCM2708_I2S_CLKI;
  101544. + break;
  101545. + case SND_SOC_DAIFMT_IB_NF:
  101546. + /*
  101547. + * Invert only bit clock. Therefore,
  101548. + * invert only frame sync for BCM
  101549. + */
  101550. + mode |= BCM2708_I2S_FSI;
  101551. + break;
  101552. + default:
  101553. + return -EINVAL;
  101554. + }
  101555. +
  101556. + regmap_write(dev->i2s_regmap, BCM2708_I2S_MODE_A_REG, mode);
  101557. +
  101558. + /* Setup the DMA parameters */
  101559. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101560. + BCM2708_I2S_RXTHR(1)
  101561. + | BCM2708_I2S_TXTHR(1)
  101562. + | BCM2708_I2S_DMAEN, 0xffffffff);
  101563. +
  101564. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_DREQ_A_REG,
  101565. + BCM2708_I2S_TX_PANIC(0x10)
  101566. + | BCM2708_I2S_RX_PANIC(0x30)
  101567. + | BCM2708_I2S_TX(0x30)
  101568. + | BCM2708_I2S_RX(0x20), 0xffffffff);
  101569. +
  101570. + /* Clear FIFOs */
  101571. + bcm2708_i2s_clear_fifos(dev, true, true);
  101572. +
  101573. + return 0;
  101574. +}
  101575. +
  101576. +static int bcm2708_i2s_prepare(struct snd_pcm_substream *substream,
  101577. + struct snd_soc_dai *dai)
  101578. +{
  101579. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101580. + uint32_t cs_reg;
  101581. +
  101582. + bcm2708_i2s_start_clock(dev);
  101583. +
  101584. + /*
  101585. + * Clear both FIFOs if the one that should be started
  101586. + * is not empty at the moment. This should only happen
  101587. + * after overrun. Otherwise, hw_params would have cleared
  101588. + * the FIFO.
  101589. + */
  101590. + regmap_read(dev->i2s_regmap, BCM2708_I2S_CS_A_REG, &cs_reg);
  101591. +
  101592. + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
  101593. + && !(cs_reg & BCM2708_I2S_TXE))
  101594. + bcm2708_i2s_clear_fifos(dev, true, false);
  101595. + else if (substream->stream == SNDRV_PCM_STREAM_CAPTURE
  101596. + && (cs_reg & BCM2708_I2S_RXD))
  101597. + bcm2708_i2s_clear_fifos(dev, false, true);
  101598. +
  101599. + return 0;
  101600. +}
  101601. +
  101602. +static void bcm2708_i2s_stop(struct bcm2708_i2s_dev *dev,
  101603. + struct snd_pcm_substream *substream,
  101604. + struct snd_soc_dai *dai)
  101605. +{
  101606. + uint32_t mask;
  101607. +
  101608. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  101609. + mask = BCM2708_I2S_RXON;
  101610. + else
  101611. + mask = BCM2708_I2S_TXON;
  101612. +
  101613. + regmap_update_bits(dev->i2s_regmap,
  101614. + BCM2708_I2S_CS_A_REG, mask, 0);
  101615. +
  101616. + /* Stop also the clock when not SND_SOC_DAIFMT_CONT */
  101617. + if (!dai->active && !(dev->fmt & SND_SOC_DAIFMT_CONT))
  101618. + bcm2708_i2s_stop_clock(dev);
  101619. +}
  101620. +
  101621. +static int bcm2708_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
  101622. + struct snd_soc_dai *dai)
  101623. +{
  101624. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101625. + uint32_t mask;
  101626. +
  101627. + switch (cmd) {
  101628. + case SNDRV_PCM_TRIGGER_START:
  101629. + case SNDRV_PCM_TRIGGER_RESUME:
  101630. + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  101631. + bcm2708_i2s_start_clock(dev);
  101632. +
  101633. + if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
  101634. + mask = BCM2708_I2S_RXON;
  101635. + else
  101636. + mask = BCM2708_I2S_TXON;
  101637. +
  101638. + regmap_update_bits(dev->i2s_regmap,
  101639. + BCM2708_I2S_CS_A_REG, mask, mask);
  101640. + break;
  101641. +
  101642. + case SNDRV_PCM_TRIGGER_STOP:
  101643. + case SNDRV_PCM_TRIGGER_SUSPEND:
  101644. + case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  101645. + bcm2708_i2s_stop(dev, substream, dai);
  101646. + break;
  101647. + default:
  101648. + return -EINVAL;
  101649. + }
  101650. +
  101651. + return 0;
  101652. +}
  101653. +
  101654. +static int bcm2708_i2s_startup(struct snd_pcm_substream *substream,
  101655. + struct snd_soc_dai *dai)
  101656. +{
  101657. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101658. +
  101659. + if (dai->active)
  101660. + return 0;
  101661. +
  101662. + /* Should this still be running stop it */
  101663. + bcm2708_i2s_stop_clock(dev);
  101664. +
  101665. + /* Enable PCM block */
  101666. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101667. + BCM2708_I2S_EN, BCM2708_I2S_EN);
  101668. +
  101669. + /*
  101670. + * Disable STBY.
  101671. + * Requires at least 4 PCM clock cycles to take effect.
  101672. + */
  101673. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101674. + BCM2708_I2S_STBY, BCM2708_I2S_STBY);
  101675. +
  101676. + return 0;
  101677. +}
  101678. +
  101679. +static void bcm2708_i2s_shutdown(struct snd_pcm_substream *substream,
  101680. + struct snd_soc_dai *dai)
  101681. +{
  101682. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101683. +
  101684. + bcm2708_i2s_stop(dev, substream, dai);
  101685. +
  101686. + /* If both streams are stopped, disable module and clock */
  101687. + if (dai->active)
  101688. + return;
  101689. +
  101690. + /* Disable the module */
  101691. + regmap_update_bits(dev->i2s_regmap, BCM2708_I2S_CS_A_REG,
  101692. + BCM2708_I2S_EN, 0);
  101693. +
  101694. + /*
  101695. + * Stopping clock is necessary, because stop does
  101696. + * not stop the clock when SND_SOC_DAIFMT_CONT
  101697. + */
  101698. + bcm2708_i2s_stop_clock(dev);
  101699. +}
  101700. +
  101701. +static const struct snd_soc_dai_ops bcm2708_i2s_dai_ops = {
  101702. + .startup = bcm2708_i2s_startup,
  101703. + .shutdown = bcm2708_i2s_shutdown,
  101704. + .prepare = bcm2708_i2s_prepare,
  101705. + .trigger = bcm2708_i2s_trigger,
  101706. + .hw_params = bcm2708_i2s_hw_params,
  101707. + .set_fmt = bcm2708_i2s_set_dai_fmt,
  101708. + .set_bclk_ratio = bcm2708_i2s_set_dai_bclk_ratio
  101709. +};
  101710. +
  101711. +static int bcm2708_i2s_dai_probe(struct snd_soc_dai *dai)
  101712. +{
  101713. + struct bcm2708_i2s_dev *dev = snd_soc_dai_get_drvdata(dai);
  101714. +
  101715. + dai->playback_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK];
  101716. + dai->capture_dma_data = &dev->dma_data[SNDRV_PCM_STREAM_CAPTURE];
  101717. +
  101718. + return 0;
  101719. +}
  101720. +
  101721. +static struct snd_soc_dai_driver bcm2708_i2s_dai = {
  101722. + .name = "bcm2708-i2s",
  101723. + .probe = bcm2708_i2s_dai_probe,
  101724. + .playback = {
  101725. + .channels_min = 2,
  101726. + .channels_max = 2,
  101727. + .rates = SNDRV_PCM_RATE_8000_192000,
  101728. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  101729. + // | SNDRV_PCM_FMTBIT_S24_LE : disable for now, it causes white noise with xbmc
  101730. + | SNDRV_PCM_FMTBIT_S32_LE
  101731. + },
  101732. + .capture = {
  101733. + .channels_min = 2,
  101734. + .channels_max = 2,
  101735. + .rates = SNDRV_PCM_RATE_8000_192000,
  101736. + .formats = SNDRV_PCM_FMTBIT_S16_LE
  101737. + | SNDRV_PCM_FMTBIT_S24_LE
  101738. + | SNDRV_PCM_FMTBIT_S32_LE
  101739. + },
  101740. + .ops = &bcm2708_i2s_dai_ops,
  101741. + .symmetric_rates = 1
  101742. +};
  101743. +
  101744. +static bool bcm2708_i2s_volatile_reg(struct device *dev, unsigned int reg)
  101745. +{
  101746. + switch (reg) {
  101747. + case BCM2708_I2S_CS_A_REG:
  101748. + case BCM2708_I2S_FIFO_A_REG:
  101749. + case BCM2708_I2S_INTSTC_A_REG:
  101750. + case BCM2708_I2S_GRAY_REG:
  101751. + return true;
  101752. + default:
  101753. + return false;
  101754. + };
  101755. +}
  101756. +
  101757. +static bool bcm2708_i2s_precious_reg(struct device *dev, unsigned int reg)
  101758. +{
  101759. + switch (reg) {
  101760. + case BCM2708_I2S_FIFO_A_REG:
  101761. + return true;
  101762. + default:
  101763. + return false;
  101764. + };
  101765. +}
  101766. +
  101767. +static bool bcm2708_clk_volatile_reg(struct device *dev, unsigned int reg)
  101768. +{
  101769. + switch (reg) {
  101770. + case BCM2708_CLK_PCMCTL_REG:
  101771. + return true;
  101772. + default:
  101773. + return false;
  101774. + };
  101775. +}
  101776. +
  101777. +static const struct regmap_config bcm2708_regmap_config[] = {
  101778. + {
  101779. + .reg_bits = 32,
  101780. + .reg_stride = 4,
  101781. + .val_bits = 32,
  101782. + .max_register = BCM2708_I2S_GRAY_REG,
  101783. + .precious_reg = bcm2708_i2s_precious_reg,
  101784. + .volatile_reg = bcm2708_i2s_volatile_reg,
  101785. + .cache_type = REGCACHE_RBTREE,
  101786. + },
  101787. + {
  101788. + .reg_bits = 32,
  101789. + .reg_stride = 4,
  101790. + .val_bits = 32,
  101791. + .max_register = BCM2708_CLK_PCMDIV_REG,
  101792. + .volatile_reg = bcm2708_clk_volatile_reg,
  101793. + .cache_type = REGCACHE_RBTREE,
  101794. + },
  101795. +};
  101796. +
  101797. +static const struct snd_soc_component_driver bcm2708_i2s_component = {
  101798. + .name = "bcm2708-i2s-comp",
  101799. +};
  101800. +
  101801. +static const struct snd_pcm_hardware bcm2708_pcm_hardware = {
  101802. + .info = SNDRV_PCM_INFO_INTERLEAVED |
  101803. + SNDRV_PCM_INFO_JOINT_DUPLEX,
  101804. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  101805. + SNDRV_PCM_FMTBIT_S24_LE |
  101806. + SNDRV_PCM_FMTBIT_S32_LE,
  101807. + .period_bytes_min = 32,
  101808. + .period_bytes_max = 64 * PAGE_SIZE,
  101809. + .periods_min = 2,
  101810. + .periods_max = 255,
  101811. + .buffer_bytes_max = 128 * PAGE_SIZE,
  101812. +};
  101813. +
  101814. +static const struct snd_dmaengine_pcm_config bcm2708_dmaengine_pcm_config = {
  101815. + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
  101816. + .pcm_hardware = &bcm2708_pcm_hardware,
  101817. + .prealloc_buffer_size = 256 * PAGE_SIZE,
  101818. +};
  101819. +
  101820. +
  101821. +static int bcm2708_i2s_probe(struct platform_device *pdev)
  101822. +{
  101823. + struct bcm2708_i2s_dev *dev;
  101824. + int i;
  101825. + int ret;
  101826. + struct regmap *regmap[2];
  101827. + struct resource *mem[2];
  101828. +
  101829. + /* Request both ioareas */
  101830. + for (i = 0; i <= 1; i++) {
  101831. + void __iomem *base;
  101832. +
  101833. + mem[i] = platform_get_resource(pdev, IORESOURCE_MEM, i);
  101834. + base = devm_ioremap_resource(&pdev->dev, mem[i]);
  101835. + if (IS_ERR(base))
  101836. + return PTR_ERR(base);
  101837. +
  101838. + regmap[i] = devm_regmap_init_mmio(&pdev->dev, base,
  101839. + &bcm2708_regmap_config[i]);
  101840. + if (IS_ERR(regmap[i])) {
  101841. + dev_err(&pdev->dev, "I2S probe: regmap init failed\n");
  101842. + return PTR_ERR(regmap[i]);
  101843. + }
  101844. + }
  101845. +
  101846. + dev = devm_kzalloc(&pdev->dev, sizeof(*dev),
  101847. + GFP_KERNEL);
  101848. + if (IS_ERR(dev))
  101849. + return PTR_ERR(dev);
  101850. +
  101851. + dev->i2s_regmap = regmap[0];
  101852. + dev->clk_regmap = regmap[1];
  101853. +
  101854. + /* Set the DMA address */
  101855. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr =
  101856. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  101857. +
  101858. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr =
  101859. + (dma_addr_t)BCM2708_I2S_FIFO_PHYSICAL_ADDR;
  101860. +
  101861. + /* Set the DREQ */
  101862. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].slave_id =
  101863. + BCM2708_DMA_DREQ_PCM_TX;
  101864. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].slave_id =
  101865. + BCM2708_DMA_DREQ_PCM_RX;
  101866. +
  101867. + /* Set the bus width */
  101868. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].addr_width =
  101869. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  101870. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].addr_width =
  101871. + DMA_SLAVE_BUSWIDTH_4_BYTES;
  101872. +
  101873. + /* Set burst */
  101874. + dev->dma_data[SNDRV_PCM_STREAM_PLAYBACK].maxburst = 2;
  101875. + dev->dma_data[SNDRV_PCM_STREAM_CAPTURE].maxburst = 2;
  101876. +
  101877. + /* BCLK ratio - use default */
  101878. + dev->bclk_ratio = 0;
  101879. +
  101880. + /* Store the pdev */
  101881. + dev->dev = &pdev->dev;
  101882. + dev_set_drvdata(&pdev->dev, dev);
  101883. +
  101884. + ret = snd_soc_register_component(&pdev->dev,
  101885. + &bcm2708_i2s_component, &bcm2708_i2s_dai, 1);
  101886. +
  101887. + if (ret) {
  101888. + dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
  101889. + ret = -ENOMEM;
  101890. + return ret;
  101891. + }
  101892. +
  101893. + ret = snd_dmaengine_pcm_register(&pdev->dev,
  101894. + &bcm2708_dmaengine_pcm_config,
  101895. + SND_DMAENGINE_PCM_FLAG_COMPAT);
  101896. + if (ret) {
  101897. + dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
  101898. + snd_soc_unregister_component(&pdev->dev);
  101899. + return ret;
  101900. + }
  101901. +
  101902. + return 0;
  101903. +}
  101904. +
  101905. +static int bcm2708_i2s_remove(struct platform_device *pdev)
  101906. +{
  101907. + snd_dmaengine_pcm_unregister(&pdev->dev);
  101908. + snd_soc_unregister_component(&pdev->dev);
  101909. + return 0;
  101910. +}
  101911. +
  101912. +static struct platform_driver bcm2708_i2s_driver = {
  101913. + .probe = bcm2708_i2s_probe,
  101914. + .remove = bcm2708_i2s_remove,
  101915. + .driver = {
  101916. + .name = "bcm2708-i2s",
  101917. + .owner = THIS_MODULE,
  101918. + },
  101919. +};
  101920. +
  101921. +module_platform_driver(bcm2708_i2s_driver);
  101922. +
  101923. +MODULE_ALIAS("platform:bcm2708-i2s");
  101924. +MODULE_DESCRIPTION("BCM2708 I2S interface");
  101925. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  101926. +MODULE_LICENSE("GPL v2");
  101927. diff -Nur linux-3.15/sound/soc/bcm/hifiberry_dac.c linux-rpi/sound/soc/bcm/hifiberry_dac.c
  101928. --- linux-3.15/sound/soc/bcm/hifiberry_dac.c 1970-01-01 01:00:00.000000000 +0100
  101929. +++ linux-rpi/sound/soc/bcm/hifiberry_dac.c 2014-06-11 21:03:58.000000000 +0200
  101930. @@ -0,0 +1,100 @@
  101931. +/*
  101932. + * ASoC Driver for HifiBerry DAC
  101933. + *
  101934. + * Author: Florian Meier <florian.meier@koalo.de>
  101935. + * Copyright 2013
  101936. + *
  101937. + * This program is free software; you can redistribute it and/or
  101938. + * modify it under the terms of the GNU General Public License
  101939. + * version 2 as published by the Free Software Foundation.
  101940. + *
  101941. + * This program is distributed in the hope that it will be useful, but
  101942. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  101943. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  101944. + * General Public License for more details.
  101945. + */
  101946. +
  101947. +#include <linux/module.h>
  101948. +#include <linux/platform_device.h>
  101949. +
  101950. +#include <sound/core.h>
  101951. +#include <sound/pcm.h>
  101952. +#include <sound/pcm_params.h>
  101953. +#include <sound/soc.h>
  101954. +#include <sound/jack.h>
  101955. +
  101956. +static int snd_rpi_hifiberry_dac_init(struct snd_soc_pcm_runtime *rtd)
  101957. +{
  101958. + return 0;
  101959. +}
  101960. +
  101961. +static int snd_rpi_hifiberry_dac_hw_params(struct snd_pcm_substream *substream,
  101962. + struct snd_pcm_hw_params *params)
  101963. +{
  101964. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  101965. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  101966. +
  101967. + unsigned int sample_bits =
  101968. + snd_pcm_format_physical_width(params_format(params));
  101969. +
  101970. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  101971. +}
  101972. +
  101973. +/* machine stream operations */
  101974. +static struct snd_soc_ops snd_rpi_hifiberry_dac_ops = {
  101975. + .hw_params = snd_rpi_hifiberry_dac_hw_params,
  101976. +};
  101977. +
  101978. +static struct snd_soc_dai_link snd_rpi_hifiberry_dac_dai[] = {
  101979. +{
  101980. + .name = "HifiBerry DAC",
  101981. + .stream_name = "HifiBerry DAC HiFi",
  101982. + .cpu_dai_name = "bcm2708-i2s.0",
  101983. + .codec_dai_name = "pcm5102a-hifi",
  101984. + .platform_name = "bcm2708-i2s.0",
  101985. + .codec_name = "pcm5102a-codec",
  101986. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  101987. + SND_SOC_DAIFMT_CBS_CFS,
  101988. + .ops = &snd_rpi_hifiberry_dac_ops,
  101989. + .init = snd_rpi_hifiberry_dac_init,
  101990. +},
  101991. +};
  101992. +
  101993. +/* audio machine driver */
  101994. +static struct snd_soc_card snd_rpi_hifiberry_dac = {
  101995. + .name = "snd_rpi_hifiberry_dac",
  101996. + .dai_link = snd_rpi_hifiberry_dac_dai,
  101997. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_dac_dai),
  101998. +};
  101999. +
  102000. +static int snd_rpi_hifiberry_dac_probe(struct platform_device *pdev)
  102001. +{
  102002. + int ret = 0;
  102003. +
  102004. + snd_rpi_hifiberry_dac.dev = &pdev->dev;
  102005. + ret = snd_soc_register_card(&snd_rpi_hifiberry_dac);
  102006. + if (ret)
  102007. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102008. +
  102009. + return ret;
  102010. +}
  102011. +
  102012. +static int snd_rpi_hifiberry_dac_remove(struct platform_device *pdev)
  102013. +{
  102014. + return snd_soc_unregister_card(&snd_rpi_hifiberry_dac);
  102015. +}
  102016. +
  102017. +static struct platform_driver snd_rpi_hifiberry_dac_driver = {
  102018. + .driver = {
  102019. + .name = "snd-hifiberry-dac",
  102020. + .owner = THIS_MODULE,
  102021. + },
  102022. + .probe = snd_rpi_hifiberry_dac_probe,
  102023. + .remove = snd_rpi_hifiberry_dac_remove,
  102024. +};
  102025. +
  102026. +module_platform_driver(snd_rpi_hifiberry_dac_driver);
  102027. +
  102028. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102029. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry DAC");
  102030. +MODULE_LICENSE("GPL v2");
  102031. diff -Nur linux-3.15/sound/soc/bcm/hifiberry_digi.c linux-rpi/sound/soc/bcm/hifiberry_digi.c
  102032. --- linux-3.15/sound/soc/bcm/hifiberry_digi.c 1970-01-01 01:00:00.000000000 +0100
  102033. +++ linux-rpi/sound/soc/bcm/hifiberry_digi.c 2014-06-11 21:03:58.000000000 +0200
  102034. @@ -0,0 +1,153 @@
  102035. +/*
  102036. + * ASoC Driver for HifiBerry Digi
  102037. + *
  102038. + * Author: Daniel Matuschek <info@crazy-audio.com>
  102039. + * based on the HifiBerry DAC driver by Florian Meier <florian.meier@koalo.de>
  102040. + * Copyright 2013
  102041. + *
  102042. + * This program is free software; you can redistribute it and/or
  102043. + * modify it under the terms of the GNU General Public License
  102044. + * version 2 as published by the Free Software Foundation.
  102045. + *
  102046. + * This program is distributed in the hope that it will be useful, but
  102047. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102048. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102049. + * General Public License for more details.
  102050. + */
  102051. +
  102052. +#include <linux/module.h>
  102053. +#include <linux/platform_device.h>
  102054. +
  102055. +#include <sound/core.h>
  102056. +#include <sound/pcm.h>
  102057. +#include <sound/pcm_params.h>
  102058. +#include <sound/soc.h>
  102059. +#include <sound/jack.h>
  102060. +
  102061. +#include "../codecs/wm8804.h"
  102062. +
  102063. +static int samplerate=44100;
  102064. +
  102065. +static int snd_rpi_hifiberry_digi_init(struct snd_soc_pcm_runtime *rtd)
  102066. +{
  102067. + struct snd_soc_codec *codec = rtd->codec;
  102068. +
  102069. + /* enable TX output */
  102070. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  102071. +
  102072. + return 0;
  102073. +}
  102074. +
  102075. +static int snd_rpi_hifiberry_digi_hw_params(struct snd_pcm_substream *substream,
  102076. + struct snd_pcm_hw_params *params)
  102077. +{
  102078. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102079. + struct snd_soc_dai *codec_dai = rtd->codec_dai;
  102080. + struct snd_soc_codec *codec = rtd->codec;
  102081. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102082. +
  102083. + int sysclk = 27000000; /* This is fixed on this board */
  102084. +
  102085. + long mclk_freq=0;
  102086. + int mclk_div=1;
  102087. +
  102088. + int ret;
  102089. +
  102090. + samplerate = params_rate(params);
  102091. +
  102092. + switch (samplerate) {
  102093. + case 44100:
  102094. + case 48000:
  102095. + case 88200:
  102096. + case 96000:
  102097. + mclk_freq=samplerate*256;
  102098. + mclk_div=WM8804_MCLKDIV_256FS;
  102099. + break;
  102100. + case 176400:
  102101. + case 192000:
  102102. + mclk_freq=samplerate*128;
  102103. + mclk_div=WM8804_MCLKDIV_128FS;
  102104. + break;
  102105. + default:
  102106. + dev_err(substream->pcm->dev,
  102107. + "Failed to set WM8804 SYSCLK, unsupported samplerate\n");
  102108. + }
  102109. +
  102110. + snd_soc_dai_set_clkdiv(codec_dai, WM8804_MCLK_DIV, mclk_div);
  102111. + snd_soc_dai_set_pll(codec_dai, 0, 0, sysclk, mclk_freq);
  102112. +
  102113. + ret = snd_soc_dai_set_sysclk(codec_dai, WM8804_TX_CLKSRC_PLL,
  102114. + sysclk, SND_SOC_CLOCK_OUT);
  102115. + if (ret < 0) {
  102116. + dev_err(substream->pcm->dev,
  102117. + "Failed to set WM8804 SYSCLK: %d\n", ret);
  102118. + return ret;
  102119. + }
  102120. +
  102121. + /* Enable TX output */
  102122. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x4, 0x0);
  102123. +
  102124. + /* Power on */
  102125. + snd_soc_update_bits(codec, WM8804_PWRDN, 0x9, 0);
  102126. +
  102127. + return snd_soc_dai_set_bclk_ratio(cpu_dai,64);
  102128. +}
  102129. +
  102130. +/* machine stream operations */
  102131. +static struct snd_soc_ops snd_rpi_hifiberry_digi_ops = {
  102132. + .hw_params = snd_rpi_hifiberry_digi_hw_params,
  102133. +};
  102134. +
  102135. +static struct snd_soc_dai_link snd_rpi_hifiberry_digi_dai[] = {
  102136. +{
  102137. + .name = "HifiBerry Digi",
  102138. + .stream_name = "HifiBerry Digi HiFi",
  102139. + .cpu_dai_name = "bcm2708-i2s.0",
  102140. + .codec_dai_name = "wm8804-spdif",
  102141. + .platform_name = "bcm2708-i2s.0",
  102142. + .codec_name = "wm8804.1-003b",
  102143. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102144. + SND_SOC_DAIFMT_CBM_CFM,
  102145. + .ops = &snd_rpi_hifiberry_digi_ops,
  102146. + .init = snd_rpi_hifiberry_digi_init,
  102147. +},
  102148. +};
  102149. +
  102150. +/* audio machine driver */
  102151. +static struct snd_soc_card snd_rpi_hifiberry_digi = {
  102152. + .name = "snd_rpi_hifiberry_digi",
  102153. + .dai_link = snd_rpi_hifiberry_digi_dai,
  102154. + .num_links = ARRAY_SIZE(snd_rpi_hifiberry_digi_dai),
  102155. +};
  102156. +
  102157. +static int snd_rpi_hifiberry_digi_probe(struct platform_device *pdev)
  102158. +{
  102159. + int ret = 0;
  102160. +
  102161. + snd_rpi_hifiberry_digi.dev = &pdev->dev;
  102162. + ret = snd_soc_register_card(&snd_rpi_hifiberry_digi);
  102163. + if (ret)
  102164. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102165. +
  102166. + return ret;
  102167. +}
  102168. +
  102169. +static int snd_rpi_hifiberry_digi_remove(struct platform_device *pdev)
  102170. +{
  102171. + return snd_soc_unregister_card(&snd_rpi_hifiberry_digi);
  102172. +}
  102173. +
  102174. +static struct platform_driver snd_rpi_hifiberry_digi_driver = {
  102175. + .driver = {
  102176. + .name = "snd-hifiberry-digi",
  102177. + .owner = THIS_MODULE,
  102178. + },
  102179. + .probe = snd_rpi_hifiberry_digi_probe,
  102180. + .remove = snd_rpi_hifiberry_digi_remove,
  102181. +};
  102182. +
  102183. +module_platform_driver(snd_rpi_hifiberry_digi_driver);
  102184. +
  102185. +MODULE_AUTHOR("Daniel Matuschek <info@crazy-audio.com>");
  102186. +MODULE_DESCRIPTION("ASoC Driver for HifiBerry Digi");
  102187. +MODULE_LICENSE("GPL v2");
  102188. diff -Nur linux-3.15/sound/soc/bcm/iqaudio-dac.c linux-rpi/sound/soc/bcm/iqaudio-dac.c
  102189. --- linux-3.15/sound/soc/bcm/iqaudio-dac.c 1970-01-01 01:00:00.000000000 +0100
  102190. +++ linux-rpi/sound/soc/bcm/iqaudio-dac.c 2014-06-11 21:03:58.000000000 +0200
  102191. @@ -0,0 +1,111 @@
  102192. +/*
  102193. + * ASoC Driver for IQaudIO DAC
  102194. + *
  102195. + * Author: Florian Meier <florian.meier@koalo.de>
  102196. + * Copyright 2013
  102197. + *
  102198. + * This program is free software; you can redistribute it and/or
  102199. + * modify it under the terms of the GNU General Public License
  102200. + * version 2 as published by the Free Software Foundation.
  102201. + *
  102202. + * This program is distributed in the hope that it will be useful, but
  102203. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102204. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102205. + * General Public License for more details.
  102206. + */
  102207. +
  102208. +#include <linux/module.h>
  102209. +#include <linux/platform_device.h>
  102210. +
  102211. +#include <sound/core.h>
  102212. +#include <sound/pcm.h>
  102213. +#include <sound/pcm_params.h>
  102214. +#include <sound/soc.h>
  102215. +#include <sound/jack.h>
  102216. +
  102217. +static int snd_rpi_iqaudio_dac_init(struct snd_soc_pcm_runtime *rtd)
  102218. +{
  102219. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  102220. +
  102221. + return 0;
  102222. +}
  102223. +
  102224. +static int snd_rpi_iqaudio_dac_hw_params(struct snd_pcm_substream *substream,
  102225. + struct snd_pcm_hw_params *params)
  102226. +{
  102227. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102228. +// NOT USED struct snd_soc_dai *codec_dai = rtd->codec_dai;
  102229. +// NOT USED struct snd_soc_codec *codec = rtd->codec;
  102230. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102231. +
  102232. + unsigned int sample_bits =
  102233. + snd_pcm_format_physical_width(params_format(params));
  102234. +
  102235. + return snd_soc_dai_set_bclk_ratio(cpu_dai, sample_bits * 2);
  102236. +}
  102237. +
  102238. +/* machine stream operations */
  102239. +static struct snd_soc_ops snd_rpi_iqaudio_dac_ops = {
  102240. + .hw_params = snd_rpi_iqaudio_dac_hw_params,
  102241. +};
  102242. +
  102243. +static struct snd_soc_dai_link snd_rpi_iqaudio_dac_dai[] = {
  102244. +{
  102245. + .name = "IQaudIO DAC",
  102246. + .stream_name = "IQaudIO DAC HiFi",
  102247. + .cpu_dai_name = "bcm2708-i2s.0",
  102248. + .codec_dai_name = "pcm512x-hifi",
  102249. + .platform_name = "bcm2708-i2s.0",
  102250. + .codec_name = "pcm512x.1-004c",
  102251. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102252. + SND_SOC_DAIFMT_CBS_CFS,
  102253. + .ops = &snd_rpi_iqaudio_dac_ops,
  102254. + .init = snd_rpi_iqaudio_dac_init,
  102255. +},
  102256. +};
  102257. +
  102258. +/* audio machine driver */
  102259. +static struct snd_soc_card snd_rpi_iqaudio_dac = {
  102260. + .name = "snd_rpi_iqaudio_dac",
  102261. + .dai_link = snd_rpi_iqaudio_dac_dai,
  102262. + .num_links = ARRAY_SIZE(snd_rpi_iqaudio_dac_dai),
  102263. +};
  102264. +
  102265. +static int snd_rpi_iqaudio_dac_probe(struct platform_device *pdev)
  102266. +{
  102267. + int ret = 0;
  102268. +
  102269. + snd_rpi_iqaudio_dac.dev = &pdev->dev;
  102270. + ret = snd_soc_register_card(&snd_rpi_iqaudio_dac);
  102271. + if (ret)
  102272. + dev_err(&pdev->dev,
  102273. + "snd_soc_register_card() failed: %d\n", ret);
  102274. +
  102275. + return ret;
  102276. +}
  102277. +
  102278. +static int snd_rpi_iqaudio_dac_remove(struct platform_device *pdev)
  102279. +{
  102280. + return snd_soc_unregister_card(&snd_rpi_iqaudio_dac);
  102281. +}
  102282. +
  102283. +static const struct of_device_id iqaudio_of_match[] = {
  102284. + { .compatible = "iqaudio,iqaudio-dac", },
  102285. + {},
  102286. +};
  102287. +
  102288. +static struct platform_driver snd_rpi_iqaudio_dac_driver = {
  102289. + .driver = {
  102290. + .name = "snd-rpi-iqaudio-dac",
  102291. + .owner = THIS_MODULE,
  102292. + .of_match_table = iqaudio_of_match,
  102293. + },
  102294. + .probe = snd_rpi_iqaudio_dac_probe,
  102295. + .remove = snd_rpi_iqaudio_dac_remove,
  102296. +};
  102297. +
  102298. +module_platform_driver(snd_rpi_iqaudio_dac_driver);
  102299. +
  102300. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102301. +MODULE_DESCRIPTION("ASoC Driver for IQAudio DAC");
  102302. +MODULE_LICENSE("GPL v2");
  102303. diff -Nur linux-3.15/sound/soc/bcm/Kconfig linux-rpi/sound/soc/bcm/Kconfig
  102304. --- linux-3.15/sound/soc/bcm/Kconfig 2014-06-08 20:19:54.000000000 +0200
  102305. +++ linux-rpi/sound/soc/bcm/Kconfig 2014-06-11 21:05:44.000000000 +0200
  102306. @@ -7,3 +7,42 @@
  102307. Say Y or M if you want to add support for codecs attached to
  102308. the BCM2835 I2S interface. You will also need
  102309. to select the audio interfaces to support below.
  102310. +
  102311. +config SND_BCM2708_SOC_I2S
  102312. + tristate "SoC Audio support for the Broadcom BCM2708 I2S module"
  102313. + depends on MACH_BCM2708
  102314. + select REGMAP_MMIO
  102315. + select SND_SOC_DMAENGINE_PCM
  102316. + select SND_SOC_GENERIC_DMAENGINE_PCM
  102317. + help
  102318. + Say Y or M if you want to add support for codecs attached to
  102319. + the BCM2708 I2S interface. You will also need
  102320. + to select the audio interfaces to support below.
  102321. +
  102322. +config SND_BCM2708_SOC_HIFIBERRY_DAC
  102323. + tristate "Support for HifiBerry DAC"
  102324. + depends on SND_BCM2708_SOC_I2S
  102325. + select SND_SOC_PCM5102A
  102326. + help
  102327. + Say Y or M if you want to add support for HifiBerry DAC.
  102328. +
  102329. +config SND_BCM2708_SOC_HIFIBERRY_DIGI
  102330. + tristate "Support for HifiBerry Digi"
  102331. + depends on SND_BCM2708_SOC_I2S
  102332. + select SND_SOC_WM8804
  102333. + help
  102334. + Say Y or M if you want to add support for HifiBerry Digi S/PDIF output board.
  102335. +
  102336. +config SND_BCM2708_SOC_RPI_DAC
  102337. + tristate "Support for RPi-DAC"
  102338. + depends on SND_BCM2708_SOC_I2S
  102339. + select SND_SOC_PCM1794A
  102340. + help
  102341. + Say Y or M if you want to add support for RPi-DAC.
  102342. +
  102343. +config SND_BCM2708_SOC_IQAUDIO_DAC
  102344. + tristate "Support for IQaudIO-DAC"
  102345. + depends on SND_BCM2708_SOC_I2S
  102346. + select SND_SOC_PCM512x
  102347. + help
  102348. + Say Y or M if you want to add support for IQaudIO-DAC.
  102349. diff -Nur linux-3.15/sound/soc/bcm/Makefile linux-rpi/sound/soc/bcm/Makefile
  102350. --- linux-3.15/sound/soc/bcm/Makefile 2014-06-08 20:19:54.000000000 +0200
  102351. +++ linux-rpi/sound/soc/bcm/Makefile 2014-06-11 21:05:44.000000000 +0200
  102352. @@ -3,3 +3,18 @@
  102353. obj-$(CONFIG_SND_BCM2835_SOC_I2S) += snd-soc-bcm2835-i2s.o
  102354. +# BCM2708 Platform Support
  102355. +snd-soc-bcm2708-i2s-objs := bcm2708-i2s.o
  102356. +
  102357. +obj-$(CONFIG_SND_BCM2708_SOC_I2S) += snd-soc-bcm2708-i2s.o
  102358. +
  102359. +# BCM2708 Machine Support
  102360. +snd-soc-hifiberry-dac-objs := hifiberry_dac.o
  102361. +snd-soc-hifiberry-digi-objs := hifiberry_digi.o
  102362. +snd-soc-rpi-dac-objs := rpi-dac.o
  102363. +snd-soc-iqaudio-dac-objs := iqaudio-dac.o
  102364. +
  102365. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) += snd-soc-hifiberry-dac.o
  102366. +obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) += snd-soc-hifiberry-digi.o
  102367. +obj-$(CONFIG_SND_BCM2708_SOC_RPI_DAC) += snd-soc-rpi-dac.o
  102368. +obj-$(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) += snd-soc-iqaudio-dac.o
  102369. diff -Nur linux-3.15/sound/soc/bcm/rpi-dac.c linux-rpi/sound/soc/bcm/rpi-dac.c
  102370. --- linux-3.15/sound/soc/bcm/rpi-dac.c 1970-01-01 01:00:00.000000000 +0100
  102371. +++ linux-rpi/sound/soc/bcm/rpi-dac.c 2014-06-11 21:03:58.000000000 +0200
  102372. @@ -0,0 +1,97 @@
  102373. +/*
  102374. + * ASoC Driver for RPi-DAC.
  102375. + *
  102376. + * Author: Florian Meier <florian.meier@koalo.de>
  102377. + * Copyright 2013
  102378. + *
  102379. + * This program is free software; you can redistribute it and/or
  102380. + * modify it under the terms of the GNU General Public License
  102381. + * version 2 as published by the Free Software Foundation.
  102382. + *
  102383. + * This program is distributed in the hope that it will be useful, but
  102384. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102385. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102386. + * General Public License for more details.
  102387. + */
  102388. +
  102389. +#include <linux/module.h>
  102390. +#include <linux/platform_device.h>
  102391. +
  102392. +#include <sound/core.h>
  102393. +#include <sound/pcm.h>
  102394. +#include <sound/pcm_params.h>
  102395. +#include <sound/soc.h>
  102396. +#include <sound/jack.h>
  102397. +
  102398. +static int snd_rpi_rpi_dac_init(struct snd_soc_pcm_runtime *rtd)
  102399. +{
  102400. + return 0;
  102401. +}
  102402. +
  102403. +static int snd_rpi_rpi_dac_hw_params(struct snd_pcm_substream *substream,
  102404. + struct snd_pcm_hw_params *params)
  102405. +{
  102406. + struct snd_soc_pcm_runtime *rtd = substream->private_data;
  102407. + struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
  102408. +
  102409. + return snd_soc_dai_set_bclk_ratio(cpu_dai, 32*2);
  102410. +}
  102411. +
  102412. +/* machine stream operations */
  102413. +static struct snd_soc_ops snd_rpi_rpi_dac_ops = {
  102414. + .hw_params = snd_rpi_rpi_dac_hw_params,
  102415. +};
  102416. +
  102417. +static struct snd_soc_dai_link snd_rpi_rpi_dac_dai[] = {
  102418. +{
  102419. + .name = "HifiBerry Mini",
  102420. + .stream_name = "HifiBerry Mini HiFi",
  102421. + .cpu_dai_name = "bcm2708-i2s.0",
  102422. + .codec_dai_name = "pcm1794a-hifi",
  102423. + .platform_name = "bcm2708-i2s.0",
  102424. + .codec_name = "pcm1794a-codec",
  102425. + .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
  102426. + SND_SOC_DAIFMT_CBS_CFS,
  102427. + .ops = &snd_rpi_rpi_dac_ops,
  102428. + .init = snd_rpi_rpi_dac_init,
  102429. +},
  102430. +};
  102431. +
  102432. +/* audio machine driver */
  102433. +static struct snd_soc_card snd_rpi_rpi_dac = {
  102434. + .name = "snd_rpi_rpi_dac",
  102435. + .dai_link = snd_rpi_rpi_dac_dai,
  102436. + .num_links = ARRAY_SIZE(snd_rpi_rpi_dac_dai),
  102437. +};
  102438. +
  102439. +static int snd_rpi_rpi_dac_probe(struct platform_device *pdev)
  102440. +{
  102441. + int ret = 0;
  102442. +
  102443. + snd_rpi_rpi_dac.dev = &pdev->dev;
  102444. + ret = snd_soc_register_card(&snd_rpi_rpi_dac);
  102445. + if (ret)
  102446. + dev_err(&pdev->dev, "snd_soc_register_card() failed: %d\n", ret);
  102447. +
  102448. + return ret;
  102449. +}
  102450. +
  102451. +static int snd_rpi_rpi_dac_remove(struct platform_device *pdev)
  102452. +{
  102453. + return snd_soc_unregister_card(&snd_rpi_rpi_dac);
  102454. +}
  102455. +
  102456. +static struct platform_driver snd_rpi_rpi_dac_driver = {
  102457. + .driver = {
  102458. + .name = "snd-rpi-dac",
  102459. + .owner = THIS_MODULE,
  102460. + },
  102461. + .probe = snd_rpi_rpi_dac_probe,
  102462. + .remove = snd_rpi_rpi_dac_remove,
  102463. +};
  102464. +
  102465. +module_platform_driver(snd_rpi_rpi_dac_driver);
  102466. +
  102467. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102468. +MODULE_DESCRIPTION("ASoC Driver for RPi-DAC");
  102469. +MODULE_LICENSE("GPL v2");
  102470. diff -Nur linux-3.15/sound/soc/codecs/Kconfig linux-rpi/sound/soc/codecs/Kconfig
  102471. --- linux-3.15/sound/soc/codecs/Kconfig 2014-06-08 20:19:54.000000000 +0200
  102472. +++ linux-rpi/sound/soc/codecs/Kconfig 2014-06-11 21:05:44.000000000 +0200
  102473. @@ -69,6 +69,9 @@
  102474. select SND_SOC_PCM3008
  102475. select SND_SOC_PCM512x_I2C if I2C
  102476. select SND_SOC_PCM512x_SPI if SPI_MASTER
  102477. + select SND_SOC_PCM1794A
  102478. + select SND_SOC_PCM5102A
  102479. + select SND_SOC_PCM512x if SND_SOC_I2C_AND_SPI
  102480. select SND_SOC_RT5631 if I2C
  102481. select SND_SOC_RT5640 if I2C
  102482. select SND_SOC_SGTL5000 if I2C
  102483. @@ -390,6 +393,15 @@
  102484. select SND_SOC_PCM512x
  102485. select REGMAP_SPI
  102486. +config SND_SOC_PCM1794A
  102487. + tristate
  102488. +
  102489. +config SND_SOC_PCM5102A
  102490. + tristate
  102491. +
  102492. +config SND_SOC_PCM512x
  102493. + tristate
  102494. +
  102495. config SND_SOC_RT5631
  102496. tristate
  102497. diff -Nur linux-3.15/sound/soc/codecs/Makefile linux-rpi/sound/soc/codecs/Makefile
  102498. --- linux-3.15/sound/soc/codecs/Makefile 2014-06-08 20:19:54.000000000 +0200
  102499. +++ linux-rpi/sound/soc/codecs/Makefile 2014-06-11 21:05:44.000000000 +0200
  102500. @@ -58,6 +58,9 @@
  102501. snd-soc-pcm512x-objs := pcm512x.o
  102502. snd-soc-pcm512x-i2c-objs := pcm512x-i2c.o
  102503. snd-soc-pcm512x-spi-objs := pcm512x-spi.o
  102504. +snd-soc-pcm1794a-objs := pcm1794a.o
  102505. +snd-soc-pcm5102a-objs := pcm5102a.o
  102506. +snd-soc-pcm512x-objs := pcm512x.o
  102507. snd-soc-rt5631-objs := rt5631.o
  102508. snd-soc-rt5640-objs := rt5640.o
  102509. snd-soc-sgtl5000-objs := sgtl5000.o
  102510. @@ -209,6 +212,9 @@
  102511. obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  102512. obj-$(CONFIG_SND_SOC_PCM512x_I2C) += snd-soc-pcm512x-i2c.o
  102513. obj-$(CONFIG_SND_SOC_PCM512x_SPI) += snd-soc-pcm512x-spi.o
  102514. +obj-$(CONFIG_SND_SOC_PCM1794A) += snd-soc-pcm1794a.o
  102515. +obj-$(CONFIG_SND_SOC_PCM5102A) += snd-soc-pcm5102a.o
  102516. +obj-$(CONFIG_SND_SOC_PCM512x) += snd-soc-pcm512x.o
  102517. obj-$(CONFIG_SND_SOC_RT5631) += snd-soc-rt5631.o
  102518. obj-$(CONFIG_SND_SOC_RT5640) += snd-soc-rt5640.o
  102519. obj-$(CONFIG_SND_SOC_SGTL5000) += snd-soc-sgtl5000.o
  102520. diff -Nur linux-3.15/sound/soc/codecs/pcm1794a.c linux-rpi/sound/soc/codecs/pcm1794a.c
  102521. --- linux-3.15/sound/soc/codecs/pcm1794a.c 1970-01-01 01:00:00.000000000 +0100
  102522. +++ linux-rpi/sound/soc/codecs/pcm1794a.c 2014-06-11 21:03:58.000000000 +0200
  102523. @@ -0,0 +1,62 @@
  102524. +/*
  102525. + * Driver for the PCM1794A codec
  102526. + *
  102527. + * Author: Florian Meier <florian.meier@koalo.de>
  102528. + * Copyright 2013
  102529. + *
  102530. + * This program is free software; you can redistribute it and/or
  102531. + * modify it under the terms of the GNU General Public License
  102532. + * version 2 as published by the Free Software Foundation.
  102533. + *
  102534. + * This program is distributed in the hope that it will be useful, but
  102535. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102536. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102537. + * General Public License for more details.
  102538. + */
  102539. +
  102540. +
  102541. +#include <linux/init.h>
  102542. +#include <linux/module.h>
  102543. +#include <linux/platform_device.h>
  102544. +
  102545. +#include <sound/soc.h>
  102546. +
  102547. +static struct snd_soc_dai_driver pcm1794a_dai = {
  102548. + .name = "pcm1794a-hifi",
  102549. + .playback = {
  102550. + .channels_min = 2,
  102551. + .channels_max = 2,
  102552. + .rates = SNDRV_PCM_RATE_8000_192000,
  102553. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  102554. + SNDRV_PCM_FMTBIT_S24_LE
  102555. + },
  102556. +};
  102557. +
  102558. +static struct snd_soc_codec_driver soc_codec_dev_pcm1794a;
  102559. +
  102560. +static int pcm1794a_probe(struct platform_device *pdev)
  102561. +{
  102562. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm1794a,
  102563. + &pcm1794a_dai, 1);
  102564. +}
  102565. +
  102566. +static int pcm1794a_remove(struct platform_device *pdev)
  102567. +{
  102568. + snd_soc_unregister_codec(&pdev->dev);
  102569. + return 0;
  102570. +}
  102571. +
  102572. +static struct platform_driver pcm1794a_codec_driver = {
  102573. + .probe = pcm1794a_probe,
  102574. + .remove = pcm1794a_remove,
  102575. + .driver = {
  102576. + .name = "pcm1794a-codec",
  102577. + .owner = THIS_MODULE,
  102578. + },
  102579. +};
  102580. +
  102581. +module_platform_driver(pcm1794a_codec_driver);
  102582. +
  102583. +MODULE_DESCRIPTION("ASoC PCM1794A codec driver");
  102584. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102585. +MODULE_LICENSE("GPL v2");
  102586. diff -Nur linux-3.15/sound/soc/codecs/pcm5102a.c linux-rpi/sound/soc/codecs/pcm5102a.c
  102587. --- linux-3.15/sound/soc/codecs/pcm5102a.c 1970-01-01 01:00:00.000000000 +0100
  102588. +++ linux-rpi/sound/soc/codecs/pcm5102a.c 2014-06-11 21:03:58.000000000 +0200
  102589. @@ -0,0 +1,63 @@
  102590. +/*
  102591. + * Driver for the PCM5102A codec
  102592. + *
  102593. + * Author: Florian Meier <florian.meier@koalo.de>
  102594. + * Copyright 2013
  102595. + *
  102596. + * This program is free software; you can redistribute it and/or
  102597. + * modify it under the terms of the GNU General Public License
  102598. + * version 2 as published by the Free Software Foundation.
  102599. + *
  102600. + * This program is distributed in the hope that it will be useful, but
  102601. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  102602. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  102603. + * General Public License for more details.
  102604. + */
  102605. +
  102606. +
  102607. +#include <linux/init.h>
  102608. +#include <linux/module.h>
  102609. +#include <linux/platform_device.h>
  102610. +
  102611. +#include <sound/soc.h>
  102612. +
  102613. +static struct snd_soc_dai_driver pcm5102a_dai = {
  102614. + .name = "pcm5102a-hifi",
  102615. + .playback = {
  102616. + .channels_min = 2,
  102617. + .channels_max = 2,
  102618. + .rates = SNDRV_PCM_RATE_8000_192000,
  102619. + .formats = SNDRV_PCM_FMTBIT_S16_LE |
  102620. + // SNDRV_PCM_FMTBIT_S24_LE | : disable for now, it causes white noise with xbmc
  102621. + SNDRV_PCM_FMTBIT_S32_LE
  102622. + },
  102623. +};
  102624. +
  102625. +static struct snd_soc_codec_driver soc_codec_dev_pcm5102a;
  102626. +
  102627. +static int pcm5102a_probe(struct platform_device *pdev)
  102628. +{
  102629. + return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_pcm5102a,
  102630. + &pcm5102a_dai, 1);
  102631. +}
  102632. +
  102633. +static int pcm5102a_remove(struct platform_device *pdev)
  102634. +{
  102635. + snd_soc_unregister_codec(&pdev->dev);
  102636. + return 0;
  102637. +}
  102638. +
  102639. +static struct platform_driver pcm5102a_codec_driver = {
  102640. + .probe = pcm5102a_probe,
  102641. + .remove = pcm5102a_remove,
  102642. + .driver = {
  102643. + .name = "pcm5102a-codec",
  102644. + .owner = THIS_MODULE,
  102645. + },
  102646. +};
  102647. +
  102648. +module_platform_driver(pcm5102a_codec_driver);
  102649. +
  102650. +MODULE_DESCRIPTION("ASoC PCM5102A codec driver");
  102651. +MODULE_AUTHOR("Florian Meier <florian.meier@koalo.de>");
  102652. +MODULE_LICENSE("GPL v2");
  102653. diff -Nur linux-3.15/sound/soc/codecs/pcm512x.c linux-rpi/sound/soc/codecs/pcm512x.c
  102654. --- linux-3.15/sound/soc/codecs/pcm512x.c 2014-06-08 20:19:54.000000000 +0200
  102655. +++ linux-rpi/sound/soc/codecs/pcm512x.c 2014-06-11 21:03:58.000000000 +0200
  102656. @@ -18,9 +18,11 @@
  102657. #include <linux/init.h>
  102658. #include <linux/module.h>
  102659. #include <linux/clk.h>
  102660. +#include <linux/i2c.h>
  102661. #include <linux/pm_runtime.h>
  102662. #include <linux/regmap.h>
  102663. #include <linux/regulator/consumer.h>
  102664. +#include <linux/spi/spi.h>
  102665. #include <sound/soc.h>
  102666. #include <sound/soc-dapm.h>
  102667. #include <sound/tlv.h>
  102668. @@ -28,7 +30,7 @@
  102669. #include "pcm512x.h"
  102670. #define PCM512x_NUM_SUPPLIES 3
  102671. -static const char * const pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  102672. +static const char *pcm512x_supply_names[PCM512x_NUM_SUPPLIES] = {
  102673. "AVDD",
  102674. "DVDD",
  102675. "CPVDD",
  102676. @@ -64,29 +66,22 @@
  102677. PCM512x_REGULATOR_EVENT(2)
  102678. static const struct reg_default pcm512x_reg_defaults[] = {
  102679. - { PCM512x_RESET, 0x00 },
  102680. - { PCM512x_POWER, 0x00 },
  102681. - { PCM512x_MUTE, 0x00 },
  102682. - { PCM512x_DSP, 0x00 },
  102683. - { PCM512x_PLL_REF, 0x00 },
  102684. - { PCM512x_DAC_ROUTING, 0x11 },
  102685. - { PCM512x_DSP_PROGRAM, 0x01 },
  102686. - { PCM512x_CLKDET, 0x00 },
  102687. - { PCM512x_AUTO_MUTE, 0x00 },
  102688. - { PCM512x_ERROR_DETECT, 0x00 },
  102689. - { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  102690. - { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  102691. - { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  102692. - { PCM512x_DIGITAL_MUTE_1, 0x22 },
  102693. - { PCM512x_DIGITAL_MUTE_2, 0x00 },
  102694. - { PCM512x_DIGITAL_MUTE_3, 0x07 },
  102695. - { PCM512x_OUTPUT_AMPLITUDE, 0x00 },
  102696. - { PCM512x_ANALOG_GAIN_CTRL, 0x00 },
  102697. - { PCM512x_UNDERVOLTAGE_PROT, 0x00 },
  102698. - { PCM512x_ANALOG_MUTE_CTRL, 0x00 },
  102699. - { PCM512x_ANALOG_GAIN_BOOST, 0x00 },
  102700. - { PCM512x_VCOM_CTRL_1, 0x00 },
  102701. - { PCM512x_VCOM_CTRL_2, 0x01 },
  102702. + { PCM512x_RESET, 0x00 },
  102703. + { PCM512x_POWER, 0x00 },
  102704. + { PCM512x_MUTE, 0x00 },
  102705. + { PCM512x_DSP, 0x00 },
  102706. + { PCM512x_PLL_REF, 0x00 },
  102707. + { PCM512x_DAC_ROUTING, 0x11 },
  102708. + { PCM512x_DSP_PROGRAM, 0x01 },
  102709. + { PCM512x_CLKDET, 0x00 },
  102710. + { PCM512x_AUTO_MUTE, 0x00 },
  102711. + { PCM512x_ERROR_DETECT, 0x00 },
  102712. + { PCM512x_DIGITAL_VOLUME_1, 0x00 },
  102713. + { PCM512x_DIGITAL_VOLUME_2, 0x30 },
  102714. + { PCM512x_DIGITAL_VOLUME_3, 0x30 },
  102715. + { PCM512x_DIGITAL_MUTE_1, 0x22 },
  102716. + { PCM512x_DIGITAL_MUTE_2, 0x00 },
  102717. + { PCM512x_DIGITAL_MUTE_3, 0x07 },
  102718. };
  102719. static bool pcm512x_readable(struct device *dev, unsigned int reg)
  102720. @@ -146,18 +141,9 @@
  102721. case PCM512x_ANALOG_MUTE_DET:
  102722. case PCM512x_GPIN:
  102723. case PCM512x_DIGITAL_MUTE_DET:
  102724. - case PCM512x_OUTPUT_AMPLITUDE:
  102725. - case PCM512x_ANALOG_GAIN_CTRL:
  102726. - case PCM512x_UNDERVOLTAGE_PROT:
  102727. - case PCM512x_ANALOG_MUTE_CTRL:
  102728. - case PCM512x_ANALOG_GAIN_BOOST:
  102729. - case PCM512x_VCOM_CTRL_1:
  102730. - case PCM512x_VCOM_CTRL_2:
  102731. - case PCM512x_CRAM_CTRL:
  102732. return true;
  102733. default:
  102734. - /* There are 256 raw register addresses */
  102735. - return reg < 0xff;
  102736. + return false;
  102737. }
  102738. }
  102739. @@ -173,22 +159,17 @@
  102740. case PCM512x_ANALOG_MUTE_DET:
  102741. case PCM512x_GPIN:
  102742. case PCM512x_DIGITAL_MUTE_DET:
  102743. - case PCM512x_CRAM_CTRL:
  102744. return true;
  102745. default:
  102746. - /* There are 256 raw register addresses */
  102747. - return reg < 0xff;
  102748. + return false;
  102749. }
  102750. }
  102751. static const DECLARE_TLV_DB_SCALE(digital_tlv, -10350, 50, 1);
  102752. -static const DECLARE_TLV_DB_SCALE(analog_tlv, -600, 600, 0);
  102753. -static const DECLARE_TLV_DB_SCALE(boost_tlv, 0, 80, 0);
  102754. -static const char * const pcm512x_dsp_program_texts[] = {
  102755. +static const char *pcm512x_dsp_program_texts[] = {
  102756. "FIR interpolation with de-emphasis",
  102757. "Low latency IIR with de-emphasis",
  102758. - "Fixed process flow",
  102759. "High attenuation with de-emphasis",
  102760. "Ringing-less low latency FIR",
  102761. };
  102762. @@ -201,31 +182,31 @@
  102763. 7,
  102764. };
  102765. -static SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  102766. - PCM512x_DSP_PROGRAM, 0, 0x1f,
  102767. - pcm512x_dsp_program_texts,
  102768. - pcm512x_dsp_program_values);
  102769. +static const SOC_VALUE_ENUM_SINGLE_DECL(pcm512x_dsp_program,
  102770. + PCM512x_DSP_PROGRAM, 0, 0x1f,
  102771. + pcm512x_dsp_program_texts,
  102772. + pcm512x_dsp_program_values);
  102773. -static const char * const pcm512x_clk_missing_text[] = {
  102774. +static const char *pcm512x_clk_missing_text[] = {
  102775. "1s", "2s", "3s", "4s", "5s", "6s", "7s", "8s"
  102776. };
  102777. static const struct soc_enum pcm512x_clk_missing =
  102778. - SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 8, pcm512x_clk_missing_text);
  102779. + SOC_ENUM_SINGLE(PCM512x_CLKDET, 0, 7, pcm512x_clk_missing_text);
  102780. -static const char * const pcm512x_autom_text[] = {
  102781. +static const char *pcm512x_autom_text[] = {
  102782. "21ms", "106ms", "213ms", "533ms", "1.07s", "2.13s", "5.33s", "10.66s"
  102783. };
  102784. static const struct soc_enum pcm512x_autom_l =
  102785. - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 8,
  102786. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATML_SHIFT, 7,
  102787. pcm512x_autom_text);
  102788. static const struct soc_enum pcm512x_autom_r =
  102789. - SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 8,
  102790. + SOC_ENUM_SINGLE(PCM512x_AUTO_MUTE, PCM512x_ATMR_SHIFT, 7,
  102791. pcm512x_autom_text);
  102792. -static const char * const pcm512x_ramp_rate_text[] = {
  102793. +static const char *pcm512x_ramp_rate_text[] = {
  102794. "1 sample/update", "2 samples/update", "4 samples/update",
  102795. "Immediate"
  102796. };
  102797. @@ -242,7 +223,7 @@
  102798. SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDF_SHIFT, 4,
  102799. pcm512x_ramp_rate_text);
  102800. -static const char * const pcm512x_ramp_step_text[] = {
  102801. +static const char *pcm512x_ramp_step_text[] = {
  102802. "4dB/step", "2dB/step", "1dB/step", "0.5dB/step"
  102803. };
  102804. @@ -258,13 +239,10 @@
  102805. SOC_ENUM_SINGLE(PCM512x_DIGITAL_MUTE_2, PCM512x_VEDS_SHIFT, 4,
  102806. pcm512x_ramp_step_text);
  102807. +/* Don't let the DAC go into clipping by limiting the alsa volume control range */
  102808. static const struct snd_kcontrol_new pcm512x_controls[] = {
  102809. -SOC_DOUBLE_R_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  102810. - PCM512x_DIGITAL_VOLUME_3, 0, 255, 1, digital_tlv),
  102811. -SOC_DOUBLE_TLV("Playback Volume", PCM512x_ANALOG_GAIN_CTRL,
  102812. - PCM512x_LAGN_SHIFT, PCM512x_RAGN_SHIFT, 1, 1, analog_tlv),
  102813. -SOC_DOUBLE_TLV("Playback Boost Volume", PCM512x_ANALOG_GAIN_BOOST,
  102814. - PCM512x_AGBL_SHIFT, PCM512x_AGBR_SHIFT, 1, 0, boost_tlv),
  102815. +SOC_DOUBLE_R_RANGE_TLV("Playback Digital Volume", PCM512x_DIGITAL_VOLUME_2,
  102816. + PCM512x_DIGITAL_VOLUME_3, 0, 40, 255, 1, digital_tlv),
  102817. SOC_DOUBLE("Playback Digital Switch", PCM512x_MUTE, PCM512x_RQML_SHIFT,
  102818. PCM512x_RQMR_SHIFT, 1, 1),
  102819. @@ -365,32 +343,27 @@
  102820. .num_dapm_routes = ARRAY_SIZE(pcm512x_dapm_routes),
  102821. };
  102822. -static const struct regmap_range_cfg pcm512x_range = {
  102823. - .name = "Pages", .range_min = PCM512x_VIRT_BASE,
  102824. - .range_max = PCM512x_MAX_REGISTER,
  102825. - .selector_reg = PCM512x_PAGE,
  102826. - .selector_mask = 0xff,
  102827. - .window_start = 0, .window_len = 0x100,
  102828. -};
  102829. -
  102830. -const struct regmap_config pcm512x_regmap = {
  102831. +static const struct regmap_config pcm512x_regmap = {
  102832. .reg_bits = 8,
  102833. .val_bits = 8,
  102834. .readable_reg = pcm512x_readable,
  102835. .volatile_reg = pcm512x_volatile,
  102836. - .ranges = &pcm512x_range,
  102837. - .num_ranges = 1,
  102838. -
  102839. .max_register = PCM512x_MAX_REGISTER,
  102840. .reg_defaults = pcm512x_reg_defaults,
  102841. .num_reg_defaults = ARRAY_SIZE(pcm512x_reg_defaults),
  102842. .cache_type = REGCACHE_RBTREE,
  102843. };
  102844. -EXPORT_SYMBOL_GPL(pcm512x_regmap);
  102845. -int pcm512x_probe(struct device *dev, struct regmap *regmap)
  102846. +static const struct of_device_id pcm512x_of_match[] = {
  102847. + { .compatible = "ti,pcm5121", },
  102848. + { .compatible = "ti,pcm5122", },
  102849. + { }
  102850. +};
  102851. +MODULE_DEVICE_TABLE(of, pcm512x_of_match);
  102852. +
  102853. +static int pcm512x_probe(struct device *dev, struct regmap *regmap)
  102854. {
  102855. struct pcm512x_priv *pcm512x;
  102856. int i, ret;
  102857. @@ -490,6 +463,8 @@
  102858. goto err_pm;
  102859. }
  102860. + dev_info(dev, "Completed initialisation - pcm512x_probe");
  102861. +
  102862. return 0;
  102863. err_pm:
  102864. @@ -502,9 +477,8 @@
  102865. pcm512x->supplies);
  102866. return ret;
  102867. }
  102868. -EXPORT_SYMBOL_GPL(pcm512x_probe);
  102869. -void pcm512x_remove(struct device *dev)
  102870. +static void pcm512x_remove(struct device *dev)
  102871. {
  102872. struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  102873. @@ -515,8 +489,8 @@
  102874. regulator_bulk_disable(ARRAY_SIZE(pcm512x->supplies),
  102875. pcm512x->supplies);
  102876. }
  102877. -EXPORT_SYMBOL_GPL(pcm512x_remove);
  102878. +/* TODO
  102879. static int pcm512x_suspend(struct device *dev)
  102880. {
  102881. struct pcm512x_priv *pcm512x = dev_get_drvdata(dev);
  102882. @@ -579,10 +553,125 @@
  102883. return 0;
  102884. }
  102885. -const struct dev_pm_ops pcm512x_pm_ops = {
  102886. +// END OF PCM512x_suspend and resume calls TODO
  102887. +*/
  102888. +
  102889. +static const struct dev_pm_ops pcm512x_pm_ops = {
  102890. SET_RUNTIME_PM_OPS(pcm512x_suspend, pcm512x_resume, NULL)
  102891. };
  102892. -EXPORT_SYMBOL_GPL(pcm512x_pm_ops);
  102893. +
  102894. +#if IS_ENABLED(CONFIG_I2C)
  102895. +static int pcm512x_i2c_probe(struct i2c_client *i2c,
  102896. + const struct i2c_device_id *id)
  102897. +{
  102898. + struct regmap *regmap;
  102899. +
  102900. + regmap = devm_regmap_init_i2c(i2c, &pcm512x_regmap);
  102901. + if (IS_ERR(regmap))
  102902. + return PTR_ERR(regmap);
  102903. +
  102904. + return pcm512x_probe(&i2c->dev, regmap);
  102905. +}
  102906. +
  102907. +static int pcm512x_i2c_remove(struct i2c_client *i2c)
  102908. +{
  102909. + pcm512x_remove(&i2c->dev);
  102910. + return 0;
  102911. +}
  102912. +
  102913. +static const struct i2c_device_id pcm512x_i2c_id[] = {
  102914. + { "pcm5121", },
  102915. + { "pcm5122", },
  102916. + { }
  102917. +};
  102918. +MODULE_DEVICE_TABLE(i2c, pcm512x_i2c_id);
  102919. +
  102920. +static struct i2c_driver pcm512x_i2c_driver = {
  102921. + .probe = pcm512x_i2c_probe,
  102922. + .remove = pcm512x_i2c_remove,
  102923. + .id_table = pcm512x_i2c_id,
  102924. + .driver = {
  102925. + .name = "pcm512x",
  102926. + .owner = THIS_MODULE,
  102927. + .of_match_table = pcm512x_of_match,
  102928. + .pm = &pcm512x_pm_ops,
  102929. + },
  102930. +};
  102931. +#endif
  102932. +
  102933. +#if defined(CONFIG_SPI_MASTER)
  102934. +static int pcm512x_spi_probe(struct spi_device *spi)
  102935. +{
  102936. + struct regmap *regmap;
  102937. + int ret;
  102938. +
  102939. + regmap = devm_regmap_init_spi(spi, &pcm512x_regmap);
  102940. + if (IS_ERR(regmap)) {
  102941. + ret = PTR_ERR(regmap);
  102942. + return ret;
  102943. + }
  102944. +
  102945. + return pcm512x_probe(&spi->dev, regmap);
  102946. +}
  102947. +
  102948. +static int pcm512x_spi_remove(struct spi_device *spi)
  102949. +{
  102950. + pcm512x_remove(&spi->dev);
  102951. + return 0;
  102952. +}
  102953. +
  102954. +static const struct spi_device_id pcm512x_spi_id[] = {
  102955. + { "pcm5121", },
  102956. + { "pcm5122", },
  102957. + { },
  102958. +};
  102959. +MODULE_DEVICE_TABLE(spi, pcm512x_spi_id);
  102960. +
  102961. +static struct spi_driver pcm512x_spi_driver = {
  102962. + .probe = pcm512x_spi_probe,
  102963. + .remove = pcm512x_spi_remove,
  102964. + .id_table = pcm512x_spi_id,
  102965. + .driver = {
  102966. + .name = "pcm512x",
  102967. + .owner = THIS_MODULE,
  102968. + .of_match_table = pcm512x_of_match,
  102969. + .pm = &pcm512x_pm_ops,
  102970. + },
  102971. +};
  102972. +#endif
  102973. +
  102974. +static int __init pcm512x_modinit(void)
  102975. +{
  102976. + int ret = 0;
  102977. +
  102978. +#if IS_ENABLED(CONFIG_I2C)
  102979. + ret = i2c_add_driver(&pcm512x_i2c_driver);
  102980. + if (ret) {
  102981. + printk(KERN_ERR "Failed to register pcm512x I2C driver: %d\n",
  102982. + ret);
  102983. + }
  102984. +#endif
  102985. +#if defined(CONFIG_SPI_MASTER)
  102986. + ret = spi_register_driver(&pcm512x_spi_driver);
  102987. + if (ret != 0) {
  102988. + printk(KERN_ERR "Failed to register pcm512x SPI driver: %d\n",
  102989. + ret);
  102990. + }
  102991. +#endif
  102992. + return ret;
  102993. +}
  102994. +module_init(pcm512x_modinit);
  102995. +
  102996. +static void __exit pcm512x_exit(void)
  102997. +{
  102998. +#if IS_ENABLED(CONFIG_I2C)
  102999. + i2c_del_driver(&pcm512x_i2c_driver);
  103000. +#endif
  103001. +#if defined(CONFIG_SPI_MASTER)
  103002. + spi_unregister_driver(&pcm512x_spi_driver);
  103003. +#endif
  103004. +}
  103005. +module_exit(pcm512x_exit);
  103006. MODULE_DESCRIPTION("ASoC PCM512x codec driver");
  103007. MODULE_AUTHOR("Mark Brown <broonie@linaro.org>");
  103008. diff -Nur linux-3.15/sound/soc/codecs/pcm512x.h linux-rpi/sound/soc/codecs/pcm512x.h
  103009. --- linux-3.15/sound/soc/codecs/pcm512x.h 2014-06-08 20:19:54.000000000 +0200
  103010. +++ linux-rpi/sound/soc/codecs/pcm512x.h 2014-06-11 21:03:58.000000000 +0200
  103011. @@ -17,81 +17,66 @@
  103012. #ifndef _SND_SOC_PCM512X
  103013. #define _SND_SOC_PCM512X
  103014. -#include <linux/pm.h>
  103015. -#include <linux/regmap.h>
  103016. -
  103017. -#define PCM512x_VIRT_BASE 0x100
  103018. -#define PCM512x_PAGE_LEN 0x100
  103019. -#define PCM512x_PAGE_BASE(n) (PCM512x_VIRT_BASE + (PCM512x_PAGE_LEN * n))
  103020. +#define PCM512x_PAGE_0_BASE 0
  103021. #define PCM512x_PAGE 0
  103022. -#define PCM512x_RESET (PCM512x_PAGE_BASE(0) + 1)
  103023. -#define PCM512x_POWER (PCM512x_PAGE_BASE(0) + 2)
  103024. -#define PCM512x_MUTE (PCM512x_PAGE_BASE(0) + 3)
  103025. -#define PCM512x_PLL_EN (PCM512x_PAGE_BASE(0) + 4)
  103026. -#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_BASE(0) + 6)
  103027. -#define PCM512x_DSP (PCM512x_PAGE_BASE(0) + 7)
  103028. -#define PCM512x_GPIO_EN (PCM512x_PAGE_BASE(0) + 8)
  103029. -#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_BASE(0) + 9)
  103030. -#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_BASE(0) + 10)
  103031. -#define PCM512x_MASTER_MODE (PCM512x_PAGE_BASE(0) + 12)
  103032. -#define PCM512x_PLL_REF (PCM512x_PAGE_BASE(0) + 13)
  103033. -#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_BASE(0) + 20)
  103034. -#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_BASE(0) + 21)
  103035. -#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_BASE(0) + 22)
  103036. -#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_BASE(0) + 23)
  103037. -#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_BASE(0) + 24)
  103038. -#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_BASE(0) + 27)
  103039. -#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_BASE(0) + 28)
  103040. -#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_BASE(0) + 29)
  103041. -#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_BASE(0) + 30)
  103042. -#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_BASE(0) + 32)
  103043. -#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_BASE(0) + 33)
  103044. -#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_BASE(0) + 34)
  103045. -#define PCM512x_IDAC_1 (PCM512x_PAGE_BASE(0) + 35)
  103046. -#define PCM512x_IDAC_2 (PCM512x_PAGE_BASE(0) + 36)
  103047. -#define PCM512x_ERROR_DETECT (PCM512x_PAGE_BASE(0) + 37)
  103048. -#define PCM512x_I2S_1 (PCM512x_PAGE_BASE(0) + 40)
  103049. -#define PCM512x_I2S_2 (PCM512x_PAGE_BASE(0) + 41)
  103050. -#define PCM512x_DAC_ROUTING (PCM512x_PAGE_BASE(0) + 42)
  103051. -#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_BASE(0) + 43)
  103052. -#define PCM512x_CLKDET (PCM512x_PAGE_BASE(0) + 44)
  103053. -#define PCM512x_AUTO_MUTE (PCM512x_PAGE_BASE(0) + 59)
  103054. -#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_BASE(0) + 60)
  103055. -#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_BASE(0) + 61)
  103056. -#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_BASE(0) + 62)
  103057. -#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_BASE(0) + 63)
  103058. -#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_BASE(0) + 64)
  103059. -#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_BASE(0) + 65)
  103060. -#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_BASE(0) + 80)
  103061. -#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_BASE(0) + 81)
  103062. -#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_BASE(0) + 82)
  103063. -#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_BASE(0) + 83)
  103064. -#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_BASE(0) + 84)
  103065. -#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_BASE(0) + 85)
  103066. -#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_BASE(0) + 86)
  103067. -#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_BASE(0) + 87)
  103068. -#define PCM512x_OVERFLOW (PCM512x_PAGE_BASE(0) + 90)
  103069. -#define PCM512x_RATE_DET_1 (PCM512x_PAGE_BASE(0) + 91)
  103070. -#define PCM512x_RATE_DET_2 (PCM512x_PAGE_BASE(0) + 92)
  103071. -#define PCM512x_RATE_DET_3 (PCM512x_PAGE_BASE(0) + 93)
  103072. -#define PCM512x_RATE_DET_4 (PCM512x_PAGE_BASE(0) + 94)
  103073. -#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_BASE(0) + 108)
  103074. -#define PCM512x_GPIN (PCM512x_PAGE_BASE(0) + 119)
  103075. -#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_BASE(0) + 120)
  103076. -
  103077. -#define PCM512x_OUTPUT_AMPLITUDE (PCM512x_PAGE_BASE(1) + 1)
  103078. -#define PCM512x_ANALOG_GAIN_CTRL (PCM512x_PAGE_BASE(1) + 2)
  103079. -#define PCM512x_UNDERVOLTAGE_PROT (PCM512x_PAGE_BASE(1) + 5)
  103080. -#define PCM512x_ANALOG_MUTE_CTRL (PCM512x_PAGE_BASE(1) + 6)
  103081. -#define PCM512x_ANALOG_GAIN_BOOST (PCM512x_PAGE_BASE(1) + 7)
  103082. -#define PCM512x_VCOM_CTRL_1 (PCM512x_PAGE_BASE(1) + 8)
  103083. -#define PCM512x_VCOM_CTRL_2 (PCM512x_PAGE_BASE(1) + 9)
  103084. -
  103085. -#define PCM512x_CRAM_CTRL (PCM512x_PAGE_BASE(44) + 1)
  103086. +#define PCM512x_RESET (PCM512x_PAGE_0_BASE + 1)
  103087. +#define PCM512x_POWER (PCM512x_PAGE_0_BASE + 2)
  103088. +#define PCM512x_MUTE (PCM512x_PAGE_0_BASE + 3)
  103089. +#define PCM512x_PLL_EN (PCM512x_PAGE_0_BASE + 4)
  103090. +#define PCM512x_SPI_MISO_FUNCTION (PCM512x_PAGE_0_BASE + 6)
  103091. +#define PCM512x_DSP (PCM512x_PAGE_0_BASE + 7)
  103092. +#define PCM512x_GPIO_EN (PCM512x_PAGE_0_BASE + 8)
  103093. +#define PCM512x_BCLK_LRCLK_CFG (PCM512x_PAGE_0_BASE + 9)
  103094. +#define PCM512x_DSP_GPIO_INPUT (PCM512x_PAGE_0_BASE + 10)
  103095. +#define PCM512x_MASTER_MODE (PCM512x_PAGE_0_BASE + 12)
  103096. +#define PCM512x_PLL_REF (PCM512x_PAGE_0_BASE + 13)
  103097. +#define PCM512x_PLL_COEFF_0 (PCM512x_PAGE_0_BASE + 20)
  103098. +#define PCM512x_PLL_COEFF_1 (PCM512x_PAGE_0_BASE + 21)
  103099. +#define PCM512x_PLL_COEFF_2 (PCM512x_PAGE_0_BASE + 22)
  103100. +#define PCM512x_PLL_COEFF_3 (PCM512x_PAGE_0_BASE + 23)
  103101. +#define PCM512x_PLL_COEFF_4 (PCM512x_PAGE_0_BASE + 24)
  103102. +#define PCM512x_DSP_CLKDIV (PCM512x_PAGE_0_BASE + 27)
  103103. +#define PCM512x_DAC_CLKDIV (PCM512x_PAGE_0_BASE + 28)
  103104. +#define PCM512x_NCP_CLKDIV (PCM512x_PAGE_0_BASE + 29)
  103105. +#define PCM512x_OSR_CLKDIV (PCM512x_PAGE_0_BASE + 30)
  103106. +#define PCM512x_MASTER_CLKDIV_1 (PCM512x_PAGE_0_BASE + 32)
  103107. +#define PCM512x_MASTER_CLKDIV_2 (PCM512x_PAGE_0_BASE + 33)
  103108. +#define PCM512x_FS_SPEED_MODE (PCM512x_PAGE_0_BASE + 34)
  103109. +#define PCM512x_IDAC_1 (PCM512x_PAGE_0_BASE + 35)
  103110. +#define PCM512x_IDAC_2 (PCM512x_PAGE_0_BASE + 36)
  103111. +#define PCM512x_ERROR_DETECT (PCM512x_PAGE_0_BASE + 37)
  103112. +#define PCM512x_I2S_1 (PCM512x_PAGE_0_BASE + 40)
  103113. +#define PCM512x_I2S_2 (PCM512x_PAGE_0_BASE + 41)
  103114. +#define PCM512x_DAC_ROUTING (PCM512x_PAGE_0_BASE + 42)
  103115. +#define PCM512x_DSP_PROGRAM (PCM512x_PAGE_0_BASE + 43)
  103116. +#define PCM512x_CLKDET (PCM512x_PAGE_0_BASE + 44)
  103117. +#define PCM512x_AUTO_MUTE (PCM512x_PAGE_0_BASE + 59)
  103118. +#define PCM512x_DIGITAL_VOLUME_1 (PCM512x_PAGE_0_BASE + 60)
  103119. +#define PCM512x_DIGITAL_VOLUME_2 (PCM512x_PAGE_0_BASE + 61)
  103120. +#define PCM512x_DIGITAL_VOLUME_3 (PCM512x_PAGE_0_BASE + 62)
  103121. +#define PCM512x_DIGITAL_MUTE_1 (PCM512x_PAGE_0_BASE + 63)
  103122. +#define PCM512x_DIGITAL_MUTE_2 (PCM512x_PAGE_0_BASE + 64)
  103123. +#define PCM512x_DIGITAL_MUTE_3 (PCM512x_PAGE_0_BASE + 65)
  103124. +#define PCM512x_GPIO_OUTPUT_1 (PCM512x_PAGE_0_BASE + 80)
  103125. +#define PCM512x_GPIO_OUTPUT_2 (PCM512x_PAGE_0_BASE + 81)
  103126. +#define PCM512x_GPIO_OUTPUT_3 (PCM512x_PAGE_0_BASE + 82)
  103127. +#define PCM512x_GPIO_OUTPUT_4 (PCM512x_PAGE_0_BASE + 83)
  103128. +#define PCM512x_GPIO_OUTPUT_5 (PCM512x_PAGE_0_BASE + 84)
  103129. +#define PCM512x_GPIO_OUTPUT_6 (PCM512x_PAGE_0_BASE + 85)
  103130. +#define PCM512x_GPIO_CONTROL_1 (PCM512x_PAGE_0_BASE + 86)
  103131. +#define PCM512x_GPIO_CONTROL_2 (PCM512x_PAGE_0_BASE + 87)
  103132. +#define PCM512x_OVERFLOW (PCM512x_PAGE_0_BASE + 90)
  103133. +#define PCM512x_RATE_DET_1 (PCM512x_PAGE_0_BASE + 91)
  103134. +#define PCM512x_RATE_DET_2 (PCM512x_PAGE_0_BASE + 92)
  103135. +#define PCM512x_RATE_DET_3 (PCM512x_PAGE_0_BASE + 93)
  103136. +#define PCM512x_RATE_DET_4 (PCM512x_PAGE_0_BASE + 94)
  103137. +#define PCM512x_ANALOG_MUTE_DET (PCM512x_PAGE_0_BASE + 108)
  103138. +#define PCM512x_GPIN (PCM512x_PAGE_0_BASE + 119)
  103139. +#define PCM512x_DIGITAL_MUTE_DET (PCM512x_PAGE_0_BASE + 120)
  103140. -#define PCM512x_MAX_REGISTER (PCM512x_PAGE_BASE(44) + 1)
  103141. +#define PCM512x_MAX_REGISTER (PCM512x_PAGE_0_BASE + 120)
  103142. /* Page 0, Register 1 - reset */
  103143. #define PCM512x_RSTR (1 << 0)
  103144. @@ -154,18 +139,4 @@
  103145. #define PCM512x_AMLE_SHIFT 1
  103146. #define PCM512x_AMLR_SHIFT 0
  103147. -/* Page 1, Register 2 - analog volume control */
  103148. -#define PCM512x_RAGN_SHIFT 0
  103149. -#define PCM512x_LAGN_SHIFT 4
  103150. -
  103151. -/* Page 1, Register 7 - analog boost control */
  103152. -#define PCM512x_AGBR_SHIFT 0
  103153. -#define PCM512x_AGBL_SHIFT 4
  103154. -
  103155. -extern const struct dev_pm_ops pcm512x_pm_ops;
  103156. -extern const struct regmap_config pcm512x_regmap;
  103157. -
  103158. -int pcm512x_probe(struct device *dev, struct regmap *regmap);
  103159. -void pcm512x_remove(struct device *dev);
  103160. -
  103161. #endif
  103162. diff -Nur linux-3.15/sound/soc/codecs/wm8804.c linux-rpi/sound/soc/codecs/wm8804.c
  103163. --- linux-3.15/sound/soc/codecs/wm8804.c 2014-06-08 20:19:54.000000000 +0200
  103164. +++ linux-rpi/sound/soc/codecs/wm8804.c 2014-06-11 21:05:44.000000000 +0200
  103165. @@ -63,6 +63,7 @@
  103166. struct regmap *regmap;
  103167. struct regulator_bulk_data supplies[WM8804_NUM_SUPPLIES];
  103168. struct notifier_block disable_nb[WM8804_NUM_SUPPLIES];
  103169. + int mclk_div;
  103170. };
  103171. static int txsrc_get(struct snd_kcontrol *kcontrol,
  103172. @@ -277,6 +278,7 @@
  103173. blen = 0x1;
  103174. break;
  103175. case SNDRV_PCM_FORMAT_S24_LE:
  103176. + case SNDRV_PCM_FORMAT_S32_LE:
  103177. blen = 0x2;
  103178. break;
  103179. default:
  103180. @@ -318,7 +320,7 @@
  103181. #define FIXED_PLL_SIZE ((1ULL << 22) * 10)
  103182. static int pll_factors(struct pll_div *pll_div, unsigned int target,
  103183. - unsigned int source)
  103184. + unsigned int source, unsigned int mclk_div)
  103185. {
  103186. u64 Kpart;
  103187. unsigned long int K, Ndiv, Nmod, tmp;
  103188. @@ -330,7 +332,8 @@
  103189. */
  103190. for (i = 0; i < ARRAY_SIZE(post_table); i++) {
  103191. tmp = target * post_table[i].div;
  103192. - if (tmp >= 90000000 && tmp <= 100000000) {
  103193. + if ((tmp >= 90000000 && tmp <= 100000000) &&
  103194. + (mclk_div == post_table[i].mclkdiv)) {
  103195. pll_div->freqmode = post_table[i].freqmode;
  103196. pll_div->mclkdiv = post_table[i].mclkdiv;
  103197. target *= post_table[i].div;
  103198. @@ -387,8 +390,11 @@
  103199. } else {
  103200. int ret;
  103201. struct pll_div pll_div;
  103202. + struct wm8804_priv *wm8804;
  103203. - ret = pll_factors(&pll_div, freq_out, freq_in);
  103204. + wm8804 = snd_soc_codec_get_drvdata(codec);
  103205. +
  103206. + ret = pll_factors(&pll_div, freq_out, freq_in, wm8804->mclk_div);
  103207. if (ret)
  103208. return ret;
  103209. @@ -452,6 +458,7 @@
  103210. int div_id, int div)
  103211. {
  103212. struct snd_soc_codec *codec;
  103213. + struct wm8804_priv *wm8804;
  103214. codec = dai->codec;
  103215. switch (div_id) {
  103216. @@ -459,6 +466,10 @@
  103217. snd_soc_update_bits(codec, WM8804_PLL5, 0x30,
  103218. (div & 0x3) << 4);
  103219. break;
  103220. + case WM8804_MCLK_DIV:
  103221. + wm8804 = snd_soc_codec_get_drvdata(codec);
  103222. + wm8804->mclk_div = div;
  103223. + break;
  103224. default:
  103225. dev_err(dai->dev, "Unknown clock divider: %d\n", div_id);
  103226. return -EINVAL;
  103227. @@ -633,7 +644,7 @@
  103228. };
  103229. #define WM8804_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  103230. - SNDRV_PCM_FMTBIT_S24_LE)
  103231. + SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
  103232. #define WM8804_RATES (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
  103233. SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
  103234. @@ -666,7 +677,7 @@
  103235. .suspend = wm8804_suspend,
  103236. .resume = wm8804_resume,
  103237. .set_bias_level = wm8804_set_bias_level,
  103238. - .idle_bias_off = true,
  103239. + .idle_bias_off = false,
  103240. .controls = wm8804_snd_controls,
  103241. .num_controls = ARRAY_SIZE(wm8804_snd_controls),
  103242. diff -Nur linux-3.15/sound/soc/codecs/wm8804.h linux-rpi/sound/soc/codecs/wm8804.h
  103243. --- linux-3.15/sound/soc/codecs/wm8804.h 2014-06-08 20:19:54.000000000 +0200
  103244. +++ linux-rpi/sound/soc/codecs/wm8804.h 2014-06-11 21:03:58.000000000 +0200
  103245. @@ -57,5 +57,9 @@
  103246. #define WM8804_CLKOUT_SRC_OSCCLK 4
  103247. #define WM8804_CLKOUT_DIV 1
  103248. +#define WM8804_MCLK_DIV 2
  103249. +
  103250. +#define WM8804_MCLKDIV_256FS 0
  103251. +#define WM8804_MCLKDIV_128FS 1
  103252. #endif /* _WM8804_H */
  103253. diff -Nur linux-3.15/sound/soc/soc-core.c linux-rpi/sound/soc/soc-core.c
  103254. --- linux-3.15/sound/soc/soc-core.c 2014-06-08 20:19:54.000000000 +0200
  103255. +++ linux-rpi/sound/soc/soc-core.c 2014-06-11 21:05:45.000000000 +0200
  103256. @@ -3024,8 +3024,8 @@
  103257. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  103258. uinfo->count = snd_soc_volsw_is_stereo(mc) ? 2 : 1;
  103259. - uinfo->value.integer.min = 0;
  103260. - uinfo->value.integer.max = platform_max - min;
  103261. + uinfo->value.integer.min = min;
  103262. + uinfo->value.integer.max = platform_max;
  103263. return 0;
  103264. }
  103265. @@ -3056,9 +3056,10 @@
  103266. unsigned int val, val_mask;
  103267. int ret;
  103268. - val = ((ucontrol->value.integer.value[0] + min) & mask);
  103269. if (invert)
  103270. - val = max - val;
  103271. + val = ((max - ucontrol->value.integer.value[0] + min) & mask);
  103272. + else
  103273. + val = (ucontrol->value.integer.value[0] & mask);
  103274. val_mask = mask << shift;
  103275. val = val << shift;
  103276. @@ -3067,9 +3068,10 @@
  103277. return ret;
  103278. if (snd_soc_volsw_is_stereo(mc)) {
  103279. - val = ((ucontrol->value.integer.value[1] + min) & mask);
  103280. if (invert)
  103281. - val = max - val;
  103282. + val = ((max - ucontrol->value.integer.value[1] + min) & mask);
  103283. + else
  103284. + val = (ucontrol->value.integer.value[1] & mask);
  103285. val_mask = mask << shift;
  103286. val = val << shift;
  103287. @@ -3107,18 +3109,14 @@
  103288. (snd_soc_read(codec, reg) >> shift) & mask;
  103289. if (invert)
  103290. ucontrol->value.integer.value[0] =
  103291. - max - ucontrol->value.integer.value[0];
  103292. - ucontrol->value.integer.value[0] =
  103293. - ucontrol->value.integer.value[0] - min;
  103294. + max - ucontrol->value.integer.value[0] + min;
  103295. if (snd_soc_volsw_is_stereo(mc)) {
  103296. ucontrol->value.integer.value[1] =
  103297. (snd_soc_read(codec, rreg) >> shift) & mask;
  103298. if (invert)
  103299. ucontrol->value.integer.value[1] =
  103300. - max - ucontrol->value.integer.value[1];
  103301. - ucontrol->value.integer.value[1] =
  103302. - ucontrol->value.integer.value[1] - min;
  103303. + max - ucontrol->value.integer.value[1] + min;
  103304. }
  103305. return 0;